Skip to content

Commit

Permalink
Instantly refresh wallet balance
Browse files Browse the repository at this point in the history
  • Loading branch information
lindlof committed Dec 8, 2020
1 parent 7fa4a7c commit bfb73de
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
7 changes: 6 additions & 1 deletion web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ export const App: React.FC = () => {
</Grid>
<Grid item xs={12} sm={4}>
<Grid container justify="flex-end">
<Wallet client={client} setClient={setClient} faucetUrl={config.faucetUrl} />
<Wallet
client={client}
setClient={setClient}
faucetUrl={config.faucetUrl}
refreshBalance={game}
/>
</Grid>
</Grid>
</Grid>
Expand Down
7 changes: 3 additions & 4 deletions web/src/wallet/Wallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ interface Props {
client: SecretJS.SigningCosmWasmClient | undefined;
setClient: (client: SecretJS.SigningCosmWasmClient | undefined) => void;
faucetUrl: string | undefined;
refreshBalance: Object;
}

interface Account {
Expand All @@ -41,7 +42,7 @@ interface Account {

const Wallet = (props: Props) => {
const classes = useStyles();
const { client, setClient, faucetUrl } = props;
const { client, setClient, faucetUrl, refreshBalance } = props;
const [walletType, setWalletType] = useLocalStorage<WalletType | undefined>(
'wallet_type',
undefined,
Expand All @@ -55,8 +56,7 @@ const Wallet = (props: Props) => {
getAccount(client, setAccount);
}, 10000);
return () => clearInterval(interval);
}, [client]);
console.log('account', account);
}, [client, refreshBalance]);

return (
<div className={classes.root}>
Expand Down Expand Up @@ -116,7 +116,6 @@ const Wallet = (props: Props) => {
const getAccount = async (client: SecretJS.SigningCosmWasmClient, setAccount: Function) => {
try {
const account = await client.getAccount(client.senderAddress);
console.log('a', account);
setAccount({ balance: getScrtBalance(account), loading: true });
} catch {
setAccount((a: Account) => ({ ...a, loading: false }));
Expand Down

0 comments on commit bfb73de

Please sign in to comment.