Skip to content

Commit

Permalink
WALL-2712/chore: make get_settings api call for idv and poa screen (b…
Browse files Browse the repository at this point in the history
…inary-com#11660)

* chore: make get_settings api call for idv and poa screen

* chore: komen
  • Loading branch information
thisyahlen-deriv committed Nov 22, 2023
1 parent 4be4ccb commit baab0db
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ import React from 'react';
import { useSettings } from '@deriv/api';
import { FlowTextField, InlineMessage, WalletText } from '../../../../../../components';
import SideNote from '../../../../../../public/images/accounts/side-note-example-image.svg';
import unixToDateString from '../../../../utils';
import { dateOfBirthValidator, firstNameValidator, lastNameValidator } from '../../../../validations';
import './IDVDocumentUploadDetails.scss';

const IDVDocumentUploadDetails = () => {
const { data: getSettings } = useSettings();

const dateOfBirth = getSettings?.date_of_birth || 0;

return (
<div className='wallets-idv-document-details'>
<InlineMessage>
Expand Down Expand Up @@ -37,6 +40,7 @@ const IDVDocumentUploadDetails = () => {
/>
{/* TODO: Replace with DatePicker component*/}
<FlowTextField
defaultValue={unixToDateString(dateOfBirth)}
label='Date of birth*'
message='Your date of birth as in your identity document'
name='dateOfBirth'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const PersonalDetails = () => {
variant='comboBox'
/>
<FlowTextField
defaultValue={getSettings?.tax_identification_number ?? formValues?.taxIdentificationNumber}
errorMessage={'Please fill in tax residence'}
isInvalid={!formValues.taxResidence || !formValues.taxIdentificationNumber}
label='Tax identification number*'
Expand Down
10 changes: 10 additions & 0 deletions packages/wallets/src/features/accounts/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default function unixToDateString(unixTimestamp: number): string {
const date = new Date(unixTimestamp * 1000);

//ensure that the day and month always have two digits.
const day = String(date.getDate()).padStart(2, '0');
const month = String(date.getMonth() + 1).padStart(2, '0');
const year = date.getFullYear();

return `${year}-${month}-${day}`;
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const Verification: FC<TVerificationProps> = ({ selectedJurisdiction }) => {
const { data: poiStatus, isSuccess: isSuccessPOIStatus } = usePOI();
const { data: poaStatus, isSuccess: isSuccessPOAStatus } = usePOA();
const { data: authenticationData } = useAuthentication();
const { data: getSettings } = useSettings();
const { data: getSettings, update: updateSettings } = useSettings();
const { getModalState, hide, show } = useModal();

const selectedMarketType = getModalState('marketType') || 'all';
Expand Down Expand Up @@ -104,8 +104,17 @@ const Verification: FC<TVerificationProps> = ({ selectedJurisdiction }) => {
}
};

const nextFlowHandler = ({ currentScreenId, switchScreen }: TFlowProviderContext<typeof screens>) => {
const nextFlowHandler = ({ currentScreenId, formValues, switchScreen }: TFlowProviderContext<typeof screens>) => {
if (['idvScreen', 'onfidoScreen', 'manualScreen'].includes(currentScreenId)) {
if (currentScreenId === 'idvScreen') {
updateSettings({
date_of_birth: formValues.dateOfBirth,
first_name: formValues.firstName,
last_name: formValues.lastName,
});
} else if (currentScreenId === 'manualScreen') {
// TODO: call the api here
}
if (hasAttemptedPOA) {
switchScreen('poaScreen');
} else if (!getSettings?.has_submitted_personal_details) {
Expand All @@ -114,8 +123,22 @@ const Verification: FC<TVerificationProps> = ({ selectedJurisdiction }) => {
show(<MT5PasswordModal marketType={selectedMarketType} platform={platform} />);
}
} else if (currentScreenId === 'poaScreen') {
updateSettings({
address_city: formValues.townCityLine,
address_line_1: formValues.firstLine,
address_line_2: formValues.secondLine,
address_postcode: formValues.zipCodeLine,
address_state: formValues.stateProvinceDropdownLine,
});
switchScreen('personalDetailsScreen');
} else if (currentScreenId === 'personalDetailsScreen') {
updateSettings({
account_opening_reason: formValues.accountOpeningReason,
citizen: formValues.citizenship,
place_of_birth: formValues.placeOfBirth,
tax_identification_number: formValues.taxIdentificationNumber,
tax_residence: formValues.taxResidence,
});
show(<MT5PasswordModal marketType={selectedMarketType} platform={platform} />);
} else {
hide();
Expand Down

0 comments on commit baab0db

Please sign in to comment.