feat(wallet): create account via dapp request
This commit is contained in:
@@ -137,6 +137,7 @@ brave_java_sources = [
|
||||
"../../brave/android/java/org/chromium/chrome/browser/crypto_wallet/model/CryptoAccountTypeInfo.java",
|
||||
"../../brave/android/java/org/chromium/chrome/browser/crypto_wallet/model/OnboardingViewModel.java",
|
||||
"../../brave/android/java/org/chromium/chrome/browser/crypto_wallet/model/TxNonSwipeableViewPager.java",
|
||||
"../../brave/android/java/org/chromium/chrome/browser/crypto_wallet/model/WalletAccountCreationRequest.java",
|
||||
"../../brave/android/java/org/chromium/chrome/browser/crypto_wallet/model/WalletListItemModel.java",
|
||||
"../../brave/android/java/org/chromium/chrome/browser/crypto_wallet/observers/ApprovedTxObserver.java",
|
||||
"../../brave/android/java/org/chromium/chrome/browser/crypto_wallet/observers/KeyringServiceObserverImpl.java",
|
||||
|
||||
@@ -66,6 +66,7 @@ import org.chromium.base.task.TaskTraits;
|
||||
import org.chromium.brave_wallet.mojom.AccountInfo;
|
||||
import org.chromium.brave_wallet.mojom.AssetRatioService;
|
||||
import org.chromium.brave_wallet.mojom.BlockchainRegistry;
|
||||
import org.chromium.brave_wallet.mojom.BraveWalletConstants;
|
||||
import org.chromium.brave_wallet.mojom.BraveWalletService;
|
||||
import org.chromium.brave_wallet.mojom.CoinType;
|
||||
import org.chromium.brave_wallet.mojom.EthTxManagerProxy;
|
||||
@@ -106,9 +107,12 @@ import org.chromium.chrome.browser.crypto_wallet.JsonRpcServiceFactory;
|
||||
import org.chromium.chrome.browser.crypto_wallet.KeyringServiceFactory;
|
||||
import org.chromium.chrome.browser.crypto_wallet.SwapServiceFactory;
|
||||
import org.chromium.chrome.browser.crypto_wallet.TxServiceFactory;
|
||||
import org.chromium.chrome.browser.crypto_wallet.activities.AddAccountActivity;
|
||||
import org.chromium.chrome.browser.crypto_wallet.activities.BraveWalletActivity;
|
||||
import org.chromium.chrome.browser.crypto_wallet.activities.BraveWalletDAppsActivity;
|
||||
import org.chromium.chrome.browser.crypto_wallet.activities.NetworkSelectorActivity;
|
||||
import org.chromium.chrome.browser.crypto_wallet.model.CryptoAccountTypeInfo;
|
||||
import org.chromium.chrome.browser.crypto_wallet.util.AssetUtils;
|
||||
import org.chromium.chrome.browser.crypto_wallet.util.Utils;
|
||||
import org.chromium.chrome.browser.crypto_wallet.util.WalletUtils;
|
||||
import org.chromium.chrome.browser.custom_layout.popup_window_tooltip.PopupWindowTooltip;
|
||||
@@ -569,6 +573,11 @@ public abstract class BraveActivity<C extends ChromeActivityComponent> extends C
|
||||
}
|
||||
}
|
||||
|
||||
public void showAccountCreation(String keyringId) {
|
||||
assert mWalletModel != null : " mWalletModel is null ";
|
||||
mWalletModel.getDappsModel().addAccountCreationRequest(keyringId);
|
||||
}
|
||||
|
||||
private void updateWalletBadgeVisibility() {
|
||||
assert mWalletModel != null;
|
||||
mWalletModel.getDappsModel().updateWalletBadgeVisibility();
|
||||
@@ -1427,8 +1436,39 @@ public abstract class BraveActivity<C extends ChromeActivityComponent> extends C
|
||||
updateWalletBadgeVisibility();
|
||||
}
|
||||
});
|
||||
|
||||
mWalletModel.getDappsModel().mWalletIconNotificationVisible.observe(
|
||||
this, visible -> { setWalletBadgeVisibility(visible); });
|
||||
|
||||
mWalletModel.getDappsModel().mPendingWalletAccountCreationRequest.observe(this, request -> {
|
||||
if (request == null) return;
|
||||
mWalletModel.getKeyringModel().isWalletLocked(isLocked -> {
|
||||
// Cannot use mWalletModel.getKeyringModel().getKeyringInfo().isLocked as account
|
||||
// creation request can be triggered when the wallet is locked and keyringInfo will
|
||||
// be null
|
||||
if (!BraveWalletPreferences.getPrefWeb3NotificationsEnabled()) return;
|
||||
if (isLocked) {
|
||||
Tab tab = getActivityTab();
|
||||
if (tab != null) {
|
||||
walletInteractionDetected(tab.getWebContents());
|
||||
}
|
||||
showWalletPanel(false);
|
||||
return;
|
||||
}
|
||||
for (CryptoAccountTypeInfo info :
|
||||
mWalletModel.getCryptoModel().getSupportedCryptoAccountTypes()) {
|
||||
if (info.getCoinType() == request.getCoinType()) {
|
||||
Intent addAccountActivityIntent =
|
||||
new Intent(this, AddAccountActivity.class);
|
||||
addAccountActivityIntent.putExtra(AddAccountActivity.ACCOUNT, info);
|
||||
startActivity(addAccountActivityIntent);
|
||||
mWalletModel.getDappsModel().removeProcessedAccountCreationRequest(request);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
mWalletModel.getCryptoModel().getNetworkModel().mNeedToCreateAccountForNetwork.observe(
|
||||
this, networkInfo -> {
|
||||
if (networkInfo == null) return;
|
||||
|
||||
@@ -13,14 +13,18 @@ import org.chromium.brave_wallet.mojom.BraveWalletService;
|
||||
import org.chromium.brave_wallet.mojom.CoinType;
|
||||
import org.chromium.brave_wallet.mojom.JsonRpcService;
|
||||
import org.chromium.brave_wallet.mojom.KeyringService;
|
||||
import org.chromium.brave_wallet.mojom.KeyringServiceObserver;
|
||||
import org.chromium.brave_wallet.mojom.SignAllTransactionsRequest;
|
||||
import org.chromium.brave_wallet.mojom.SignTransactionRequest;
|
||||
import org.chromium.brave_wallet.mojom.TransactionInfo;
|
||||
import org.chromium.brave_wallet.mojom.TransactionStatus;
|
||||
import org.chromium.chrome.browser.crypto_wallet.activities.BraveWalletDAppsActivity;
|
||||
import org.chromium.chrome.browser.crypto_wallet.model.WalletAccountCreationRequest;
|
||||
import org.chromium.chrome.browser.crypto_wallet.util.AssetUtils;
|
||||
import org.chromium.chrome.browser.crypto_wallet.util.PendingTxHelper;
|
||||
import org.chromium.chrome.browser.crypto_wallet.util.Utils;
|
||||
import org.chromium.mojo.bindings.Callbacks;
|
||||
import org.chromium.mojo.system.MojoException;
|
||||
import org.chromium.mojo.system.Pair;
|
||||
import org.chromium.url.internal.mojom.Origin;
|
||||
|
||||
@@ -29,7 +33,7 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class DappsModel {
|
||||
public class DappsModel implements KeyringServiceObserver {
|
||||
private JsonRpcService mJsonRpcService;
|
||||
private KeyringService mKeyringService;
|
||||
private BraveWalletService mBraveWalletService;
|
||||
@@ -43,6 +47,9 @@ public class DappsModel {
|
||||
private final MutableLiveData<List<SignAllTransactionsRequest>> _mSignAllTxRequests;
|
||||
private final LiveData<List<SignTransactionRequest>> mSignTxRequests;
|
||||
private final LiveData<List<SignAllTransactionsRequest>> mSignAllTxRequests;
|
||||
private List<WalletAccountCreationRequest> mPendingWalletAccountCreationRequests;
|
||||
private MutableLiveData<WalletAccountCreationRequest> _mPendingWalletAccountCreationRequest;
|
||||
public LiveData<WalletAccountCreationRequest> mPendingWalletAccountCreationRequest;
|
||||
public final LiveData<Boolean> mWalletIconNotificationVisible = _mWalletIconNotificationVisible;
|
||||
public final LiveData<BraveWalletDAppsActivity.ActivityType> mProcessNextDAppsRequest =
|
||||
_mProcessNextDAppsRequest;
|
||||
@@ -57,32 +64,38 @@ public class DappsModel {
|
||||
mSignTxRequests = _mSignTxRequests;
|
||||
_mSignAllTxRequests = new MutableLiveData<>(Collections.emptyList());
|
||||
mSignAllTxRequests = _mSignAllTxRequests;
|
||||
_mPendingWalletAccountCreationRequest = new MutableLiveData<>();
|
||||
mPendingWalletAccountCreationRequest = _mPendingWalletAccountCreationRequest;
|
||||
mPendingWalletAccountCreationRequests = new ArrayList<>();
|
||||
mKeyringService.addObserver(this);
|
||||
}
|
||||
|
||||
public void fetchAccountsForConnectionReq(@CoinType.EnumType int coinType,
|
||||
Callbacks.Callback1<Pair<AccountInfo, List<AccountInfo>>> callback) {
|
||||
if (coinType == CoinType.ETH || coinType == CoinType.SOL) {
|
||||
mKeyringService.getKeyringInfo(Utils.getKeyringForCoinType(coinType), keyringInfo -> {
|
||||
mKeyringService.getSelectedAccount(coinType, accountAddress -> {
|
||||
if (coinType == CoinType.SOL) {
|
||||
// only the selected account is used for solana dapps
|
||||
for (AccountInfo accountInfo : keyringInfo.accountInfos) {
|
||||
if (accountAddress.equals(accountInfo.address)) {
|
||||
List<AccountInfo> accountInfos = new ArrayList<>();
|
||||
accountInfos.add(accountInfo);
|
||||
mKeyringService.getKeyringInfo(
|
||||
AssetUtils.getKeyringForCoinType(coinType), keyringInfo -> {
|
||||
mKeyringService.getSelectedAccount(coinType, accountAddress -> {
|
||||
if (coinType == CoinType.SOL) {
|
||||
// only the selected account is used for solana dapps
|
||||
for (AccountInfo accountInfo : keyringInfo.accountInfos) {
|
||||
if (accountAddress.equals(accountInfo.address)) {
|
||||
List<AccountInfo> accountInfos = new ArrayList<>();
|
||||
accountInfos.add(accountInfo);
|
||||
callback.call(new Pair<>(
|
||||
Utils.findAccount(
|
||||
keyringInfo.accountInfos, accountAddress),
|
||||
accountInfos));
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
callback.call(new Pair<>(
|
||||
Utils.findAccount(keyringInfo.accountInfos, accountAddress),
|
||||
accountInfos));
|
||||
return;
|
||||
Arrays.asList(keyringInfo.accountInfos)));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
callback.call(new Pair<>(
|
||||
Utils.findAccount(keyringInfo.accountInfos, accountAddress),
|
||||
Arrays.asList(keyringInfo.accountInfos)));
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
} else {
|
||||
callback.call(new Pair<>(null, Collections.emptyList()));
|
||||
}
|
||||
@@ -189,6 +202,32 @@ public class DappsModel {
|
||||
_mWalletIconNotificationVisible.setValue(false);
|
||||
}
|
||||
|
||||
public void addAccountCreationRequest(String keyringId) {
|
||||
if (keyringId == null) return;
|
||||
Utils.removeIf(mPendingWalletAccountCreationRequests,
|
||||
request -> request.getKeyringId().equals(keyringId));
|
||||
WalletAccountCreationRequest request = new WalletAccountCreationRequest(keyringId);
|
||||
mPendingWalletAccountCreationRequests.add(request);
|
||||
updatePendingAccountCreationRequest();
|
||||
}
|
||||
|
||||
public void removeProcessedAccountCreationRequest(WalletAccountCreationRequest request) {
|
||||
if (request == null) return;
|
||||
Utils.removeIf(mPendingWalletAccountCreationRequests,
|
||||
input -> input.getCoinType() == request.getCoinType());
|
||||
updatePendingAccountCreationRequest();
|
||||
}
|
||||
|
||||
public void showPendingAccountCreationRequest() {
|
||||
WalletAccountCreationRequest request = _mPendingWalletAccountCreationRequest.getValue();
|
||||
if (request != null) {
|
||||
_mPendingWalletAccountCreationRequest.postValue(request);
|
||||
} else if (!mPendingWalletAccountCreationRequests.isEmpty()) {
|
||||
_mPendingWalletAccountCreationRequest.postValue(
|
||||
mPendingWalletAccountCreationRequests.get(0));
|
||||
}
|
||||
}
|
||||
|
||||
private void updateWalletBadgeVisibilityInternal() {
|
||||
if (mBraveWalletService == null || mJsonRpcService == null || mPendingTxHelper == null) {
|
||||
return;
|
||||
@@ -243,4 +282,48 @@ public class DappsModel {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updatePendingAccountCreationRequest() {
|
||||
if (mPendingWalletAccountCreationRequests.isEmpty()) {
|
||||
_mPendingWalletAccountCreationRequest.postValue(null);
|
||||
} else {
|
||||
_mPendingWalletAccountCreationRequest.postValue(
|
||||
mPendingWalletAccountCreationRequests.get(0));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyringCreated(String keyringId) {}
|
||||
|
||||
@Override
|
||||
public void keyringRestored(String keyringId) {}
|
||||
|
||||
@Override
|
||||
public void keyringReset() {}
|
||||
|
||||
@Override
|
||||
public void locked() {}
|
||||
|
||||
@Override
|
||||
public void unlocked() {
|
||||
showPendingAccountCreationRequest();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void backedUp() {}
|
||||
|
||||
@Override
|
||||
public void accountsChanged() {}
|
||||
|
||||
@Override
|
||||
public void autoLockMinutesChanged() {}
|
||||
|
||||
@Override
|
||||
public void selectedAccountChanged(int coin) {}
|
||||
|
||||
@Override
|
||||
public void onConnectionError(MojoException e) {}
|
||||
|
||||
@Override
|
||||
public void close() {}
|
||||
}
|
||||
|
||||
@@ -273,6 +273,10 @@ public class KeyringModel implements KeyringServiceObserver {
|
||||
});
|
||||
}
|
||||
|
||||
public void isWalletLocked(Callbacks.Callback1<Boolean> callback) {
|
||||
mKeyringService.isLocked(isWalletLocked -> callback.call(isWalletLocked));
|
||||
}
|
||||
|
||||
private KeyringInfo getSelectedCoinKeyringInfo(int coinType) {
|
||||
String selectedCoinKeyringId = getSelectedCoinKeyringId(coinType);
|
||||
for (KeyringInfo keyringInfo : _mKeyringInfosLiveData.getValue()) {
|
||||
|
||||
+8
@@ -45,6 +45,14 @@ public class BraveWalletProviderDelegateImplHelper {
|
||||
return BraveWalletPreferences.getPrefWeb3NotificationsEnabled();
|
||||
}
|
||||
|
||||
@CalledByNative
|
||||
public static void ShowAccountCreation(String keyringId) {
|
||||
BraveActivity activity = BraveActivity.getBraveActivity();
|
||||
if (activity != null) {
|
||||
activity.showAccountCreation(keyringId);
|
||||
}
|
||||
}
|
||||
|
||||
public static void IsSolanaConnected(
|
||||
WebContents webContents, String account, Callbacks.Callback1<Boolean> callback) {
|
||||
Callback<Boolean> callbackWrapper = result -> {
|
||||
|
||||
+2
-1
@@ -39,6 +39,7 @@ import org.chromium.chrome.browser.crypto_wallet.listeners.OnWalletListItemClick
|
||||
import org.chromium.chrome.browser.crypto_wallet.model.CryptoAccountTypeInfo;
|
||||
import org.chromium.chrome.browser.crypto_wallet.model.WalletListItemModel;
|
||||
import org.chromium.chrome.browser.crypto_wallet.observers.ApprovedTxObserver;
|
||||
import org.chromium.chrome.browser.crypto_wallet.util.AssetUtils;
|
||||
import org.chromium.chrome.browser.crypto_wallet.util.PortfolioHelper;
|
||||
import org.chromium.chrome.browser.crypto_wallet.util.Utils;
|
||||
import org.chromium.chrome.browser.init.AsyncInitializationActivity;
|
||||
@@ -154,7 +155,7 @@ public class AccountDetailActivity
|
||||
|
||||
private void fetchAccountInfo(NetworkInfo selectedNetwork) {
|
||||
assert mKeyringService != null;
|
||||
mKeyringService.getKeyringInfo(Utils.getKeyringForCoinType(mCoinType), keyringInfo -> {
|
||||
mKeyringService.getKeyringInfo(AssetUtils.getKeyringForCoinType(mCoinType), keyringInfo -> {
|
||||
if (keyringInfo == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
+5
-2
@@ -26,6 +26,7 @@ import org.chromium.chrome.R;
|
||||
import org.chromium.chrome.browser.app.BraveActivity;
|
||||
import org.chromium.chrome.browser.app.domain.WalletModel;
|
||||
import org.chromium.chrome.browser.crypto_wallet.model.CryptoAccountTypeInfo;
|
||||
import org.chromium.chrome.browser.crypto_wallet.util.AssetUtils;
|
||||
import org.chromium.chrome.browser.crypto_wallet.util.Utils;
|
||||
import org.chromium.chrome.browser.crypto_wallet.util.WalletUtils;
|
||||
|
||||
@@ -95,7 +96,8 @@ public class AddAccountActivity extends BraveWalletBaseActivity {
|
||||
if (mIsUpdate) {
|
||||
if (mIsImported) {
|
||||
mKeyringService.setKeyringImportedAccountName(
|
||||
Utils.getKeyringForCoinType(mCryptoAccountTypeInfo.getCoinType()),
|
||||
AssetUtils.getKeyringForCoinType(
|
||||
mCryptoAccountTypeInfo.getCoinType()),
|
||||
mAddress, mAddAccountText.getText().toString(), result -> {
|
||||
if (result) {
|
||||
Intent returnIntent = new Intent();
|
||||
@@ -110,7 +112,8 @@ public class AddAccountActivity extends BraveWalletBaseActivity {
|
||||
});
|
||||
} else {
|
||||
mKeyringService.setKeyringDerivedAccountName(
|
||||
Utils.getKeyringForCoinType(mCryptoAccountTypeInfo.getCoinType()),
|
||||
AssetUtils.getKeyringForCoinType(
|
||||
mCryptoAccountTypeInfo.getCoinType()),
|
||||
mAddress, mAddAccountText.getText().toString(), result -> {
|
||||
if (result) {
|
||||
Intent returnIntent = new Intent();
|
||||
|
||||
+64
-58
@@ -302,67 +302,73 @@ public class AssetDetailActivity
|
||||
KeyringService keyringService = getKeyringService();
|
||||
JsonRpcService jsonRpcService = getJsonRpcService();
|
||||
if (keyringService != null && jsonRpcService != null) {
|
||||
keyringService.getKeyringInfo(Utils.getKeyringForCoinType(mCoinType), keyringInfo -> {
|
||||
if (keyringInfo == null) return;
|
||||
accountInfos = keyringInfo.accountInfos;
|
||||
jsonRpcService.getNetwork(mCoinType, selectedNetwork -> {
|
||||
WalletListItemModel thisAssetItemModel = new WalletListItemModel(
|
||||
R.drawable.ic_eth, mAsset.name, mAsset.symbol, mAsset.tokenId, "", "");
|
||||
Utils.getTxExtraInfo(this, selectedNetwork, accountInfos,
|
||||
new BlockchainToken[] {mAsset}, false,
|
||||
(assetPrices, fullTokenList, nativeAssetsBalances,
|
||||
blockchainTokensBalances) -> {
|
||||
thisAssetItemModel.setBlockchainToken(mAsset);
|
||||
Utils.setUpTransactionList(this, accountInfos, thisAssetItemModel,
|
||||
assetPrices, fullTokenList, nativeAssetsBalances,
|
||||
blockchainTokensBalances,
|
||||
findViewById(R.id.rv_transactions), this,
|
||||
mWalletTxCoinAdapter);
|
||||
keyringService.getKeyringInfo(
|
||||
AssetUtils.getKeyringForCoinType(mCoinType), keyringInfo -> {
|
||||
if (keyringInfo == null) return;
|
||||
accountInfos = keyringInfo.accountInfos;
|
||||
jsonRpcService.getNetwork(mCoinType, selectedNetwork -> {
|
||||
WalletListItemModel thisAssetItemModel =
|
||||
new WalletListItemModel(R.drawable.ic_eth, mAsset.name,
|
||||
mAsset.symbol, mAsset.tokenId, "", "");
|
||||
Utils.getTxExtraInfo(this, selectedNetwork, accountInfos,
|
||||
new BlockchainToken[] {mAsset}, false,
|
||||
(assetPrices, fullTokenList, nativeAssetsBalances,
|
||||
blockchainTokensBalances) -> {
|
||||
thisAssetItemModel.setBlockchainToken(mAsset);
|
||||
Utils.setUpTransactionList(this, accountInfos,
|
||||
thisAssetItemModel, assetPrices, fullTokenList,
|
||||
nativeAssetsBalances, blockchainTokensBalances,
|
||||
findViewById(R.id.rv_transactions), this,
|
||||
mWalletTxCoinAdapter);
|
||||
|
||||
double thisPrice = Utils.getOrDefault(assetPrices,
|
||||
mAsset.symbol.toLowerCase(Locale.getDefault()), 0.0d);
|
||||
List<WalletListItemModel> walletListItemModelList =
|
||||
new ArrayList<>();
|
||||
for (AccountInfo accountInfo : accountInfos) {
|
||||
final String accountAddressLower =
|
||||
accountInfo.address.toLowerCase(Locale.getDefault());
|
||||
double thisAccountBalance =
|
||||
Utils.isNativeToken(selectedNetwork, mAsset)
|
||||
? Utils.getOrDefault(
|
||||
nativeAssetsBalances, accountAddressLower, 0.0d)
|
||||
: Utils.getOrDefault(
|
||||
Utils.getOrDefault(blockchainTokensBalances,
|
||||
accountAddressLower,
|
||||
new HashMap<String, Double>()),
|
||||
Utils.tokenToString(mAsset), 0.0d);
|
||||
final String fiatBalanceString =
|
||||
String.format(Locale.getDefault(), "$%,.2f",
|
||||
thisPrice * thisAccountBalance);
|
||||
final String cryptoBalanceString =
|
||||
String.format(Locale.getDefault(), "%.4f %s",
|
||||
thisAccountBalance, mAsset.symbol);
|
||||
double thisPrice = Utils.getOrDefault(assetPrices,
|
||||
mAsset.symbol.toLowerCase(Locale.getDefault()),
|
||||
0.0d);
|
||||
List<WalletListItemModel> walletListItemModelList =
|
||||
new ArrayList<>();
|
||||
for (AccountInfo accountInfo : accountInfos) {
|
||||
final String accountAddressLower =
|
||||
accountInfo.address.toLowerCase(
|
||||
Locale.getDefault());
|
||||
double thisAccountBalance =
|
||||
Utils.isNativeToken(selectedNetwork, mAsset)
|
||||
? Utils.getOrDefault(nativeAssetsBalances,
|
||||
accountAddressLower, 0.0d)
|
||||
: Utils.getOrDefault(
|
||||
Utils.getOrDefault(
|
||||
blockchainTokensBalances,
|
||||
accountAddressLower,
|
||||
new HashMap<String, Double>()),
|
||||
Utils.tokenToString(mAsset), 0.0d);
|
||||
final String fiatBalanceString =
|
||||
String.format(Locale.getDefault(), "$%,.2f",
|
||||
thisPrice * thisAccountBalance);
|
||||
final String cryptoBalanceString =
|
||||
String.format(Locale.getDefault(), "%.4f %s",
|
||||
thisAccountBalance, mAsset.symbol);
|
||||
|
||||
WalletListItemModel model = new WalletListItemModel(
|
||||
R.drawable.ic_eth, accountInfo.name,
|
||||
accountInfo.address, fiatBalanceString,
|
||||
cryptoBalanceString, accountInfo.isImported);
|
||||
model.setAccountInfo(accountInfo);
|
||||
walletListItemModelList.add(model);
|
||||
WalletListItemModel model = new WalletListItemModel(
|
||||
R.drawable.ic_eth, accountInfo.name,
|
||||
accountInfo.address, fiatBalanceString,
|
||||
cryptoBalanceString, accountInfo.isImported);
|
||||
model.setAccountInfo(accountInfo);
|
||||
walletListItemModelList.add(model);
|
||||
|
||||
if (walletCoinAdapter != null) {
|
||||
walletCoinAdapter.setWalletListItemModelList(
|
||||
walletListItemModelList);
|
||||
walletCoinAdapter.setOnWalletListItemClick(
|
||||
AssetDetailActivity.this);
|
||||
walletCoinAdapter.setWalletListItemType(Utils.ACCOUNT_ITEM);
|
||||
rvAccounts.setAdapter(walletCoinAdapter);
|
||||
rvAccounts.setLayoutManager(
|
||||
new LinearLayoutManager(AssetDetailActivity.this));
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
if (walletCoinAdapter != null) {
|
||||
walletCoinAdapter.setWalletListItemModelList(
|
||||
walletListItemModelList);
|
||||
walletCoinAdapter.setOnWalletListItemClick(
|
||||
AssetDetailActivity.this);
|
||||
walletCoinAdapter.setWalletListItemType(
|
||||
Utils.ACCOUNT_ITEM);
|
||||
rvAccounts.setAdapter(walletCoinAdapter);
|
||||
rvAccounts.setLayoutManager(new LinearLayoutManager(
|
||||
AssetDetailActivity.this));
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+51
-46
@@ -53,6 +53,7 @@ import org.chromium.chrome.browser.crypto_wallet.adapters.ApproveTxFragmentPageA
|
||||
import org.chromium.chrome.browser.crypto_wallet.listeners.TransactionConfirmationListener;
|
||||
import org.chromium.chrome.browser.crypto_wallet.observers.ApprovedTxObserver;
|
||||
import org.chromium.chrome.browser.crypto_wallet.util.AndroidUtils;
|
||||
import org.chromium.chrome.browser.crypto_wallet.util.AssetUtils;
|
||||
import org.chromium.chrome.browser.crypto_wallet.util.ParsedTransaction;
|
||||
import org.chromium.chrome.browser.crypto_wallet.util.SolanaTransactionsGasHelper;
|
||||
import org.chromium.chrome.browser.crypto_wallet.util.TokenUtils;
|
||||
@@ -249,54 +250,58 @@ public class ApproveTxBottomSheetDialogFragment extends BottomSheetDialogFragmen
|
||||
mCoinType = TransactionUtils.getCoinFromTxDataUnion(mTxInfo.txDataUnion);
|
||||
jsonRpcService.getNetwork(mCoinType, selectedNetwork -> {
|
||||
networkName.setText(selectedNetwork.chainName);
|
||||
keyringService.getKeyringInfo(Utils.getKeyringForCoinType(mCoinType), keyringInfo -> {
|
||||
final AccountInfo[] accounts = keyringInfo.accountInfos;
|
||||
// First fill in data that does not require remote queries
|
||||
TokenUtils.getAllTokensFiltered(getBraveWalletService(), getBlockchainRegistry(),
|
||||
selectedNetwork, selectedNetwork.coin, TokenUtils.TokenType.ALL,
|
||||
tokenList -> {
|
||||
SolanaTransactionsGasHelper solanaTransactionsGasHelper =
|
||||
new SolanaTransactionsGasHelper(
|
||||
(BraveWalletBaseActivity) getActivity(),
|
||||
new TransactionInfo[] {mTxInfo});
|
||||
solanaTransactionsGasHelper.maybeGetSolanaGasEstimations(() -> {
|
||||
HashMap<String, Long> perTxFee =
|
||||
solanaTransactionsGasHelper.getPerTxFee();
|
||||
if (perTxFee.get(mTxInfo.id) != null) {
|
||||
mSolanaEstimatedTxFee = perTxFee.get(mTxInfo.id);
|
||||
}
|
||||
if (!canUpdateUi()) return;
|
||||
ParsedTransaction parsedTx = fillAssetDependentControls(view,
|
||||
selectedNetwork, accounts, new HashMap<String, Double>(),
|
||||
tokenList, new HashMap<String, Double>(),
|
||||
new HashMap<String, HashMap<String, Double>>(),
|
||||
mSolanaEstimatedTxFee);
|
||||
keyringService.getKeyringInfo(
|
||||
AssetUtils.getKeyringForCoinType(mCoinType), keyringInfo -> {
|
||||
final AccountInfo[] accounts = keyringInfo.accountInfos;
|
||||
// First fill in data that does not require remote queries
|
||||
TokenUtils.getAllTokensFiltered(getBraveWalletService(),
|
||||
getBlockchainRegistry(), selectedNetwork, selectedNetwork.coin,
|
||||
TokenUtils.TokenType.ALL, tokenList -> {
|
||||
SolanaTransactionsGasHelper solanaTransactionsGasHelper =
|
||||
new SolanaTransactionsGasHelper(
|
||||
(BraveWalletBaseActivity) getActivity(),
|
||||
new TransactionInfo[] {mTxInfo});
|
||||
solanaTransactionsGasHelper.maybeGetSolanaGasEstimations(() -> {
|
||||
HashMap<String, Long> perTxFee =
|
||||
solanaTransactionsGasHelper.getPerTxFee();
|
||||
if (perTxFee.get(mTxInfo.id) != null) {
|
||||
mSolanaEstimatedTxFee = perTxFee.get(mTxInfo.id);
|
||||
}
|
||||
if (!canUpdateUi()) return;
|
||||
ParsedTransaction parsedTx = fillAssetDependentControls(
|
||||
view, selectedNetwork, accounts,
|
||||
new HashMap<String, Double>(), tokenList,
|
||||
new HashMap<String, Double>(),
|
||||
new HashMap<String, HashMap<String, Double>>(),
|
||||
mSolanaEstimatedTxFee);
|
||||
|
||||
// Get tokens involved in this transaction
|
||||
List<BlockchainToken> tokens = new ArrayList<>();
|
||||
tokens.add(Utils.makeNetworkAsset(
|
||||
selectedNetwork)); // Always add native asset
|
||||
if (parsedTx.getIsSwap()) {
|
||||
tokens.add(parsedTx.getSellToken());
|
||||
tokens.add(parsedTx.getBuyToken());
|
||||
} else if (parsedTx.getToken() != null)
|
||||
tokens.add(parsedTx.getToken());
|
||||
BlockchainToken[] filterByTokens =
|
||||
tokens.toArray(new BlockchainToken[0]);
|
||||
// Get tokens involved in this transaction
|
||||
List<BlockchainToken> tokens = new ArrayList<>();
|
||||
tokens.add(Utils.makeNetworkAsset(
|
||||
selectedNetwork)); // Always add native asset
|
||||
if (parsedTx.getIsSwap()) {
|
||||
tokens.add(parsedTx.getSellToken());
|
||||
tokens.add(parsedTx.getBuyToken());
|
||||
} else if (parsedTx.getToken() != null)
|
||||
tokens.add(parsedTx.getToken());
|
||||
BlockchainToken[] filterByTokens =
|
||||
tokens.toArray(new BlockchainToken[0]);
|
||||
|
||||
Utils.getTxExtraInfo((BraveWalletBaseActivity) getActivity(),
|
||||
selectedNetwork, accounts, filterByTokens, false,
|
||||
(assetPrices, fullTokenList, nativeAssetsBalances,
|
||||
blockchainTokensBalances) -> {
|
||||
if (!canUpdateUi()) return;
|
||||
fillAssetDependentControls(view, selectedNetwork,
|
||||
accounts, assetPrices, fullTokenList,
|
||||
nativeAssetsBalances, blockchainTokensBalances,
|
||||
mSolanaEstimatedTxFee);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
Utils.getTxExtraInfo(
|
||||
(BraveWalletBaseActivity) getActivity(),
|
||||
selectedNetwork, accounts, filterByTokens, false,
|
||||
(assetPrices, fullTokenList, nativeAssetsBalances,
|
||||
blockchainTokensBalances) -> {
|
||||
if (!canUpdateUi()) return;
|
||||
fillAssetDependentControls(view,
|
||||
selectedNetwork, accounts, assetPrices,
|
||||
fullTokenList, nativeAssetsBalances,
|
||||
blockchainTokensBalances,
|
||||
mSolanaEstimatedTxFee);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
ImageView icon = (ImageView) view.findViewById(R.id.account_picture);
|
||||
Utils.setBlockiesBitmapResource(mExecutor, mHandler, icon, mTxInfo.fromAddress, true);
|
||||
|
||||
+2
-1
@@ -47,6 +47,7 @@ import org.chromium.chrome.browser.crypto_wallet.activities.BraveWalletActivity;
|
||||
import org.chromium.chrome.browser.crypto_wallet.adapters.WalletCoinAdapter;
|
||||
import org.chromium.chrome.browser.crypto_wallet.listeners.OnWalletListItemClick;
|
||||
import org.chromium.chrome.browser.crypto_wallet.observers.ApprovedTxObserver;
|
||||
import org.chromium.chrome.browser.crypto_wallet.util.AssetUtils;
|
||||
import org.chromium.chrome.browser.crypto_wallet.util.PendingTxHelper;
|
||||
import org.chromium.chrome.browser.crypto_wallet.util.PortfolioHelper;
|
||||
import org.chromium.chrome.browser.crypto_wallet.util.SmoothLineChartEquallySpaced;
|
||||
@@ -402,7 +403,7 @@ public class PortfolioFragment
|
||||
return;
|
||||
}
|
||||
keyringService.getKeyringInfo(
|
||||
Utils.getKeyringForCoinType(selectedNetwork.coin), keyringInfo -> {
|
||||
AssetUtils.getKeyringForCoinType(selectedNetwork.coin), keyringInfo -> {
|
||||
AccountInfo[] accountInfos = new AccountInfo[] {};
|
||||
if (keyringInfo != null) {
|
||||
accountInfos = keyringInfo.accountInfos;
|
||||
|
||||
@@ -48,6 +48,7 @@ import org.chromium.chrome.browser.crypto_wallet.activities.AccountSelectorActiv
|
||||
import org.chromium.chrome.browser.crypto_wallet.activities.BraveWalletDAppsActivity;
|
||||
import org.chromium.chrome.browser.crypto_wallet.activities.NetworkSelectorActivity;
|
||||
import org.chromium.chrome.browser.crypto_wallet.util.AccountsPermissionsHelper;
|
||||
import org.chromium.chrome.browser.crypto_wallet.util.AssetUtils;
|
||||
import org.chromium.chrome.browser.crypto_wallet.util.AssetsPricesHelper;
|
||||
import org.chromium.chrome.browser.crypto_wallet.util.BalanceHelper;
|
||||
import org.chromium.chrome.browser.crypto_wallet.util.Utils;
|
||||
@@ -91,7 +92,7 @@ public class BraveWalletPanel implements DialogInterface {
|
||||
if (accountInfo == null) return;
|
||||
mSelectedAccount = accountInfo;
|
||||
mBraveWalletPanelServices.getKeyringService().getKeyringInfo(
|
||||
Utils.getKeyringForCoinType(mSelectedAccount.coin), keyringInfo -> {
|
||||
AssetUtils.getKeyringForCoinType(mSelectedAccount.coin), keyringInfo -> {
|
||||
if (keyringInfo != null) {
|
||||
mAccountInfos = keyringInfo.accountInfos;
|
||||
}
|
||||
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
/* Copyright (c) 2022 The Brave Authors. All rights reserved.
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.chromium.chrome.browser.crypto_wallet.model;
|
||||
|
||||
import org.chromium.brave_wallet.mojom.CoinType;
|
||||
import org.chromium.chrome.browser.crypto_wallet.util.AssetUtils;
|
||||
|
||||
public class WalletAccountCreationRequest {
|
||||
private String mKeyringId;
|
||||
private @CoinType.EnumType int mCoinType;
|
||||
|
||||
public WalletAccountCreationRequest(String keyringId) {
|
||||
assert keyringId != null : " keyringId should not be null";
|
||||
mKeyringId = keyringId;
|
||||
mCoinType = AssetUtils.getCoinForKeyring(keyringId);
|
||||
}
|
||||
|
||||
public String getKeyringId() {
|
||||
return mKeyringId;
|
||||
}
|
||||
|
||||
public int getCoinType() {
|
||||
return mCoinType;
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ package org.chromium.chrome.browser.crypto_wallet.util;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import org.chromium.brave_wallet.mojom.BraveWalletConstants;
|
||||
import org.chromium.brave_wallet.mojom.CoinType;
|
||||
|
||||
public class AssetUtils {
|
||||
public static String AURORA_SUPPORTED_CONTRACT_ADDRESSES[] = {
|
||||
@@ -56,4 +57,41 @@ public class AssetUtils {
|
||||
return (isEthereumBridgeAddress || isNativeAsset)
|
||||
&& chainId.equals(BraveWalletConstants.MAINNET_CHAIN_ID);
|
||||
}
|
||||
|
||||
public static String getKeyringForCoinType(int coinType) {
|
||||
String keyring = BraveWalletConstants.DEFAULT_KEYRING_ID;
|
||||
switch (coinType) {
|
||||
case CoinType.ETH:
|
||||
keyring = BraveWalletConstants.DEFAULT_KEYRING_ID;
|
||||
break;
|
||||
case CoinType.SOL:
|
||||
keyring = BraveWalletConstants.SOLANA_KEYRING_ID;
|
||||
break;
|
||||
case CoinType.FIL:
|
||||
keyring = BraveWalletConstants.FILECOIN_KEYRING_ID;
|
||||
break;
|
||||
default:
|
||||
keyring = BraveWalletConstants.DEFAULT_KEYRING_ID;
|
||||
break;
|
||||
}
|
||||
|
||||
return keyring;
|
||||
}
|
||||
|
||||
public static @CoinType.EnumType int getCoinForKeyring(String keyringId) {
|
||||
int coin = CoinType.ETH; // For default keyring
|
||||
switch (keyringId) {
|
||||
case BraveWalletConstants.SOLANA_KEYRING_ID:
|
||||
coin = CoinType.SOL;
|
||||
break;
|
||||
// Todo(pav): Un-comment once Filecoin is supported
|
||||
// case BraveWalletConstants.FILECOIN_KEYRING_ID:
|
||||
// case BraveWalletConstants.FILECOIN_TESTNET_KEYRING_ID:
|
||||
// coin = CoinType.FIL;
|
||||
// break;
|
||||
default:
|
||||
// Do nothing
|
||||
}
|
||||
return coin;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,9 @@ void ShowWalletOnboarding(content::WebContents*) {
|
||||
|
||||
void ShowAccountCreation(content::WebContents* web_contents,
|
||||
const std::string& keyring_id) {
|
||||
NOTIMPLEMENTED();
|
||||
JNIEnv* env = base::android::AttachCurrentThread();
|
||||
Java_BraveWalletProviderDelegateImplHelper_ShowAccountCreation(
|
||||
env, base::android::ConvertUTF8ToJavaString(env, keyring_id));
|
||||
}
|
||||
|
||||
void WalletInteractionDetected(content::WebContents* web_contents) {
|
||||
|
||||
Reference in New Issue
Block a user