Merge pull request #14538 from brave/android_solana_buy_swap
Hides Solana accounts and network on Buy and Swap on Android
This commit is contained in:
@@ -202,6 +202,17 @@ public class KeyringModel implements KeyringServiceObserver {
|
||||
}
|
||||
}
|
||||
|
||||
public List<AccountInfo> stripNoBuySwapAccounts(List<AccountInfo> accountInfos) {
|
||||
List<AccountInfo> accountInfosFiltered = new ArrayList<>();
|
||||
for (AccountInfo accountInfo : accountInfos) {
|
||||
if (accountInfo.coin != CoinType.SOL) {
|
||||
accountInfosFiltered.add(accountInfo);
|
||||
}
|
||||
}
|
||||
|
||||
return accountInfosFiltered;
|
||||
}
|
||||
|
||||
public void getAccounts(Callbacks.Callback1<AccountInfo[]> callback1) {
|
||||
mKeyringService.getKeyringsInfo(mSharedData.getEnabledKeyrings(), keyringInfos -> {
|
||||
List<AccountInfo> accountInfos = WalletUtils.getAccountInfosFromKeyrings(keyringInfos);
|
||||
|
||||
@@ -16,6 +16,7 @@ import org.chromium.brave_wallet.mojom.JsonRpcServiceObserver;
|
||||
import org.chromium.brave_wallet.mojom.NetworkInfo;
|
||||
import org.chromium.chrome.browser.crypto_wallet.model.CryptoAccountTypeInfo;
|
||||
import org.chromium.chrome.browser.crypto_wallet.util.NetworkResponsesCollector;
|
||||
import org.chromium.chrome.browser.crypto_wallet.util.Utils;
|
||||
import org.chromium.chrome.browser.util.Triple;
|
||||
import org.chromium.mojo.bindings.Callbacks;
|
||||
import org.chromium.mojo.system.MojoException;
|
||||
@@ -213,6 +214,17 @@ public class NetworkModel implements JsonRpcServiceObserver {
|
||||
_mNeedToCreateAccountForNetwork.postValue(null);
|
||||
}
|
||||
|
||||
public NetworkInfo[] stripNoBuySwapNetworks(NetworkInfo[] networkInfos) {
|
||||
List<NetworkInfo> networkInfosFiltered = new ArrayList<>();
|
||||
for (NetworkInfo networkInfo : networkInfos) {
|
||||
if (Utils.allowBuyAndSwap(networkInfo.chainId)) {
|
||||
networkInfosFiltered.add(networkInfo);
|
||||
}
|
||||
}
|
||||
|
||||
return networkInfosFiltered.toArray(new NetworkInfo[networkInfosFiltered.size()]);
|
||||
}
|
||||
|
||||
private NetworkInfo[] stripDebugNetwork(Context context, NetworkInfo[] networkInfos) {
|
||||
if ((context.getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
|
||||
return networkInfos;
|
||||
|
||||
+8
-11
@@ -161,7 +161,7 @@ public class AssetDetailActivity
|
||||
BuySendSwapActivity.ActivityType.SWAP, mAssetSymbol);
|
||||
}
|
||||
});
|
||||
if (mNativeInitialized) adjustButtonsVisibilities();
|
||||
adjustButtonsVisibilities();
|
||||
|
||||
RadioGroup radioGroup = findViewById(R.id.asset_duration_radio_group);
|
||||
checkedTimeframeType = radioGroup.getCheckedRadioButtonId();
|
||||
@@ -331,7 +331,6 @@ public class AssetDetailActivity
|
||||
public void finishNativeInitialization() {
|
||||
super.finishNativeInitialization();
|
||||
mNativeInitialized = true;
|
||||
if (mBtnBuy != null && mBtnSwap != null) adjustButtonsVisibilities();
|
||||
getPriceHistory(mAssetSymbol, "usd", AssetPriceTimeframe.ONE_DAY);
|
||||
getPrice(mAssetSymbol, "btc", AssetPriceTimeframe.LIVE);
|
||||
getBlockchainToken(() -> setUpAccountList());
|
||||
@@ -385,14 +384,12 @@ public class AssetDetailActivity
|
||||
}
|
||||
|
||||
private void adjustButtonsVisibilities() {
|
||||
Utils.isCustomNetwork(getJsonRpcService(), mCoinType, mChainId, isCustomNetwork -> {
|
||||
if (!isCustomNetwork) {
|
||||
mBtnBuy.setVisibility(View.VISIBLE);
|
||||
mBtnSwap.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
mBtnBuy.setVisibility(View.GONE);
|
||||
mBtnSwap.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
if (Utils.allowBuyAndSwap(mChainId)) {
|
||||
mBtnBuy.setVisibility(View.VISIBLE);
|
||||
mBtnSwap.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
mBtnBuy.setVisibility(View.GONE);
|
||||
mBtnSwap.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+30
-16
@@ -1533,6 +1533,28 @@ public class BuySendSwapActivity extends BraveWalletBaseActivity
|
||||
mSwapService = SwapServiceFactory.getInstance().getSwapService(this);
|
||||
}
|
||||
|
||||
private void initAccountsUI() {
|
||||
if (mSelectedAccount == null || mSelectedNetwork == null) {
|
||||
return;
|
||||
}
|
||||
if (mActivityType != ActivityType.SEND) {
|
||||
mAccountInfos = mWalletModel.getKeyringModel().stripNoBuySwapAccounts(mAccountInfos);
|
||||
}
|
||||
|
||||
mCustomAccountAdapter.setAccounts(mAccountInfos);
|
||||
if (mAccountInfos.size() > 0) {
|
||||
String selectedAccountAddress = mSelectedAccount != null ? mSelectedAccount.address
|
||||
: mAccountInfos.get(0).address;
|
||||
mAccountSpinner.setSelection(
|
||||
WalletUtils.getSelectedAccountIndex(mSelectedAccount, mAccountInfos));
|
||||
}
|
||||
mAccountSpinner.setOnItemSelectedListener(this);
|
||||
// Before updating, make sure we are on a network with the same coin type
|
||||
if (mSelectedNetwork != null && mSelectedAccount.coin == mSelectedNetwork.coin) {
|
||||
resetSwapFromToAssets();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finishNativeInitialization() {
|
||||
super.finishNativeInitialization();
|
||||
@@ -1542,7 +1564,11 @@ public class BuySendSwapActivity extends BraveWalletBaseActivity
|
||||
this, chainAllNetworksAllNetwork -> {
|
||||
mCurrentChainId = chainAllNetworksAllNetwork.first;
|
||||
mSelectedNetwork = chainAllNetworksAllNetwork.second;
|
||||
NetworkInfo[] networks = chainAllNetworksAllNetwork.third;
|
||||
NetworkInfo[] networks = mActivityType != ActivityType.SEND
|
||||
? mWalletModel.getCryptoModel()
|
||||
.getNetworkModel()
|
||||
.stripNoBuySwapNetworks(chainAllNetworksAllNetwork.third)
|
||||
: chainAllNetworksAllNetwork.third;
|
||||
|
||||
mNetworkAdapter.setNetworks(networks);
|
||||
setSelected(mSelectedNetwork, networks);
|
||||
@@ -1554,7 +1580,7 @@ public class BuySendSwapActivity extends BraveWalletBaseActivity
|
||||
mSelectedNetwork.symbol, getResources().getDisplayMetrics().density,
|
||||
mFromAssetText, this, true, (float) 0.5);
|
||||
|
||||
// before updating, make sure we are same network with same account type
|
||||
// Before updating, make sure we are on a network with the same coin type
|
||||
if (mSelectedAccount != null
|
||||
&& mSelectedAccount.coin == mSelectedNetwork.coin) {
|
||||
resetSwapFromToAssets();
|
||||
@@ -1562,26 +1588,14 @@ public class BuySendSwapActivity extends BraveWalletBaseActivity
|
||||
if (mActivityType == ActivityType.BUY) {
|
||||
adjustTestFaucetControls(getPerNetworkUiInfo(mSelectedNetwork));
|
||||
}
|
||||
initAccountsUI();
|
||||
});
|
||||
mWalletModel.getKeyringModel().mAccountAllAccountsPair.observe(
|
||||
this, accountInfoListPair -> {
|
||||
mSelectedAccount = accountInfoListPair.first;
|
||||
mAccountInfos = accountInfoListPair.second;
|
||||
|
||||
mCustomAccountAdapter.setAccounts(mAccountInfos);
|
||||
if (mAccountInfos.size() > 0) {
|
||||
String selectedAccountAddress = mSelectedAccount != null
|
||||
? mSelectedAccount.address
|
||||
: mAccountInfos.get(0).address;
|
||||
mAccountSpinner.setSelection(WalletUtils.getSelectedAccountIndex(
|
||||
mSelectedAccount, mAccountInfos));
|
||||
}
|
||||
mAccountSpinner.setOnItemSelectedListener(this);
|
||||
// before updating, make sure we are same network with same account type
|
||||
if (mSelectedNetwork != null
|
||||
&& mSelectedAccount.coin == mSelectedNetwork.coin) {
|
||||
resetSwapFromToAssets();
|
||||
}
|
||||
initAccountsUI();
|
||||
});
|
||||
|
||||
mWalletModel.getCryptoModel().getNetworkModel().mNeedToCreateAccountForNetwork.observe(this, networkInfo -> {
|
||||
|
||||
@@ -1639,4 +1639,19 @@ public class Utils {
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static boolean allowBuyAndSwap(String chainId) {
|
||||
switch (chainId) {
|
||||
case BraveWalletConstants.MAINNET_CHAIN_ID:
|
||||
case BraveWalletConstants.RINKEBY_CHAIN_ID:
|
||||
case BraveWalletConstants.ROPSTEN_CHAIN_ID:
|
||||
case BraveWalletConstants.GOERLI_CHAIN_ID:
|
||||
case BraveWalletConstants.KOVAN_CHAIN_ID:
|
||||
return true;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user