diff --git a/src/keychain/index.ts b/src/keychain/index.ts index 0ef3d78771a..782d3f06a8d 100644 --- a/src/keychain/index.ts +++ b/src/keychain/index.ts @@ -115,6 +115,7 @@ export async function get(key: string, options: KeychainOptions = {}): Promise({ privateKey = await loadPrivateKey(addressToUse, isHardwareWallet); } - if (privateKey === -1 || privateKey === -2) { + // 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 === kc.ErrorType.UserCanceled || privateKey === kc.ErrorType.NotAuthenticated) { return null; } if (isHardwareWalletKey(privateKey)) { @@ -536,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); @@ -550,8 +556,8 @@ export const loadPrivateKey = async (address: EthereumAddress, hardware: boolean if (!privateKey) { const privateKeyData = await getKeyForWallet(address, hardware); - if (privateKeyData === -1) { - return -1; + if (privateKeyData === kc.ErrorType.UserCanceled || privateKeyData === kc.ErrorType.NotAuthenticated) { + return privateKeyData; } privateKey = privateKeyData?.privateKey ?? null; } @@ -911,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 { @@ -971,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 }; @@ -984,11 +995,26 @@ export const getPrivateKey = async (address: EthereumAddress): Promise { screen: SCREEN_FOR_REQUEST_SOURCE[source], operation: TimeToSignOperation.KeychainRead, })({ - address: accountInfo.address, + address: toChecksumAddress(accountInfo.address), provider: providerToUse, timeTracking: { screen: SCREEN_FOR_REQUEST_SOURCE[source], diff --git a/src/utils/ethereumUtils.ts b/src/utils/ethereumUtils.ts index 9d96405b93f..3ce5b2ae24d 100644 --- a/src/utils/ethereumUtils.ts +++ b/src/utils/ethereumUtils.ts @@ -501,6 +501,8 @@ const calculateL1FeeOptimism = async (tx: RainbowTransaction, provider: Provider newTx.nonce = Number(await provider.getTransactionCount(newTx.from)); } + // @ts-expect-error operand should be optional + delete newTx?.chainId; // @ts-expect-error operand should be optional delete newTx?.from; // @ts-expect-error gas is not in type RainbowTransaction