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