mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
handle balance refetching
* refresh balance when account popup is opened * refresh balance periodically when advanced price widget is visible
This commit is contained in:
parent
991a646dd7
commit
7c0a1f9c39
@ -21,7 +21,7 @@ export default function Advanced({
|
||||
onChange: (event: ChangeEvent<HTMLInputElement>) => void
|
||||
}): ReactElement {
|
||||
const { appConfig } = useSiteMetadata()
|
||||
const { account, balance, chainId } = useOcean()
|
||||
const { account, balance, chainId, refreshBalance } = useOcean()
|
||||
|
||||
const [error, setError] = useState<string>()
|
||||
const correctNetwork = isCorrectNetwork(chainId)
|
||||
@ -42,6 +42,17 @@ export default function Advanced({
|
||||
}
|
||||
}, [ocean])
|
||||
|
||||
// refetch balance periodically
|
||||
useEffect(() => {
|
||||
if (!account) return
|
||||
|
||||
const balanceInterval = setInterval(() => refreshBalance(), 10000) // 10 sec.
|
||||
|
||||
return () => {
|
||||
clearInterval(balanceInterval)
|
||||
}
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<div className={stylesIndex.content}>
|
||||
<div className={styles.advanced}>
|
||||
|
@ -14,10 +14,13 @@ const animation = {
|
||||
}
|
||||
|
||||
export default function Wallet(): ReactElement {
|
||||
const { accountId } = useOcean()
|
||||
const { accountId, refreshBalance } = useOcean()
|
||||
const [props, setSpring] = useSpring(() => animation.from)
|
||||
|
||||
// always refetch balance when popover is opened
|
||||
function onMount() {
|
||||
accountId && refreshBalance()
|
||||
|
||||
setSpring({
|
||||
transform: 'scale(1) translateY(0)',
|
||||
onRest: (): void => null,
|
||||
|
Loading…
Reference in New Issue
Block a user