-
-
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.
Merge branch 'main' into 10778-sentry-axioserror-network-error
- Loading branch information
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.