Skip to content

Commit

Permalink
fix: token holder display percentage holder
Browse files Browse the repository at this point in the history
  • Loading branch information
tiendn committed Oct 31, 2022
1 parent 5dc5a89 commit 61cdc02
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions components/Search/ResultView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface SearchResultViewItem {
time?: string
status?: string
value: string
key: string | number
linkValue?: string
}

Expand Down
7 changes: 6 additions & 1 deletion components/Search/SearchResult.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default function SearchResult({ status, data }: SearchResultProps) {
items.push({
time: item.blockTime,
type: 'Block',
key: item.blockHeight,
value: item.blockHash,
linkValue: `${item.blockHeight}`
})
Expand All @@ -32,6 +33,7 @@ export default function SearchResult({ status, data }: SearchResultProps) {
items.push({
time: item.blockTime,
type: 'Block',
key: item.blockHash,
value: item.blockHash
})
}
Expand All @@ -40,6 +42,7 @@ export default function SearchResult({ status, data }: SearchResultProps) {
for (let item of transactions) {
items.push({
time: item.blockTime,
key: item.hash,
type: 'Transaction',
value: item.hash,
linkValue: item.hash
Expand All @@ -52,6 +55,7 @@ export default function SearchResult({ status, data }: SearchResultProps) {
items.push({
status: item.status,
type: 'Validator',
key: item.operatorAddress,
value: item.operatorAddress,
linkValue: item.operatorAddress
})
Expand All @@ -62,6 +66,7 @@ export default function SearchResult({ status, data }: SearchResultProps) {
items.push({
linkValue: item.addressHash,
type: 'Token',
key: item.addressHash,
value: `${item.name} (${item.symbol})`,
time: item.insertedAt
})
Expand Down Expand Up @@ -94,7 +99,7 @@ export default function SearchResult({ status, data }: SearchResultProps) {
</div>
<div className={styles.resultScroll}>
{items.map(item => (
<ResultView key={item.value} item={item} />
<ResultView key={item.key} item={item} />
))}
</div>
</div>
Expand Down
3 changes: 2 additions & 1 deletion pages/tokens.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { PaginationLite, Row } from '@astraprotocol/astra-ui'
import { PaginationLite } from '@astraprotocol/astra-ui'
import Container from 'components/Container'
import Row from 'components/Grid/Row'
import RowLoader from 'components/Loader/RowLoader'
import { PageTitle } from 'components/Typography/PageTitle'
import usePageQuery from 'hooks/usePageQuery'
Expand Down
4 changes: 3 additions & 1 deletion views/tokens/tabs/TokenHolderTab/TokenHolder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ type Props = {
}

export default function TokenHolder({ index, account, tokenData }: Props) {
let percentage = (parseFloat(account.balance) / parseFloat(tokenData.totalSupply)) * 100
percentage = percentage < 10 ** -3 ? 0 : percentage
return (
<div
className={clsx(
Expand Down Expand Up @@ -44,7 +46,7 @@ export default function TokenHolder({ index, account, tokenData }: Props) {
'padding-left-lg text-center money money-2xs contrast-color-70 block-ver-center col-2'
)}
>
{numeral((parseFloat(account.balance) / parseFloat(tokenData.totalSupply)) * 100).format('0,0.00')}%
{numeral(percentage).format('0,0.00')}%
</div>
</div>
)
Expand Down
10 changes: 9 additions & 1 deletion views/tokens/tabs/TokenHolderTab/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { PaginationLite } from '@astraprotocol/astra-ui'
import Row from 'components/Grid/Row'
import Empty from 'components/Typography/Empty'
import { useState } from 'react'
import { getEnvNumber } from 'utils/helper'
import useTokenHolders from 'views/tokens/hook/useTokenHolders'
import TokenHolder from './TokenHolder'

Expand Down Expand Up @@ -31,7 +32,14 @@ const TokenHolderTab = ({ token, tokenData }: Props) => {
) : (
<div className="padding-bottom-sm" style={{ overflowY: 'scroll' }}>
{tokens?.map((item: Holder, index: number) => {
return <TokenHolder key={item.address} tokenData={tokenData} index={index + 1} account={item} />
return (
<TokenHolder
key={item.address}
tokenData={tokenData}
index={index + (currentPage - 1) * getEnvNumber('NEXT_PUBLIC_PAGE_OFFSET') + 1}
account={item}
/>
)
})}
</div>
)}
Expand Down

0 comments on commit 61cdc02

Please sign in to comment.