diff --git a/apps/trading/components/rewards-container/active-rewards.tsx b/apps/trading/components/rewards-container/active-rewards.tsx index 941f49df6..232efa97f 100644 --- a/apps/trading/components/rewards-container/active-rewards.tsx +++ b/apps/trading/components/rewards-container/active-rewards.tsx @@ -316,49 +316,30 @@ export const ActiveRewardCard = ({ MarketState.STATE_CLOSED, ].includes(m.state) ); + if (marketSettled) { return null; } - const assetInSettledMarket = + const assetInActiveMarket = allMarkets && Object.values(allMarkets).some((m: MarketFieldsFragment | null) => { if (m && getAsset(m).id === dispatchStrategy.dispatchMetricAssetId) { - return ( - m?.state && - [ - MarketState.STATE_TRADING_TERMINATED, - MarketState.STATE_SETTLED, - MarketState.STATE_CANCELLED, - MarketState.STATE_CLOSED, - ].includes(m.state) - ); + return m?.state && MarketState.STATE_ACTIVE === m.state; } return false; }); - // Gray out the cards that are related to suspended markets - const suspended = transferNode.markets?.some( + const marketSuspended = transferNode.markets?.some( (m) => m?.state === MarketState.STATE_SUSPENDED || m?.state === MarketState.STATE_SUSPENDED_VIA_GOVERNANCE ); - const assetInSuspendedMarket = - allMarkets && - Object.values(allMarkets).some((m: MarketFieldsFragment | null) => { - if (m && getAsset(m).id === dispatchStrategy.dispatchMetricAssetId) { - return ( - m?.state === MarketState.STATE_SUSPENDED || - m?.state === MarketState.STATE_SUSPENDED_VIA_GOVERNANCE - ); - } - return false; - }); - // Gray out the cards that are related to suspended markets + // Or settlement assets in markets that are not active and eligible for rewards const { gradientClassName, mainClassName } = - suspended || assetInSuspendedMarket || assetInSettledMarket + marketSuspended || !assetInActiveMarket ? { gradientClassName: 'from-vega-cdark-500 to-vega-clight-400', mainClassName: 'from-vega-cdark-400 dark:from-vega-cdark-600 to-20%', @@ -449,12 +430,12 @@ export const ActiveRewardCard = ({ {DispatchMetricLabels[dispatchStrategy.dispatchMetric]} •{' '} { }); it.each([ - { - targetText: 'Include transfer fee', - tooltipText: - 'The fee will be taken from the amount you are transferring.', - }, { targetText: 'Transfer fee', tooltipText: /transfer\.fee\.factor/, @@ -276,9 +271,6 @@ describe('TransferForm', () => { const amountInput = screen.getByLabelText('Amount'); - const checkbox = screen.getByTestId('include-transfer-fee'); - expect(checkbox).not.toBeChecked(); - await userEvent.clear(amountInput); await userEvent.type(amountInput, '50'); @@ -288,10 +280,7 @@ describe('TransferForm', () => { await userEvent.click(screen.getByRole('button', { name: 'Use max' })); expect(amountInput).toHaveValue('100.00'); - // If transfering from a vested account 'include fees' checkbox should - // be disabled and fees should be 0 - expect(checkbox).not.toBeChecked(); - expect(checkbox).toBeDisabled(); + // If transfering from a vested account fees should be 0 const expectedFee = '0'; const total = new BigNumber(amount).plus(expectedFee).toFixed(); @@ -396,78 +385,7 @@ describe('TransferForm', () => { }); }); }); - describe('IncludeFeesCheckbox', () => { - it('validates fields and submits when checkbox is checked', async () => { - const mockSubmit = jest.fn(); - renderComponent({ ...props, submitTransfer: mockSubmit }); - - // check current pubkey not shown - const keySelect = screen.getByLabelText('To Vega key'); - const pubKeyOptions = ['', pubKey, props.pubKeys[1]]; - expect(keySelect.children).toHaveLength(pubKeyOptions.length); - expect(Array.from(keySelect.options).map((o) => o.value)).toEqual( - pubKeyOptions - ); - - await submit(); - expect(await screen.findAllByText('Required')).toHaveLength(2); // pubkey set as default value - - // Select a pubkey - await userEvent.selectOptions( - screen.getByLabelText('To Vega key'), - props.pubKeys[1] - ); - - // Select asset - await selectAsset(asset); - - await userEvent.selectOptions( - screen.getByLabelText('From account'), - `${AccountType.ACCOUNT_TYPE_GENERAL}-${asset.id}` - ); - - const amountInput = screen.getByLabelText('Amount'); - const checkbox = screen.getByTestId('include-transfer-fee'); - - // 1003-TRAN-022 - expect(checkbox).not.toBeChecked(); - - await userEvent.clear(amountInput); - await userEvent.type(amountInput, amount); - await userEvent.click(checkbox); - - expect(checkbox).toBeChecked(); - const expectedFee = new BigNumber(amount) - .times(props.feeFactor) - .toFixed(); - const expectedAmount = new BigNumber(amount).minus(expectedFee).toFixed(); - - // 1003-TRAN-020 - expect(screen.getByTestId('transfer-fee')).toHaveTextContent(expectedFee); - expect(screen.getByTestId('transfer-amount')).toHaveTextContent( - expectedAmount - ); - expect(screen.getByTestId('total-transfer-fee')).toHaveTextContent( - amount - ); - - await submit(); - - await waitFor(() => { - // 1003-TRAN-023 - expect(mockSubmit).toHaveBeenCalledTimes(1); - expect(mockSubmit).toHaveBeenCalledWith({ - fromAccountType: AccountType.ACCOUNT_TYPE_GENERAL, - toAccountType: AccountType.ACCOUNT_TYPE_GENERAL, - to: props.pubKeys[1], - asset: asset.id, - amount: removeDecimal(expectedAmount, asset.decimals), - oneOff: {}, - }); - }); - }); - it('validates fields when checkbox is not checked', async () => { renderComponent(props); @@ -497,11 +415,8 @@ describe('TransferForm', () => { ); const amountInput = screen.getByLabelText('Amount'); - const checkbox = screen.getByTestId('include-transfer-fee'); - expect(checkbox).not.toBeChecked(); await userEvent.type(amountInput, amount); - expect(checkbox).not.toBeChecked(); const expectedFee = new BigNumber(amount) .times(props.feeFactor) .toFixed(); diff --git a/libs/accounts/src/lib/transfer-form.tsx b/libs/accounts/src/lib/transfer-form.tsx index dc1adf77a..d69f8dfde 100644 --- a/libs/accounts/src/lib/transfer-form.tsx +++ b/libs/accounts/src/lib/transfer-form.tsx @@ -15,7 +15,6 @@ import { TradingRichSelect, TradingSelect, Tooltip, - TradingCheckbox, TradingButton, } from '@vegaprotocol/ui-toolkit'; import type { Transfer } from '@vegaprotocol/wallet'; @@ -135,32 +134,17 @@ export const TransferForm = ({ const accountBalance = account && addDecimal(account.balance, account.asset.decimals); - const [includeFee, setIncludeFee] = useState(false); - // Max amount given selected asset and from account const max = accountBalance ? new BigNumber(accountBalance) : new BigNumber(0); - const transferAmount = useMemo(() => { - if (!amount) return undefined; - if (includeFee && feeFactor) { - return new BigNumber(1).minus(feeFactor).times(amount).toString(); - } - return amount; - }, [amount, includeFee, feeFactor]); - - const fee = useMemo(() => { - if (!transferAmount) return undefined; - if (includeFee) { - return new BigNumber(amount).minus(transferAmount).toString(); - } - return ( - feeFactor && new BigNumber(feeFactor).times(transferAmount).toString() - ); - }, [amount, includeFee, transferAmount, feeFactor]); + const fee = useMemo( + () => feeFactor && new BigNumber(feeFactor).times(amount).toString(), + [amount, feeFactor] + ); const onSubmit = useCallback( (fields: FormFields) => { - if (!transferAmount) { + if (!amount) { throw new Error('Submitted transfer with no amount selected'); } @@ -173,7 +157,7 @@ export const TransferForm = ({ const transfer = normalizeTransfer( fields.toVegaKey, - transferAmount, + amount, type, AccountType.ACCOUNT_TYPE_GENERAL, // field is readonly in the form { @@ -183,7 +167,7 @@ export const TransferForm = ({ ); submitTransfer(transfer); }, - [submitTransfer, transferAmount, assets] + [submitTransfer, amount, assets] ); // reset for placeholder workaround https://github.com/radix-ui/primitives/issues/1569 @@ -279,7 +263,6 @@ export const TransferForm = ({ ) { setValue('toVegaKey', pubKey); setToVegaKeyMode('select'); - setIncludeFee(false); } }} > @@ -449,27 +432,9 @@ export const TransferForm = ({ )} -
- -
- setIncludeFee((x) => !x)} - /> -
-
-
- {transferAmount && fee && ( + {amount && fee && ( { const t = useT(); - if (!feeFactor || !amount || !transferAmount || !fee) return null; - if ( - isNaN(Number(feeFactor)) || - isNaN(Number(amount)) || - isNaN(Number(transferAmount)) || - isNaN(Number(fee)) - ) { + if (!feeFactor || !amount || !fee) return null; + if (isNaN(Number(feeFactor)) || isNaN(Number(amount)) || isNaN(Number(fee))) { return null; } - const totalValue = new BigNumber(transferAmount).plus(fee).toString(); + const totalValue = new BigNumber(amount).plus(fee).toString(); return (
diff --git a/libs/i18n/src/locales/en/accounts.json b/libs/i18n/src/locales/en/accounts.json index e581189c3..cface53cb 100644 --- a/libs/i18n/src/locales/en/accounts.json +++ b/libs/i18n/src/locales/en/accounts.json @@ -21,7 +21,6 @@ "Deposited on the network, but not allocated to a market. Free to use for placing orders or providing liquidity.": "Deposited on the network, but not allocated to a market. Free to use for placing orders or providing liquidity.", "Enter manually": "Enter manually", "From account": "From account", - "Include transfer fee": "Include transfer fee", "initial level": "initial level", "maintenance level": "maintenance level", "Margin health": "Margin health", @@ -33,7 +32,6 @@ "release level": "release level", "search level": "search level", "Select from wallet": "Select from wallet", - "The fee will be taken from the amount you are transferring.": "The fee will be taken from the amount you are transferring.", "The total amount of each asset on this key. Includes used and available collateral.": "The total amount of each asset on this key. Includes used and available collateral.", "The total amount taken from your account. The amount to be transferred plus the fee.": "The total amount taken from your account. The amount to be transferred plus the fee.", "The total amount to be transferred (without the fee)": "The total amount to be transferred (without the fee)", diff --git a/specs/1003-TRAN-transfer.md b/specs/1003-TRAN-transfer.md index 4e8b1eee5..b6d08f33f 100644 --- a/specs/1003-TRAN-transfer.md +++ b/specs/1003-TRAN-transfer.md @@ -40,22 +40,12 @@ ## Transfer -- **Must** can select include transfer fee (1003-TRAN-015) - -- **Must** display tooltip for "Include transfer fee" when hovered over.(1003-TRAN-016) - - **Must** display tooltip for "Transfer fee when hovered over.(1003-TRAN-017) - **Must** display tooltip for "Amount to be transferred" when hovered over.(1003-TRAN-018) - **Must** display tooltip for "Total amount (with fee)" when hovered over.(1003-TRAN-019) -- **Must** amount to be transferred and transfer fee update correctly when include transfer fee is selected (1003-TRAN-020) - -- **Must** total amount with fee is correct with and without "Include transfer fee" selected (1003-TRAN-021) - -- **Must** i cannot select include transfer fee unless amount is entered (1003-TRAN-022) - - **Must** With all fields entered correctly, clicking "confirm transfer" button will start transaction(1003-TRAN-023) ### Transfer page