From 7f8b1aa15c808193c25a2bb81b6fc3eaf65ea5f7 Mon Sep 17 00:00:00 2001 From: JavidHaji-zada Date: Fri, 3 Nov 2023 15:35:47 +0400 Subject: [PATCH] Allow only numeric characters in Passcode & minor fix during account creation --- src/components/modular/Passcode/index.tsx | 8 +++++--- src/utils/string.ts | 5 +++-- src/utils/wallet.ts | 7 +++---- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/components/modular/Passcode/index.tsx b/src/components/modular/Passcode/index.tsx index 2badafbc6..6b1f2db81 100644 --- a/src/components/modular/Passcode/index.tsx +++ b/src/components/modular/Passcode/index.tsx @@ -3,6 +3,7 @@ import { View, TextInput } from 'react-native'; import { styles } from '@components/modular/Passcode/styles'; import { Button } from '@components/base'; import { useForwardedRef } from '@hooks'; +import { StringUtils } from '@utils/string'; interface PasscodeProps { onPasscodeChange: (passcode: string[]) => void; @@ -15,11 +16,12 @@ export const Passcode = forwardRef( const localRef = useForwardedRef(ref); const handleCodeChange = (text: string) => { - setCode(text); - const passcodeArray = text.split(''); + const numericText = StringUtils.removeNonNumericCharacters(text, false); + setCode(numericText); + const passcodeArray = numericText.split(''); onPasscodeChange(passcodeArray); if (type === 'change') { - if (text.length === 4) { + if (numericText.length === 4) { setTimeout(() => setCode(''), 50); } } diff --git a/src/utils/string.ts b/src/utils/string.ts index 10fc651f4..23b00014e 100644 --- a/src/utils/string.ts +++ b/src/utils/string.ts @@ -34,9 +34,10 @@ const pluralize = (count: number, str: string, pluralForm?: string): string => { return count + ' ' + finalForm; }; -const removeNonNumericCharacters = (str: string): string => { +const removeNonNumericCharacters = (str: string, allowDot = true): string => { if (!str) return ''; - return str.replace(/[^.\d]+/g, ''); + if (allowDot) return str.replace(/[^.\d]+/g, ''); + return str.replace(/[^\d]+/g, ''); }; const removeNonAlphabeticCharacters = (str: string): string => { diff --git a/src/utils/wallet.ts b/src/utils/wallet.ts index 9fe0da57d..de7b20e6d 100644 --- a/src/utils/wallet.ts +++ b/src/utils/wallet.ts @@ -72,10 +72,10 @@ const processWallet = async (mnemonic: string) => { mnemonic: mnemonic }); const currencyCode = AirDAODictTypes.Code.AMB; // TODO this needs to be changed if we support multiple currencies + // create wallet in db + walletInDb = await WalletDB.createWallet(fullWallet); // eslint-disable-next-line @typescript-eslint/no-unused-vars - const [walletInDbResult, _, accountInDbResult] = await Promise.all([ - // create wallet in db - WalletDB.createWallet(fullWallet), + const [_, accountInDbResult] = await Promise.all([ // securely store private key Cache.setItem( `${CacheKey.WalletPrivateKey}-${fullWallet.hash}`, @@ -90,7 +90,6 @@ const processWallet = async (mnemonic: string) => { currencyCode ) ]); - walletInDb = walletInDbResult; accountInDb = accountInDbResult; // subscribe to notifications API.watcherService.watchAddresses([_account.address]);