From ea06eb4f421c9ba6ae98e7147cd0e245a18ee5ce Mon Sep 17 00:00:00 2001 From: thisyahlen <104053934+thisyahlen-deriv@users.noreply.github.com> Date: Fri, 30 Jun 2023 11:48:26 +0800 Subject: [PATCH] Thisyahlen/WALL-1020/ List of wallets according to authorize and balance (#9010) * chore: add balance from response, switching and refactor * fix: test and verification only for eu users * fix: tests * fix: modal first, then switch account * fix: refactor logic to hooks * fix: refactor to use wallet_account instead of data * redeploy: vercel * fix: refactor test * fix: tests and address comments * fix: use debounce instead of settimeout * fix: refactor tests and hooks * fix: use landing_company_name instead of shortcode * fix: test title * fix: scroll to active wallet upon click * fix: resolve test and comments * fix: test * fix: tests again --- package-lock.json | 33 +- packages/appstore/package.json | 4 +- .../containers/__tests__/wallets.spec.tsx | 66 ++-- .../src/components/containers/wallet.tsx | 45 ++- .../__tests__/wallet-modal-body.spec.tsx | 57 +++- .../__tests__/wallet-modal.spec.tsx | 78 ++--- .../modals/wallet-modal/wallet-modal-body.tsx | 140 ++++---- .../modals/wallet-modal/wallet-modal.tsx | 86 ++--- .../__tests__/wallet-content.spec.tsx | 37 ++- .../wallet-content/wallet-cfds-listing.tsx | 10 +- .../wallet-content/wallet-content.tsx | 18 +- .../wallet-option-multipliers-listing.tsx | 8 +- .../__tests__/wallet-header.spec.tsx | 303 ++++++------------ .../wallet-header/wallet-currency-card.tsx | 21 +- .../wallet-header/wallet-header-balance.tsx | 35 +- .../wallet-header/wallet-header-buttons.tsx | 22 +- .../wallet-header/wallet-header-title.tsx | 45 +-- .../wallet-header/wallet-header.tsx | 114 ++++--- packages/appstore/src/constants/utils.ts | 30 +- .../traders-hub/account-with-wallets.tsx | 23 +- .../src/modules/traders-hub/index.tsx | 2 - packages/appstore/src/types/common.types.ts | 4 +- .../Layout/header/trading-hub-header.jsx | 11 - packages/core/src/Stores/traders-hub-store.js | 14 + .../src/__tests__/useActiveWallet.spec.tsx | 76 +++++ .../src/__tests__/useWalletsList.spec.tsx | 13 +- packages/hooks/src/index.ts | 3 +- packages/hooks/src/useActiveWallet.ts | 11 + packages/hooks/src/useWalletsList.ts | 18 +- packages/stores/src/mockStore.ts | 5 +- packages/stores/types.ts | 4 + 31 files changed, 704 insertions(+), 632 deletions(-) create mode 100644 packages/hooks/src/__tests__/useActiveWallet.spec.tsx create mode 100644 packages/hooks/src/useActiveWallet.ts diff --git a/package-lock.json b/package-lock.json index 19d00497a9c1..d0e24a782883 100644 --- a/package-lock.json +++ b/package-lock.json @@ -38,6 +38,7 @@ "@testing-library/react-hooks": "^7.0.2", "@testing-library/user-event": "^13.5.0", "@types/jest": "^27.4.1", + "@types/lodash.debounce": "^4.0.7", "@types/node": "^17.0.27", "@types/react": "^18.0.7", "@types/react-dom": "^18.0.0", @@ -78,7 +79,7 @@ "ts-jest": "^26.4.2" }, "engines": { - "node": "^18.16.0" + "node": "18.x" }, "optionalDependencies": { "fsevents": "^2.3.2" @@ -6134,6 +6135,21 @@ "dev": true, "license": "MIT" }, + "node_modules/@types/lodash": { + "version": "4.14.195", + "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.195.tgz", + "integrity": "sha512-Hwx9EUgdwf2GLarOjQp5ZH8ZmblzcbTBC2wtQWNKARBSxM9ezRIAUpeDTgoQRAFB0+8CNWXVA9+MaSOzOF3nPg==", + "dev": true + }, + "node_modules/@types/lodash.debounce": { + "version": "4.0.7", + "resolved": "https://registry.npmjs.org/@types/lodash.debounce/-/lodash.debounce-4.0.7.tgz", + "integrity": "sha512-X1T4wMZ+gT000M2/91SYj0d/7JfeNZ9PeeOldSNoE/lunLeQXKvkmIumI29IaKMotU/ln/McOIvgzZcQ/3TrSA==", + "dev": true, + "dependencies": { + "@types/lodash": "*" + } + }, "node_modules/@types/mdast": { "version": "3.0.10", "dev": true, @@ -27287,6 +27303,21 @@ "version": "0.0.29", "dev": true }, + "@types/lodash": { + "version": "4.14.195", + "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.195.tgz", + "integrity": "sha512-Hwx9EUgdwf2GLarOjQp5ZH8ZmblzcbTBC2wtQWNKARBSxM9ezRIAUpeDTgoQRAFB0+8CNWXVA9+MaSOzOF3nPg==", + "dev": true + }, + "@types/lodash.debounce": { + "version": "4.0.7", + "resolved": "https://registry.npmjs.org/@types/lodash.debounce/-/lodash.debounce-4.0.7.tgz", + "integrity": "sha512-X1T4wMZ+gT000M2/91SYj0d/7JfeNZ9PeeOldSNoE/lunLeQXKvkmIumI29IaKMotU/ln/McOIvgzZcQ/3TrSA==", + "dev": true, + "requires": { + "@types/lodash": "*" + } + }, "@types/mdast": { "version": "3.0.10", "dev": true, diff --git a/packages/appstore/package.json b/packages/appstore/package.json index 1e2c79c81ea1..5fd6aa5bfb0f 100644 --- a/packages/appstore/package.json +++ b/packages/appstore/package.json @@ -31,15 +31,17 @@ "@deriv/cashier": "^1.0.0", "@deriv/components": "^1.0.0", "@deriv/cfd": "^1.0.0", - "@deriv/hooks": "^1.0.0", "@deriv/shared": "^1.0.0", "@deriv/stores": "^1.0.0", + "@testing-library/jest-dom": "^5.12.0", + "@deriv/hooks": "^1.0.0", "@deriv/trader": "^3.8.0", "@deriv/translations": "^1.0.0", "@deriv/hooks": "^1.0.0", "@deriv/ui": "^0.8.0", "classnames": "^2.2.6", "formik": "^2.1.4", + "lodash.debounce": "^4.0.8", "mobx": "^6.6.1", "mobx-react-lite": "^3.4.0", "object.fromentries": "^2.0.0", diff --git a/packages/appstore/src/components/containers/__tests__/wallets.spec.tsx b/packages/appstore/src/components/containers/__tests__/wallets.spec.tsx index b74579950238..18908b25a607 100644 --- a/packages/appstore/src/components/containers/__tests__/wallets.spec.tsx +++ b/packages/appstore/src/components/containers/__tests__/wallets.spec.tsx @@ -1,10 +1,10 @@ import React from 'react'; -import { render, screen } from '@testing-library/react'; +import { render, screen, waitFor } from '@testing-library/react'; import '@testing-library/jest-dom'; import userEvent from '@testing-library/user-event'; import { mockStore, StoreProvider } from '@deriv/stores'; -import { TCoreStores } from '@deriv/stores/types'; import Wallet from '../wallet'; +import { TWalletAccount } from 'Types'; const mockedRootStore = mockStore({ modules: { @@ -14,46 +14,53 @@ const mockedRootStore = mockStore({ }, }); +jest.mock('react-transition-group', () => ({ + CSSTransition: jest.fn(({ children }) =>