-
Notifications
You must be signed in to change notification settings - Fork 5.4k
chore: update accounts metric payload #38420
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
Changes from all commits
44fe130
0544a0f
020b8c9
98df175
09d5582
7962b6c
4d831ba
5e24fef
4c0a990
bf76d61
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -151,8 +151,8 @@ import { | |
|
|
||
| import { | ||
| HardwareDeviceNames, | ||
| HardwareKeyringType, | ||
| LedgerTransportTypes, | ||
| KEYRING_DEVICE_PROPERTY_MAP, | ||
| } from '../../shared/constants/hardware-wallets'; | ||
| import { KeyringType } from '../../shared/constants/keyring'; | ||
| import { RestrictedMethods } from '../../shared/constants/permissions'; | ||
|
|
@@ -5448,7 +5448,7 @@ export default class MetamaskController extends EventEmitter { | |
| async getHardwareTypeForMetric(address) { | ||
| return await this.keyringController.withKeyring( | ||
| { address }, | ||
| ({ keyring }) => HardwareKeyringType[keyring.type], | ||
| ({ keyring }) => KEYRING_DEVICE_PROPERTY_MAP[keyring.type], | ||
| ); | ||
| } | ||
|
|
||
|
|
@@ -5486,7 +5486,7 @@ export default class MetamaskController extends EventEmitter { | |
| case KeyringType.lattice: | ||
| case KeyringType.qr: | ||
| case KeyringType.ledger: | ||
| return 'hardware'; | ||
| return KEYRING_DEVICE_PROPERTY_MAP[keyringType]; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: But the jsdoc is now wrong, since we're not returning |
||
| case KeyringType.imported: | ||
| return 'imported'; | ||
| case KeyringType.snap: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,7 +50,7 @@ import { KeyringTypes } from '@metamask/keyring-controller'; | |
| import { createTestProviderTools } from '../../test/stub/provider'; | ||
| import { | ||
| HardwareDeviceNames, | ||
| HardwareKeyringType, | ||
| KEYRING_DEVICE_PROPERTY_MAP, | ||
| } from '../../shared/constants/hardware-wallets'; | ||
| import { KeyringType } from '../../shared/constants/keyring'; | ||
| import { LOG_EVENT } from '../../shared/constants/logs'; | ||
|
|
@@ -1630,7 +1630,7 @@ describe('MetaMaskController', () => { | |
| const result = | ||
| await metamaskController.getHardwareTypeForMetric('0x123'); | ||
|
|
||
| expect(result).toBe(HardwareKeyringType[type]); | ||
| expect(result).toBe(KEYRING_DEVICE_PROPERTY_MAP[type]); | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: We could have used |
||
| }, | ||
| ); | ||
| }); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -147,6 +147,14 @@ export const DEVICE_KEYRING_MAP = { | |
| [HardwareDeviceNames.qr]: KeyringTypes.qr, | ||
| }; | ||
|
|
||
| export const KEYRING_DEVICE_PROPERTY_MAP = { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see a lot of duplication in here. It might be too complex to refactor now but maybe something we can aim to do later on. |
||
| [KeyringTypes.ledger]: 'Ledger', | ||
| [KeyringTypes.trezor]: 'Trezor', | ||
| [KeyringTypes.oneKey]: 'OneKey', | ||
| [KeyringTypes.lattice]: 'Lattice', | ||
| [KeyringTypes.qr]: 'QR Hardware', | ||
| }; | ||
|
|
||
| export const U2F_ERROR = 'U2F'; | ||
|
|
||
| export const LEDGER_ERRORS_CODES = { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Map key mismatch causes undefined return for hardware wallets
The
getAccountTypefunction usesKEYRING_DEVICE_PROPERTY_MAP[keyringType]to look up the hardware wallet display name. However,KEYRING_DEVICE_PROPERTY_MAPis keyed byKeyringTypes.xxxvalues from@metamask/keyring-controller, whilekeyringTypecomes from the switch case which matches againstKeyringType.xxxvalues (like'Ledger Hardware'). If these values differ (e.g.,KeyringTypes.ledger='ledger'vsKeyringType.ledger='Ledger Hardware'), the map lookup will returnundefinedinstead of the expected display name like'Ledger'. The PR discussion mentions missingaccount_hardware_typeproperties, which aligns with this lookup returning falsy values.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's ok, the
keyringTypeshould always be valid, so as long asKEYRING_DEVICE_PROPERTY_MAPusesKeyringTypes(and is exhaustive and complete) that should be fine.