From ecd362615eff697a1911027ae524d60d8bbe5226 Mon Sep 17 00:00:00 2001
From: Maciek
Date: Mon, 10 Apr 2023 13:59:02 +0200
Subject: [PATCH] chore(deposits): impove UX on deposit dialog (#3401)
---
.../trading-e2e/src/integration/deposit.cy.ts | 5 +-
.../deposits/src/lib/approve-notification.tsx | 29 +++--
libs/deposits/src/lib/deposit-form.spec.tsx | 53 ++++++--
libs/deposits/src/lib/deposit-form.tsx | 115 ++++++++++--------
libs/deposits/src/lib/deposit-limits.tsx | 62 +++++++---
libs/deposits/src/setup-tests.ts | 3 +
6 files changed, 179 insertions(+), 88 deletions(-)
diff --git a/apps/trading-e2e/src/integration/deposit.cy.ts b/apps/trading-e2e/src/integration/deposit.cy.ts
index dad973e56..0f0fae630 100644
--- a/apps/trading-e2e/src/integration/deposit.cy.ts
+++ b/apps/trading-e2e/src/integration/deposit.cy.ts
@@ -87,7 +87,10 @@ describe('deposit form validation', { tags: '@smoke' }, () => {
.clear()
.type('850')
.next(`[data-testid="${formFieldError}"]`)
- .should('have.text', 'Insufficient amount in Ethereum wallet');
+ .should(
+ 'have.text',
+ "You can't deposit more than you have in your Ethereum wallet, 800 tEURO"
+ );
});
});
diff --git a/libs/deposits/src/lib/approve-notification.tsx b/libs/deposits/src/lib/approve-notification.tsx
index 9b2d6a62f..9f3a006ce 100644
--- a/libs/deposits/src/lib/approve-notification.tsx
+++ b/libs/deposits/src/lib/approve-notification.tsx
@@ -51,11 +51,12 @@ export const ApproveNotification = ({
intent={intent}
testId="approve-default"
message={t(
- `Before you can make a deposit of your chosen asset, ${selectedAsset?.symbol}, you need to approve its use in your Ethereum wallet`
+ 'Before you can make a deposit of your chosen asset, %s, you need to approve its use in your Ethereum wallet',
+ selectedAsset?.symbol
)}
buttonProps={{
size: 'sm',
- text: `Approve ${selectedAsset?.symbol}`,
+ text: t('Approve %s', selectedAsset?.symbol),
action: onApprove,
dataTestId: 'approve-submit',
}}
@@ -68,13 +69,12 @@ export const ApproveNotification = ({
intent={intent}
testId="reapprove-default"
message={t(
- `Approve again to deposit more than ${formatNumber(
- balances.allowance.toString()
- )}`
+ 'Approve again to deposit more than %s',
+ formatNumber(balances.allowance.toString())
)}
buttonProps={{
size: 'sm',
- text: `Approve ${selectedAsset?.symbol}`,
+ text: t('Approve %s', selectedAsset?.symbol),
action: onApprove,
dataTestId: 'reapprove-submit',
}}
@@ -157,7 +157,8 @@ const ApprovalTxFeedback = ({
intent={Intent.Warning}
testId="approve-requested"
message={t(
- `Go to your Ethereum wallet and approve the transaction to enable the use of ${selectedAsset?.symbol}`
+ 'Go to your Ethereum wallet and approve the transaction to enable the use of %s',
+ selectedAsset?.symbol
)}
/>
@@ -174,7 +175,8 @@ const ApprovalTxFeedback = ({
<>
{t(
- `Your ${selectedAsset?.symbol} approval is being confirmed by the Ethereum network. When this is complete, you can continue your deposit`
+ 'Your %s approval is being confirmed by the Ethereum network. When this is complete, you can continue your deposit',
+ selectedAsset?.symbol
)}{' '}
- {t(
- `You can now make deposits in ${
- selectedAsset?.symbol
- }, up to a maximum of ${formatNumber(
- allowance?.toString() || 0
- )}`
- )}
+ {t('You approved deposits of up to %s %s.', [
+ selectedAsset?.symbol,
+ formatNumber(allowance?.toString() || 0),
+ ])}
{txLink &&
{txLink}
}
>
diff --git a/libs/deposits/src/lib/deposit-form.spec.tsx b/libs/deposits/src/lib/deposit-form.spec.tsx
index 3ce7565b4..8a3e3fde4 100644
--- a/libs/deposits/src/lib/deposit-form.spec.tsx
+++ b/libs/deposits/src/lib/deposit-form.spec.tsx
@@ -1,4 +1,11 @@
-import { waitFor, fireEvent, render, screen } from '@testing-library/react';
+import {
+ waitFor,
+ fireEvent,
+ render,
+ screen,
+ act,
+} from '@testing-library/react';
+import userEvent from '@testing-library/user-event';
import BigNumber from 'bignumber.js';
import type { DepositFormProps } from './deposit-form';
import { DepositForm } from './deposit-form';
@@ -141,12 +148,14 @@ describe('Deposit form', () => {
fireEvent.submit(screen.getByTestId('deposit-form'));
expect(
- await screen.findByText('Insufficient amount in Ethereum wallet')
+ await screen.findByText(
+ "You can't deposit more than you have in your Ethereum wallet, 5"
+ )
).toBeInTheDocument();
});
it('fails when submitted amount is more than the maximum limit', async () => {
- render();
+ render();
const amountMoreThanLimit = '21';
fireEvent.change(screen.getByLabelText('Amount'), {
@@ -155,7 +164,9 @@ describe('Deposit form', () => {
fireEvent.submit(screen.getByTestId('deposit-form'));
expect(
- await screen.findByText('Amount is above lifetime deposit limit')
+ await screen.findByText(
+ "You can't deposit more than your remaining deposit allowance, 10 asset-symbol"
+ )
).toBeInTheDocument();
});
@@ -179,7 +190,9 @@ describe('Deposit form', () => {
fireEvent.submit(screen.getByTestId('deposit-form'));
expect(
- await screen.findByText('Amount is above approved amount')
+ await screen.findByText(
+ "You can't deposit more than your approved deposit amount, 30"
+ )
).toBeInTheDocument();
});
@@ -283,8 +296,6 @@ describe('Deposit form', () => {
expect(screen.getByTestId('BALANCE_AVAILABLE_value')).toHaveTextContent(
'50'
);
- expect(screen.getByTestId('MAX_LIMIT_value')).toHaveTextContent('20');
- expect(screen.getByTestId('DEPOSITED_value')).toHaveTextContent('10');
expect(screen.getByTestId('REMAINING_value')).toHaveTextContent('10');
fireEvent.change(screen.getByLabelText('Amount'), {
@@ -365,4 +376,32 @@ describe('Deposit form', () => {
/this app only works on/i
);
});
+
+ it('Remaining deposit allowance tooltip should be rendered', async () => {
+ render();
+ await act(async () => {
+ await userEvent.hover(screen.getByText('Remaining deposit allowance'));
+ });
+ await waitFor(async () => {
+ await expect(
+ screen.getByRole('tooltip', {
+ name: /VEGA has a lifetime deposit limit of 20 asset-symbol per address/,
+ })
+ ).toBeInTheDocument();
+ });
+ });
+
+ it('Ethereum deposit cap tooltip should be rendered', async () => {
+ render();
+ await act(async () => {
+ await userEvent.hover(screen.getByText('Ethereum deposit cap'));
+ });
+ await waitFor(async () => {
+ await expect(
+ screen.getByRole('tooltip', {
+ name: /The deposit cap is set when you approve an asset for use with this app/,
+ })
+ ).toBeInTheDocument();
+ });
+ });
});
diff --git a/libs/deposits/src/lib/deposit-form.tsx b/libs/deposits/src/lib/deposit-form.tsx
index e403a0bf5..23721f885 100644
--- a/libs/deposits/src/lib/deposit-form.tsx
+++ b/libs/deposits/src/lib/deposit-form.tsx
@@ -8,6 +8,7 @@ import {
maxSafe,
addDecimal,
isAssetTypeERC20,
+ formatNumber,
} from '@vegaprotocol/utils';
import { t } from '@vegaprotocol/i18n';
import { useLocalStorage } from '@vegaprotocol/react-helpers';
@@ -133,11 +134,8 @@ export const DepositForm = ({
return _pubKeys ? _pubKeys.map((pk) => pk.publicKey) : [];
}, [_pubKeys]);
- const approved = balances
- ? balances.allowance.isGreaterThan(0)
- ? true
- : false
- : false;
+ const approved =
+ balances && balances.allowance.isGreaterThan(0) ? true : false;
return (