Shows a correct balance for SOL and SOL tokens on Portfolio screen on Android

This commit is contained in:
Serg
2022-08-02 14:54:13 -04:00
parent c74434409a
commit 6285ece9fb
3 changed files with 26 additions and 4 deletions
@@ -698,9 +698,8 @@ public class BuySendSwapActivity extends BraveWalletBaseActivity
// some old calls are returning ETH result when SOL is selected so do nothing
try {
int decimals = token != null ? token.decimals : Utils.ETH_DEFAULT_DECIMALS;
fromToBalance = token != null && token.coin == CoinType.SOL
? Utils.fromWei(balance, decimals)
: Utils.fromHexWei(balance, decimals);
int tokenCoin = token != null ? token.coin : CoinType.ETH;
fromToBalance = Utils.getBalanceForCoinType(tokenCoin, decimals, balance);
} catch (NumberFormatException e) {
return;
}
@@ -69,7 +69,8 @@ public class BalanceHelper {
final int networkDecimals = selectedNetwork.decimals;
for (AsyncUtils.GetBalanceResponseBaseContext context : contexts) {
Double nativeAssetBalance = (context.error == ProviderError.SUCCESS)
? Utils.fromHexWei(context.balance, networkDecimals)
? Utils.getBalanceForCoinType(
selectedNetwork.coin, networkDecimals, context.balance)
: 0.0d;
nativeAssetsBalances.put(context.accountAddress, nativeAssetBalance);
}
@@ -1588,4 +1588,26 @@ public class Utils {
return keyring;
}
// TODO(sergz): Move getCoinIcon, getKeyringForCoinType, getBalanceForCoinType
// to some kind of a separate Utils file that is related to diff networks only
public static double getBalanceForCoinType(int coinType, int decimals, String balance) {
double result = 0.0d;
switch (coinType) {
case CoinType.ETH:
result = Utils.fromHexWei(balance, decimals);
break;
case CoinType.SOL:
result = Utils.fromWei(balance, decimals);
break;
case CoinType.FIL:
// TODO(sergz): Add FIL asset balance
break;
default:
result = Utils.fromHexWei(balance, decimals);
break;
}
return result;
}
}