diff --git a/app/util/address/index.js b/app/util/address/index.js index 8c70e79c973..d8527bbdc1b 100644 --- a/app/util/address/index.js +++ b/app/util/address/index.js @@ -171,11 +171,11 @@ export function isQRHardwareAccount(address) { * get address's kerying * * @param {String} address - String corresponding to an address - * @returns {Keyring} - Returns address's account keyriong + * @returns {Keyring | undefined} - Returns the keyring of the provided address if keyring found, otherwise returns undefined */ export function getKeyringByAddress(address) { if (!isValidHexAddress(address)) { - throw new Error(`Invalid address: ${address}`); + return undefined; } const { KeyringController } = Engine.context; const { keyrings } = KeyringController.state; diff --git a/app/util/address/index.test.ts b/app/util/address/index.test.ts index 63d5fc18180..e934a63b697 100644 --- a/app/util/address/index.test.ts +++ b/app/util/address/index.test.ts @@ -247,10 +247,11 @@ describe('isQRHardwareAccount', () => { }); }); describe('getKeyringByAddress', () => { - it('should throw an error if argument address is undefined', () => { - expect(() => getKeyringByAddress(undefined as any)).toThrow( - 'Invalid address: undefined', - ); + it('should return undefined if argument address is undefined', () => { + expect(getKeyringByAddress(undefined as any)).toBeUndefined(); + }); + it('should return undefined if argument address is not hex address', () => { + expect(getKeyringByAddress('ens.eth')).toBeUndefined(); }); it('should return address if found', () => { expect(