From 4c481a74cf403d89dd97943e240fc1480dcce24c Mon Sep 17 00:00:00 2001 From: Hamid Date: Tue, 27 Sep 2022 11:34:04 +0330 Subject: [PATCH] hamid/74066/migrate-shared-components-to-ts (#6342) * Migrate Error to TS * Migrate ResendEmailButtonWrapper to TS * Migrate SideNote to TS * Migrate USDTSideNote to TS * Fix typo * Rename RootStore to TRootStore Co-authored-by: Carol Sachdeva <58209918+carol-binary@users.noreply.github.com> --- .../cashier-container/virtual/virtual.tsx | 4 +- .../cashier-locked/cashier-locked.tsx | 4 +- .../crypto-fiat-converter.tsx | 4 +- .../crypto-transactions-cancel-modal.tsx | 4 +- .../crypto-transactions-history.tsx | 4 +- .../crypto-transactions-renderer.tsx | 4 +- .../crypto-transactions-status-modal.tsx | 4 +- .../components/error-dialog/error-dialog.tsx | 4 +- .../{error.spec.js => error.spec.tsx} | 3 +- .../components/error/{error.jsx => error.tsx} | 40 +++++++++---- .../cashier/src/components/error/index.js | 3 - .../cashier/src/components/error/index.ts | 3 + .../funds-protection/funds-protection.tsx | 4 +- .../src/components/no-balance/no-balance.tsx | 4 +- .../recent-transaction/recent-transaction.tsx | 4 +- ...s => resend-email-button-wrapper.spec.tsx} | 2 +- .../{index.js => index.ts} | 2 +- ...er.jsx => resend-email-button-wrapper.tsx} | 18 +++--- .../{side-note.spec.js => side-note.spec.tsx} | 6 +- .../cashier/src/components/side-note/index.js | 3 - .../cashier/src/components/side-note/index.ts | 3 + .../{side-note.jsx => side-note.tsx} | 59 +++++++++++++------ ...e-note.spec.js => usdt-side-note.spec.tsx} | 0 .../src/components/usdt-side-note/index.js | 3 - .../src/components/usdt-side-note/index.ts | 3 + ...{usdt-side-note.jsx => usdt-side-note.tsx} | 6 +- .../src/types/stores/root-store.types.ts | 4 +- 27 files changed, 123 insertions(+), 79 deletions(-) rename packages/cashier/src/components/error/__tests__/{error.spec.js => error.spec.tsx} (97%) rename packages/cashier/src/components/error/{error.jsx => error.tsx} (84%) delete mode 100644 packages/cashier/src/components/error/index.js create mode 100644 packages/cashier/src/components/error/index.ts rename packages/cashier/src/components/resend-email-button-wrapper/__tests__/{resend-email-button-wrapper.spec.js => resend-email-button-wrapper.spec.tsx} (95%) rename packages/cashier/src/components/resend-email-button-wrapper/{index.js => index.ts} (91%) rename packages/cashier/src/components/resend-email-button-wrapper/{resend-email-button-wrapper.jsx => resend-email-button-wrapper.tsx} (74%) rename packages/cashier/src/components/side-note/__tests__/{side-note.spec.js => side-note.spec.tsx} (75%) delete mode 100644 packages/cashier/src/components/side-note/index.js create mode 100644 packages/cashier/src/components/side-note/index.ts rename packages/cashier/src/components/side-note/{side-note.jsx => side-note.tsx} (61%) rename packages/cashier/src/components/usdt-side-note/__tests__/{usdt-side-note.spec.js => usdt-side-note.spec.tsx} (100%) delete mode 100644 packages/cashier/src/components/usdt-side-note/index.js create mode 100644 packages/cashier/src/components/usdt-side-note/index.ts rename packages/cashier/src/components/usdt-side-note/{usdt-side-note.jsx => usdt-side-note.tsx} (96%) diff --git a/packages/cashier/src/components/cashier-container/virtual/virtual.tsx b/packages/cashier/src/components/cashier-container/virtual/virtual.tsx index 1ec15974fac2..ac903c10066c 100644 --- a/packages/cashier/src/components/cashier-container/virtual/virtual.tsx +++ b/packages/cashier/src/components/cashier-container/virtual/virtual.tsx @@ -6,7 +6,7 @@ import { Text } from '@deriv/components'; import { isMobile } from '@deriv/shared'; import { Localize } from '@deriv/translations'; import { connect } from 'Stores/connect'; -import { RootStore } from 'Types'; +import { TRootStore } from 'Types'; import './virtual.scss'; type TVirtualProps = RouteComponentProps & { @@ -51,7 +51,7 @@ const Virtual = ({ is_dark_mode_on, toggleAccountsDialog }: TVirtualProps) => { ); }; -export default connect(({ ui }: RootStore) => ({ +export default connect(({ ui }: TRootStore) => ({ is_dark_mode_on: ui.is_dark_mode_on, toggleAccountsDialog: ui.toggleAccountsDialog, }))(withRouter(Virtual)); diff --git a/packages/cashier/src/components/cashier-locked/cashier-locked.tsx b/packages/cashier/src/components/cashier-locked/cashier-locked.tsx index 806231bb3603..01f4b193b38f 100644 --- a/packages/cashier/src/components/cashier-locked/cashier-locked.tsx +++ b/packages/cashier/src/components/cashier-locked/cashier-locked.tsx @@ -4,7 +4,7 @@ import { Icon, Text } from '@deriv/components'; import { localize, Localize } from '@deriv/translations'; import { formatDate } from '@deriv/shared'; import { connect } from 'Stores/connect'; -import { RootStore } from 'Types'; +import { TRootStore } from 'Types'; type TAccount = NonNullable[0]; @@ -292,7 +292,7 @@ const CashierLocked = ({ ); }; -export default connect(({ client, modules }: RootStore) => ({ +export default connect(({ client, modules }: TRootStore) => ({ account_status: client.account_status, accounts: client.accounts, current_currency_type: client.current_currency_type, diff --git a/packages/cashier/src/components/crypto-fiat-converter/crypto-fiat-converter.tsx b/packages/cashier/src/components/crypto-fiat-converter/crypto-fiat-converter.tsx index fe2c7394af87..017d06270a8d 100644 --- a/packages/cashier/src/components/crypto-fiat-converter/crypto-fiat-converter.tsx +++ b/packages/cashier/src/components/crypto-fiat-converter/crypto-fiat-converter.tsx @@ -4,7 +4,7 @@ import { DesktopWrapper, Input, Icon, MobileWrapper, Text, useInterval } from '@ import { getCurrencyDisplayCode } from '@deriv/shared'; import { localize, Localize } from '@deriv/translations'; import { connect } from 'Stores/connect'; -import { RootStore, TReactChangeEvent, TReactChildren } from 'Types'; +import { TRootStore, TReactChangeEvent, TReactChildren } from 'Types'; import './crypto-fiat-converter.scss'; type TTimerProps = { @@ -170,7 +170,7 @@ const CryptoFiatConverter = ({ ); }; -export default connect(({ modules }: RootStore) => ({ +export default connect(({ modules }: TRootStore) => ({ converter_from_amount: modules.cashier.crypto_fiat_converter.converter_from_amount, converter_from_error: modules.cashier.crypto_fiat_converter.converter_from_error, converter_to_error: modules.cashier.crypto_fiat_converter.converter_to_error, diff --git a/packages/cashier/src/components/crypto-transactions-history/crypto-transactions-cancel-modal.tsx b/packages/cashier/src/components/crypto-transactions-history/crypto-transactions-cancel-modal.tsx index 773badbbd6e7..bd76cfa576f5 100644 --- a/packages/cashier/src/components/crypto-transactions-history/crypto-transactions-cancel-modal.tsx +++ b/packages/cashier/src/components/crypto-transactions-history/crypto-transactions-cancel-modal.tsx @@ -2,7 +2,7 @@ import React from 'react'; import { Button, Modal } from '@deriv/components'; import { localize, Localize } from '@deriv/translations'; import { connect } from 'Stores/connect'; -import { RootStore } from 'Types'; +import { TRootStore } from 'Types'; type TCryptoTransactionsCancelModalProps = { cancelCryptoTransaction: (selected_crypto_transaction_id: string) => void; @@ -45,7 +45,7 @@ const CryptoTransactionsCancelModal = ({ ); }; -export default connect(({ modules }: RootStore) => ({ +export default connect(({ modules }: TRootStore) => ({ cancelCryptoTransaction: modules.cashier.transaction_history.cancelCryptoTransaction, hideCryptoTransactionsCancelModal: modules.cashier.transaction_history.hideCryptoTransactionsCancelModal, is_cancel_modal_visible: modules.cashier.transaction_history.is_crypto_transactions_cancel_modal_visible, diff --git a/packages/cashier/src/components/crypto-transactions-history/crypto-transactions-history.tsx b/packages/cashier/src/components/crypto-transactions-history/crypto-transactions-history.tsx index 47c5a24fd6c4..66b312dbd8d1 100644 --- a/packages/cashier/src/components/crypto-transactions-history/crypto-transactions-history.tsx +++ b/packages/cashier/src/components/crypto-transactions-history/crypto-transactions-history.tsx @@ -3,7 +3,7 @@ import { DataList, Icon, Loading, MobileWrapper, Table, Text } from '@deriv/comp import { isDesktop, isMobile, routes } from '@deriv/shared'; import { localize, Localize } from '@deriv/translations'; import { connect } from 'Stores/connect'; -import { RootStore, TCryptoTransactionDetails } from 'Types'; +import { TRootStore, TCryptoTransactionDetails } from 'Types'; import CryptoTransactionsCancelModal from './crypto-transactions-cancel-modal'; import CryptoTransactionsStatusModal from './crypto-transactions-status-modal'; import CryptoTransactionsRenderer from './crypto-transactions-renderer'; @@ -102,7 +102,7 @@ const CryptoTransactionsHistory = ({ ); }; -export default connect(({ client, modules }: RootStore) => ({ +export default connect(({ client, modules }: TRootStore) => ({ crypto_transactions: modules.cashier.transaction_history.crypto_transactions, currency: client.currency, is_loading: modules.cashier.transaction_history.is_loading, diff --git a/packages/cashier/src/components/crypto-transactions-history/crypto-transactions-renderer.tsx b/packages/cashier/src/components/crypto-transactions-history/crypto-transactions-renderer.tsx index d282b5444bbb..88af614491d5 100644 --- a/packages/cashier/src/components/crypto-transactions-history/crypto-transactions-renderer.tsx +++ b/packages/cashier/src/components/crypto-transactions-history/crypto-transactions-renderer.tsx @@ -5,7 +5,7 @@ import { epochToMoment, formatMoney, isMobile } from '@deriv/shared'; import { localize, Localize } from '@deriv/translations'; import { getStatus } from 'Constants/transaction-status'; import { connect } from 'Stores/connect'; -import { RootStore, TCryptoTransactionDetails } from 'Types'; +import { TRootStore, TCryptoTransactionDetails } from 'Types'; type TCryptoTransactionsRendererProps = { row: TCryptoTransactionDetails; @@ -304,7 +304,7 @@ const CryptoTransactionsRenderer = ({ ); }; -export default connect(({ client, modules }: RootStore) => ({ +export default connect(({ client, modules }: TRootStore) => ({ currency: client.currency, cancelCryptoTransaction: modules.cashier.transaction_history.cancelCryptoTransaction, showCryptoTransactionsCancelModal: modules.cashier.transaction_history.showCryptoTransactionsCancelModal, diff --git a/packages/cashier/src/components/crypto-transactions-history/crypto-transactions-status-modal.tsx b/packages/cashier/src/components/crypto-transactions-history/crypto-transactions-status-modal.tsx index 7cb3aa5fbc0e..c299ae10c408 100644 --- a/packages/cashier/src/components/crypto-transactions-history/crypto-transactions-status-modal.tsx +++ b/packages/cashier/src/components/crypto-transactions-history/crypto-transactions-status-modal.tsx @@ -2,7 +2,7 @@ import React from 'react'; import { Button, Modal } from '@deriv/components'; import { localize } from '@deriv/translations'; import { connect } from 'Stores/connect'; -import { TReactMouseEvent, RootStore } from 'Types'; +import { TReactMouseEvent, TRootStore } from 'Types'; type TCryptoTransactionsStatusModalProps = { hideCryptoTransactionsStatusModal: (e: TReactMouseEvent) => void; @@ -34,7 +34,7 @@ const CryptoTransactionsStatusModal = ({ ); }; -export default connect(({ modules }: RootStore) => ({ +export default connect(({ modules }: TRootStore) => ({ hideCryptoTransactionsStatusModal: modules.cashier.transaction_history.hideCryptoTransactionsStatusModal, is_status_modal_visible: modules.cashier.transaction_history.is_crypto_transactions_status_modal_visible, selected_crypto_status: modules.cashier.transaction_history.selected_crypto_status, diff --git a/packages/cashier/src/components/error-dialog/error-dialog.tsx b/packages/cashier/src/components/error-dialog/error-dialog.tsx index d30581334615..b8419cb429c7 100644 --- a/packages/cashier/src/components/error-dialog/error-dialog.tsx +++ b/packages/cashier/src/components/error-dialog/error-dialog.tsx @@ -4,7 +4,7 @@ import { Dialog } from '@deriv/components'; import { localize, Localize } from '@deriv/translations'; import { routes } from '@deriv/shared'; import { connect } from 'Stores/connect'; -import { RootStore, TError, TReactElement } from 'Types'; +import { TRootStore, TError, TReactElement } from 'Types'; type TErrorDialogProps = { disableApp: () => void; @@ -148,7 +148,7 @@ const ErrorDialog = ({ disableApp, enableApp, error = {} }: TErrorDialogProps) = ); }; -export default connect(({ ui }: RootStore) => ({ +export default connect(({ ui }: TRootStore) => ({ disableApp: ui.disableApp, enableApp: ui.enableApp, }))(ErrorDialog); diff --git a/packages/cashier/src/components/error/__tests__/error.spec.js b/packages/cashier/src/components/error/__tests__/error.spec.tsx similarity index 97% rename from packages/cashier/src/components/error/__tests__/error.spec.js rename to packages/cashier/src/components/error/__tests__/error.spec.tsx index c44e79e2c0bc..c07f8420fc67 100644 --- a/packages/cashier/src/components/error/__tests__/error.spec.js +++ b/packages/cashier/src/components/error/__tests__/error.spec.tsx @@ -62,13 +62,14 @@ describe('', () => { }); it('should clear an error.message if one of the buttons ["Resend email", "Update my details", "Try again"] was clicked', () => { - let checkButton = (btn_name, error_code) => { + const checkButton = (btn_name, error_code) => { const history = createBrowserHistory(); const error = { code: error_code, setErrorMessage(value) { this.message = value; }, + message: '', }; const { unmount } = render( diff --git a/packages/cashier/src/components/error/error.jsx b/packages/cashier/src/components/error/error.tsx similarity index 84% rename from packages/cashier/src/components/error/error.jsx rename to packages/cashier/src/components/error/error.tsx index 5bbcc80ae37a..15f312a85105 100644 --- a/packages/cashier/src/components/error/error.jsx +++ b/packages/cashier/src/components/error/error.tsx @@ -1,11 +1,33 @@ -import PropTypes from 'prop-types'; import React from 'react'; import { Button, Icon, ButtonLink, StaticUrl, Text } from '@deriv/components'; import { isMobile } from '@deriv/shared'; import { localize, Localize } from '@deriv/translations'; import './error.scss'; -const ErrorComponent = ({ header, message, button_link, onClickButton, button_text, footer }) => ( +type TErrorComponentProps = { + button_link?: string; + button_text?: string; + footer?: JSX.Element; + header?: JSX.Element | string; + message?: JSX.Element; + onClickButton?: () => void; +}; + +type TErrorFields = { + [k: string]: string; +}; + +type TErrorProps = { + error: { + onClickButton?: () => void; + setErrorMessage?: (message: string) => void; + message?: JSX.Element | string; + code?: string; + fields?: string[]; + }; +}; + +const ErrorComponent = ({ header, message, button_link, onClickButton, button_text, footer }: TErrorComponentProps) => (
{header && ( @@ -34,8 +56,8 @@ const ErrorComponent = ({ header, message, button_link, onClickButton, button_te
); -const Error = ({ error }) => { - const error_fields = { +const Error = ({ error }: TErrorProps) => { + const error_fields: TErrorFields = { address_city: localize('Town/City'), address_line_1: localize('First line of home address'), address_postcode: localize('Postal Code/ZIP'), @@ -53,7 +75,7 @@ const Error = ({ error }) => { }; const clearErrorMessage = () => { - error.setErrorMessage(''); + error.setErrorMessage?.(''); }; let AccountError; @@ -86,7 +108,9 @@ const Error = ({ error }) => { error_fields[field] || field).join(', '), + details: error.fields + .map((field: string) => error_fields[field] || field) + .join(', '), interpolation: { escapeValue: false }, }} /> @@ -126,8 +150,4 @@ const Error = ({ error }) => { return AccountError; }; -Error.propTypes = { - error: PropTypes.object, -}; - export default Error; diff --git a/packages/cashier/src/components/error/index.js b/packages/cashier/src/components/error/index.js deleted file mode 100644 index 44f86e2b30ee..000000000000 --- a/packages/cashier/src/components/error/index.js +++ /dev/null @@ -1,3 +0,0 @@ -import Error from './error.jsx'; - -export default Error; diff --git a/packages/cashier/src/components/error/index.ts b/packages/cashier/src/components/error/index.ts new file mode 100644 index 000000000000..882a0f2fb0a7 --- /dev/null +++ b/packages/cashier/src/components/error/index.ts @@ -0,0 +1,3 @@ +import Error from './error'; + +export default Error; diff --git a/packages/cashier/src/components/funds-protection/funds-protection.tsx b/packages/cashier/src/components/funds-protection/funds-protection.tsx index 43c59cc12dca..7470280414e8 100644 --- a/packages/cashier/src/components/funds-protection/funds-protection.tsx +++ b/packages/cashier/src/components/funds-protection/funds-protection.tsx @@ -2,7 +2,7 @@ import React from 'react'; import { Icon, Button, Text } from '@deriv/components'; import { Localize, localize } from '@deriv/translations'; import { connect } from 'Stores/connect'; -import { RootStore } from 'Types'; +import { TRootStore } from 'Types'; import './funds-protection.scss'; type TFundsProtectionProps = { @@ -40,6 +40,6 @@ const FundsProtection = ({ submitFundsProtection }: TFundsProtectionProps) => { ); }; -export default connect(({ modules }: RootStore) => ({ +export default connect(({ modules }: TRootStore) => ({ submitFundsProtection: modules.cashier.deposit.submitFundsProtection, }))(FundsProtection); diff --git a/packages/cashier/src/components/no-balance/no-balance.tsx b/packages/cashier/src/components/no-balance/no-balance.tsx index cc14972dad4f..b9be2e56d45d 100644 --- a/packages/cashier/src/components/no-balance/no-balance.tsx +++ b/packages/cashier/src/components/no-balance/no-balance.tsx @@ -4,7 +4,7 @@ import { Button, Icon, Text } from '@deriv/components'; import { routes, getCurrencyDisplayCode } from '@deriv/shared'; import { localize, Localize } from '@deriv/translations'; import { connect } from 'Stores/connect'; -import { RootStore } from 'Types'; +import { TRootStore } from 'Types'; type TNoBalanceProps = RouteComponentProps & { currency: string; @@ -48,7 +48,7 @@ const NoBalance = ({ currency, history, is_deposit_locked, setTabIndex }: TNoBal }; export default withRouter( - connect(({ client, modules }: RootStore) => ({ + connect(({ client, modules }: TRootStore) => ({ currency: client.currency, is_deposit_locked: modules.cashier.deposit.is_deposit_locked, setTabIndex: modules.cashier.general_store.setCashierTabIndex, diff --git a/packages/cashier/src/components/recent-transaction/recent-transaction.tsx b/packages/cashier/src/components/recent-transaction/recent-transaction.tsx index 6fedbccfed3e..909b937e4914 100644 --- a/packages/cashier/src/components/recent-transaction/recent-transaction.tsx +++ b/packages/cashier/src/components/recent-transaction/recent-transaction.tsx @@ -4,7 +4,7 @@ import { ButtonLink, Text, Icon } from '@deriv/components'; import { Localize } from '@deriv/translations'; import { epochToMoment } from '@deriv/shared'; import { connect } from 'Stores/connect'; -import { RootStore } from 'Types'; +import { TRootStore } from 'Types'; import { getStatus } from 'Constants/transaction-status'; import './recent-transaction.scss'; @@ -132,7 +132,7 @@ const RecentTransaction = ({ ); }; -export default connect(({ modules, client }: RootStore) => ({ +export default connect(({ modules, client }: TRootStore) => ({ crypto_transactions: modules.cashier.transaction_history.crypto_transactions, currency: client.currency, onMount: modules.cashier.transaction_history.onMount, diff --git a/packages/cashier/src/components/resend-email-button-wrapper/__tests__/resend-email-button-wrapper.spec.js b/packages/cashier/src/components/resend-email-button-wrapper/__tests__/resend-email-button-wrapper.spec.tsx similarity index 95% rename from packages/cashier/src/components/resend-email-button-wrapper/__tests__/resend-email-button-wrapper.spec.js rename to packages/cashier/src/components/resend-email-button-wrapper/__tests__/resend-email-button-wrapper.spec.tsx index 50f335d3b9c0..60677f609ea2 100644 --- a/packages/cashier/src/components/resend-email-button-wrapper/__tests__/resend-email-button-wrapper.spec.js +++ b/packages/cashier/src/components/resend-email-button-wrapper/__tests__/resend-email-button-wrapper.spec.tsx @@ -26,7 +26,7 @@ describe('', () => { it('Resend button should not be disabled when resend_timeout is greater then 60', () => { render(); - expect(screen.getByRole('button')).not.toBeDisabled(); + expect(screen.getByRole('button')).toBeEnabled(); }); it('resendVerificationEmail function to be called when resend button is called', () => { diff --git a/packages/cashier/src/components/resend-email-button-wrapper/index.js b/packages/cashier/src/components/resend-email-button-wrapper/index.ts similarity index 91% rename from packages/cashier/src/components/resend-email-button-wrapper/index.js rename to packages/cashier/src/components/resend-email-button-wrapper/index.ts index e3af9c4d1a41..a434c00dc2e1 100644 --- a/packages/cashier/src/components/resend-email-button-wrapper/index.js +++ b/packages/cashier/src/components/resend-email-button-wrapper/index.ts @@ -1,3 +1,3 @@ -import ResendEmailButtonWrapper from './resend-email-button-wrapper.jsx'; +import ResendEmailButtonWrapper from './resend-email-button-wrapper'; export default ResendEmailButtonWrapper; diff --git a/packages/cashier/src/components/resend-email-button-wrapper/resend-email-button-wrapper.jsx b/packages/cashier/src/components/resend-email-button-wrapper/resend-email-button-wrapper.tsx similarity index 74% rename from packages/cashier/src/components/resend-email-button-wrapper/resend-email-button-wrapper.jsx rename to packages/cashier/src/components/resend-email-button-wrapper/resend-email-button-wrapper.tsx index b8fb7f6a152a..b7af0537c0a3 100644 --- a/packages/cashier/src/components/resend-email-button-wrapper/resend-email-button-wrapper.jsx +++ b/packages/cashier/src/components/resend-email-button-wrapper/resend-email-button-wrapper.tsx @@ -1,10 +1,16 @@ -import PropTypes from 'prop-types'; import React from 'react'; import { Button } from '@deriv/components'; import { localize } from '@deriv/translations'; import { connect } from 'Stores/connect'; +import { TRootStore } from 'Types'; -const ResendEmailButtonWrapper = ({ resend_timeout, resendVerificationEmail }) => ( +type TResetEmailButtonWrapperProps = { + is_withdrawal: boolean; + resend_timeout: number; + resendVerificationEmail: () => void; +}; + +const ResendEmailButtonWrapper = ({ resend_timeout, resendVerificationEmail }: TResetEmailButtonWrapperProps) => (