Skip to content

Commit

Permalink
fix: fix total balance
Browse files Browse the repository at this point in the history
  • Loading branch information
salimtb committed Feb 20, 2024
1 parent b1be882 commit bf5a2ec
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 deletions.
14 changes: 10 additions & 4 deletions app/components/UI/Tokens/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -520,10 +520,16 @@ const Tokens: React.FC<TokensI> = ({ 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) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,6 @@ class NetworkSettings extends PureComponent {
popularNetwork: {},
showWarningModal: false,
showNetworkDetailsModal: false,
matchedChain: null,
isNameFieldFocused: false,
isSymbolFieldFocused: false,
};
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -388,10 +387,6 @@ class NetworkSettings extends PureComponent {
this.setState({ addMode: true });
}

this.setState({
matchedChainNetwork,
});

setTimeout(() => {
this.setState({
inputWidth: { width: '100%' },
Expand Down Expand Up @@ -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;

Expand All @@ -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;

Expand Down
11 changes: 8 additions & 3 deletions app/core/Engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1203,7 +1203,10 @@ class Engine {
AccountTrackerController.refresh();
}

getTotalFiatAccountBalance = () => {
getTotalFiatAccountBalance = (): {
ethFiat: number;
tokenFiat: number;
} => {
const {
CurrencyRateController,
PreferencesController,
Expand Down Expand Up @@ -1270,8 +1273,10 @@ class Engine {
);
}

const total = ethFiat + tokenFiat;
return total;
return {
ethFiat,
tokenFiat,
};
};

/**
Expand Down

0 comments on commit bf5a2ec

Please sign in to comment.