Merge pull request #13733 from brave/dapps-implement-wallet-badge

Dapps implement wallet notification/badge no address bar
This commit is contained in:
Qamar Zaman
2022-06-15 01:03:18 +05:00
committed by GitHub
8 changed files with 142 additions and 28 deletions
+1
View File
@@ -44,6 +44,7 @@ brave_java_sources = [
"../../brave/android/java/org/chromium/chrome/browser/app/appmenu/AppMenuIconRowFooter.java",
"../../brave/android/java/org/chromium/chrome/browser/app/appmenu/BraveAppMenuPropertiesDelegateImpl.java",
"../../brave/android/java/org/chromium/chrome/browser/app/domain/CryptoModel.java",
"../../brave/android/java/org/chromium/chrome/browser/app/domain/DappsModel.java",
"../../brave/android/java/org/chromium/chrome/browser/app/domain/CryptoSharedData.java",
"../../brave/android/java/org/chromium/chrome/browser/app/domain/KeyringModel.java",
"../../brave/android/java/org/chromium/chrome/browser/app/domain/NetworkModel.java",
@@ -348,6 +348,14 @@ public abstract class BraveActivity<C extends ChromeActivityComponent> extends C
});
}
private void setWalletBadgeVisibility(boolean visibile) {
BraveToolbarLayoutImpl layout = getBraveToolbarLayout();
if (layout != null) {
layout.updateWalletBadgeVisibility(visibile);
}
}
private void maybeShowPendingTransactions() {
assert walletModel != null;
// trigger to observer to refresh data to process the pending request
@@ -472,9 +480,15 @@ public abstract class BraveActivity<C extends ChromeActivityComponent> extends C
BraveToolbarLayoutImpl layout = getBraveToolbarLayout();
if (layout != null) {
layout.showWalletIcon(true);
updateWalletBadgeVisibility();
}
}
private void updateWalletBadgeVisibility() {
assert walletModel != null;
walletModel.getDappsModel().updateWalletBadgeVisibility();
}
private void verifySubscription() {
List<Purchase> purchases = InAppPurchaseWrapper.getInstance().queryPurchases();
if (purchases != null && purchases.size() == 1) {
@@ -657,6 +671,7 @@ public abstract class BraveActivity<C extends ChromeActivityComponent> extends C
// If active tab is private, set private DSE as an active DSE.
BraveSearchEngineUtils.updateActiveDSE(tab.isIncognito());
BraveStatsUtil.removeShareStatsFile();
updateWalletBadgeVisibility();
}
@Override
@@ -1319,6 +1334,9 @@ public abstract class BraveActivity<C extends ChromeActivityComponent> extends C
BraveWalletDAppsActivity.ActivityType.CONFIRM_TRANSACTION);
}
});
walletModel.getDappsModel().mWalletIconNotificationVisible.removeObservers(this);
walletModel.getDappsModel().mWalletIconNotificationVisible.observe(
this, visible -> { setWalletBadgeVisibility(visible); });
}
private void showBraveRateDialog() {
@@ -0,0 +1,96 @@
/* 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.app.domain;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.Transformations;
import org.chromium.brave_wallet.mojom.AccountInfo;
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.JsonRpcService;
import org.chromium.brave_wallet.mojom.KeyringService;
import org.chromium.brave_wallet.mojom.TransactionInfo;
import org.chromium.brave_wallet.mojom.TransactionStatus;
import org.chromium.chrome.browser.crypto_wallet.util.PendingTxHelper;
import org.chromium.chrome.browser.crypto_wallet.util.Utils;
public class DappsModel {
private JsonRpcService mJsonRpcService;
private BraveWalletService mBraveWalletService;
private CryptoModel mCryptoModel;
private PendingTxHelper mPendingTxHelper;
private final MutableLiveData<Boolean> _mWalletIconNotificationVisible =
new MutableLiveData<>(false);
public final LiveData<Boolean> mWalletIconNotificationVisible = _mWalletIconNotificationVisible;
public DappsModel(JsonRpcService jsonRpcService,
BraveWalletService braveWalletService, PendingTxHelper pendingTxHelper) {
mBraveWalletService = braveWalletService;
mJsonRpcService = jsonRpcService;
mPendingTxHelper = pendingTxHelper;
}
public void resetServices(JsonRpcService jsonRpcService,
BraveWalletService braveWalletService, PendingTxHelper pendingTxHelper) {
mBraveWalletService = braveWalletService;
mJsonRpcService = jsonRpcService;
mPendingTxHelper = pendingTxHelper;
}
public void updateWalletBadgeVisibility() {
_mWalletIconNotificationVisible.setValue(false);
mBraveWalletService.getPendingSignMessageRequests(requests -> {
if (requests != null && requests.length > 0) {
setWalletBadgeVisible();
return;
}
});
mBraveWalletService.getPendingAddSuggestTokenRequests(requests -> {
if (requests != null && requests.length > 0) {
setWalletBadgeVisible();
return;
}
});
mBraveWalletService.getPendingGetEncryptionPublicKeyRequests(requests -> {
if (requests != null && requests.length > 0) {
setWalletBadgeVisible();
return;
}
});
mJsonRpcService.getPendingAddChainRequests(networks -> {
if (networks != null && networks.length > 0) {
setWalletBadgeVisible();
return;
}
});
mJsonRpcService.getPendingSwitchChainRequests(requests -> {
if (requests != null && requests.length > 0) {
setWalletBadgeVisible();
return;
}
});
for (TransactionInfo info : mPendingTxHelper.mTransactionInfoLd.getValue()) {
if (info.txStatus == TransactionStatus.UNAPPROVED) {
setWalletBadgeVisible();
break;
}
}
}
public void setWalletBadgeVisible() {
_mWalletIconNotificationVisible.setValue(true);
}
public void setWalletBadgeInvisible() {
_mWalletIconNotificationVisible.setValue(false);
}
}
@@ -26,6 +26,7 @@ public class WalletModel {
private BraveWalletService mBraveWalletService;
private AssetRatioService mAssetRatioService;
private final CryptoModel mCryptoModel;
private final DappsModel mDappsModel;
private final KeyringModel mKeyringModel;
public WalletModel(KeyringService keyringService, BlockchainRegistry blockchainRegistry,
@@ -43,6 +44,7 @@ public class WalletModel {
mCryptoModel = new CryptoModel(mTxService, mKeyringService, mBlockchainRegistry,
mJsonRpcService, mEthTxManagerProxy, mSolanaTxManagerProxy, mBraveWalletService,
mAssetRatioService);
mDappsModel = new DappsModel(mJsonRpcService, mBraveWalletService, mCryptoModel.getPendingTxHelper());
mKeyringModel = new KeyringModel(keyringService, mCryptoModel.getSharedData());
init();
}
@@ -62,6 +64,7 @@ public class WalletModel {
mCryptoModel.resetServices(mTxService, mKeyringService, mBlockchainRegistry,
mJsonRpcService, mEthTxManagerProxy, mSolanaTxManagerProxy, mBraveWalletService,
mAssetRatioService);
mDappsModel.resetServices(mJsonRpcService, mBraveWalletService, mCryptoModel.getPendingTxHelper());
mKeyringModel.resetService(mKeyringService);
init();
}
@@ -89,6 +92,10 @@ public class WalletModel {
return mCryptoModel;
}
public DappsModel getDappsModel() {
return mDappsModel;
}
public KeyringService getKeyringService() {
return mKeyringService;
}
@@ -76,6 +76,9 @@ public class PendingTxHelper implements TxServiceObserver {
public void fetchTransactions(Runnable runWhenDone) {
isFetchingTx = true;
mTransactionInfos.clear();
mCacheTransactionInfos.clear();
mTxInfos.clear();
_mTransactionInfos.postValue(Collections.emptyList());
_mSelectedPendingRequest.postValue(null);
AsyncUtils.MultiResponseHandler allTxMultiResponse =
@@ -171,7 +174,6 @@ public class PendingTxHelper implements TxServiceObserver {
}
private void updateTransactionList() {
mTransactionInfos.clear();
for (TransactionInfo[] transactionInfoArr : mTxInfos.values()) {
Collections.addAll(mTransactionInfos, transactionInfoArr);
}
@@ -169,6 +169,7 @@ public abstract class BraveToolbarLayoutImpl extends ToolbarLayout
private BraveShieldsContentSettingsObserver mBraveShieldsContentSettingsObserver;
private TextView mBraveRewardsNotificationsCount;
private ImageView mBraveRewardsOnboardingIcon;
private View mBraveWalletBadge;
private boolean mShieldsLayoutIsColorBackground;
private int mCurrentToolbarColor;
@@ -224,6 +225,7 @@ public abstract class BraveToolbarLayoutImpl extends ToolbarLayout
mBraveShieldsButton = (ImageButton) findViewById(R.id.brave_shields_button);
mBraveRewardsButton = (ImageButton) findViewById(R.id.brave_rewards_button);
mHomeButton = (HomeButton) findViewById(R.id.home_button);
mBraveWalletBadge = findViewById(R.id.wallet_notfication_badge);
if (mHomeButton != null) {
mHomeButton.setOnLongClickListener(this);
@@ -1256,6 +1258,11 @@ public abstract class BraveToolbarLayoutImpl extends ToolbarLayout
BraveMenuButtonCoordinator.setMenuFromBottom(isMenuButtonOnBottom());
}
public void updateWalletBadgeVisibility(boolean visible) {
assert mBraveWalletBadge!=null;
mBraveWalletBadge.setVisibility(visible ? View.VISIBLE : View.GONE);
}
public void updateMenuButtonState() {
BraveMenuButtonCoordinator.setMenuFromBottom(mIsBottomToolbarVisible);
}
+9 -27
View File
@@ -27,33 +27,15 @@
android:layout_gravity="center"
android:contentDescription="@string/accessibility_toolbar_btn_brave_wallet" />
<org.chromium.chrome.browser.BraveBadge
android:id="@+id/brave_wallet_badge_small"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_marginStart="28dp"
android:layout_marginTop="6dp"
android:gravity="center"
android:visibility="invisible"
android:background="@drawable/brave_badge_shields_background_small"
android:textColor="@android:color/white"
android:translationZ="1dp"
android:fontFamily="sans-serif-bold"
android:textSize="12sp" />
<org.chromium.chrome.browser.BraveBadge
android:id="@+id/brave_wallet_badge_large"
android:layout_width="18dp"
android:layout_height="16dp"
android:layout_marginStart="28dp"
android:layout_marginTop="6dp"
android:gravity="center"
android:visibility="invisible"
android:background="@drawable/brave_badge_shields_background_large"
android:textColor="@android:color/white"
android:translationZ="1dp"
android:fontFamily="sans-serif-bold"
android:textSize="12sp" />
<View
android:id="@+id/wallet_notfication_badge"
android:layout_width="10dp"
android:layout_height="10dp"
android:layout_marginTop="7dp"
android:layout_marginEnd="6dp"
android:layout_gravity="end"
android:visibility="gone"
android:background="@drawable/brave_rewards_circle"/>
</FrameLayout>
<FrameLayout android:id="@+id/brave_shields_button_layout"
@@ -7,6 +7,7 @@
android:background="@color/wallet_bg"
android:paddingHorizontal="12dp"
android:paddingTop="48dp"
android:paddingBottom="20dp"
tools:context=".browser.crypto_wallet.fragments.dapps.SignMessageFragment">
<ImageView