2024-03-01 14:25:56 +00:00
|
|
|
import { useVegaWallet } from '@vegaprotocol/wallet-react';
|
2023-11-28 15:08:21 +00:00
|
|
|
import { useStakeAvailableQuery } from './__generated__/StakeAvailable';
|
2023-09-21 13:25:19 +00:00
|
|
|
|
2023-11-28 15:08:21 +00:00
|
|
|
/**
|
|
|
|
* Gets the current stake available for given public key and required stake for
|
|
|
|
* the referral program.
|
|
|
|
*
|
|
|
|
* (Uses currently connected public key if left empty)
|
|
|
|
*/
|
|
|
|
export const useStakeAvailable = (pubKey?: string) => {
|
|
|
|
const { pubKey: currentPubKey } = useVegaWallet();
|
|
|
|
const partyId = pubKey || currentPubKey;
|
|
|
|
const { data } = useStakeAvailableQuery({
|
|
|
|
variables: { partyId: partyId || '' },
|
|
|
|
skip: !partyId,
|
2023-09-21 13:25:19 +00:00
|
|
|
errorPolicy: 'ignore',
|
|
|
|
});
|
|
|
|
|
2023-11-28 15:08:21 +00:00
|
|
|
const stakeAvailable = data
|
|
|
|
? BigInt(data.party?.stakingSummary.currentStakeAvailable || '0')
|
|
|
|
: undefined;
|
|
|
|
const requiredStake = data
|
|
|
|
? BigInt(data.networkParameter?.value || '0')
|
|
|
|
: undefined;
|
|
|
|
|
2023-09-21 13:25:19 +00:00
|
|
|
return {
|
2023-11-28 15:08:21 +00:00
|
|
|
stakeAvailable,
|
|
|
|
requiredStake,
|
|
|
|
isEligible:
|
|
|
|
stakeAvailable != null &&
|
|
|
|
requiredStake != null &&
|
|
|
|
stakeAvailable >= requiredStake,
|
2023-09-21 13:25:19 +00:00
|
|
|
};
|
|
|
|
};
|