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

metaport#214 Fix token balances update #218

Merged
merged 1 commit into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/components/ChainApps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default function ChainApps(props: {
skaleNetwork: SkaleNetwork
chainName: string
handle?: (schainName: string, app?: string) => void
size?: 'sm' | 'md',
size?: 'sm' | 'md'
prim?: boolean
}) {
const apps = getChainAppsMeta(props.chainName, props.skaleNetwork)
Expand Down
15 changes: 6 additions & 9 deletions src/components/TokenList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,15 @@ export default function TokenList() {
const { address } = useAccount()

useEffect(() => {
updateTokenBalances(address)
const intervalId = setInterval(() => {
const fetchBalances = () => {
updateTokenBalances(address)
}, BALANCE_UPDATE_INTERVAL_MS)
}
fetchBalances()
const intervalId = setInterval(fetchBalances, BALANCE_UPDATE_INTERVAL_MS)
return () => {
clearInterval(intervalId) // Clear interval on component unmount
clearInterval(intervalId)
}
}, [updateTokenBalances])

useEffect(() => {
updateTokenBalances(address)
}, [updateTokenBalances, tokenContracts, address])
}, [address, updateTokenBalances, tokenContracts])

useEffect(() => {
const defaultToken = getDefaultToken(tokens)
Expand Down
82 changes: 42 additions & 40 deletions src/components/TokenListSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,47 +31,49 @@ export default function TokenListSection(props: {
>
{props.type}
</p>
{Object.keys(props.tokens).sort().map((key, _) => (
<Button
key={key}
color="secondary"
size="small"
className={cmn.fullWidth}
onClick={() => handle(props.tokens[key])}
>
<div className={cls(cmn.flex, cmn.flexcv, cmn.fullWidth, cmn.mtop10, cmn.mbott10)}>
<div className={cls(cmn.flex, cmn.flexc, cmn.mleft10)}>
<TokenIcon
tokenSymbol={props.tokens[key]?.meta.symbol}
iconUrl={props.tokens[key]?.meta.iconUrl}
/>
{Object.keys(props.tokens)
.sort()
.map((key, _) => (
<Button
key={key}
color="secondary"
size="small"
className={cmn.fullWidth}
onClick={() => handle(props.tokens[key])}
>
<div className={cls(cmn.flex, cmn.flexcv, cmn.fullWidth, cmn.mtop10, cmn.mbott10)}>
<div className={cls(cmn.flex, cmn.flexc, cmn.mleft10)}>
<TokenIcon
tokenSymbol={props.tokens[key]?.meta.symbol}
iconUrl={props.tokens[key]?.meta.iconUrl}
/>
</div>
<p
className={cls(
cmn.p,
cmn.p3,
cmn.p600,
cmn.pPrim,
cmn.flex,
cmn.flexg,
cmn.mri10,
cmn.mleft10
)}
>
{getTokenName(props.tokens[key])}
</p>
<div className={cmn.mri10}>
<TokenBalance
balance={
props.tokenBalances ? props.tokenBalances[props.tokens[key]?.keyname] : null
}
symbol={props.tokens[key]?.meta.symbol}
decimals={props.tokens[key]?.meta.decimals}
/>
</div>
</div>
<p
className={cls(
cmn.p,
cmn.p3,
cmn.p600,
cmn.pPrim,
cmn.flex,
cmn.flexg,
cmn.mri10,
cmn.mleft10
)}
>
{getTokenName(props.tokens[key])}
</p>
<div className={cmn.mri10}>
<TokenBalance
balance={
props.tokenBalances ? props.tokenBalances[props.tokens[key]?.keyname] : null
}
symbol={props.tokens[key]?.meta.symbol}
decimals={props.tokens[key]?.meta.decimals}
/>
</div>
</div>
</Button>
))}
</Button>
))}
</div>
)
}
3 changes: 1 addition & 2 deletions src/core/interfaces/Tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
* @copyright SKALE Labs 2022-Present
*/

import { AddressType } from "."

import { AddressType } from '.'

export interface EthToken {
chains: ConnectedChainMap
Expand Down
Loading