Skip to content

Commit

Permalink
Merge pull request #14482 from brave/pr14438_android_solana_portfolio…
Browse files Browse the repository at this point in the history
…_1.42.x

Shows a correct balance for SOL and SOL tokens on Portfolio screen on Android (uplift to 1.42.x)
  • Loading branch information
srirambv authored Aug 5, 2022
2 parents 0ca8105 + a146a22 commit 809a3f8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -702,9 +702,8 @@ private void populateBalance(String balance, boolean from) {
// 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ public static void getNativeAssetsBalances(JsonRpcService jsonRpcService,
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1587,4 +1587,26 @@ public static String getKeyringForCoinType(int coinType) {

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;
}
}

0 comments on commit 809a3f8

Please sign in to comment.