From bf5a2ecf464b17ca8737cab80f934c4931a0e7e7 Mon Sep 17 00:00:00 2001 From: Salim Toubal Date: Tue, 20 Feb 2024 11:54:42 +0100 Subject: [PATCH] fix: fix total balance --- app/components/UI/Tokens/index.tsx | 14 +++++++++---- .../NetworksSettings/NetworkSettings/index.js | 20 ++++++++----------- app/core/Engine.ts | 11 +++++++--- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/app/components/UI/Tokens/index.tsx b/app/components/UI/Tokens/index.tsx index 7a60a8080896..7062f5211a11 100644 --- a/app/components/UI/Tokens/index.tsx +++ b/app/components/UI/Tokens/index.tsx @@ -520,10 +520,16 @@ const Tokens: React.FC = ({ tokens }) => { }; const renderNetworth = () => { - const fiatBalance = `${renderFiat( - Engine.getTotalFiatAccountBalance(), - currentCurrency, - )}`; + const balance = Engine.getTotalFiatAccountBalance(); + let total; + if (isOriginalNativeTokenSymbol) { + const tokenFiatTotal = balance?.tokenFiat ?? 0; + const ethFiatTotal = balance?.ethFiat ?? 0; + total = tokenFiatTotal + ethFiatTotal; + } else { + total = balance?.tokenFiat ?? 0; + } + const fiatBalance = `${renderFiat(total, currentCurrency)}`; const onOpenPortfolio = () => { const existingPortfolioTab = browserTabs.find((tab: BrowserTab) => diff --git a/app/components/Views/Settings/NetworksSettings/NetworkSettings/index.js b/app/components/Views/Settings/NetworksSettings/NetworkSettings/index.js index 520c13161a51..6ac5c760ebdc 100644 --- a/app/components/Views/Settings/NetworksSettings/NetworkSettings/index.js +++ b/app/components/Views/Settings/NetworksSettings/NetworkSettings/index.js @@ -292,7 +292,6 @@ class NetworkSettings extends PureComponent { popularNetwork: {}, showWarningModal: false, showNetworkDetailsModal: false, - matchedChain: null, isNameFieldFocused: false, isSymbolFieldFocused: false, }; @@ -335,7 +334,7 @@ class NetworkSettings extends PureComponent { componentDidMount = () => { this.updateNavBar(); - const { route, networkConfigurations, matchedChainNetwork } = this.props; + const { route, networkConfigurations } = this.props; const isCustomMainnet = route.params?.isCustomMainnet; const networkTypeOrRpcUrl = route.params?.network; @@ -388,10 +387,6 @@ class NetworkSettings extends PureComponent { this.setState({ addMode: true }); } - this.setState({ - matchedChainNetwork, - }); - setTimeout(() => { this.setState({ inputWidth: { width: '100%' }, @@ -708,14 +703,15 @@ class NetworkSettings extends PureComponent { * Validates that symbol match with the chainId, setting a warningSymbol if is invalid */ validateSymbol = async () => { - const { ticker, matchedChain } = this.state; - const { useSafeChainsListValidation } = this.props; + const { ticker } = this.state; + const { useSafeChainsListValidation, matchedChainNetwork } = this.props; if (!useSafeChainsListValidation) { return; } - const symbol = matchedChain?.nativeCurrency?.symbol ?? null; + const symbol = + matchedChainNetwork?.matchedChainNetwork?.nativeCurrency?.symbol ?? null; const symbolToUse = symbol === ticker ? undefined : symbol; @@ -728,14 +724,14 @@ class NetworkSettings extends PureComponent { * Validates that name match with the chainId, setting a warningName if is invalid */ validateName = async () => { - const { matchedChain, nickname } = this.state; - const { useSafeChainsListValidation } = this.props; + const { nickname } = this.state; + const { useSafeChainsListValidation, matchedChainNetwork } = this.props; if (!useSafeChainsListValidation) { return; } - const name = matchedChain?.chain ?? null; + const name = matchedChainNetwork?.matchedChainNetwork?.chain ?? null; const nameToUse = name === nickname ? undefined : name; diff --git a/app/core/Engine.ts b/app/core/Engine.ts index 5e4426887a71..118496dee084 100644 --- a/app/core/Engine.ts +++ b/app/core/Engine.ts @@ -1203,7 +1203,10 @@ class Engine { AccountTrackerController.refresh(); } - getTotalFiatAccountBalance = () => { + getTotalFiatAccountBalance = (): { + ethFiat: number; + tokenFiat: number; + } => { const { CurrencyRateController, PreferencesController, @@ -1270,8 +1273,10 @@ class Engine { ); } - const total = ethFiat + tokenFiat; - return total; + return { + ethFiat, + tokenFiat, + }; }; /**