Skip to content

Commit

Permalink
Revert "Farzin/Hamid/wall 250/withdraw hooks (#8489)" (#8745)
Browse files Browse the repository at this point in the history
This reverts commit c96c51f.
  • Loading branch information
farzin-deriv committed May 25, 2023
1 parent 998e0cc commit 9f6a90b
Show file tree
Hide file tree
Showing 20 changed files with 73 additions and 230 deletions.
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import CashierLocked from '../cashier-locked';
import { useCashierLocked, useDepositLocked, useWithdrawLocked } from '@deriv/hooks';
import { useCashierLocked, useDepositLocked } from '@deriv/hooks';
import { mockStore } from '@deriv/stores';
import CashierProviders from '../../../cashier-providers';

jest.mock('@deriv/hooks', () => ({
...jest.requireActual('@deriv/hooks'),
useDepositLocked: jest.fn(() => false),
useCashierLocked: jest.fn(() => false),
useWithdrawLocked: jest.fn(() => false),
}));
const mockUseDepositLocked = useDepositLocked as jest.MockedFunction<typeof useDepositLocked>;
const mockUseCashierLocked = useCashierLocked as jest.MockedFunction<typeof useCashierLocked>;
const mockUseWithdrawLocked = useWithdrawLocked as jest.MockedFunction<typeof useWithdrawLocked>;

describe('<CashierLocked />', () => {
beforeEach(() => {
mockUseDepositLocked.mockReturnValue(false);
mockUseCashierLocked.mockReturnValue(false);
mockUseWithdrawLocked.mockReturnValue(false);
});

it('should show the proper message if there is a crypto cashier maintenance', () => {
Expand Down Expand Up @@ -48,11 +45,11 @@ describe('<CashierLocked />', () => {
});

it('should show the proper message if crypto withdrawal is suspended', () => {
(useWithdrawLocked as jest.Mock).mockReturnValue(true);
const mock_root_store = mockStore({
client: {
account_status: { cashier_validation: ['system_maintenance'] },
current_currency_type: 'crypto',
is_withdrawal_lock: true,
mt5_login_list: [
{
account_type: 'demo',
Expand All @@ -74,7 +71,6 @@ describe('<CashierLocked />', () => {
});

it('should show the proper message if crypto deposit is suspended', () => {
(useDepositLocked as jest.Mock).mockReturnValue(true);
const mock_root_store = mockStore({
client: {
account_status: { cashier_validation: ['system_maintenance'] },
Expand Down Expand Up @@ -418,8 +414,7 @@ describe('<CashierLocked />', () => {
).toBeInTheDocument();
});

it('should show the proper message if the client has self-excluded from the website', () => {
(useDepositLocked as jest.Mock).mockReturnValue(true);
it('should show the proper message if the client has self-exluded from the website', () => {
const mock_root_store = mockStore({
client: {
account_status: { cashier_validation: ['SelfExclusion'] },
Expand All @@ -446,7 +441,6 @@ describe('<CashierLocked />', () => {
});

it('should show the proper message if the client has unwelcome_status', () => {
(useDepositLocked as jest.Mock).mockReturnValue(true);
const mock_root_store = mockStore({
client: {
account_status: { cashier_validation: ['unwelcome_status'] },
Expand All @@ -469,11 +463,11 @@ describe('<CashierLocked />', () => {
});

it('should show the proper message if the client has no_withdrawal_or_trading_status', () => {
useWithdrawLocked.mockReturnValue(true);
const mock_root_store = mockStore({
client: {
account_status: { cashier_validation: ['no_withdrawal_or_trading_status'] },
current_currency_type: 'fiat',
is_withdrawal_lock: true,
mt5_login_list: [
{
account_type: 'demo',
Expand All @@ -493,12 +487,11 @@ describe('<CashierLocked />', () => {
});

it('should show the proper message if the client has withdrawal_locked_status', () => {
(useDepositLocked as jest.Mock).mockReturnValue(false);
(useWithdrawLocked as jest.Mock).mockReturnValue(true);
const mock_root_store = mockStore({
client: {
account_status: { cashier_validation: ['withdrawal_locked_status'] },
current_currency_type: 'fiat',
is_withdrawal_lock: true,
mt5_login_list: [
{
account_type: 'demo',
Expand All @@ -518,12 +511,11 @@ describe('<CashierLocked />', () => {
});

it('should show the proper message if the client has only_pa_withdrawals_allowed_status', () => {
(useDepositLocked as jest.Mock).mockReturnValue(false);
(useWithdrawLocked as jest.Mock).mockReturnValue(true);
const mock_root_store = mockStore({
client: {
account_status: { cashier_validation: ['only_pa_withdrawals_allowed_status'] },
current_currency_type: 'fiat',
is_withdrawal_lock: true,
mt5_login_list: [
{
account_type: 'demo',
Expand Down Expand Up @@ -565,7 +557,6 @@ describe('<CashierLocked />', () => {
});

it('should show cashier locked message if the client has a combo of deposit and withdrawal locked reasons', () => {
(useDepositLocked as jest.Mock).mockReturnValue(false);
const mock_root_store = mockStore({
client: {
account_status: { cashier_validation: ['no_withdrawal_or_trading_status', 'unwelcome_status'] },
Expand All @@ -590,12 +581,11 @@ describe('<CashierLocked />', () => {
});

it('should show the proper message if the client has PACommisionWithdrawalLimit', () => {
(useDepositLocked as jest.Mock).mockReturnValue(false);
(useWithdrawLocked as jest.Mock).mockReturnValue(true);
const mock_root_store = mockStore({
client: {
account_status: { cashier_validation: ['PACommisionWithdrawalLimit'] },
current_currency_type: 'fiat',
is_withdrawal_lock: true,
mt5_login_list: [
{
account_type: 'demo',
Expand Down
14 changes: 10 additions & 4 deletions packages/cashier/src/components/cashier-locked/cashier-locked.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
import React from 'react';
import { useStore, observer } from '@deriv/stores';
import { useCashierLocked, useDepositLocked, useIsSystemMaintenance, useWithdrawLocked } from '@deriv/hooks';
import { useCashierLocked, useDepositLocked, useIsSystemMaintenance } from '@deriv/hooks';
import EmptyState from 'Components/empty-state';
import getMessage from './cashier-locked-provider';

const CashierLocked = observer(() => {
const { client } = useStore();
const { account_status, accounts, current_currency_type, loginid, is_identity_verification_needed } = client;
const {
account_status,
accounts,
current_currency_type,
is_withdrawal_lock: is_withdrawal_locked,
loginid,
is_identity_verification_needed,
} = client;
const is_cashier_locked = useCashierLocked();
const is_system_maintenance = useIsSystemMaintenance();
const is_deposit_locked = useDepositLocked();
const is_withdrawal_locked = useWithdrawLocked();

const state = getMessage({
cashier_validation: account_status?.cashier_validation,
cashier_validation: account_status.cashier_validation,
is_crypto: current_currency_type === 'crypto',
is_system_maintenance,
is_cashier_locked,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import { isDesktop } from '@deriv/shared';
import Withdrawal from '../withdrawal';
import CashierProviders from '../../../cashier-providers';
import { mockStore } from '@deriv/stores';
import { useCashierLocked, useWithdrawLocked } from '@deriv/hooks';
import { useCashierLocked } from '@deriv/hooks';

jest.mock('@deriv/hooks');
jest.mock('Components/cashier-locked', () => jest.fn(() => 'CashierLocked'));
jest.mock('Components/cashier-container/virtual', () => jest.fn(() => 'Virtual'));
jest.mock('../withdrawal-locked', () => jest.fn(() => 'WithdrawalLocked'));
Expand All @@ -31,10 +30,8 @@ jest.mock('@deriv/shared/src/utils/screen/responsive', () => ({
jest.mock('@deriv/hooks', () => ({
...jest.requireActual('@deriv/hooks'),
useCashierLocked: jest.fn(() => false),
useWithdrawLocked: jest.fn(() => false),
}));
const mockUseCashierLocked = useCashierLocked as jest.MockedFunction<typeof useCashierLocked>;
const mockUseWithdrawLocked = useWithdrawLocked as jest.MockedFunction<typeof useWithdrawLocked>;

const cashier_mock = {
general_store: {
Expand Down Expand Up @@ -69,7 +66,6 @@ describe('<Withdrawal />', () => {
beforeEach(() => {
setSideNotes = jest.fn();
mockUseCashierLocked.mockReturnValue(false);
mockUseWithdrawLocked.mockReturnValue(false);
});

const mockWithdrawal = (mock_root_store: ReturnType<typeof mockStore>, is_rerender = false) => {
Expand All @@ -83,7 +79,6 @@ describe('<Withdrawal />', () => {
};

it('should render <CashierLocked /> component', () => {
mockUseWithdrawLocked.mockReturnValue(true);
const mock_root_store = mockStore({
client: {
account_status: { cashier_validation: ['system_maintenance'] },
Expand Down Expand Up @@ -156,7 +151,6 @@ describe('<Withdrawal />', () => {
});

it('should render <WithdrawalLocked /> component', () => {
mockUseWithdrawLocked.mockReturnValue(true);
const mock_root_store = mockStore({
client: {
balance: '1000',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import React from 'react';
import { act } from 'react-dom/test-utils';
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
import { useCurrentAccountDetails } from '@deriv/hooks';
import CryptoWithdrawForm from '../crypto-withdraw-form';
import CashierProviders from '../../../../cashier-providers';
import { mockStore } from '@deriv/stores';

jest.mock('@deriv/hooks');

describe('<CryptoWithdrawForm />', () => {
(useCurrentAccountDetails as jest.Mock).mockReturnValue({ icon: 'icon' });
let mockRootStore: ReturnType<typeof mockStore>;
beforeEach(() => {
mockRootStore = mockStore({
Expand All @@ -31,6 +27,7 @@ describe('<CryptoWithdrawForm />', () => {
onMount: jest.fn(),
},
withdraw: {
account_platform_icon: 'icon',
blockchain_address: 'tb1ql7w62elx9ucw4pj5lgw4l028hmuw80sndtntxt',
onMountCryptoWithdraw: jest.fn(),
requestWithdraw: jest.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import React from 'react';
import { Field, FieldProps, Formik, FormikProps } from 'formik';
import { Button, Icon, Input, Loading, MobileWrapper, Text } from '@deriv/components';
import { CryptoConfig, getCurrencyName, isCryptocurrency, isMobile } from '@deriv/shared';
import { useCurrentAccountDetails } from '@deriv/hooks';
import { localize, Localize } from '@deriv/translations';
import { useStore, observer } from '@deriv/stores';
import CryptoFiatConverter from '../../../components/crypto-fiat-converter';
Expand Down Expand Up @@ -59,6 +58,7 @@ const CryptoWithdrawForm = observer(() => {
const { crypto_fiat_converter, general_store, transaction_history, withdraw } = useCashierStore();
const crypto_currency = currency;
const {
account_platform_icon,
blockchain_address,
onMountCryptoWithdraw: onMountWithdraw,
requestWithdraw,
Expand All @@ -77,7 +77,6 @@ const CryptoWithdrawForm = observer(() => {
} = crypto_fiat_converter;
const { is_loading, percentage, percentageSelectorSelectionStatus, should_percentage_reset } = general_store;
const { crypto_transactions, onMount: recentTransactionOnMount } = transaction_history;
const account_details = useCurrentAccountDetails();

React.useEffect(() => {
recentTransactionOnMount();
Expand Down Expand Up @@ -109,7 +108,7 @@ const CryptoWithdrawForm = observer(() => {
<div className='cashier__wrapper' data-testid='dt_crypto_withdraw_form'>
{!isMobile() && <Header currency={currency} />}
<div className={classNames({ 'crypto-withdraw-form__icon': isMobile() })}>
<Icon icon={`IcCurrency-${account_details?.icon?.toLowerCase()}`} size={isMobile() ? 64 : 128} />
<Icon icon={`IcCurrency-${account_platform_icon?.toLowerCase()}`} size={isMobile() ? 64 : 128} />
</div>
{isMobile() && <Header currency={currency} />}
<Formik
Expand Down
4 changes: 2 additions & 2 deletions packages/cashier/src/pages/withdrawal/withdrawal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Loading } from '@deriv/components';
import { Localize } from '@deriv/translations';
import { isCryptocurrency, isDesktop } from '@deriv/shared';
import { useStore, observer } from '@deriv/stores';
import { useWithdrawLocked, useCashierLocked, useIsSystemMaintenance } from '@deriv/hooks';
import CryptoTransactionsHistory from '../../components/crypto-transactions-history';
import CryptoWithdrawForm from './crypto-withdraw-form';
import CryptoWithdrawReceipt from './crypto-withdraw-receipt';
Expand All @@ -18,6 +17,7 @@ import SideNote from '../../components/side-note';
import USDTSideNote from '../../components/usdt-side-note';
import { Virtual } from '../../components/cashier-container';
import { useCashierStore } from '../../stores/useCashierStores';
import { useCashierLocked, useIsSystemMaintenance } from '@deriv/hooks';

type TWithdrawalSideNoteProps = {
currency: string;
Expand Down Expand Up @@ -75,10 +75,10 @@ const Withdrawal = observer(({ setSideNotes }: TWithdrawalProps) => {
error,
is_10k_withdrawal_limit_reached,
is_withdraw_confirmed,
is_withdrawal_locked,
error: { setErrorMessage },
willMountWithdraw,
} = withdraw;
const is_withdrawal_locked = useWithdrawLocked();

React.useEffect(() => {
if (!is_crypto_transactions_visible) {
Expand Down
26 changes: 26 additions & 0 deletions packages/cashier/src/stores/__tests__/withdraw-store.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,28 @@ describe('WithdrawStore', () => {
expect(setLoading).toHaveBeenCalledWith(false);
});

it('should return is_withdrawal_locked equal to false if there is no account status', () => {
withdraw_store.root_store.client.account_status = {
currency_config: {},
prompt_client_to_authenticate: 0,
risk_classification: '',
status: [],
p2p_status: 'none',
};
expect(withdraw_store.is_withdrawal_locked).toBeFalsy();
});

it('should return is_withdrawal_locked equal to true if client needs POI verification', () => {
withdraw_store.root_store.client.account_status.status = ['authentication_needed'];
withdraw_store.error.is_ask_authentication = true;
expect(withdraw_store.is_withdrawal_locked).toBeTruthy();
});

it('should return is_withdrawal_locked equal to true if client needs financial risk approval', () => {
withdraw_store.error.is_ask_financial_risk_approval = true;
expect(withdraw_store.is_withdrawal_locked).toBeTruthy();
});

it('should set max_withdraw_amount', () => {
withdraw_store.setMaxWithdrawAmount(100);
expect(withdraw_store.max_withdraw_amount).toBe(100);
Expand Down Expand Up @@ -306,4 +328,8 @@ describe('WithdrawStore', () => {
withdraw_store.validateWithdrawToAmount();
expect(setConverterToError).toHaveBeenCalledWith(error_message);
});

it('should get account_platform_icon', () => {
expect(withdraw_store.account_platform_icon).toBe('icon');
});
});
20 changes: 20 additions & 0 deletions packages/cashier/src/stores/withdraw-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ export default class WithdrawStore {
setBlockchainAddress: action.bound,
onMountWithdraw: action.bound,
onMountCryptoWithdraw: action.bound,
is_withdrawal_locked: computed,
setMaxWithdrawAmount: action.bound,
check10kLimit: action.bound,
set10kLimitation: action.bound,
setCryptoConfig: action.bound,
setWithdrawPercentageSelectorResult: action.bound,
validateWithdrawFromAmount: action.bound,
validateWithdrawToAmount: action.bound,
account_platform_icon: computed,
});

this.root_store = root_store;
Expand Down Expand Up @@ -267,6 +269,17 @@ export default class WithdrawStore {
this.crypto_config = (await this.WS.cryptoConfig())?.crypto_config;
}

get is_withdrawal_locked() {
const { client } = this.root_store;
const { authentication } = client.account_status;

if (!client.account_status?.status) return false;
const need_poi = authentication?.needs_verification.includes('identity');
const need_authentication = this.error.is_ask_authentication && need_poi;

return client.is_withdrawal_lock || need_authentication || this.error.is_ask_financial_risk_approval;
}

setMaxWithdrawAmount(amount: number) {
this.max_withdraw_amount = amount;
}
Expand Down Expand Up @@ -371,4 +384,11 @@ export default class WithdrawStore {

setConverterToError(error_message);
}

get account_platform_icon() {
const { account_list, loginid } = this.root_store.client;
const platform_icon = account_list.find(acc => loginid === acc.loginid)?.icon;

return platform_icon;
}
}
1 change: 0 additions & 1 deletion packages/core/src/Stores/client-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,6 @@ export default class ClientStore extends BaseStore {
return this.account_status?.status?.some(status_name => status_name === 'deposit_locked');
}

// @deprecated use `useWithdrawLock` hook from `@deriv/hooks` instead
get is_withdrawal_lock() {
return this.account_status?.status?.some(status_name => status_name === 'withdrawal_locked');
}
Expand Down
Loading

1 comment on commit 9f6a90b

@vercel
Copy link

@vercel vercel bot commented on 9f6a90b May 25, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

deriv-app – ./

binary.sx
deriv-app.vercel.app
deriv-app.binary.sx
deriv-app-git-master.binary.sx

Please sign in to comment.