diff --git a/src/model/wallet.ts b/src/model/wallet.ts index e2a0879b617..c4bc99c6518 100644 --- a/src/model/wallet.ts +++ b/src/model/wallet.ts @@ -289,10 +289,10 @@ export const loadWallet = async ({ privateKey = await loadPrivateKey(addressToUse, isHardwareWallet); } - // -1 means the user cancelled, so we don't wanna do anything - // -2 Means the user is not authenticated (maybe removed biometrics). + // kc.ErrorType.UserCanceled means the user cancelled, so we don't wanna do anything + // kc.ErrorType.NotAuthenticated means the user is not authenticated (maybe removed biometrics). // In this case we show an alert inside loadPrivateKey - if (privateKey === -1 || privateKey === -2) { + if (privateKey === kc.ErrorType.UserCanceled || privateKey === kc.ErrorType.NotAuthenticated) { return null; } if (isHardwareWalletKey(privateKey)) { @@ -539,7 +539,10 @@ export const oldLoadSeedPhrase = async (): Promise => export const loadAddress = (): Promise => keychain.loadString(addressKey) as Promise; -export const loadPrivateKey = async (address: EthereumAddress, hardware: boolean): Promise => { +export const loadPrivateKey = async ( + address: EthereumAddress, + hardware: boolean +): Promise => { try { const isSeedPhraseMigrated = await keychain.loadString(oldSeedPhraseMigratedKey); @@ -553,7 +556,7 @@ export const loadPrivateKey = async (address: EthereumAddress, hardware: boolean if (!privateKey) { const privateKeyData = await getKeyForWallet(address, hardware); - if (privateKeyData === -1 || privateKeyData === -2) { + if (privateKeyData === kc.ErrorType.UserCanceled || privateKeyData === kc.ErrorType.NotAuthenticated) { return privateKeyData; } privateKey = privateKeyData?.privateKey ?? null; @@ -914,9 +917,12 @@ export const saveKeyForWallet = async ( * @desc Gets wallet keys for the given address depending wallet type * @param address The wallet address. * @param hardware If the wallet is a hardware wallet. - * @return null | PrivateKeyData | -1 + * @return null | PrivateKeyData | kc.ErrorType.UserCanceled | kc.ErrorType.NotAuthenticated */ -export const getKeyForWallet = async (address: EthereumAddress, hardware: boolean): Promise => { +export const getKeyForWallet = async ( + address: EthereumAddress, + hardware: boolean +): Promise => { if (hardware) { return await getHardwareKey(address); } else { @@ -974,9 +980,11 @@ export const saveHardwareKey = async ( /** * @desc Gets wallet private key for a given address. * @param address The wallet address. - * @return null | PrivateKeyData | -1 + * @return null | PrivateKeyData | kc.ErrorType.UserCanceled | kc.ErrorType.NotAuthenticated */ -export const getPrivateKey = async (address: EthereumAddress): Promise => { +export const getPrivateKey = async ( + address: EthereumAddress +): Promise => { try { const key = `${address}_${privateKeyKey}`; const options = { authenticationPrompt }; @@ -988,17 +996,17 @@ export const getPrivateKey = async (address: EthereumAddress): Promise