Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 7862 invalid address error #7881

Merged
merged 5 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 2 additions & 2 deletions app/util/address/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 address's account keyriong if keyring found, otherwise return undefined
sethkfman marked this conversation as resolved.
Show resolved Hide resolved
*/
export function getKeyringByAddress(address) {
if (!isValidHexAddress(address)) {
throw new Error(`Invalid address: ${address}`);
return undefined;
}
const { KeyringController } = Engine.context;
const { keyrings } = KeyringController.state;
Expand Down
9 changes: 5 additions & 4 deletions app/util/address/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading