Skip to content

Commit

Permalink
UX: Multichain: Fix useAccountTotalFiatBalance when getWeiHexFromDeci…
Browse files Browse the repository at this point in the history
…malValue returns "NaN" (#21359)

## **Description**

While onboarding with `MULTICHAIN` environment variable turned on, I
noticed a crash upon initial loading screen. The cause was
`getWeiHexFromDecimalValue` returning "NaN" in this block:

```
const totalWeiBalance = getWeiHexFromDecimalValue({
    value: totalFiatBalance,
    fromCurrency: currentCurrency,
    conversionRate,
    invertConversionRate: true,
  });
```

with params: 

* `value`: `"0"`
* `fromCurrency`: `"usd"`
* `conversionRate`: `0`

Checking for valid output and returning `0x0` prevents the balance error

## **Manual testing steps**

0.  `MULTICHAIN=1 yarn start`
_1. Remove your local Metamask 
_2. Re-install and go through onboarding
_3. Get to home wallet screen without crashing


## **Related issues**

_Fixes #???_

## **Pre-merge author checklist**

- [ ] I’ve followed [MetaMask Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've clearly explained:
  - [ ] What problem this PR is solving.
  - [ ] How this problem was solved.
  - [ ] How reviewers can test my changes.
- [ ] I’ve indicated what issue this PR is linked to: Fixes #???
- [ ] I’ve included tests if applicable.
- [ ] I’ve documented any added code.
- [ ] 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)).
- [ ] I’ve properly set the pull request status:
  - [ ] In case it's not yet "ready for review", I've set it to "draft".
- [ ] In case it's "ready for review", I've changed it from "draft" to
"non-draft".

## **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.
  • Loading branch information
darkwing authored Oct 13, 2023
1 parent 384ba3d commit 6e82ec2
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion ui/hooks/useAccountTotalFiatBalance.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,19 @@ export const useAccountTotalFiatBalance = (
const formattedFiat = formatCurrency(totalFiatBalance, currentCurrency);

// WEI Number which can be used with UserPreferencedCurrencyDisplay component
const totalWeiBalance = getWeiHexFromDecimalValue({
let totalWeiBalance = getWeiHexFromDecimalValue({
value: totalFiatBalance,
fromCurrency: currentCurrency,
conversionRate,
invertConversionRate: true,
});

// If we have a totalFiatBalance of "0" and conversionRate of "0",
// getWeiHexFromDecimalValue responds with "NaN"
if (totalWeiBalance === 'NaN') {
totalWeiBalance = '0x0';
}

return {
formattedFiat,
totalWeiBalance,
Expand Down

0 comments on commit 6e82ec2

Please sign in to comment.