diff --git a/packages/account/src/Containers/proof-of-ownership/card.tsx b/packages/account/src/Containers/proof-of-ownership/card.tsx index c3b300042744..6933af2858b6 100644 --- a/packages/account/src/Containers/proof-of-ownership/card.tsx +++ b/packages/account/src/Containers/proof-of-ownership/card.tsx @@ -5,7 +5,7 @@ import ExpandedCard from './expanded-card'; import { TPaymentMethodInfo } from '../../Types'; type TCardProps = { - details: TPaymentMethodInfo; + details?: TPaymentMethodInfo; index: number; updateErrors: (index: number, item_index: number, sub_index: number) => void; }; @@ -44,13 +44,18 @@ const Card = ({ details, index, updateErrors }: TCardProps) => { return (
- + - {details.payment_method} + {details?.payment_method}
@@ -278,12 +301,4 @@ const ProofOfOwnershipForm = ({ ); }; -ProofOfOwnershipForm.propTypes = { - client_email: PropTypes.string, - grouped_payment_method_data: PropTypes.object, - refreshNotifications: PropTypes.func, - updateAccountStatus: PropTypes.func, - citizen: PropTypes.string, -}; - export default ProofOfOwnershipForm; 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 70% 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..cd8039843e6e 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,42 @@ 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 ProofOfOwnershipForm from './proof-of-ownership-form'; 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 { is_dark_mode_on: is_dark_mode, is_mobile } = ui; 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,19 +44,19 @@ 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 ( ); // Proof of ownership is required. } diff --git a/packages/account/src/Types/common.type.ts b/packages/account/src/Types/common.type.ts index 1df505d78b6c..d245ca855abd 100644 --- a/packages/account/src/Types/common.type.ts +++ b/packages/account/src/Types/common.type.ts @@ -3,8 +3,9 @@ import React from 'react'; import { FormikHandlers, FormikProps, FormikValues } from 'formik'; import { Redirect } from 'react-router-dom'; import { Authorize, GetAccountStatus, IdentityVerificationAddDocumentResponse, ResidenceList } from '@deriv/api-types'; -import { IDENTIFIER_TYPES } from '../Constants/poo-identifier'; import { Platforms } from '@deriv/shared'; +import { IDENTIFIER_TYPES } from '../Constants/poo-identifier'; +import getPaymentMethodsConfig from '../Configs/payment-method-config'; export type TToken = { display_name: string; @@ -192,9 +193,17 @@ export type TPaymentMethodInfo = { documents_required: number; icon: string; payment_method: string; - items: NonNullable['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; + +export type TPaymentMethodUploadData = { + files: Blob[]; + id: number; + payment_method_identifier: string; +} & Pick; diff --git a/packages/shared/src/utils/files/file-uploader-utils.ts b/packages/shared/src/utils/files/file-uploader-utils.ts index 0608bf1cab04..9f91096ec617 100644 --- a/packages/shared/src/utils/files/file-uploader-utils.ts +++ b/packages/shared/src/utils/files/file-uploader-utils.ts @@ -1,29 +1,19 @@ import { compressImg, convertToBase64, isImageType, getFormatFromMIME, TImage, TFile } from './image/image_utility'; export type TSettings = { - documentType: { - passport: string; - national_identity_card: string; - driving_licence: string; - utility_bill: string; - bankstatement: string; - power_of_attorney: string; - amlglobalcheck: string; - docverification: string; - proofid: string; - driverslicense: string; - proofaddress: string; - other: string; - }; - pageType: { - front: string; - back: string; - photo: string; - }; + documentType?: typeof DOCUMENT_TYPE[keyof typeof DOCUMENT_TYPE]; + pageType?: typeof PAGE_TYPE[keyof typeof PAGE_TYPE]; expirationDate?: string; documentId?: string; lifetimeValid?: boolean; document_issuing_country?: string; + proof_of_ownership?: { + details?: { + email: string; + payment_identifier: string; + }; + id?: number; + }; }; type TFileObject = TSettings & { @@ -106,26 +96,26 @@ export const max_document_size = 8388608; export const supported_filetypes = 'image/png, image/jpeg, image/jpg, image/gif, application/pdf'; export const DOCUMENT_TYPE = { - passport: 'passport', - national_identity_card: 'national_identity_card', - driving_licence: 'driving_licence', - utility_bill: 'utility_bill', - bankstatement: 'bankstatement', - power_of_attorney: 'power_of_attorney', amlglobalcheck: 'amlglobalcheck', + bankstatement: 'bankstatement', docverification: 'docverification', - proofid: 'proofid', driverslicense: 'driverslicense', - proofaddress: 'proofaddress', - proof_of_ownership: 'proof_of_ownership', + driving_licence: 'driving_licence', + national_identity_card: 'national_identity_card', other: 'other', -}; + passport: 'passport', + power_of_attorney: 'power_of_attorney', + proof_of_ownership: 'proof_of_ownership', + proofaddress: 'proofaddress', + proofid: 'proofid', + utility_bill: 'utility_bill', +} as const; export const PAGE_TYPE = { - front: 'front', back: 'back', + front: 'front', photo: 'photo', -}; +} as const; export const getSupportedFiles = (filename: string) => /^.*\.(png|PNG|jpg|JPG|jpeg|JPEG|gif|GIF|pdf|PDF)$/.test(filename);