Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: poo ts #52

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import POO from './proof-of-ownership';

export default POO;
Original file line number Diff line number Diff line change
@@ -1,51 +1,56 @@
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<GetAccountStatus>['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<Record<TPaymentMethod, TPaymentMethodInfo>> = {};
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,
};
}
});
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 (
<ProofOfOwnershipForm
grouped_payment_method_data={grouped_payment_method_data.groups}
Expand Down
11 changes: 7 additions & 4 deletions packages/account/src/Types/common.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -202,9 +203,11 @@ export type TPaymentMethodInfo = {
documents_required: number;
icon: string;
payment_method: string;
items: NonNullable<NonNullable<GetAccountStatus['authentication']>['ownership']>['requests'];
instructions: Array<string>;
input_label: string;
items: DeepRequired<GetAccountStatus>['authentication']['ownership']['requests'];
instructions: string[] | JSX.Element[];
input_label: string | null;
identifier_type: TPaymentMethodIdentifier;
is_generic_pm: boolean;
};

export type TPaymentMethod = keyof ReturnType<typeof getPaymentMethodsConfig>;
Loading