Skip to content
Open
Show file tree
Hide file tree
Changes from 5 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
12 changes: 10 additions & 2 deletions src/libs/actions/MergeAccounts.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import {Str} from 'expensify-common';
import Onyx from 'react-native-onyx';
import type {OnyxUpdate} from 'react-native-onyx';
import * as API from '@libs/API';
import type {GetValidateCodeForAccountMergeParams, MergeWithValidateCodeParams} from '@libs/API/parameters';
import {WRITE_COMMANDS} from '@libs/API/types';
import {appendCountryCode} from '@libs/LoginUtils';
import {parsePhoneNumber} from '@libs/PhoneNumber';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';

function requestValidationCodeForAccountMerge(email: string, validateCodeResent = false) {
function requestValidationCodeForAccountMerge(email: string, validateCodeResent = false, countryCode: number = CONST.DEFAULT_COUNTRY_CODE) {
// Normalize the email/phone input
const parsedPhoneNumber = parsePhoneNumber(appendCountryCode(Str.removeSMSDomain(email), countryCode));
const normalizedEmail = parsedPhoneNumber.possible && parsedPhoneNumber.number?.e164 ? parsedPhoneNumber.number.e164 : email.toLowerCase();

const optimisticData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
Expand Down Expand Up @@ -51,7 +59,7 @@ function requestValidationCodeForAccountMerge(email: string, validateCodeResent
];

const parameters: GetValidateCodeForAccountMergeParams = {
email,
email: normalizedEmail,
};

API.write(WRITE_COMMANDS.GET_VALIDATE_CODE_FOR_ACCOUNT_MERGE, parameters, {optimisticData, successData, failureData});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ function AccountDetailsPage() {
<FormProvider
formID={ONYXKEYS.FORMS.MERGE_ACCOUNT_DETAILS_FORM}
onSubmit={(values) => {
requestValidationCodeForAccountMerge(values[INPUT_IDS.PHONE_OR_EMAIL]);
requestValidationCodeForAccountMerge(values[INPUT_IDS.PHONE_OR_EMAIL], false, countryCode);
}}
style={[styles.flexGrow1, styles.mh5]}
shouldTrimValues
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ function AccountValidatePage() {
canBeMissing: true,
});

const [countryCode = CONST.DEFAULT_COUNTRY_CODE] = useOnyx(ONYXKEYS.COUNTRY_CODE, {canBeMissing: false});

const privateSubscription = usePrivateSubscription();
const currentUserPersonalDetails = useCurrentUserPersonalDetails();

Expand Down Expand Up @@ -190,7 +192,7 @@ function AccountValidatePage() {
mergeWithValidateCodeAction(email, code);
}}
sendValidateCode={() => {
requestValidationCodeForAccountMerge(email, true);
requestValidationCodeForAccountMerge(email, true, countryCode);
}}
shouldSkipInitialValidation
clearError={() => clearMergeWithValidateCode()}
Expand Down
Loading