* test: allow connecting to a local ganache node by signing transactions in brower * chore: update environment variables * fix: disassocaition * chore: remove redundant code * chore: rewrite promise as async/await * fix: approval amount too low * chore: address PR comments * test: fix tets * revert changes to env file * chore: changes as per pr comments
34 lines
1.0 KiB
TypeScript
34 lines
1.0 KiB
TypeScript
import { toBigNum } from '@vegaprotocol/react-helpers';
|
|
import React from 'react';
|
|
|
|
import {
|
|
AppStateActionType,
|
|
useAppState,
|
|
} from '../contexts/app-state/app-state-context';
|
|
import { useContracts } from '../contexts/contracts/contracts-context';
|
|
|
|
export function useRefreshAssociatedBalances() {
|
|
const {
|
|
appDispatch,
|
|
appState: { decimals },
|
|
} = useAppState();
|
|
const { staking, vesting } = useContracts();
|
|
|
|
return React.useCallback(
|
|
async (ethAddress: string, vegaKey: string) => {
|
|
const [walletAssociatedBalance, vestingAssociatedBalance] =
|
|
await Promise.all([
|
|
staking.stakeBalance(ethAddress, vegaKey),
|
|
vesting.stakeBalance(ethAddress, vegaKey),
|
|
]);
|
|
|
|
appDispatch({
|
|
type: AppStateActionType.REFRESH_ASSOCIATED_BALANCES,
|
|
walletAssociatedBalance: toBigNum(walletAssociatedBalance, decimals),
|
|
vestingAssociatedBalance: toBigNum(vestingAssociatedBalance, decimals),
|
|
});
|
|
},
|
|
[staking, vesting, appDispatch, decimals]
|
|
);
|
|
}
|