From 35212ec7a7cc9339f428230d30972dee5c013e35 Mon Sep 17 00:00:00 2001 From: tommasini <46944231+tommasini@users.noreply.github.com> Date: Tue, 19 Nov 2024 17:25:36 +0000 Subject: [PATCH] fix: tags pending approvals receiving undefined (#12331) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## **Description** Fix this: https://metamask.sentry.io/issues/6063420089/events/d1047fbf9e814a6d9fc0c86bf2115f2a/?project=2299799&referrer=previous-event `selectPendingApprovals` may return undefined, and when we do `Object.values(undefined)` a error is thrown ## **Related issues** Fixes: ## **Manual testing steps** 1. Go to this page... 2. 3. ## **Screenshots/Recordings** ### **Before** ### **After** ## **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. --- app/util/sentry/tags/index.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/util/sentry/tags/index.ts b/app/util/sentry/tags/index.ts index efe04f24968..41e5c395180 100644 --- a/app/util/sentry/tags/index.ts +++ b/app/util/sentry/tags/index.ts @@ -13,6 +13,7 @@ export function getTraceTags(state: RootState) { if (!state?.engine?.backgroundState?.TokensController) return; if (!state?.engine?.backgroundState?.TransactionController) return; if (!state?.engine?.backgroundState?.NotificationServicesController) return; + if (!state?.engine?.backgroundState?.ApprovalController) return; if (!Object.keys(state?.engine?.backgroundState).length) return; const unlocked = state.user.userLoggedIn; @@ -21,9 +22,10 @@ export function getTraceTags(state: RootState) { const notificationCount = getNotificationsList(state).length; const tokenCount = selectAllTokensFlat(state).length; const transactionCount = selectTransactions(state).length; - const pendingApprovals = Object.values(selectPendingApprovals(state)); + const pendingApprovals = selectPendingApprovals(state); + const pendingApprovalsValues = Object.values(pendingApprovals ?? {}); - const firstApprovalType = pendingApprovals?.[0]?.type; + const firstApprovalType = pendingApprovalsValues?.[0]?.type; return { 'wallet.account_count': accountCount,