Adds a basic Solana NFT support on Android
This commit is contained in:
+13
-7
@@ -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) -> {
|
||||
|
||||
+37
-10
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
tools:ignore="LabelFor, Autofill" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/token_contract_address_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="24dp"
|
||||
@@ -83,6 +84,7 @@
|
||||
tools:ignore="LabelFor, Autofill" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/token_decimals_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="24dp"
|
||||
@@ -115,6 +117,7 @@
|
||||
android:textSize="18sp" />
|
||||
|
||||
<View
|
||||
android:id="@+id/advanced_section_separator"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_marginStart="12dp"
|
||||
@@ -151,6 +154,14 @@
|
||||
tools:ignore="LabelFor, Autofill" />
|
||||
</LinearLayout>
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/nft_check"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="24dp"
|
||||
android:text="@string/wallet_add_solana_nft_checkbox"
|
||||
android:visibility="gone" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
@@ -3249,6 +3249,12 @@ If you don't accept this request, VPN will not reconnect and your internet conne
|
||||
<message name="IDS_WALLET_NON_ASCII_CHARACTERS_ASCII" desc="A title to view an ASCII message if Unicode characters detected">
|
||||
View message in ASCII encoding
|
||||
</message>
|
||||
<message name="IDS_WALLET_ADD_SOLANA_NFT_CHECKBOX" desc="A title for a Solana NFT custom assets checkbox" translateable="false">
|
||||
NFT
|
||||
</message>
|
||||
<message name="IDS_WALLET_ADD_CUSTOM_ASSET_TOKEN_ADDRESS" desc="Add custom asset dialog Token contract address field for Solana NFT">
|
||||
Token address
|
||||
</message>
|
||||
</messages>
|
||||
</release>
|
||||
</grit>
|
||||
|
||||
Reference in New Issue
Block a user