fix(withdraws): minimal withdrawal amount validation (#3993)
This commit is contained in:
parent
6f9f432c90
commit
878bed9c7a
@ -99,6 +99,8 @@ export const NetworkParams = {
|
|||||||
governance_proposal_freeform_minProposerBalance:
|
governance_proposal_freeform_minProposerBalance:
|
||||||
'governance_proposal_freeform_minProposerBalance',
|
'governance_proposal_freeform_minProposerBalance',
|
||||||
validators_delegation_minAmount: 'validators_delegation_minAmount',
|
validators_delegation_minAmount: 'validators_delegation_minAmount',
|
||||||
|
spam_protection_minimumWithdrawalQuantumMultiple:
|
||||||
|
'spam_protection_minimumWithdrawalQuantumMultiple',
|
||||||
spam_protection_voting_min_tokens: 'spam_protection_voting_min_tokens',
|
spam_protection_voting_min_tokens: 'spam_protection_voting_min_tokens',
|
||||||
spam_protection_proposal_min_tokens: 'spam_protection_proposal_min_tokens',
|
spam_protection_proposal_min_tokens: 'spam_protection_proposal_min_tokens',
|
||||||
market_liquidity_stakeToCcyVolume: 'market_liquidity_stakeToCcyVolume',
|
market_liquidity_stakeToCcyVolume: 'market_liquidity_stakeToCcyVolume',
|
||||||
|
@ -3,13 +3,14 @@ import { addDecimal } from '@vegaprotocol/utils';
|
|||||||
import { localLoggerFactory } from '@vegaprotocol/logger';
|
import { localLoggerFactory } from '@vegaprotocol/logger';
|
||||||
import * as Schema from '@vegaprotocol/types';
|
import * as Schema from '@vegaprotocol/types';
|
||||||
import BigNumber from 'bignumber.js';
|
import BigNumber from 'bignumber.js';
|
||||||
import { useCallback, useEffect } from 'react';
|
import { useCallback, useEffect, useMemo } from 'react';
|
||||||
import type { AccountFieldsFragment } from '@vegaprotocol/accounts';
|
import type { AccountFieldsFragment } from '@vegaprotocol/accounts';
|
||||||
import {
|
import {
|
||||||
useGetWithdrawDelay,
|
useGetWithdrawDelay,
|
||||||
useGetWithdrawThreshold,
|
useGetWithdrawThreshold,
|
||||||
} from '@vegaprotocol/web3';
|
} from '@vegaprotocol/web3';
|
||||||
import { useWithdrawStore } from './withdraw-store';
|
import { useWithdrawStore } from './withdraw-store';
|
||||||
|
import { useNetworkParam } from '@vegaprotocol/network-parameters';
|
||||||
|
|
||||||
export const useWithdrawAsset = (
|
export const useWithdrawAsset = (
|
||||||
assets: Asset[],
|
assets: Asset[],
|
||||||
@ -19,6 +20,17 @@ export const useWithdrawAsset = (
|
|||||||
const { asset, balance, min, threshold, delay, update } = useWithdrawStore();
|
const { asset, balance, min, threshold, delay, update } = useWithdrawStore();
|
||||||
const getThreshold = useGetWithdrawThreshold();
|
const getThreshold = useGetWithdrawThreshold();
|
||||||
const getDelay = useGetWithdrawDelay();
|
const getDelay = useGetWithdrawDelay();
|
||||||
|
const { param } = useNetworkParam(
|
||||||
|
'spam_protection_minimumWithdrawalQuantumMultiple'
|
||||||
|
);
|
||||||
|
|
||||||
|
const minimumWithdrawalQuantumMultiple = useMemo(() => {
|
||||||
|
const factor = new BigNumber(param || '');
|
||||||
|
if (factor.isNaN()) {
|
||||||
|
return new BigNumber(1);
|
||||||
|
}
|
||||||
|
return factor;
|
||||||
|
}, [param]);
|
||||||
|
|
||||||
// Every time an asset is selected we need to find the corresponding
|
// Every time an asset is selected we need to find the corresponding
|
||||||
// account, balance, min viable amount and delay threshold
|
// account, balance, min viable amount and delay threshold
|
||||||
@ -37,7 +49,9 @@ export const useWithdrawAsset = (
|
|||||||
const min = asset
|
const min = asset
|
||||||
? BigNumber.max(
|
? BigNumber.max(
|
||||||
new BigNumber(addDecimal('1', asset.decimals)),
|
new BigNumber(addDecimal('1', asset.decimals)),
|
||||||
new BigNumber(addDecimal(asset.quantum, asset.decimals))
|
new BigNumber(addDecimal(asset.quantum, asset.decimals)).times(
|
||||||
|
minimumWithdrawalQuantumMultiple
|
||||||
|
)
|
||||||
)
|
)
|
||||||
: new BigNumber(0);
|
: new BigNumber(0);
|
||||||
// Query collateral bridge for threshold for selected asset
|
// Query collateral bridge for threshold for selected asset
|
||||||
@ -56,7 +70,14 @@ export const useWithdrawAsset = (
|
|||||||
|
|
||||||
update({ asset, balance, min, threshold, delay });
|
update({ asset, balance, min, threshold, delay });
|
||||||
},
|
},
|
||||||
[accounts, assets, update, getThreshold, getDelay]
|
[
|
||||||
|
assets,
|
||||||
|
accounts,
|
||||||
|
minimumWithdrawalQuantumMultiple,
|
||||||
|
update,
|
||||||
|
getThreshold,
|
||||||
|
getDelay,
|
||||||
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -15,6 +15,18 @@ jest.mock('@vegaprotocol/data-provider', () => ({
|
|||||||
}));
|
}));
|
||||||
jest.mock('@web3-react/core');
|
jest.mock('@web3-react/core');
|
||||||
jest.mock('@vegaprotocol/accounts');
|
jest.mock('@vegaprotocol/accounts');
|
||||||
|
jest.mock('@vegaprotocol/network-parameters', () => {
|
||||||
|
const impl = jest.requireActual('@vegaprotocol/network-parameters');
|
||||||
|
return {
|
||||||
|
...impl,
|
||||||
|
useNetworkParam: jest.fn((param) => {
|
||||||
|
if (param === 'spam_protection_minimumWithdrawalQuantumMultiple') {
|
||||||
|
return { param: '10.00', loading: false, error: undefined };
|
||||||
|
}
|
||||||
|
return impl.useNetworkParam(param);
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
describe('WithdrawFormContainer', () => {
|
describe('WithdrawFormContainer', () => {
|
||||||
const props = {
|
const props = {
|
||||||
@ -99,7 +111,7 @@ describe('WithdrawFormContainer', () => {
|
|||||||
accountDecimals: null,
|
accountDecimals: null,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
afterEach(() => {
|
afterAll(() => {
|
||||||
jest.resetAllMocks();
|
jest.resetAllMocks();
|
||||||
});
|
});
|
||||||
it('should be properly rendered', async () => {
|
it('should be properly rendered', async () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user