From f8f8e74b00b5690a3ee3c2bb72fd9d243a07fcbb Mon Sep 17 00:00:00 2001 From: heorhi-deriv Date: Fri, 17 May 2024 15:40:30 +0300 Subject: [PATCH] fix(wallets): :ambulance: fix demo cfd balance --- .../AvailableCTraderAccountsList.tsx | 1 - .../CTraderSuccessModal/CTraderSuccessModal.tsx | 10 +++++----- .../DxtradeEnterPasswordModal.tsx | 12 ++++++------ .../cfd/modals/MT5AccountAdded/MT5AccountAdded.tsx | 10 ++-------- .../__tests__/MT5AccountAdded.spec.tsx | 5 ++++- 5 files changed, 17 insertions(+), 21 deletions(-) diff --git a/packages/wallets/src/features/cfd/flows/CTrader/AvailableCTraderAccountsList/AvailableCTraderAccountsList.tsx b/packages/wallets/src/features/cfd/flows/CTrader/AvailableCTraderAccountsList/AvailableCTraderAccountsList.tsx index 148c93201ff5..c105a2dc0914 100644 --- a/packages/wallets/src/features/cfd/flows/CTrader/AvailableCTraderAccountsList/AvailableCTraderAccountsList.tsx +++ b/packages/wallets/src/features/cfd/flows/CTrader/AvailableCTraderAccountsList/AvailableCTraderAccountsList.tsx @@ -32,7 +32,6 @@ const AvailableCTraderAccountsList: React.FC = () => { show( diff --git a/packages/wallets/src/features/cfd/modals/CTraderSuccessModal/CTraderSuccessModal.tsx b/packages/wallets/src/features/cfd/modals/CTraderSuccessModal/CTraderSuccessModal.tsx index ac98526d843a..5b731541df05 100644 --- a/packages/wallets/src/features/cfd/modals/CTraderSuccessModal/CTraderSuccessModal.tsx +++ b/packages/wallets/src/features/cfd/modals/CTraderSuccessModal/CTraderSuccessModal.tsx @@ -10,18 +10,18 @@ import { CTraderSuccessModalButtons } from './components'; type TCTraderSuccessModal = { createdAccount?: THooks.CreateOtherCFDAccount; - displayBalance?: string; isDemo: boolean; walletCurrencyType: THooks.WalletAccountsList['wallet_currency_type']; }; -const CTraderSuccessModal = ({ createdAccount, displayBalance, isDemo, walletCurrencyType }: TCTraderSuccessModal) => { +const CTraderSuccessModal = ({ createdAccount, isDemo, walletCurrencyType }: TCTraderSuccessModal) => { const { data: cTraderAccounts } = useCtraderAccountsList(); const { isMobile } = useDevice(); const { hide } = useModal(); + const cTraderBalance = cTraderAccounts?.find(account => account.login)?.formatted_balance; const description = isDemo - ? `Let's practise trading with ${displayBalance} virtual funds.` + ? `Let's practise trading with ${cTraderBalance} virtual funds.` : `Transfer funds from your ${walletCurrencyType} Wallet to your ${PlatformDetails.ctrader.title} account to start trading.`; if (isMobile) { @@ -34,7 +34,7 @@ const CTraderSuccessModal = ({ createdAccount, displayBalance, isDemo, walletCur > account.login)?.formatted_balance} + displayBalance={cTraderBalance} marketType='all' platform='ctrader' renderButton={() => ( @@ -50,7 +50,7 @@ const CTraderSuccessModal = ({ createdAccount, displayBalance, isDemo, walletCur account.login)?.formatted_balance} + displayBalance={cTraderBalance} marketType='all' platform={PlatformDetails.ctrader.platform} renderButton={() => ( diff --git a/packages/wallets/src/features/cfd/modals/DxtradeEnterPasswordModal/DxtradeEnterPasswordModal.tsx b/packages/wallets/src/features/cfd/modals/DxtradeEnterPasswordModal/DxtradeEnterPasswordModal.tsx index 606c0be87325..a198975abdc9 100644 --- a/packages/wallets/src/features/cfd/modals/DxtradeEnterPasswordModal/DxtradeEnterPasswordModal.tsx +++ b/packages/wallets/src/features/cfd/modals/DxtradeEnterPasswordModal/DxtradeEnterPasswordModal.tsx @@ -54,11 +54,15 @@ const DxtradeEnterPasswordModal = () => { }).catch(() => setPassword('')); }, [mutateAsync, accountType, password, dxtradePlatform]); + const dxtradeBalance = useMemo(() => { + return dxtradeAccount?.find(account => account.market_type === 'all')?.display_balance; + }, [dxtradeAccount]); + const successDescription = useMemo(() => { return accountType === 'demo' - ? `Let's practise trading with ${activeWallet?.display_balance} virtual funds.` + ? `Let's practise trading with ${dxtradeBalance} virtual funds.` : `Transfer funds from your ${activeWallet?.currency} Wallet to your ${PlatformDetails.dxtrade.title} account to start trading.`; - }, [accountType, activeWallet?.currency, activeWallet?.display_balance]); + }, [accountType, activeWallet?.currency, dxtradeBalance]); useEffect(() => { if (!isResetPasswordSuccessful) return; @@ -77,10 +81,6 @@ const DxtradeEnterPasswordModal = () => { } }, [dxtradePlatform, hide, isDxtradePasswordNotSet, isMobile, isResetPasswordSuccessful, show]); - const dxtradeBalance = useMemo(() => { - return dxtradeAccount?.find(account => account.market_type === 'all')?.display_balance; - }, [dxtradeAccount]); - const renderFooter = useMemo(() => { if (isCreateAccountSuccessful) { if (accountType === 'demo') { diff --git a/packages/wallets/src/features/cfd/modals/MT5AccountAdded/MT5AccountAdded.tsx b/packages/wallets/src/features/cfd/modals/MT5AccountAdded/MT5AccountAdded.tsx index 5fda93bbca35..81bda0c7162a 100644 --- a/packages/wallets/src/features/cfd/modals/MT5AccountAdded/MT5AccountAdded.tsx +++ b/packages/wallets/src/features/cfd/modals/MT5AccountAdded/MT5AccountAdded.tsx @@ -77,16 +77,10 @@ const MT5AccountAdded: FC = ({ account, marketType, platform }) => { const renderSuccessDescription = useMemo(() => { if (isDemo) { - return `Let's practise trading with ${activeWallet?.display_balance} virtual funds.`; + return `Let's practise trading with ${displayBalance} virtual funds.`; } return `Transfer funds from your ${activeWallet?.wallet_currency_type} Wallet to your ${marketTypeTitle} ${landingCompanyName} account to start trading.`; - }, [ - activeWallet?.display_balance, - activeWallet?.wallet_currency_type, - isDemo, - landingCompanyName, - marketTypeTitle, - ]); + }, [activeWallet?.wallet_currency_type, displayBalance, isDemo, landingCompanyName, marketTypeTitle]); const renderMainContent = useMemo(() => { if (!isSuccess) return null; diff --git a/packages/wallets/src/features/cfd/modals/MT5AccountAdded/__tests__/MT5AccountAdded.spec.tsx b/packages/wallets/src/features/cfd/modals/MT5AccountAdded/__tests__/MT5AccountAdded.spec.tsx index 8859f3bce329..70e1b2a78ac2 100644 --- a/packages/wallets/src/features/cfd/modals/MT5AccountAdded/__tests__/MT5AccountAdded.spec.tsx +++ b/packages/wallets/src/features/cfd/modals/MT5AccountAdded/__tests__/MT5AccountAdded.spec.tsx @@ -30,6 +30,9 @@ jest.mock('@deriv/api-v2', () => ({ })), isSuccess: true, })), + useMT5AccountsList: jest.fn(() => ({ + data: [{ display_balance: '10,000.00 USD', market_type: 'financial' }], + })), usePOI: jest.fn(() => ({ data: { current: { @@ -63,7 +66,7 @@ describe('MT5AccountAdded', () => { ); expect(screen.getByText('Your Financial demo account is ready')).toBeInTheDocument(); - expect(screen.getByText("Let's practise trading with 10000 USD virtual funds.")).toBeInTheDocument(); + expect(screen.getByText("Let's practise trading with 10,000.00 USD virtual funds.")).toBeInTheDocument(); const okButton = screen.getByRole('button', { name: 'OK' }); expect(okButton).toBeInTheDocument(); expect(okButton).toBeEnabled();