Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tokens: Move renderEntry hook calls into its own component & fix crash #1171

Merged
merged 1 commit into from
Jun 17, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 32 additions & 22 deletions apps/token-manager/app/src/screens/Holders.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ function Holders({
fields={groupMode ? ['Owner'] : ['Holder', 'Balance']}
entries={mappedEntries}
renderEntry={([address, balance, vestings]) => {
const theme = useTheme()
const { totalLocked } = useTotalVestedTokensInfo(vestings)

const isCurrentUser = addressesEqual(address, connectedAccount)

const values = [
Expand All @@ -89,25 +86,11 @@ function Holders({

if (!groupMode) {
values.push(
<div
css={`
display: flex;
align-items: center;
`}
>
{formatTokenAmount(balance, tokenDecimals)}
{!totalLocked.isZero() && (
<div
css={`
padding-left: ${1 * GU}px;
${textStyle('label1')};
color: ${theme.surfaceContentSecondary};
`}
>
({formatTokenAmount(totalLocked, tokenDecimals)} locked)
</div>
)}
</div>
<TokenAmount
balance={balance}
tokenDecimals={tokenDecimals}
vestings={vestings}
/>
)
}

Expand Down Expand Up @@ -224,4 +207,31 @@ function EntryActions({
)
}

function TokenAmount({ balance, tokenDecimals, vestings }) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the things above directly into this component; left it on the same file as it's related to the DataView only, but if preferred, we can move it.

const theme = useTheme()
const { totalLocked } = useTotalVestedTokensInfo(vestings)

return (
<div
css={`
display: flex;
align-items: center;
`}
>
{formatTokenAmount(balance, tokenDecimals)}
{!totalLocked.isZero() && (
<div
css={`
padding-left: ${1 * GU}px;
${textStyle('label1')};
color: ${theme.surfaceContentSecondary};
`}
>
({formatTokenAmount(totalLocked, tokenDecimals)} locked)
</div>
)}
</div>
)
}

export default Holders