diff --git a/android/java/org/chromium/chrome/browser/crypto_wallet/activities/BuySendSwapActivity.java b/android/java/org/chromium/chrome/browser/crypto_wallet/activities/BuySendSwapActivity.java index 6a88dcf9023..c172a33d898 100644 --- a/android/java/org/chromium/chrome/browser/crypto_wallet/activities/BuySendSwapActivity.java +++ b/android/java/org/chromium/chrome/browser/crypto_wallet/activities/BuySendSwapActivity.java @@ -587,7 +587,7 @@ public class BuySendSwapActivity extends BraveWalletBaseActivity if (error != ProviderError.SUCCESS) { return; } - populateBalance(balance, from); + populateBalance(balance, from, 0); }); } else if (mSelectedNetwork.coin == CoinType.SOL) { mJsonRpcService.getSolanaBalance( @@ -596,7 +596,7 @@ public class BuySendSwapActivity extends BraveWalletBaseActivity if (error != ProviderError.SUCCESS) { return; } - populateBalance(String.valueOf(balance), from); + populateBalance(String.valueOf(balance), from, 0); }); } } else if (blockchainToken.isErc721) { @@ -607,7 +607,7 @@ public class BuySendSwapActivity extends BraveWalletBaseActivity if (error != ProviderError.SUCCESS) { return; } - populateBalance(balance, from); + populateBalance(balance, from, 0); }); } else if (mSelectedNetwork.coin == CoinType.SOL && !TextUtils.isEmpty(blockchainToken.contractAddress)) { @@ -615,7 +615,7 @@ public class BuySendSwapActivity extends BraveWalletBaseActivity mJsonRpcService.getSplTokenAccountBalance(address, blockchainToken.contractAddress, mSelectedNetwork.chainId, (amount, decimals, uiAmountString, solanaProvideError, error_message) -> { - populateBalance(amount, from); + populateBalance(amount, from, decimals); }); } else { mJsonRpcService.getErc20TokenBalance(blockchainToken.contractAddress, address, @@ -624,7 +624,7 @@ public class BuySendSwapActivity extends BraveWalletBaseActivity if (error != ProviderError.SUCCESS) { return; } - populateBalance(balance, from); + populateBalance(balance, from, 0); }); } } @@ -646,7 +646,7 @@ public class BuySendSwapActivity extends BraveWalletBaseActivity updateBalanceMaybeSwap(getCurrentSelectedAccountAddr()); } - private void populateBalance(String balance, boolean from) { + private void populateBalance(String balance, boolean from, int responseDecimals) { BlockchainToken token = from ? mCurrentBlockchainToken : mCurrentSwapToBlockchainToken; TextView textView = from ? mFromBalanceText : mToBalanceText; @@ -654,7 +654,10 @@ 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; + int decimals = responseDecimals; + if (decimals == 0) { + decimals = token != null ? token.decimals : Utils.ETH_DEFAULT_DECIMALS; + } int tokenCoin = token != null ? token.coin : CoinType.ETH; fromToBalance = Utils.getBalanceForCoinType(tokenCoin, decimals, balance); } catch (NumberFormatException e) { @@ -929,6 +932,9 @@ public class BuySendSwapActivity extends BraveWalletBaseActivity mCurrentBlockchainToken.contractAddress); } } else if (mSelectedAccount.coin == CoinType.SOL) { + int decimals = mCurrentBlockchainToken.decimals != 0 + ? mCurrentBlockchainToken.decimals + : mSelectedNetwork.decimals; mSendModel.sendSolanaToken(mCurrentBlockchainToken, mSelectedAccount.address, to, Utils.toDecimalLamport(value, mCurrentBlockchainToken.decimals), (success, txMetaId, errorMessage) -> { diff --git a/android/java/org/chromium/chrome/browser/crypto_wallet/fragments/EditVisibleAssetsBottomSheetDialogFragment.java b/android/java/org/chromium/chrome/browser/crypto_wallet/fragments/EditVisibleAssetsBottomSheetDialogFragment.java index fa32a728b18..7384c3f2fcc 100644 --- a/android/java/org/chromium/chrome/browser/crypto_wallet/fragments/EditVisibleAssetsBottomSheetDialogFragment.java +++ b/android/java/org/chromium/chrome/browser/crypto_wallet/fragments/EditVisibleAssetsBottomSheetDialogFragment.java @@ -293,17 +293,37 @@ public class EditVisibleAssetsBottomSheetDialogFragment extends BottomSheetDialo dialog.setContentView(R.layout.brave_wallet_add_custom_asset); dialog.show(); - LinearLayout advancedSection = dialog.findViewById(R.id.advanced_section); TextView advancedTitle = dialog.findViewById(R.id.advanced_title); - advancedTitle.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (advancedSection.getVisibility() == View.GONE) - advancedSection.setVisibility(View.VISIBLE); - else - advancedSection.setVisibility(View.GONE); + CheckBox isNft = dialog.findViewById(R.id.nft_check); + if (mSelectedNetwork.coin == CoinType.ETH) { + LinearLayout advancedSection = dialog.findViewById(R.id.advanced_section); + advancedTitle.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (advancedSection.getVisibility() == View.GONE) + advancedSection.setVisibility(View.VISIBLE); + else + advancedSection.setVisibility(View.GONE); + } + }); + } else { + advancedTitle.setVisibility(View.GONE); + dialog.findViewById(R.id.advanced_section_separator).setVisibility(View.GONE); + if (mSelectedNetwork.coin == CoinType.SOL) { + isNft.setVisibility(View.VISIBLE); + isNft.setOnClickListener(v -> { + boolean isNftChecked = isNft.isChecked(); + dialog.findViewById(R.id.token_decimals_title) + .setVisibility(isNftChecked ? View.GONE : View.VISIBLE); + dialog.findViewById(R.id.token_decimals) + .setVisibility(isNftChecked ? View.GONE : View.VISIBLE); + ((TextView) dialog.findViewById(R.id.token_contract_address_title)) + .setText(getString(isNftChecked + ? R.string.wallet_add_custom_asset_token_address + : R.string.wallet_add_custom_asset_token_contract_address)); + }); } - }); + } Button cancel = dialog.findViewById(R.id.cancel); cancel.setOnClickListener(new View.OnClickListener() { @@ -346,6 +366,12 @@ public class EditVisibleAssetsBottomSheetDialogFragment extends BottomSheetDialo token.decimals = Integer.valueOf(tokenDecimalsEdit.getText().toString()); } catch (NumberFormatException exc) { } + if (mSelectedNetwork.coin == CoinType.SOL) { + token.isNft = isNft.isChecked(); + if (token.isNft) { + token.decimals = 0; + } + } token.visible = true; braveWalletService.addUserAsset(token, success -> { @@ -437,7 +463,8 @@ public class EditVisibleAssetsBottomSheetDialogFragment extends BottomSheetDialo } if (tokenName.isEmpty() || tokenSymbol.isEmpty() - || tokenDecimalsEdit.getText().toString().isEmpty()) { + || mSelectedNetwork.coin == CoinType.ETH + && tokenDecimalsEdit.getText().toString().isEmpty()) { return; } diff --git a/android/java/org/chromium/chrome/browser/crypto_wallet/util/BalanceHelper.java b/android/java/org/chromium/chrome/browser/crypto_wallet/util/BalanceHelper.java index 7d9c38cae68..6ab45286082 100644 --- a/android/java/org/chromium/chrome/browser/crypto_wallet/util/BalanceHelper.java +++ b/android/java/org/chromium/chrome/browser/crypto_wallet/util/BalanceHelper.java @@ -149,7 +149,8 @@ public class BalanceHelper { final String tokenKey = Utils.tokenToString(context.userAsset); final int decimals = (context.userAsset.decimals != 0 || context.userAsset.isErc721) ? context.userAsset.decimals - : selectedNetwork.decimals; + : (context.userAsset.coin == CoinType.SOL ? context.decimals + : selectedNetwork.decimals); Double tokenBalance = (context.error == ProviderError.SUCCESS && context.balance != null && !context.balance.isEmpty()) diff --git a/android/java/res/layout/brave_wallet_add_custom_asset.xml b/android/java/res/layout/brave_wallet_add_custom_asset.xml index 868f87783c8..50baff8446a 100644 --- a/android/java/res/layout/brave_wallet_add_custom_asset.xml +++ b/android/java/res/layout/brave_wallet_add_custom_asset.xml @@ -45,6 +45,7 @@ tools:ignore="LabelFor, Autofill" /> + + View message in ASCII encoding + + NFT + + + Token address +