feat(deposits): mark remaining deposit allowance as exempt (#3902)
This commit is contained in:
parent
19580fb9ce
commit
7a89dc984d
@ -58,6 +58,7 @@ beforeEach(() => {
|
||||
max: new BigNumber(20),
|
||||
allowance: new BigNumber(30),
|
||||
deposited: new BigNumber(10),
|
||||
exempt: false,
|
||||
};
|
||||
props = {
|
||||
assets: [asset],
|
||||
@ -287,6 +288,7 @@ describe('Deposit form', () => {
|
||||
balance,
|
||||
max,
|
||||
deposited,
|
||||
exempt: false,
|
||||
}}
|
||||
selectedAsset={asset}
|
||||
/>
|
||||
|
@ -18,6 +18,7 @@ interface DepositLimitsProps {
|
||||
asset: Asset;
|
||||
balance?: BigNumber;
|
||||
allowance?: BigNumber;
|
||||
exempt?: boolean;
|
||||
}
|
||||
|
||||
export const DepositLimits = ({
|
||||
@ -26,6 +27,7 @@ export const DepositLimits = ({
|
||||
asset,
|
||||
balance,
|
||||
allowance,
|
||||
exempt,
|
||||
}: DepositLimitsProps) => {
|
||||
const limits = [
|
||||
{
|
||||
@ -68,11 +70,13 @@ export const DepositLimits = ({
|
||||
</Tooltip>
|
||||
),
|
||||
rawValue: max.minus(deposited),
|
||||
value: (
|
||||
value: !exempt ? (
|
||||
<CompactNumber
|
||||
number={max.minus(deposited)}
|
||||
decimals={asset.decimals}
|
||||
/>
|
||||
) : (
|
||||
<div data-testid="exempt">{t('Exempt')}</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
|
@ -3,17 +3,22 @@ import { useCallback, useEffect, useState } from 'react';
|
||||
import BigNumber from 'bignumber.js';
|
||||
import { useGetAllowance } from './use-get-allowance';
|
||||
import { useGetBalanceOfERC20Token } from './use-get-balance-of-erc20-token';
|
||||
import { useGetDepositMaximum } from './use-get-deposit-maximum';
|
||||
import {
|
||||
useGetDepositMaximum,
|
||||
useIsExemptDepositor,
|
||||
} from './use-get-deposit-maximum';
|
||||
import { useGetDepositedAmount } from './use-get-deposited-amount';
|
||||
import { isAssetTypeERC20, localLoggerFactory } from '@vegaprotocol/utils';
|
||||
import { useAccountBalance } from '@vegaprotocol/accounts';
|
||||
import type { Asset } from '@vegaprotocol/assets';
|
||||
import { useWeb3React } from '@web3-react/core';
|
||||
|
||||
export interface DepositBalances {
|
||||
balance: BigNumber; // amount in Ethereum wallet
|
||||
allowance: BigNumber; // amount approved
|
||||
deposited: BigNumber; // total amounted deposited over lifetime
|
||||
max: BigNumber; // life time deposit cap
|
||||
exempt: boolean; // if exempt then deposit cap doesn't matter
|
||||
}
|
||||
|
||||
const initialState: DepositBalances = {
|
||||
@ -21,6 +26,7 @@ const initialState: DepositBalances = {
|
||||
allowance: new BigNumber(0),
|
||||
deposited: new BigNumber(0),
|
||||
max: new BigNumber(0),
|
||||
exempt: false,
|
||||
};
|
||||
|
||||
/**
|
||||
@ -28,6 +34,7 @@ const initialState: DepositBalances = {
|
||||
* whenever the asset changes in the form
|
||||
*/
|
||||
export const useDepositBalances = (asset: Asset | undefined) => {
|
||||
const { account } = useWeb3React();
|
||||
const tokenContract = useTokenContract(
|
||||
isAssetTypeERC20(asset) ? asset.source.contractAddress : undefined
|
||||
);
|
||||
@ -35,6 +42,7 @@ export const useDepositBalances = (asset: Asset | undefined) => {
|
||||
const getAllowance = useGetAllowance(tokenContract, asset);
|
||||
const getBalance = useGetBalanceOfERC20Token(tokenContract, asset);
|
||||
const getDepositMaximum = useGetDepositMaximum(bridgeContract, asset);
|
||||
const isExemptDepositor = useIsExemptDepositor(bridgeContract, account);
|
||||
const getDepositedAmount = useGetDepositedAmount(asset);
|
||||
const [state, setState] = useState<DepositBalances | null>(null);
|
||||
|
||||
@ -46,11 +54,12 @@ export const useDepositBalances = (asset: Asset | undefined) => {
|
||||
try {
|
||||
logger.info('get deposit balances', { asset: asset.id });
|
||||
setState(null);
|
||||
const [max, deposited, balance, allowance] = await Promise.all([
|
||||
const [max, deposited, balance, allowance, exempt] = await Promise.all([
|
||||
getDepositMaximum(),
|
||||
getDepositedAmount(),
|
||||
getBalance(),
|
||||
getAllowance(),
|
||||
isExemptDepositor(),
|
||||
]);
|
||||
|
||||
setState({
|
||||
@ -58,12 +67,20 @@ export const useDepositBalances = (asset: Asset | undefined) => {
|
||||
deposited: deposited ?? initialState.deposited,
|
||||
balance: balance ?? initialState.balance,
|
||||
allowance: allowance ?? initialState.allowance,
|
||||
exempt,
|
||||
});
|
||||
} catch (err) {
|
||||
logger.error('get deposit balances', err);
|
||||
setState(null);
|
||||
}
|
||||
}, [asset, getAllowance, getBalance, getDepositMaximum, getDepositedAmount]);
|
||||
}, [
|
||||
asset,
|
||||
getAllowance,
|
||||
getBalance,
|
||||
getDepositMaximum,
|
||||
getDepositedAmount,
|
||||
isExemptDepositor,
|
||||
]);
|
||||
|
||||
const reset = useCallback(() => {
|
||||
setState(null);
|
||||
|
@ -28,3 +28,25 @@ export const useGetDepositMaximum = (
|
||||
|
||||
return getDepositMaximum;
|
||||
};
|
||||
|
||||
export const useIsExemptDepositor = (
|
||||
contract: CollateralBridge | null,
|
||||
address: string | undefined
|
||||
) => {
|
||||
const isExemptDepositor = useCallback(async () => {
|
||||
if (!contract || !address) {
|
||||
return false;
|
||||
}
|
||||
const logger = localLoggerFactory({ application: 'deposits' });
|
||||
try {
|
||||
logger.info('is exempted depositor', { address });
|
||||
const res = await contract.is_exempt_depositor(address);
|
||||
return res;
|
||||
} catch (err) {
|
||||
logger.error('is exempted depositor', err);
|
||||
return false;
|
||||
}
|
||||
}, [contract, address]);
|
||||
|
||||
return isExemptDepositor;
|
||||
};
|
||||
|
@ -35,6 +35,9 @@ export class CollateralBridge {
|
||||
get_deposit_maximum(assetSource: string): Promise<BigNumber> {
|
||||
return this.contract.get_asset_deposit_lifetime_limit(assetSource);
|
||||
}
|
||||
is_exempt_depositor(address: string): Promise<boolean> {
|
||||
return this.contract.is_exempt_depositor(address);
|
||||
}
|
||||
get_multisig_control_address() {
|
||||
return this.contract.get_multisig_control_address();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user