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 23 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 = {
className?: string;
icon: string;
message: JSX.Element | string;
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
message: JSX.Element | string;
message: string;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@heorhi-deriv suggested me to use <Localize /> component instead of the function as he pointed out that the function variant is used only for simple strings and not for dynamic data throughout the project.

};

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

export default AlertBanner;
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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';
Expand Down Expand Up @@ -135,4 +136,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,8 @@
position: static;
}
}

&-body {
font-size: var(--text-size-xxs);
}
}
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, Modal, Table, Text } from '@deriv/components';
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,19 @@ const CryptoTransactionsHistory = observer(() => {
</div>
)}
</div>
<Modal
has_close_icon
is_open={is_modal_visible}
title='Note'
toggleModal={() => setIsModalVisible(old => !old)}
width='44rem'
height='14rem'
className='crypto-transactions-history__modal'
>
<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 @@ -61,6 +62,8 @@ const CryptoTransactionsRenderer = observer(({ row: crypto }: TCryptoTransaction
showCryptoTransactionsStatusModal(description, name);
};

const is_third_party_transaction = transaction_url?.includes('CP:');

if (isMobile()) {
return (
<div>
Expand Down Expand Up @@ -130,6 +133,15 @@ const CryptoTransactionsRenderer = observer(({ row: crypto }: TCryptoTransaction
<Text as='p' color='prominent' size='xxs' weight='bold'>
{localize('Transaction hash')}
</Text>
{is_third_party_transaction && (
<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 +235,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>
{is_third_party_transaction && (
<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='var(--status-adjustment)' />
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,24 @@ 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,
},
},
},
isLoading: false,
isSuccess: true,
})),
};
});

describe('<CryptoDeposit />', () => {
let history: ReturnType<typeof createBrowserHistory>;
const renderWithRouter = (component: JSX.Element, mockRootStore: TRootStore) => {
Expand Down Expand Up @@ -437,4 +455,37 @@ 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 minimum_deposit = 2;
const currency = 'tUSDT';
const mockRootStore = {
client: {
currency: 'tUSDT',
},
aum-deriv marked this conversation as resolved.
Show resolved Hide resolved
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
expect(
screen.getByText(
`A minimum deposit value of ${minimum_deposit} ${currency} is required. Otherwise, the funds will be lost and cannot be recovered.`
aum-deriv marked this conversation as resolved.
Show resolved Hide resolved
)
).toBeInTheDocument();
});
});
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: $color-yellow;

.dc-text {
background-color: $color-yellow;
color: $color-black-1;
}

.dc-icon {
--fill-color1: $color-black-1;
}
}
}
&__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