Skip to content

Commit

Permalink
fix: `Cannot destructure property 'balance' of 'K[Z]' as it is undefi…
Browse files Browse the repository at this point in the history
…ned` fromAddress error when no transaction is loaded in ConfirmTransactionBase (#25506)

In `confirm-transaction-base.container.js`, while the transaction is
switching, the component may be in a state without transaction data. In
this case, we can handle the empty transaction data appropriately until
the expected data comes in to allow the user flow to continue without
breaking.

**note:** I was unable to reproduce this in `develop` after some time,
but I successfully repro'd this in `Version-v12.0.0` which allowed me to
verify the fix works. Possibly the underlying empty transaction data
state was fixed by other code in `develop`

This PR is planned to be cherry-picked for Version-v12.0.0

Fixes: #25406

See [Issue](#25406)
for repro steps

`confirm-transaction-base.container.js`
![CleanShot 2024-06-25 at 15 58
13@2x](https://github.com/MetaMask/metamask-extension/assets/20778143/4c3ccc3f-8583-4b76-b6cc-9bebc1f1045c)

See error in
[Issue](#25406)
screenshots

No error message is shown and app works as expected

<!-- [screenshots/recordings] -->

- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.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-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

- [ ] 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.
  • Loading branch information
digiwand committed Jun 27, 2024
1 parent f5631fb commit ea84b69
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {
TransactionStatus,
TransactionType,
} from '@metamask/transaction-controller';
import { captureException } from '@sentry/browser';

///: BEGIN:ONLY_INCLUDE_IF(build-mmi)
import { showCustodianDeepLink } from '@metamask-institutional/extension';
import { mmiActionsFactory } from '../../../store/institutional/institution-background';
Expand Down Expand Up @@ -169,7 +171,16 @@ const mapStateToProps = (state, ownProps) => {
const transactionData = parseStandardTokenTransactionData(data);
const tokenToAddress = getTokenAddressParam(transactionData);

const { balance } = accounts[fromAddress];
if (!accounts[fromAddress]) {
captureException(
new Error(
`ConfirmTransactionBase: Unexpected state - No account found for sender address. ` +
`chainId: ${chainId}. fromAddress?: ${Boolean(fromAddress)}`,
),
);
}

const { balance } = accounts[fromAddress] || { balance: '0x0' };
const fromInternalAccount = getInternalAccountByAddress(state, fromAddress);
const fromName = fromInternalAccount?.metadata.name;
const keyring = findKeyringForAddress(state, fromAddress);
Expand Down

0 comments on commit ea84b69

Please sign in to comment.