Skip to content

Commit

Permalink
fix: improve assets perfs + fix blurred balances and prices (#12843)
Browse files Browse the repository at this point in the history
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**

<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->

## **Related issues**

Fixes:  #12724

## **Manual testing steps**

1. Build android project locally
2. Add your account or create new one
3. switch btw network ( the perfs should be good )
4. switch btw popular network and current network on the token list and
check the perfs
5. the list of assets should be displayed quickly

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

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

### **After**

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

https://github.com/user-attachments/assets/cdd70d65-820b-40fc-ba7f-85a6dceb66c1


## **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.
  • Loading branch information
salimtb authored Jan 24, 2025
1 parent f7da406 commit 08f48cd
Show file tree
Hide file tree
Showing 14 changed files with 1,322 additions and 502 deletions.
48 changes: 29 additions & 19 deletions app/components/UI/Tokens/TokenList/PortfolioBalance/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useMemo, useCallback } from 'react';
import { View, TouchableOpacity } from 'react-native';
import { useNavigation } from '@react-navigation/native';
import { useSelector } from 'react-redux';
Expand Down Expand Up @@ -56,7 +56,7 @@ import { InternalAccount } from '@metamask/keyring-internal-api';
import { getChainIdsToPoll } from '../../../../../selectors/tokensController';
import AggregatedPercentageCrossChains from '../../../../../component-library/components-temp/Price/AggregatedPercentage/AggregatedPercentageCrossChains';

export const PortfolioBalance = () => {
export const PortfolioBalance = React.memo(() => {
const { PreferencesController } = Engine.context;
const { colors } = useTheme();
const styles = createStyles(colors);
Expand Down Expand Up @@ -112,24 +112,24 @@ export const PortfolioBalance = () => {
type,
);

let total;
if (isOriginalNativeTokenSymbol) {
if (isPortfolioViewEnabled()) {
total = totalFiatBalance ?? 0;
} else {
const total = useMemo(() => {
if (isOriginalNativeTokenSymbol) {
if (isPortfolioViewEnabled()) {
return totalFiatBalance ?? 0;
}
const tokenFiatTotal = balance?.tokenFiat ?? 0;
const ethFiatTotal = balance?.ethFiat ?? 0;
total = tokenFiatTotal + ethFiatTotal;
return tokenFiatTotal + ethFiatTotal;
}
if (isPortfolioViewEnabled()) {
return totalTokenFiat ?? 0;
}
} else if (isPortfolioViewEnabled()) {
total = totalTokenFiat ?? 0;
} else {
total = balance?.tokenFiat ?? 0;
}
return balance?.tokenFiat ?? 0;
}, [isOriginalNativeTokenSymbol, totalFiatBalance, totalTokenFiat, balance]);

const fiatBalance = `${renderFiat(total, currentCurrency)}`;

const onOpenPortfolio = () => {
const onOpenPortfolio = useCallback(() => {
const existingPortfolioTab = browserTabs.find(({ url }: BrowserTab) =>
isPortfolioUrl(url),
);
Expand Down Expand Up @@ -172,7 +172,14 @@ export const PortfolioBalance = () => {
})
.build(),
);
};
}, [
navigation,
trackEvent,
createEventBuilder,
isEnabled,
isDataCollectionForMarketingEnabled,
browserTabs,
]);

const renderAggregatedPercentage = () => {
if (isTestNet(chainId)) {
Expand All @@ -199,9 +206,12 @@ export const PortfolioBalance = () => {
);
};

const toggleIsBalanceAndAssetsHidden = (value: boolean) => {
PreferencesController.setPrivacyMode(value);
};
const toggleIsBalanceAndAssetsHidden = useCallback(
(value: boolean) => {
PreferencesController.setPrivacyMode(value);
},
[PreferencesController],
);

return (
<View style={styles.portfolioBalance}>
Expand Down Expand Up @@ -247,4 +257,4 @@ export const PortfolioBalance = () => {
</View>
</View>
);
};
});
Loading

0 comments on commit 08f48cd

Please sign in to comment.