-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add tags to custom spans (#11977)
## **Description** Cherry-picked this [PR](#11623) Android build: https://app.bitrise.io/build/3cf918b6-a0b8-4a46-a3e8-78ebd74b9006 ## **Related issues** Fixes: ## **Manual testing steps** 1. Go to this page... 2. 3. ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [ ] I’ve followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. --------- Co-authored-by: Aslau Mario-Daniel <marioaslau@gmail.com>
- Loading branch information
1 parent
5482dbd
commit 475e9bf
Showing
8 changed files
with
470 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,229 @@ | ||
import { RootState } from '../../../reducers'; | ||
import { getTraceTags } from './'; | ||
import initialRootState, { | ||
backgroundState, | ||
} from '../../../util/test/initial-root-state'; | ||
import { userInitialState } from '../../../reducers/user'; | ||
import { createMockAccountsControllerState } from '../../../util/test/accountsControllerTestUtils'; | ||
|
||
describe('Tags Utils', () => { | ||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
describe('getTraceTags', () => { | ||
it('includes if unlocked', () => { | ||
const state = { | ||
...initialRootState, | ||
user: { ...userInitialState, userLoggedIn: true }, | ||
}; | ||
|
||
const tags = getTraceTags(state); | ||
|
||
expect(tags?.['wallet.unlocked']).toStrictEqual(true); | ||
}); | ||
|
||
it('includes if not unlocked', () => { | ||
const state = { | ||
...initialRootState, | ||
user: { ...userInitialState, userLoggedIn: false }, | ||
}; | ||
|
||
const tags = getTraceTags(state); | ||
|
||
expect(tags?.['wallet.unlocked']).toStrictEqual(false); | ||
}); | ||
|
||
it('includes pending approval type', () => { | ||
const state = { | ||
...initialRootState, | ||
engine: { | ||
backgroundState: { | ||
...backgroundState, | ||
ApprovalController: { | ||
...backgroundState.ApprovalController, | ||
pendingApprovals: { | ||
1: { | ||
type: 'eth_sendTransaction', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} as unknown as RootState; | ||
|
||
const tags = getTraceTags(state); | ||
|
||
expect(tags?.['wallet.pending_approval']).toStrictEqual( | ||
'eth_sendTransaction', | ||
); | ||
}); | ||
|
||
it('includes first pending approval type if multiple', () => { | ||
const state = { | ||
...initialRootState, | ||
engine: { | ||
backgroundState: { | ||
...backgroundState, | ||
|
||
ApprovalController: { | ||
...backgroundState.ApprovalController, | ||
pendingApprovals: { | ||
1: { | ||
type: 'eth_sendTransaction', | ||
}, | ||
2: { | ||
type: 'personal_sign', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} as unknown as RootState; | ||
|
||
const tags = getTraceTags(state); | ||
|
||
expect(tags?.['wallet.pending_approval']).toStrictEqual( | ||
'eth_sendTransaction', | ||
); | ||
}); | ||
|
||
it('includes account count', () => { | ||
const state = { | ||
...initialRootState, | ||
engine: { | ||
backgroundState: { | ||
...backgroundState, | ||
AccountsController: createMockAccountsControllerState([ | ||
'0x1234', | ||
'0x4321', | ||
]), | ||
}, | ||
}, | ||
} as unknown as RootState; | ||
|
||
const tags = getTraceTags(state); | ||
|
||
expect(tags?.['wallet.account_count']).toStrictEqual(2); | ||
}); | ||
|
||
it('includes nft count', () => { | ||
const state = { | ||
...initialRootState, | ||
engine: { | ||
backgroundState: { | ||
...backgroundState, | ||
NftController: { | ||
...backgroundState.NftController, | ||
allNfts: { | ||
'0x1234': { | ||
'0x1': [ | ||
{ | ||
tokenId: '1', | ||
}, | ||
{ | ||
tokenId: '2', | ||
}, | ||
], | ||
'0x2': [ | ||
{ | ||
tokenId: '3', | ||
}, | ||
{ | ||
tokenId: '4', | ||
}, | ||
], | ||
}, | ||
'0x4321': { | ||
'0x3': [ | ||
{ | ||
tokenId: '5', | ||
}, | ||
], | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} as unknown as RootState; | ||
|
||
const tags = getTraceTags(state); | ||
|
||
expect(tags?.['wallet.nft_count']).toStrictEqual(5); | ||
}); | ||
|
||
it('includes notification count', () => { | ||
const state = { | ||
...initialRootState, | ||
engine: { | ||
backgroundState: { | ||
...backgroundState, | ||
NotificationServicesController: { | ||
metamaskNotificationsList: [{}, {}, {}], | ||
}, | ||
}, | ||
}, | ||
} as unknown as RootState; | ||
|
||
const tags = getTraceTags(state); | ||
|
||
expect(tags?.['wallet.notification_count']).toStrictEqual(3); | ||
}); | ||
|
||
it('includes token count', () => { | ||
const state = { | ||
...initialRootState, | ||
engine: { | ||
backgroundState: { | ||
...backgroundState, | ||
TokensController: { | ||
allTokens: { | ||
'0x1': { | ||
'0x1234': [{}, {}], | ||
'0x4321': [{}], | ||
}, | ||
'0x2': { | ||
'0x5678': [{}], | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} as unknown as RootState; | ||
|
||
const tags = getTraceTags(state); | ||
|
||
expect(tags?.['wallet.token_count']).toStrictEqual(4); | ||
}); | ||
|
||
it('includes transaction count', () => { | ||
const state = { | ||
...initialRootState, | ||
engine: { | ||
backgroundState: { | ||
...backgroundState, | ||
TransactionController: { | ||
transactions: [ | ||
{ | ||
id: 1, | ||
chainId: '0x1', | ||
}, | ||
{ | ||
id: 2, | ||
chainId: '0x1', | ||
}, | ||
{ | ||
id: 3, | ||
chainId: '0x2', | ||
}, | ||
], | ||
}, | ||
}, | ||
}, | ||
} as unknown as RootState; | ||
const tags = getTraceTags(state); | ||
|
||
expect(tags?.['wallet.transaction_count']).toStrictEqual(3); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { RootState } from '../../../reducers'; | ||
import { selectAllNftsFlat } from '../../../selectors/nftController'; | ||
import { selectInternalAccounts } from '../../../selectors/accountsController'; | ||
import { selectAllTokensFlat } from '../../../selectors/tokensController'; | ||
import { getNotificationsList } from '../../../selectors/notifications'; | ||
import { selectTransactions } from '../../../selectors/transactionController'; | ||
import { selectPendingApprovals } from '../../../selectors/approvalController'; | ||
|
||
export function getTraceTags(state: RootState) { | ||
if (!Object.keys(state?.engine?.backgroundState).length) return; | ||
const unlocked = state.user.userLoggedIn; | ||
const accountCount = selectInternalAccounts(state).length; | ||
const nftCount = selectAllNftsFlat(state).length; | ||
const notificationCount = getNotificationsList(state).length; | ||
const tokenCount = selectAllTokensFlat(state).length; | ||
const transactionCount = selectTransactions(state).length; | ||
const pendingApprovals = Object.values(selectPendingApprovals(state)); | ||
|
||
const firstApprovalType = pendingApprovals?.[0]?.type; | ||
|
||
return { | ||
'wallet.account_count': accountCount, | ||
'wallet.nft_count': nftCount, | ||
'wallet.notification_count': notificationCount, | ||
'wallet.pending_approval': firstApprovalType, | ||
'wallet.token_count': tokenCount, | ||
'wallet.transaction_count': transactionCount, | ||
'wallet.unlocked': unlocked, | ||
}; | ||
} |
Oops, something went wrong.