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

chore: fix cfd modal display #9163

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const AccountTransferModal = observer(({ is_modal_open, toggleModal }: TAccountT
const {
modules: {
cashier: {
account_transfer: { is_transfer_confirm, should_switch_account },
account_transfer: { is_transfer_confirm, should_switch_account, setShouldSwitchAccount },
},
},
traders_hub: { closeModal, setSelectedAccount },
Expand All @@ -25,6 +25,7 @@ const AccountTransferModal = observer(({ is_modal_open, toggleModal }: TAccountT

React.useEffect(() => {
return () => {
setShouldSwitchAccount(false);
setSelectedAccount({});
closeModal();
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@
}
.dc-modal__container_account_transfer {
&_switch_modal {
transition: none;
.dc-modal {
@include mobile() {
&-header__close {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ describe('<AccountTransferReceipt />', () => {
common: {
is_from_derivgo: false,
},
traders_hub: {
closeAccountTransferModal: jest.fn(),
},
modules: {
cashier: {
account_transfer: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ type TSwitch = {
};

type TAccountTransferReceipt = RouteComponentProps & {
onClose?: () => void;
onClose: () => void;
};

const AccountTransferReceipt = observer(({ onClose, history }: TAccountTransferReceipt) => {
const { common, client } = useStore();
const { common, client, traders_hub } = useStore();
const { account_transfer } = useCashierStore();
const { is_from_derivgo } = common;
const { loginid, switchAccount } = client;
const { closeAccountTransferModal } = traders_hub;
const { receipt, resetAccountTransfer, selected_from, selected_to, setShouldSwitchAccount } = account_transfer;

const is_from_outside_cashier = !location.pathname.startsWith(routes.cashier);
Expand All @@ -33,6 +34,7 @@ const AccountTransferReceipt = observer(({ onClose, history }: TAccountTransferR
React.useEffect(() => {
return () => {
resetAccountTransfer();
closeAccountTransferModal();
};
}, [resetAccountTransfer]);

Expand Down Expand Up @@ -62,13 +64,10 @@ const AccountTransferReceipt = observer(({ onClose, history }: TAccountTransferR
} else {
// if the account transferred to is a Deriv MT5 account that can't be switched to, switch to from account instead
// otherwise switch to the account transferred to
setShouldSwitchAccount();
setShouldSwitchAccount(true);
setSwitchTo(selected_to.is_mt ? selected_from : selected_to);
toggleSwitchAlert();
}
// close modal only when the user try to transfer money from traders-hub, not from cashier
// because in cashier this component is not a modal
if (is_from_outside_cashier) onClose?.();
};

return (
Expand Down Expand Up @@ -156,7 +155,16 @@ const AccountTransferReceipt = observer(({ onClose, history }: TAccountTransferR
/>
</Modal.Body>
<Modal.Footer>
<Button has_effect text={localize('Cancel')} onClick={toggleSwitchAlert} secondary large />
<Button
has_effect
text={localize('Cancel')}
onClick={() => {
setShouldSwitchAccount(false);
toggleSwitchAlert();
}}
secondary
large
/>
<Button
has_effect
text={localize(`Switch to ${switch_to.currency} account`)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ const AccountTransfer = observer(({ onClickDeposit, onClickNotes, onClose, setSi
setSideNotes={setSideNotes}
onClickDeposit={onClickDeposit}
onClickNotes={onClickNotes}
onClose={onClose}
/>
);
});
Expand Down
4 changes: 2 additions & 2 deletions packages/cashier/src/stores/account-transfer-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ export default class AccountTransferStore {
return need_financial_assessment && this.error.is_ask_financial_risk_approval;
}

setShouldSwitchAccount() {
this.should_switch_account = true;
setShouldSwitchAccount(value: boolean) {
this.should_switch_account = value;
}

setBalanceByLoginId(loginid: string, balance: string | number) {
Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/Stores/traders-hub-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export default class TradersHubStore extends BaseStore {
show_eu_related_content: computed,
startTrade: action.bound,
toggleAccountTransferModal: action.bound,
closeAccountTransferModal: action.bound,
toggleAccountTypeModalVisibility: action.bound,
setIsOnboardingVisited: action.bound,
toggleFailedVerificationModalVisibility: action.bound,
Expand Down Expand Up @@ -727,6 +728,10 @@ export default class TradersHubStore extends BaseStore {
});
}

closeAccountTransferModal() {
this.is_account_transfer_modal_open = false;
}

toggleAccountTransferModal() {
this.is_account_transfer_modal_open = !this.is_account_transfer_modal_open;
}
Expand Down
1 change: 1 addition & 0 deletions packages/stores/src/mockStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ const mock = (): TStores & { is_mock: boolean } => {
selectRegion: jest.fn(),
setSelectedAccount: jest.fn(),
is_low_risk_cr_eu_real: false,
closeAccountTransferModal: jest.fn(),
toggleRegulatorsCompareModal: jest.fn(),
selected_region: '',
is_demo: false,
Expand Down
1 change: 1 addition & 0 deletions packages/stores/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ type TTradersHubStore = {
setTogglePlatformType: (platform_type: string) => void;
is_real: boolean;
selectRegion: (region: string) => void;
closeAccountTransferModal: () => void;
toggleRegulatorsCompareModal: () => void;
selected_region: string;
openFailedVerificationModal: (selected_account_type: string) => void;
Expand Down