Skip to content

Commit

Permalink
getAddressAccountType: throw error if address is undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
jpcloureiro committed Aug 28, 2023
1 parent 1672f0f commit 24308d6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
10 changes: 7 additions & 3 deletions app/components/Views/EditAccountName/EditAccountName.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,13 @@ const EditAccountName = () => {

InteractionManager.runAfterInteractions(() => {
const analyticsProperties = async () => {
const accountType = getAddressAccountType(selectedAddress);
const account_type = accountType === 'QR' ? 'hardware' : accountType;
return { account_type, chain_id: chainId };
try {
const accountType = getAddressAccountType(selectedAddress);
const account_type = accountType === 'QR' ? 'hardware' : accountType;
return { account_type, chain_id: chainId };
} catch {
return { account_type: 'no account selected', chain_id: chainId };
}
};
Analytics.trackEventWithParameters(
MetaMetricsEvents.ACCOUNT_RENAMED,
Expand Down
4 changes: 3 additions & 1 deletion app/util/address/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ export function isQRHardwareAccount(address) {
* @returns {String} - Returns address's account type
*/
export function getAddressAccountType(address) {
if (!address) return false;
if (!address) {
throw new Error('address is not defined');
}

const { KeyringController } = Engine.context;
const { keyrings } = KeyringController.state;
Expand Down
6 changes: 4 additions & 2 deletions app/util/address/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,10 @@ describe('isQRHardwareAccount', () => {
});
});
describe('getAddressAccountType', () => {
it('should return false if argument address is undefined', () => {
expect(getAddressAccountType(undefined as any)).toBeFalsy();
it('should throw an error if argument address is undefined', () => {
expect(() => getAddressAccountType(undefined as any)).toThrow(
'address is not defined',
);
});
it('should return QR if address is from a keyring type qr', () => {
expect(getAddressAccountType('account-qr-stub-1')).toBe('QR');
Expand Down

0 comments on commit 24308d6

Please sign in to comment.