Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aum/wall 228/crypto cashier changes for third party processor coinspaid #8343

Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
7fd955c
feat: Tooltip for crypto transactions processed by third-party payeme…
aum-deriv Apr 13, 2023
adb5c7d
feat: Added popup note for mobile view for third-party payment tooltip
aum-deriv Apr 19, 2023
e4b47a5
feat: added alert banner component in cashier package
aum-deriv Apr 25, 2023
9646075
feat: added IcAlertWarningDark icon
aum-deriv Apr 25, 2023
4b4e7b3
chore: working on test cases 1
aum-deriv Apr 25, 2023
0dec7ed
chore: reseting testcase to upstream/master
aum-deriv Apr 25, 2023
c5db122
chore: added test case for tooltip in desktop mode
aum-deriv Apr 25, 2023
7fad31a
feat: AlertBanner for cryptoc with minimum deposit using third-party …
aum-deriv Apr 25, 2023
7186391
feat: changed styles for crypto-deposit.tsx
aum-deriv Apr 25, 2023
c02b91d
chore: added data-testid for tooltip in mobile view
aum-deriv Apr 25, 2023
e46f1cc
chore: added test cases for crypto-deposit.tsx
aum-deriv May 1, 2023
ee572bb
Merge branch 'master' of github.com:binary-com/deriv-app into aum/WAL…
aum-deriv May 1, 2023
2f7354d
chore: added test cases for crypto-deposit.tsx
aum-deriv May 1, 2023
d2ac397
Merge branch 'master' of github.com:binary-com/deriv-app into aum/WAL…
aum-deriv May 2, 2023
fc70051
fix: fixed the test cases for crypto-deposit.tsx
aum-deriv May 2, 2023
172ca8e
Merge branch 'master' of github.com:binary-com/deriv-app into aum/WAL…
aum-deriv May 3, 2023
7b21fb8
chore: made changes based on comments in PR
aum-deriv May 3, 2023
03cd138
chore: fixing changes suggested by @heorhi-deriv
aum-deriv May 3, 2023
69b2432
Merge branch 'master' of github.com:binary-com/deriv-app into aum/WAL…
aum-deriv May 3, 2023
7b86af7
chore: updated alert-banner.tsx
aum-deriv May 3, 2023
e1a5070
refactor: changed the way localization is handled by alert-banner.tsx
aum-deriv May 3, 2023
16c386a
chore: minor fixes
aum-deriv May 3, 2023
b7208e4
chore: removed unused classnames
aum-deriv May 4, 2023
729626f
chore: add test cases and made changes suggested by @nijil-deriv
aum-deriv May 4, 2023
5096677
Merge branch 'master' of github.com:binary-com/deriv-app into aum/WAL…
aum-deriv May 5, 2023
7cf5b40
Merge branch 'master' of github.com:binary-com/deriv-app into aum/WAL…
aum-deriv May 5, 2023
b4ed579
chore: made changes for the comments in PR
aum-deriv May 5, 2023
915a5ef
Update packages/cashier/src/components/alert-banner/__tests__/alert-b…
aum-deriv May 8, 2023
4dbc748
Merge branch 'master' into aum/WALL-228/crypto-cashier-changes-for-th…
aum-deriv May 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/cashier/src/components/alert-banner/alert-banner.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.alert-banner {
display: grid;
grid-template-columns: auto auto;
width: auto;
padding: 0.8rem;
margin: 2.4rem 0;
border-radius: $BORDER_RADIUS;
background-color: $alpha-color-yellow-1;

svg {
margin: 0.3rem 0.3rem 0 0;
}
aum-deriv marked this conversation as resolved.
Show resolved Hide resolved
}
24 changes: 24 additions & 0 deletions packages/cashier/src/components/alert-banner/alert-banner.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from 'react';
import classNames from 'classnames';
import { Icon, Text } from '@deriv/components';
import { Localize } from '@deriv/translations';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import { Localize } from '@deriv/translations';

import './alert-banner.scss';

type TAlertBanner = {
icon: string;
message: string;
classname?: string;
aum-deriv marked this conversation as resolved.
Show resolved Hide resolved
};

const AlertBanner = ({ icon, message, classname }: TAlertBanner) => {
return (
<div className={classNames('alert-banner', classname)}>
<Icon size={16} icon={icon} className='alert-banner__icon' />
<Text as='p' align='center' size='xs' className='alert-banner__text'>
<Localize i18n_default_text={`${message}`} />
aum-deriv marked this conversation as resolved.
Show resolved Hide resolved
</Text>
</div>
);
};

export default AlertBanner;
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import React from 'react';
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
import { render, screen, waitFor } from '@testing-library/react';

import userEvent from '@testing-library/user-event';
import { isMobile } from '@deriv/shared';
import CryptoTransactionsRenderer from '../crypto-transactions-renderer';
import CashierProviders from '../../../cashier-providers';
import { transaction } from 'mobx';
import { freemem } from 'os';
aum-deriv marked this conversation as resolved.
Show resolved Hide resolved

jest.mock('@deriv/shared/src/utils/screen/responsive', () => ({
...jest.requireActual('@deriv/shared/src/utils/screen/responsive'),
Expand Down Expand Up @@ -135,4 +138,68 @@ describe('<CryptoTransactionsRenderer />', () => {
mockRootStore.modules.cashier.transaction_history.showCryptoTransactionsCancelModal
).toHaveBeenCalledTimes(1);
});

it('should display popover when hovering on tooltip for third-party transactions (CoinsPaid)', () => {
(isMobile as jest.Mock).mockReturnValue(false);
const tooltip_props = {
row: {
address_hash: 'tb1ql7w62elx9ucw4pj5lgw4l028hmuw80sndtntxt',
address_url: 'https://explorer.coinspaid.com/CP:Abcd1234',
amount: 0.005,
id: '3',
is_valid_to_cancel: 1,
status_code: 'LOCKED',
status_message:
"We're reviewing your withdrawal request. You may still cancel this transaction if you wish. Once we start processing, you won't be able to cancel.",
submit_date: 1640603927,
transaction_type: 'withdrawal',
transaction_url: 'CP:Abcd1234',
},
};

render(<CryptoTransactionsRenderer {...tooltip_props} />, {
wrapper: ({ children }) => <CashierProviders store={mockRootStore}>{children}</CashierProviders>,
});

const crypto_transactions_history_table_tooltip = screen.getByTestId(
'dt_crypto_transactions_history_table_tooltip'
);

expect(crypto_transactions_history_table_tooltip).toBeInTheDocument();

userEvent.hover(crypto_transactions_history_table_tooltip);
expect(screen.getByText('The details of this transaction is available on CoinsPaid.')).toBeInTheDocument();
userEvent.unhover(crypto_transactions_history_table_tooltip);
});

it('should check whether the tooltip is clickable for third-party transactions (CoinsPaid)', () => {
(isMobile as jest.Mock).mockReturnValue(true);
const tooltip_props = {
row: {
address_hash: 'tb1ql7w62elx9ucw4pj5lgw4l028hmuw80sndtntxt',
address_url: 'https://explorer.coinspaid.com/CP:Abcd1234',
amount: 0.005,
id: '3',
is_valid_to_cancel: 1,
status_code: 'LOCKED',
status_message:
"We're reviewing your withdrawal request. You may still cancel this transaction if you wish. Once we start processing, you won't be able to cancel.",
submit_date: 1640603927,
transaction_type: 'withdrawal',
transaction_url: 'CP:Abcd1234',
},
onTooltipClick: jest.fn(),
};

render(<CryptoTransactionsRenderer {...tooltip_props} />, {
wrapper: ({ children }) => <CashierProviders store={mockRootStore}>{children}</CashierProviders>,
});

const crypto_transactions_history_table_tooltip_mobile = screen.getByTestId(
'dt_crypto_transactions_history_table_tooltip_mobile'
);

expect(crypto_transactions_history_table_tooltip_mobile).toBeInTheDocument();
fireEvent.click(crypto_transactions_history_table_tooltip_mobile);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fireEvent.click(crypto_transactions_history_table_tooltip_mobile);
userEvent.click(crypto_transactions_history_table_tooltip_mobile);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@henry-deriv can you please provide a reason for using userEvent instead of fireEvent?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

userEvent reflects user interaction better than fireEvent. Mimics a more realistic user interaction than fireEvent. Also, by convention we have stopped using fireEvent in our repo.

});
});
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,14 @@
justify-content: center;
}
}

&-tooltip {
margin-left: 0.4rem;
svg {
display: flex;
align-items: center;
}
}
}
&__data-list {
flex: 1;
Expand Down Expand Up @@ -186,4 +194,7 @@
position: static;
}
}
&__modal-body {
font-size: 1.5rem;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { DataList, Icon, Loading, MobileWrapper, Table, Text } from '@deriv/components';
import { DataList, Icon, Loading, MobileWrapper, Table, Text, Modal } from '@deriv/components';
aum-deriv marked this conversation as resolved.
Show resolved Hide resolved
import { isDesktop, isMobile, routes } from '@deriv/shared';
import { localize, Localize } from '@deriv/translations';
import { useStore, observer } from '@deriv/stores';
Expand Down Expand Up @@ -29,6 +29,7 @@ const CryptoTransactionsHistory = observer(() => {
const { crypto_transactions, is_loading, setIsCryptoTransactionsVisible } = transaction_history;
const { setIsDeposit } = general_store;
const { currency } = client;
const [is_modal_visible, setIsModalVisible] = React.useState(false);

React.useEffect(() => {
return () => setIsCryptoTransactionsVisible(false);
Expand Down Expand Up @@ -79,7 +80,10 @@ const CryptoTransactionsHistory = observer(() => {
// TODO: CHECK THIS TYPE ERROR
data_source={crypto_transactions}
rowRenderer={(row_props: TCryptoTransactionDetailsRow) => (
<CryptoTransactionsRenderer {...row_props} />
<CryptoTransactionsRenderer
{...row_props}
onTooltipClick={() => setIsModalVisible(true)}
/>
)}
keyMapper={(row: TCryptoTransactionDetails) => row.id}
row_gap={isMobile() ? 8 : 0}
Expand All @@ -95,6 +99,18 @@ const CryptoTransactionsHistory = observer(() => {
</div>
)}
</div>
<Modal
has_close_icon
is_open={is_modal_visible}
title={'Note'}
aum-deriv marked this conversation as resolved.
Show resolved Hide resolved
toggleModal={() => setIsModalVisible(old => !old)}
width={'44rem'}
height={'14rem'}
aum-deriv marked this conversation as resolved.
Show resolved Hide resolved
>
<Modal.Body className='crypto-transactions-history__modal-body'>
{localize('The details of this transaction is available on CoinsPaid.')}
</Modal.Body>
</Modal>
</React.Fragment>
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import { useCashierStore } from '../../stores/useCashierStores';

type TCryptoTransactionsRendererProps = {
row: TCryptoTransactionDetails;
onTooltipClick: VoidFunction;
};

const CryptoTransactionsRenderer = observer(({ row: crypto }: TCryptoTransactionsRendererProps) => {
const CryptoTransactionsRenderer = observer(({ row: crypto, onTooltipClick }: TCryptoTransactionsRendererProps) => {
const { client } = useStore();
const { transaction_history } = useCashierStore();
const { cancelCryptoTransaction, showCryptoTransactionsCancelModal, showCryptoTransactionsStatusModal } =
Expand Down Expand Up @@ -130,6 +131,15 @@ const CryptoTransactionsRenderer = observer(({ row: crypto }: TCryptoTransaction
<Text as='p' color='prominent' size='xxs' weight='bold'>
{localize('Transaction hash')}
</Text>
{transaction_url?.includes('CP:') && (
aum-deriv marked this conversation as resolved.
Show resolved Hide resolved
<Icon
className='crypto-transactions-history__table-tooltip'
data_testid='dt_crypto_transactions_history_table_tooltip_mobile'
onClick={onTooltipClick}
icon='IcHelpCentre'
custom_color='#999999'
aum-deriv marked this conversation as resolved.
Show resolved Hide resolved
/>
)}
</Table.Cell>
<Table.Cell className='crypto-transactions-history__table-hash'>
<a
Expand Down Expand Up @@ -223,22 +233,34 @@ const CryptoTransactionsRenderer = observer(({ row: crypto }: TCryptoTransaction
</Table.Cell>
<Table.Cell className='crypto-transactions-history__table-hash'>
{transaction_url ? (
<Popover
alignment='right'
className='crypto-transactions-history__table-popover'
message={localize('View transaction on Blockchain')}
>
<a
className='crypto-transactions-history__table-link'
href={transaction_url}
rel='noopener noreferrer'
target='_blank'
<>
<Popover
alignment='right'
className='crypto-transactions-history__table-popover'
message={localize('View transaction on Blockchain')}
>
<Text as='p' size='xs' color='red'>
{status.transaction_hash}
</Text>
</a>
</Popover>
<a
className='crypto-transactions-history__table-link'
href={transaction_url}
rel='noopener noreferrer'
target='_blank'
>
<Text as='p' size='xs' color='red'>
{status.transaction_hash}
</Text>
</a>
</Popover>
{transaction_url.includes('CP:') && (
aum-deriv marked this conversation as resolved.
Show resolved Hide resolved
<Popover
alignment='right'
className='crypto-transactions-history__table-tooltip'
data_testid='dt_crypto_transactions_history_table_tooltip'
message={localize('The details of this transaction is available on CoinsPaid.')}
>
<Icon icon='IcHelpCentre' custom_color='#999999' />
aum-deriv marked this conversation as resolved.
Show resolved Hide resolved
</Popover>
)}
</>
) : (
<Text as='p' size='xs' color='red'>
{status.transaction_hash}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,40 @@ jest.mock('Components/recent-transaction', () => {
return RecentTransactions;
});

jest.mock('@deriv/api', () => {
return {
...jest.requireActual('@deriv/api'),
useFetch: jest.fn(() => ({
data: {
currencies_config: {
tUSDT: {
minimum_deposit: 2,
minimum_withdrawal: 4.54,
},
BTC: {
minimum_deposit: undefined,
minimum_withdrawal: undefined,
},
ETH: {
minimum_deposit: undefined,
minimum_withdrawal: undefined,
},
USDC: {
minimum_deposit: undefined,
minimum_withdrawal: undefined,
},
eUSDT: {
minimum_deposit: undefined,
minimum_withdrawal: undefined,
},
aum-deriv marked this conversation as resolved.
Show resolved Hide resolved
},
},
isLoading: false,
isSuccess: true,
})),
};
});

describe('<CryptoDeposit />', () => {
let history: ReturnType<typeof createBrowserHistory>;
const renderWithRouter = (component: JSX.Element, mockRootStore: TRootStore) => {
Expand Down Expand Up @@ -437,4 +471,30 @@ describe('<CryptoDeposit />', () => {

expect(screen.getByText('RecentTransactions')).toBeInTheDocument();
});

it('should show AlertBanner for minimum deposit when third-party payment processor is used (CoinsPaid)', () => {
aum-deriv marked this conversation as resolved.
Show resolved Hide resolved
const mockRootStore = {
client: {
currency: 'tUSDT',
},
modules: {
cashier: {
onramp: {
is_deposit_address_loading: false,
api_error: '',
deposit_address: 'tb1ql7w62elx9ucw4pj5lgw4l028hmuw80sndtntxt',
pollApiForDepositAddress: jest.fn(),
},
transaction_history: {
crypto_transactions: [{}],
onMount: jest.fn(),
},
general_store: {
setIsDeposit: jest.fn(),
},
},
},
};
renderWithRouter(<CryptoDeposit />, mockRootStore as TRootStore);
aum-deriv marked this conversation as resolved.
Show resolved Hide resolved
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,24 @@
flex-direction: column;
align-items: center;

&__text {
display: flex;
justify-content: space-between;
width: auto;
padding: 0.8rem;
margin: 2.4rem 0;
border-radius: $BORDER_RADIUS;
background-color: $alpha-color-yellow-1;

svg {
margin-right: 0.3rem;
}
}
.dc-btn {
max-width: 6rem;
padding: 0.3rem 0.8rem;
}
}

.crypto-third-party-alert {
aum-deriv marked this conversation as resolved.
Show resolved Hide resolved
background-color: #ffad3a;
aum-deriv marked this conversation as resolved.
Show resolved Hide resolved

.dc-text {
background-color: #ffad3a;
aum-deriv marked this conversation as resolved.
Show resolved Hide resolved
color: #333333;
aum-deriv marked this conversation as resolved.
Show resolved Hide resolved
}

.dc-icon {
--fill-color1: #333333;
aum-deriv marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
&__transaction-currency {
margin: 2.4rem 0 0.8rem;
Expand Down Expand Up @@ -89,4 +89,17 @@
&__fiat-onramp-button {
margin-bottom: 2.4rem;
}

&__alert-message-box {
display: flex;
flex-direction: row;
align-items: center;
padding: 1.6rem;
background-color: $color-yellow;

&__text {
margin-left: 0.8rem;
color: $color-black-1;
}
}
aum-deriv marked this conversation as resolved.
Show resolved Hide resolved
}
Loading