Skip to content

Commit

Permalink
Finance, Tokens, Voting: update badges (#971)
Browse files Browse the repository at this point in the history
  • Loading branch information
sohkai authored Sep 4, 2019
1 parent d937d4c commit a81b015
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react'
import PropTypes from 'prop-types'
import styled from 'styled-components'
import { useNetwork } from '@aragon/api-react'
import { IdentityBadge, Tag, GU } from '@aragon/ui'
import { IconLabel, IdentityBadge, Tag, GU } from '@aragon/ui'
import { useIdentity } from '../IdentityManager/IdentityManager'

const LocalIdentityBadge = ({ entity, ...props }) => {
Expand All @@ -11,18 +11,33 @@ const LocalIdentityBadge = ({ entity, ...props }) => {
const handleClick = () => showLocalIdentityModal(entity)
return (
<IdentityBadge
customLabel={label || ''}
label={label || ''}
entity={entity}
networkType={network && network.type}
popoverAction={{
label: `${label ? 'Edit' : 'Add'} custom label`,
label: (
<div
css={`
display: flex;
align-content: center;
`}
>
<IconLabel
css={`
margin-right: ${1 * GU}px;
`}
/>
{label ? 'Edit' : 'Add'} custom label
</div>
),
onClick: handleClick,
}}
popoverTitle={
label ? (
<Wrap>
<Label>{label}</Label>
<Tag
mode="identifier"
css={`
margin-left: ${2 * GU}px;
`}
Expand All @@ -47,7 +62,6 @@ const Wrap = styled.div`
display: grid;
align-items: center;
grid-template-columns: auto 1fr;
padding-right: ${3 * GU}px;
`

const Label = styled.span`
Expand Down
4 changes: 3 additions & 1 deletion apps/finance/app/src/components/NewTransfer/Deposit.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,9 @@ class Deposit extends React.Component {
<VSpace size={1} />
<IdentityBadge
entity={proxyAddress}
fontSize="small"
labelStyle={`
${textStyle('body3')}
`}
networkType={network.type}
shorten={false}
/>
Expand Down
8 changes: 6 additions & 2 deletions apps/finance/app/src/components/Transfers.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
useLayout,
useTheme,
} from '@aragon/ui'
import { useNetwork } from '@aragon/api-react'
import { useConnectedAccount, useNetwork } from '@aragon/api-react'
import { saveAs } from 'file-saver'
import * as TransferTypes from '../transfer-types'
import { addressesEqual, toChecksumAddress } from '../lib/web3-utils'
Expand Down Expand Up @@ -115,6 +115,7 @@ const getDownloadFilename = (proxyAddress, { start, end }) => {
}

const Transfers = React.memo(({ proxyAddress, tokens, transactions }) => {
const connectedAccount = useConnectedAccount()
const network = useNetwork()
const theme = useTheme()
const { layoutName } = useLayout()
Expand Down Expand Up @@ -284,7 +285,10 @@ const Transfers = React.memo(({ proxyAddress, tokens, transactions }) => {
: ''}
`}
>
<LocalIdentityBadge entity={entity} address={entity} />
<LocalIdentityBadge
connectedAccount={addressesEqual(entity, connectedAccount)}
entity={entity}
/>
</div>,
<div
css={`
Expand Down
2 changes: 1 addition & 1 deletion apps/finance/app/src/lib/web3-utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { toChecksumAddress } from 'web3-utils'

// Check address equality without checksums
// Check address equality with checksums
export function addressesEqual(first, second) {
first = first && toChecksumAddress(first)
second = second && toChecksumAddress(second)
Expand Down
15 changes: 2 additions & 13 deletions apps/token-manager/app/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class App extends React.PureComponent {
appStateReady: false,
isSyncing: true,
holders: [],
connectedAccount: '',
groupMode: false,
}
state = {
Expand Down Expand Up @@ -95,7 +94,6 @@ class App extends React.PureComponent {
render() {
const {
appStateReady,
connectedAccount,
groupMode,
holders,
isSyncing,
Expand Down Expand Up @@ -167,7 +165,6 @@ class App extends React.PureComponent {
tokenSupply={tokenSupply}
tokenSymbol={tokenSymbol}
tokenTransfersEnabled={tokenTransfersEnabled}
userAccount={connectedAccount}
onAssignTokens={this.handleLaunchAssignTokens}
onRemoveTokens={this.handleLaunchRemoveTokens}
/>
Expand Down Expand Up @@ -202,17 +199,9 @@ class App extends React.PureComponent {
}

export default () => {
const { api, appState, connectedAccount } = useAragonApi()
const { api, appState } = useAragonApi()
const theme = useTheme()
const { layoutName } = useLayout()

return (
<App
api={api}
connectedAccount={connectedAccount}
layoutName={layoutName}
theme={theme}
{...appState}
/>
)
return <App api={api} layoutName={layoutName} theme={theme} {...appState} />
}
28 changes: 16 additions & 12 deletions apps/token-manager/app/src/components/InfoBoxes.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React, { useMemo } from 'react'
import { useNetwork } from '@aragon/api-react'
import { useConnectedAccount, useNetwork } from '@aragon/api-react'
import { Box, Distribution, GU, TokenBadge, useTheme } from '@aragon/ui'
import { formatBalance, stakesPercentages } from '../utils'
import { addressesEqual } from '../web3-utils'
import LocalIdentityBadge from './LocalIdentityBadge/LocalIdentityBadge'
import You from './You'

Expand Down Expand Up @@ -31,11 +32,11 @@ function InfoBoxes({
tokenName,
tokenSupply,
tokenSymbol,
userAccount,
tokenTransfersEnabled,
}) {
const network = useNetwork()
const theme = useTheme()
const connectedAccount = useConnectedAccount()
const network = useNetwork()

const stakes = useMemo(() => displayedStakes(holders, tokenSupply), [
holders,
Expand Down Expand Up @@ -104,15 +105,18 @@ function InfoBoxes({
<Distribution
heading="Token holder stakes"
items={stakes}
renderLegendItem={({ item: account }) => (
<div>
<LocalIdentityBadge
entity={account}
connectedAccount={account === userAccount}
/>
{account === userAccount && <You />}
</div>
)}
renderLegendItem={({ item: account }) => {
const isCurrentUser = addressesEqual(account, connectedAccount)
return (
<div>
<LocalIdentityBadge
entity={account}
connectedAccount={isCurrentUser}
/>
{isCurrentUser && <You />}
</div>
)
}}
/>
</Box>
</React.Fragment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react'
import PropTypes from 'prop-types'
import styled from 'styled-components'
import { useNetwork } from '@aragon/api-react'
import { IdentityBadge, Tag, GU } from '@aragon/ui'
import { IconLabel, IdentityBadge, Tag, GU } from '@aragon/ui'
import { useIdentity } from '../IdentityManager/IdentityManager'

const LocalIdentityBadge = ({ entity, ...props }) => {
Expand All @@ -11,18 +11,33 @@ const LocalIdentityBadge = ({ entity, ...props }) => {
const handleClick = () => showLocalIdentityModal(entity)
return (
<IdentityBadge
customLabel={label || ''}
label={label || ''}
entity={entity}
networkType={network && network.type}
popoverAction={{
label: `${label ? 'Edit' : 'Add'} custom label`,
label: (
<div
css={`
display: flex;
align-content: center;
`}
>
<IconLabel
css={`
margin-right: ${1 * GU}px;
`}
/>
{label ? 'Edit' : 'Add'} custom label
</div>
),
onClick: handleClick,
}}
popoverTitle={
label ? (
<Wrap>
<Label>{label}</Label>
<Tag
mode="identifier"
css={`
margin-left: ${2 * GU}px;
`}
Expand All @@ -47,7 +62,6 @@ const Wrap = styled.div`
display: grid;
align-items: center;
grid-template-columns: auto 1fr;
padding-right: ${3 * GU}px;
`

const Label = styled.span`
Expand Down
10 changes: 4 additions & 6 deletions apps/token-manager/app/src/screens/Holders.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useCallback } from 'react'
import PropTypes from 'prop-types'
import BN from 'bn.js'
import { useConnectedAccount } from '@aragon/api-react'
import {
ContextMenu,
ContextMenuItem,
Expand All @@ -13,6 +14,7 @@ import {
useTheme,
} from '@aragon/ui'
import { formatBalance } from '../utils'
import { addressesEqual } from '../web3-utils'
import InfoBoxes from '../components/InfoBoxes'
import LocalIdentityBadge from '../components/LocalIdentityBadge/LocalIdentityBadge'
import { useIdentity } from '../components/IdentityManager/IdentityManager'
Expand All @@ -30,8 +32,8 @@ function Holders({
tokenSupply,
tokenSymbol,
tokenTransfersEnabled,
userAccount,
}) {
const connectedAccount = useConnectedAccount()
return (
<Split
primary={
Expand All @@ -40,9 +42,7 @@ function Holders({
fields={groupMode ? ['Owner'] : ['Holder', 'Balance']}
entries={holders.map(({ address, balance }) => [address, balance])}
renderEntry={([address, balance]) => {
const isCurrentUser = Boolean(
userAccount && userAccount === address
)
const isCurrentUser = addressesEqual(address, connectedAccount)

const values = [
<div
Expand Down Expand Up @@ -85,7 +85,6 @@ function Holders({
tokenSupply={tokenSupply}
tokenSymbol={tokenSymbol}
tokenTransfersEnabled={tokenTransfersEnabled}
userAccount={userAccount}
/>
}
/>
Expand All @@ -104,7 +103,6 @@ Holders.propTypes = {
tokenSupply: PropTypes.instanceOf(BN),
tokenSymbol: PropTypes.string,
tokenTransfersEnabled: PropTypes.bool,
userAccount: PropTypes.string,
}

Holders.defaultProps = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react'
import PropTypes from 'prop-types'
import styled from 'styled-components'
import { useNetwork } from '@aragon/api-react'
import { IdentityBadge, Tag, GU } from '@aragon/ui'
import { IconLabel, IdentityBadge, Tag, GU } from '@aragon/ui'
import { useIdentity } from '../../identity-manager'

const LocalIdentityBadge = ({ entity, ...props }) => {
Expand All @@ -11,18 +11,33 @@ const LocalIdentityBadge = ({ entity, ...props }) => {
const handleClick = () => showLocalIdentityModal(entity)
return (
<IdentityBadge
customLabel={label || ''}
label={label || ''}
entity={entity}
networkType={network && network.type}
popoverAction={{
label: `${label ? 'Edit' : 'Add'} custom label`,
label: (
<div
css={`
display: flex;
align-content: center;
`}
>
<IconLabel
css={`
margin-right: ${1 * GU}px;
`}
/>
{label ? 'Edit' : 'Add'} custom label
</div>
),
onClick: handleClick,
}}
popoverTitle={
label ? (
<Wrap>
<Label>{label}</Label>
<Tag
mode="identifier"
css={`
margin-left: ${2 * GU}px;
`}
Expand All @@ -47,7 +62,6 @@ const Wrap = styled.div`
display: grid;
align-items: center;
grid-template-columns: auto 1fr;
padding-right: ${3 * GU}px;
`

const Label = styled.span`
Expand Down
12 changes: 10 additions & 2 deletions apps/voting/app/src/screens/VoteDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
useLayout,
useTheme,
} from '@aragon/ui'
import { useAppState, useNetwork } from '@aragon/api-react'
import { useAppState, useConnectedAccount, useNetwork } from '@aragon/api-react'
import { format } from 'date-fns'
import AppBadge from '../components/AppBadge'
import LocalIdentityBadge from '../components/LocalIdentityBadge/LocalIdentityBadge'
Expand All @@ -27,6 +27,7 @@ import VoteCasted from '../components/VoteCasted'
import { percentageList, round, safeDiv } from '../math-utils'
import { getQuorumProgress } from '../vote-utils'
import { VOTE_NAY, VOTE_YEA } from '../vote-types'
import { addressesEqual } from '../web3-utils'

const formatDate = date => `${format(date, 'do MMM yy, HH:mm')} UTC`

Expand All @@ -37,6 +38,7 @@ function VoteDetail({ vote, onBack, onVote, onExecute }) {
const theme = useTheme()
const { layoutName } = useLayout()
const { tokenSymbol } = useAppState()
const connectedAccount = useConnectedAccount()

const { data, numData, voteId, connectedAccountVote } = vote
const { minAcceptQuorum, supportRequired, yea, nay } = numData
Expand Down Expand Up @@ -143,7 +145,13 @@ function VoteDetail({ vote, onBack, onVote, onExecute }) {
align-items: flex-start;
`}
>
<LocalIdentityBadge entity={creator} />
<LocalIdentityBadge
connectedAccount={addressesEqual(
creator,
connectedAccount
)}
entity={creator}
/>
</div>
</div>
</div>
Expand Down

0 comments on commit a81b015

Please sign in to comment.