e47298761a
* feat: make use max only use account balance, add custom max messages * fix: withdraw threshold limit display * feat: add callstatic to ethereum transaction hook * feat: improve types for useTransaction hook * chore: fix types and remove ts-ignore * chore: convert all smart contract wrapper methods to match metaclass methods * fix: this context for calling tx * chore: fix comment and any type * chore: typo Co-authored-by: Edd <edd@vega.xyz> Co-authored-by: Edd <edd@vega.xyz>
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.stake_balance(ethAddress, vegaKey),
|
|
vesting.stake_balance(ethAddress, vegaKey),
|
|
]);
|
|
|
|
appDispatch({
|
|
type: AppStateActionType.REFRESH_ASSOCIATED_BALANCES,
|
|
walletAssociatedBalance: toBigNum(walletAssociatedBalance, decimals),
|
|
vestingAssociatedBalance: toBigNum(vestingAssociatedBalance, decimals),
|
|
});
|
|
},
|
|
[staking, vesting, appDispatch, decimals]
|
|
);
|
|
}
|