From b6e3955141e4f2937a3a49176578d776540dba94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cyauheni-kryzhyk-deriv=E2=80=9D?= <“yauheni@deriv.me”> Date: Tue, 26 Sep 2023 17:41:11 +0300 Subject: [PATCH] chore: poo ts --- .../Verification/ProofOfOwnership/index.js | 3 --- .../Verification/ProofOfOwnership/index.ts | 3 +++ ...f-ownership.jsx => proof-of-ownership.tsx} | 25 +++++++++++-------- packages/account/src/Types/common.type.ts | 11 +++++--- 4 files changed, 25 insertions(+), 17 deletions(-) delete mode 100644 packages/account/src/Sections/Verification/ProofOfOwnership/index.js create mode 100644 packages/account/src/Sections/Verification/ProofOfOwnership/index.ts rename packages/account/src/Sections/Verification/ProofOfOwnership/{proof-of-ownership.jsx => proof-of-ownership.tsx} (75%) diff --git a/packages/account/src/Sections/Verification/ProofOfOwnership/index.js b/packages/account/src/Sections/Verification/ProofOfOwnership/index.js deleted file mode 100644 index 3e8b8cd6b9a9..000000000000 --- a/packages/account/src/Sections/Verification/ProofOfOwnership/index.js +++ /dev/null @@ -1,3 +0,0 @@ -import POO from './proof-of-ownership.jsx'; - -export default POO; diff --git a/packages/account/src/Sections/Verification/ProofOfOwnership/index.ts b/packages/account/src/Sections/Verification/ProofOfOwnership/index.ts new file mode 100644 index 000000000000..4ffb8f05098c --- /dev/null +++ b/packages/account/src/Sections/Verification/ProofOfOwnership/index.ts @@ -0,0 +1,3 @@ +import POO from './proof-of-ownership'; + +export default POO; diff --git a/packages/account/src/Sections/Verification/ProofOfOwnership/proof-of-ownership.jsx b/packages/account/src/Sections/Verification/ProofOfOwnership/proof-of-ownership.tsx similarity index 75% rename from packages/account/src/Sections/Verification/ProofOfOwnership/proof-of-ownership.jsx rename to packages/account/src/Sections/Verification/ProofOfOwnership/proof-of-ownership.tsx index 0fc03d9135ec..aaeff6eeff4e 100644 --- a/packages/account/src/Sections/Verification/ProofOfOwnership/proof-of-ownership.jsx +++ b/packages/account/src/Sections/Verification/ProofOfOwnership/proof-of-ownership.tsx @@ -1,38 +1,43 @@ import React, { useEffect, useState } from 'react'; import { withRouter } from 'react-router-dom'; +import { GetAccountStatus } from '@deriv/api-types'; import { Loading } from '@deriv/components'; import { observer, useStore } from '@deriv/stores'; import ProofOfOwnershipForm from './proof-of-ownership-form.jsx'; import { POONotRequired, POOVerified, POORejetced, POOSubmitted } from 'Components/poo/statuses'; -import { POO_STATUSES } from '../../../Constants/poo-identifier.ts'; +import { POO_STATUSES } from 'Constants/poo-identifier'; import getPaymentMethodsConfig from '../../../Configs/payment-method-config'; +import { TPaymentMethod, TPaymentMethodIdentifier, TPaymentMethodInfo } from 'Types'; export const ProofOfOwnership = observer(() => { const { client, notifications, ui } = useStore(); const { account_status, email: client_email, updateAccountStatus } = client; const { refreshNotifications } = notifications; const { is_dark_mode_on: is_dark_mode } = ui; - const cards = account_status?.authentication?.ownership?.requests; + const cards = account_status?.authentication?.ownership + ?.requests as DeepRequired['authentication']['ownership']['requests']; const [status, setStatus] = useState(POO_STATUSES.NONE); const citizen = client?.account_settings?.citizen || client?.account_settings?.country_code; const grouped_payment_method_data = React.useMemo(() => { - const groups = {}; + const groups: Partial> = {}; const payment_methods_config = getPaymentMethodsConfig(); cards?.forEach(card => { + const card_payment_method = card?.payment_method?.toLowerCase() || ''; const card_details = - payment_methods_config[card.payment_method.toLowerCase()] || payment_methods_config.other; - if (groups[card?.payment_method?.toLowerCase()]) { - groups[card?.payment_method?.toLowerCase()].items.push(card); + payment_methods_config[card_payment_method as TPaymentMethod] || payment_methods_config.other; + + if (groups[card_payment_method as TPaymentMethod]) { + groups[card_payment_method as TPaymentMethod]?.items?.push(card); } else { - groups[card?.payment_method?.toLowerCase()] = { + groups[card_payment_method as TPaymentMethod] = { documents_required: card?.documents_required, icon: is_dark_mode ? card_details?.icon_dark : card_details?.icon_light, payment_method: card?.payment_method, items: [card], instructions: card_details.instructions, input_label: card_details?.input_label, - identifier_type: card_details.identifier_type, + identifier_type: card_details.identifier_type as TPaymentMethodIdentifier, is_generic_pm: !card_details?.input_label, }; } @@ -40,12 +45,12 @@ export const ProofOfOwnership = observer(() => { return { groups }; }, [cards, is_dark_mode]); useEffect(() => { - setStatus(account_status?.authentication?.ownership?.status?.toLowerCase()); + setStatus(account_status?.authentication?.ownership?.status?.toLowerCase() || ''); }, [account_status]); const onTryAgain = () => { setStatus(POO_STATUSES.NONE); }; - if (cards?.length > 0 && status !== POO_STATUSES.REJECTED) { + if (cards?.length && status !== POO_STATUSES.REJECTED) { return ( ['ownership']>['requests']; - instructions: Array; - input_label: string; + items: DeepRequired['authentication']['ownership']['requests']; + instructions: string[] | JSX.Element[]; + input_label: string | null; identifier_type: TPaymentMethodIdentifier; is_generic_pm: boolean; }; + +export type TPaymentMethod = keyof ReturnType;