1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-09-28 03:58:59 +02: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:
Matthias Kretschmann 2020-08-05 13:45:51 +02:00
parent 991a646dd7
commit 7c0a1f9c39
Signed by: m
GPG Key ID: 606EEEF3C479A91F
2 changed files with 16 additions and 2 deletions

View File

@ -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}>

View File

@ -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,