Skip to content

Commit

Permalink
fix #52: hideZeroBalanceTokens is not working
Browse files Browse the repository at this point in the history
  • Loading branch information
wk3368 committed Mar 1, 2022
1 parent 3ccd249 commit 9342fb1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
14 changes: 13 additions & 1 deletion ui/app/helpers/utils/confirm-tx.util.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export function formatCurrency(value, currencyCode) {

export function stringifyBalance(balance, decimals, currency, numberOfDecimals) {
const multiplier = Math.pow(10, Number(decimals || 0));
const value = conversionUtil(balance, {
let value = conversionUtil(balance, {
// fromCurrency,
toCurrency: currency,
fromNumericBase: 'hex',
Expand All @@ -120,6 +120,18 @@ export function stringifyBalance(balance, decimals, currency, numberOfDecimals)
conversionRate: multiplier,
invertConversionRate: true,
});
// avoid disply 0 while hideZeroBalanceTokens = true
if (Number(value) === 0 && balance !== '0x0') {
value = conversionUtil(balance, {
// fromCurrency,
toCurrency: currency,
fromNumericBase: 'hex',
toNumericBase: 'dec',
decimals,
conversionRate: multiplier,
invertConversionRate: true,
});
}
return formatCurrency(value, currency);
}

Expand Down
29 changes: 16 additions & 13 deletions ui/app/hooks/useTokenTracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,22 @@ export function useTokenTracker(
});
}
// added to wallet but not enabled accept_tokens ones
const unAcceptTokens = tokens.filter((token) => currentAssets && !currentAssets[token.code]);
unAcceptTokens.map(({ code, decimals, symbol }) => {
const numberOfDecimals = decimals <= 9 ? 4 : 9;
const token = {
code,
balance: currentAssets[code],
symbol,
decimals,
string: stringifyBalance(currentAssets[code], decimals, symbol, numberOfDecimals),
accepted: false,
};
tokensWithBalances.push(token);
});
if (!hideZeroBalanceTokens) {
const unAcceptTokens = tokens.filter((token) => currentAssets && !currentAssets[token.code]);
unAcceptTokens.map(({ code, decimals, symbol }) => {
console.log('unAcceptTokens', code, currentAssets[code])
const numberOfDecimals = decimals <= 9 ? 4 : 9;
const token = {
code,
balance: currentAssets[code],
symbol,
decimals,
string: stringifyBalance(currentAssets[code], decimals, symbol, numberOfDecimals),
accepted: false,
};
tokensWithBalances.push(token);
});
}
const loading = false;
const error = null;
return { loading, tokensWithBalances, error };
Expand Down

0 comments on commit 9342fb1

Please sign in to comment.