From dfbc4e9fd4efd95ce62965e6af324e01b00d8237 Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Tue, 5 Sep 2023 13:39:50 -0700 Subject: [PATCH] Add permission duration to connect from panel on desktop --- .../brave_wallet_provider_delegate_impl.cc | 12 ------ .../brave_wallet_service_delegate_impl.cc | 12 ------ .../brave_wallet_service_delegate_impl.h | 3 -- .../ethereum_provider_impl_unittest.cc | 10 ++--- .../send_or_sign_transaction_browsertest.cc | 17 ++------- .../solana_provider_impl_unittest.cc | 11 ++---- .../webui/brave_wallet/panel_handler/BUILD.gn | 1 + .../panel_handler/wallet_panel_handler.cc | 38 +++++++++++++++++++ .../panel_handler/wallet_panel_handler.h | 2 + .../browser/brave_wallet_service.cc | 12 ------ .../browser/brave_wallet_service.h | 2 - .../brave_wallet/browser/permission_utils.cc | 12 ++++++ .../brave_wallet/browser/permission_utils.h | 3 ++ .../browser/permission_utils_unittest.cc | 22 +++++++++++ .../brave_wallet/common/brave_wallet.mojom | 11 ++++-- .../common/actions/wallet_actions.ts | 1 - .../brave_wallet_ui/common/async/handlers.ts | 7 ---- .../common/constants/action_types.ts | 4 -- .../common/slices/wallet.slice.ts | 3 -- .../connected-account-item/index.tsx | 4 +- .../change-account-button.tsx | 6 ++- .../dapp-connection-main.tsx | 6 ++- .../panel/actions/wallet_panel_actions.ts | 3 ++ .../panel/async/wallet_panel_async_handler.ts | 8 ++++ .../panel/constants/action_types.ts | 4 ++ 25 files changed, 122 insertions(+), 92 deletions(-) diff --git a/browser/brave_wallet/brave_wallet_provider_delegate_impl.cc b/browser/brave_wallet/brave_wallet_provider_delegate_impl.cc index 31e2bda7a10f..6b3caf300063 100644 --- a/browser/brave_wallet/brave_wallet_provider_delegate_impl.cc +++ b/browser/brave_wallet/brave_wallet_provider_delegate_impl.cc @@ -57,18 +57,6 @@ void OnRequestPermissions( } } -absl::optional CoinTypeToPermissionRequestType( - mojom::CoinType coin_type) { - switch (coin_type) { - case mojom::CoinType::ETH: - return permissions::RequestType::kBraveEthereum; - case mojom::CoinType::SOL: - return permissions::RequestType::kBraveSolana; - default: - return absl::nullopt; - } -} - } // namespace BraveWalletProviderDelegateImpl::BraveWalletProviderDelegateImpl( diff --git a/browser/brave_wallet/brave_wallet_service_delegate_impl.cc b/browser/brave_wallet/brave_wallet_service_delegate_impl.cc index 2edefeb51b2c..1c200262f110 100644 --- a/browser/brave_wallet/brave_wallet_service_delegate_impl.cc +++ b/browser/brave_wallet/brave_wallet_service_delegate_impl.cc @@ -149,18 +149,6 @@ void BraveWalletServiceDelegateImpl::ContinueGetImportInfoFromExternalWallet( } } -bool BraveWalletServiceDelegateImpl::AddPermission(mojom::CoinType coin, - const url::Origin& origin, - const std::string& account) { - auto type = CoinTypeToPermissionType(coin); - if (!type) { - return false; - } - - return permissions::BraveWalletPermissionContext::AddPermission( - *type, context_, origin, account); -} - bool BraveWalletServiceDelegateImpl::HasPermission(mojom::CoinType coin, const url::Origin& origin, const std::string& account) { diff --git a/browser/brave_wallet/brave_wallet_service_delegate_impl.h b/browser/brave_wallet/brave_wallet_service_delegate_impl.h index 36caa3a67907..ba004e210cc3 100644 --- a/browser/brave_wallet/brave_wallet_service_delegate_impl.h +++ b/browser/brave_wallet/brave_wallet_service_delegate_impl.h @@ -50,9 +50,6 @@ class BraveWalletServiceDelegateImpl : public BraveWalletServiceDelegate, const std::string& password, GetImportInfoCallback callback) override; - bool AddPermission(mojom::CoinType coin, - const url::Origin& origin, - const std::string& account) override; bool HasPermission(mojom::CoinType coin, const url::Origin& origin, const std::string& account) override; diff --git a/browser/brave_wallet/ethereum_provider_impl_unittest.cc b/browser/brave_wallet/ethereum_provider_impl_unittest.cc index 20585aec0892..0fa10f5721b5 100644 --- a/browser/brave_wallet/ethereum_provider_impl_unittest.cc +++ b/browser/brave_wallet/ethereum_provider_impl_unittest.cc @@ -464,13 +464,9 @@ class EthereumProviderImplUnitTest : public testing::Test { } void AddEthereumPermission(const mojom::AccountIdPtr& account_id) { - base::RunLoop run_loop; - brave_wallet_service_->AddPermission( - account_id.Clone(), base::BindLambdaForTesting([&](bool success) { - EXPECT_TRUE(success); - run_loop.Quit(); - })); - run_loop.Run(); + EXPECT_TRUE(permissions::BraveWalletPermissionContext::AddPermission( + blink::PermissionType::BRAVE_ETHEREUM, browser_context(), GetOrigin(), + account_id->address)); } void ResetEthereumPermission(const mojom::AccountIdPtr& account_id) { diff --git a/browser/brave_wallet/send_or_sign_transaction_browsertest.cc b/browser/brave_wallet/send_or_sign_transaction_browsertest.cc index c307b8271837..54da53d771a1 100644 --- a/browser/brave_wallet/send_or_sign_transaction_browsertest.cc +++ b/browser/brave_wallet/send_or_sign_transaction_browsertest.cc @@ -11,12 +11,10 @@ #include "base/strings/stringprintf.h" #include "base/test/bind.h" #include "base/test/scoped_feature_list.h" -#include "brave/browser/brave_wallet/brave_wallet_service_factory.h" #include "brave/browser/brave_wallet/brave_wallet_tab_helper.h" #include "brave/browser/brave_wallet/json_rpc_service_factory.h" #include "brave/browser/brave_wallet/keyring_service_factory.h" #include "brave/browser/brave_wallet/tx_service_factory.h" -#include "brave/components/brave_wallet/browser/brave_wallet_service.h" #include "brave/components/brave_wallet/browser/brave_wallet_utils.h" #include "brave/components/brave_wallet/browser/json_rpc_service.h" #include "brave/components/brave_wallet/browser/keyring_service.h" @@ -190,9 +188,6 @@ class SendOrSignTransactionBrowserTest : public InProcessBrowserTest { https_server_for_files()->ServeFilesFromDirectory(test_data_dir); ASSERT_TRUE(https_server_for_files()->Start()); - brave_wallet_service_ = - brave_wallet::BraveWalletServiceFactory::GetServiceForContext( - browser()->profile()); keyring_service_ = KeyringServiceFactory::GetServiceForContext(browser()->profile()); tx_service_ = TxServiceFactory::GetServiceForContext(browser()->profile()); @@ -340,13 +335,10 @@ class SendOrSignTransactionBrowserTest : public InProcessBrowserTest { } void AddEthereumPermission(const mojom::AccountIdPtr& account_id) { - base::RunLoop run_loop; - brave_wallet_service_->AddPermission( - account_id.Clone(), base::BindLambdaForTesting([&](bool success) { - EXPECT_TRUE(success); - run_loop.Quit(); - })); - run_loop.Run(); + EXPECT_TRUE(permissions::BraveWalletPermissionContext::AddPermission( + blink::PermissionType::BRAVE_ETHEREUM, browser()->profile(), + web_contents()->GetPrimaryMainFrame()->GetLastCommittedOrigin(), + account_id->address)); } const mojom::AccountInfoPtr& default_account() const { @@ -604,7 +596,6 @@ class SendOrSignTransactionBrowserTest : public InProcessBrowserTest { } protected: - raw_ptr brave_wallet_service_ = nullptr; mojom::AccountInfoPtr default_account_; private: diff --git a/browser/brave_wallet/solana_provider_impl_unittest.cc b/browser/brave_wallet/solana_provider_impl_unittest.cc index 2bbf321cb6cf..17f269edd74a 100644 --- a/browser/brave_wallet/solana_provider_impl_unittest.cc +++ b/browser/brave_wallet/solana_provider_impl_unittest.cc @@ -32,6 +32,7 @@ #include "brave/components/brave_wallet/common/features.h" #include "brave/components/brave_wallet/common/solana_utils.h" #include "brave/components/permissions/brave_permission_manager.h" +#include "brave/components/permissions/contexts/brave_wallet_permission_context.h" #include "chrome/browser/content_settings/host_content_settings_map_factory.h" #include "chrome/browser/permissions/permission_manager_factory.h" #include "chrome/test/base/scoped_testing_local_state.h" @@ -266,13 +267,9 @@ class SolanaProviderImplUnitTest : public testing::Test { } void AddSolanaPermission(const mojom::AccountIdPtr& account_id) { - base::RunLoop run_loop; - brave_wallet_service_->AddPermission( - account_id.Clone(), base::BindLambdaForTesting([&](bool success) { - EXPECT_TRUE(success); - run_loop.Quit(); - })); - run_loop.Run(); + EXPECT_TRUE(permissions::BraveWalletPermissionContext::AddPermission( + blink::PermissionType::BRAVE_SOLANA, browser_context(), GetOrigin(), + account_id->address)); } std::string Connect(absl::optional arg, diff --git a/browser/ui/webui/brave_wallet/panel_handler/BUILD.gn b/browser/ui/webui/brave_wallet/panel_handler/BUILD.gn index d94d9ddf7697..495319c121d3 100644 --- a/browser/ui/webui/brave_wallet/panel_handler/BUILD.gn +++ b/browser/ui/webui/brave_wallet/panel_handler/BUILD.gn @@ -12,6 +12,7 @@ source_set("panel_handler") { "//brave/browser/brave_wallet", "//brave/browser/brave_wallet:tab_helper", "//brave/components/brave_wallet/browser", + "//brave/components/brave_wallet/browser:permission_utils", "//brave/components/brave_wallet/common:mojom", "//chrome/browser/profiles:profile", "//components/permissions", diff --git a/browser/ui/webui/brave_wallet/panel_handler/wallet_panel_handler.cc b/browser/ui/webui/brave_wallet/panel_handler/wallet_panel_handler.cc index 463e275446f8..5de98c558897 100644 --- a/browser/ui/webui/brave_wallet/panel_handler/wallet_panel_handler.cc +++ b/browser/ui/webui/brave_wallet/panel_handler/wallet_panel_handler.cc @@ -9,6 +9,7 @@ #include "base/functional/callback.h" #include "brave/browser/brave_wallet/brave_wallet_tab_helper.h" +#include "brave/components/brave_wallet/browser/permission_utils.h" #include "brave/components/permissions/contexts/brave_wallet_permission_context.h" #include "content/public/browser/render_frame_host.h" #include "content/public/browser/web_contents.h" @@ -83,3 +84,40 @@ void WalletPanelHandler::IsSolanaAccountConnected( std::move(callback).Run( tab_helper->IsSolanaAccountConnected(rfh->GetGlobalId(), account)); } + +void WalletPanelHandler::RequestPermission( + brave_wallet::mojom::AccountIdPtr account_id, + RequestPermissionCallback callback) { + content::RenderFrameHost* rfh = nullptr; + if (!(rfh = active_web_contents_->GetFocusedFrame())) { + std::move(callback).Run(false); + return; + } + + auto request_type = + brave_wallet::CoinTypeToPermissionRequestType(account_id->coin); + auto permission = brave_wallet::CoinTypeToPermissionType(account_id->coin); + if (!request_type || !permission) { + std::move(callback).Run(false); + return; + } + + if (permissions::BraveWalletPermissionContext::HasRequestsInProgress( + rfh, *request_type)) { + std::move(callback).Run(false); + return; + } + + permissions::BraveWalletPermissionContext::RequestPermissions( + *permission, rfh, {account_id->address}, + base::BindOnce( + [](RequestPermissionCallback cb, + const std::vector& responses) { + if (responses.empty() || responses.size() != 1u) { + std::move(cb).Run(false); + } else { + std::move(cb).Run(true); + } + }, + std::move(callback))); +} diff --git a/browser/ui/webui/brave_wallet/panel_handler/wallet_panel_handler.h b/browser/ui/webui/brave_wallet/panel_handler/wallet_panel_handler.h index a40272808fab..beefd42bf743 100644 --- a/browser/ui/webui/brave_wallet/panel_handler/wallet_panel_handler.h +++ b/browser/ui/webui/brave_wallet/panel_handler/wallet_panel_handler.h @@ -44,6 +44,8 @@ class WalletPanelHandler : public brave_wallet::mojom::PanelHandler { void IsSolanaAccountConnected( const std::string& account, IsSolanaAccountConnectedCallback callback) override; + void RequestPermission(brave_wallet::mojom::AccountIdPtr account_id, + RequestPermissionCallback callback) override; private: mojo::Receiver receiver_; diff --git a/components/brave_wallet/browser/brave_wallet_service.cc b/components/brave_wallet/browser/brave_wallet_service.cc index d1efd4235a32..2e506752a3c9 100644 --- a/components/brave_wallet/browser/brave_wallet_service.cc +++ b/components/brave_wallet/browser/brave_wallet_service.cc @@ -926,18 +926,6 @@ void BraveWalletService::OnBraveWalletNftDiscoveryEnabled() { } } -void BraveWalletService::AddPermission(mojom::AccountIdPtr account_id, - AddPermissionCallback callback) { - auto origin = delegate_->GetActiveOrigin(); - if (!origin) { - std::move(callback).Run(false); - return; - } - - std::move(callback).Run( - delegate_->AddPermission(account_id->coin, *origin, account_id->address)); -} - void BraveWalletService::HasPermission( std::vector accounts, HasPermissionCallback callback) { diff --git a/components/brave_wallet/browser/brave_wallet_service.h b/components/brave_wallet/browser/brave_wallet_service.h index 20b9bb72cf0a..abe3381016bf 100644 --- a/components/brave_wallet/browser/brave_wallet_service.h +++ b/components/brave_wallet/browser/brave_wallet_service.h @@ -171,8 +171,6 @@ class BraveWalletService : public KeyedService, void SetNetworkForSelectedAccountOnActiveOrigin( const std::string& chain_id, SetNetworkForSelectedAccountOnActiveOriginCallback callback) override; - void AddPermission(mojom::AccountIdPtr account_id, - AddPermissionCallback callback) override; void HasPermission(std::vector accounts, HasPermissionCallback callback) override; void ResetPermission(mojom::AccountIdPtr account_id, diff --git a/components/brave_wallet/browser/permission_utils.cc b/components/brave_wallet/browser/permission_utils.cc index 24fd7d8f0f3f..f0b6e4565a16 100644 --- a/components/brave_wallet/browser/permission_utils.cc +++ b/components/brave_wallet/browser/permission_utils.cc @@ -216,4 +216,16 @@ absl::optional CoinTypeToPermissionType( } } +absl::optional CoinTypeToPermissionRequestType( + mojom::CoinType coin_type) { + switch (coin_type) { + case mojom::CoinType::ETH: + return permissions::RequestType::kBraveEthereum; + case mojom::CoinType::SOL: + return permissions::RequestType::kBraveSolana; + default: + return absl::nullopt; + } +} + } // namespace brave_wallet diff --git a/components/brave_wallet/browser/permission_utils.h b/components/brave_wallet/browser/permission_utils.h index 00ccf8def642..674de63e7291 100644 --- a/components/brave_wallet/browser/permission_utils.h +++ b/components/brave_wallet/browser/permission_utils.h @@ -81,6 +81,9 @@ GURL GetConnectWithSiteWebUIURL(const GURL& webui_base_url, absl::optional CoinTypeToPermissionType( mojom::CoinType coin_type); +absl::optional CoinTypeToPermissionRequestType( + mojom::CoinType coin_type); + } // namespace brave_wallet #endif // BRAVE_COMPONENTS_BRAVE_WALLET_BROWSER_PERMISSION_UTILS_H_ diff --git a/components/brave_wallet/browser/permission_utils_unittest.cc b/components/brave_wallet/browser/permission_utils_unittest.cc index 9e0bd9b298a5..737763e1a918 100644 --- a/components/brave_wallet/browser/permission_utils_unittest.cc +++ b/components/brave_wallet/browser/permission_utils_unittest.cc @@ -373,4 +373,26 @@ TEST(PermissionUtilsUnitTest, SyncingWithCreatePermissionLifetimeOptions) { absl::nullopt); } +TEST(PermissionUtilsUnitTest, CoinTypeToPermissionType) { + auto type = CoinTypeToPermissionType(mojom::CoinType::ETH); + ASSERT_TRUE(type); + EXPECT_EQ(*type, blink::PermissionType::BRAVE_ETHEREUM); + type = CoinTypeToPermissionType(mojom::CoinType::SOL); + ASSERT_TRUE(type); + EXPECT_EQ(*type, blink::PermissionType::BRAVE_SOLANA); + EXPECT_FALSE(CoinTypeToPermissionType(mojom::CoinType::FIL)); + EXPECT_FALSE(CoinTypeToPermissionType(mojom::CoinType::BTC)); +} + +TEST(PermissionUtilsUnitTest, CoinTypeToPermissionRequestType) { + auto request = CoinTypeToPermissionRequestType(mojom::CoinType::ETH); + ASSERT_TRUE(request); + EXPECT_EQ(*request, permissions::RequestType::kBraveEthereum); + request = CoinTypeToPermissionRequestType(mojom::CoinType::SOL); + ASSERT_TRUE(request); + EXPECT_EQ(*request, permissions::RequestType::kBraveSolana); + EXPECT_FALSE(CoinTypeToPermissionType(mojom::CoinType::FIL)); + EXPECT_FALSE(CoinTypeToPermissionType(mojom::CoinType::BTC)); +} + } // namespace brave_wallet diff --git a/components/brave_wallet/common/brave_wallet.mojom b/components/brave_wallet/common/brave_wallet.mojom index 70c126401157..873a51afece1 100644 --- a/components/brave_wallet/common/brave_wallet.mojom +++ b/components/brave_wallet/common/brave_wallet.mojom @@ -394,6 +394,13 @@ interface PanelHandler { Focus(); IsSolanaAccountConnected(string account) => (bool connected); + + // Create a permission request for users based on active web contents. + // The flow will be similar to dapp request permission except it is initiated + // from panel. Desktop front end will be opened with same #connectWitSite ref + // and we need to call ConnectToSite or CancelConnectToSite based on user + // decision. + RequestPermission(AccountId account_id) => (bool success); }; // Browser-side handler for requests from WebUI page. @@ -1758,10 +1765,6 @@ interface BraveWalletService { GetNetworkForSelectedAccountOnActiveOrigin() => (NetworkInfo? network); SetNetworkForSelectedAccountOnActiveOrigin(string chain_id) => (bool success); - // Adds the permission for the account on active origin. - AddPermission(AccountId account_id) - => (bool success); - // Filters accounts with permissions on active origin. HasPermission(array accounts) => (bool success, array accounts_with_permission); diff --git a/components/brave_wallet_ui/common/actions/wallet_actions.ts b/components/brave_wallet_ui/common/actions/wallet_actions.ts index af448c74268a..ec53035a064f 100644 --- a/components/brave_wallet_ui/common/actions/wallet_actions.ts +++ b/components/brave_wallet_ui/common/actions/wallet_actions.ts @@ -11,7 +11,6 @@ export const { activeOriginChanged, addAccount, addFavoriteApp, - addSitePermission, addUserAsset, addUserAssetError, autoLockMinutesChanged, diff --git a/components/brave_wallet_ui/common/async/handlers.ts b/components/brave_wallet_ui/common/async/handlers.ts index b9867e6b1957..914afa9b2b30 100644 --- a/components/brave_wallet_ui/common/async/handlers.ts +++ b/components/brave_wallet_ui/common/async/handlers.ts @@ -8,7 +8,6 @@ import { mapLimit } from 'async' import AsyncActionHandler from '../../../common/AsyncActionHandler' import * as WalletActions from '../actions/wallet_actions' import { - AddSitePermissionPayloadType, RemoveSitePermissionPayloadType, SetUserAssetVisiblePayloadType, UnlockWalletPayloadType, @@ -320,12 +319,6 @@ handler.on(WalletActions.removeSitePermission.type, async (store: Store, payload await refreshWalletInfo(store) }) -handler.on(WalletActions.addSitePermission.type, async (store: Store, payload: AddSitePermissionPayloadType) => { - const braveWalletService = getAPIProxy().braveWalletService - await braveWalletService.addPermission(payload.accountId) - await refreshWalletInfo(store) -}) - handler.on(WalletActions.expandWalletNetworks.type, async (store) => { chrome.tabs.create({ url: 'chrome://settings/wallet/networks' }, () => { if (chrome.runtime.lastError) { diff --git a/components/brave_wallet_ui/common/constants/action_types.ts b/components/brave_wallet_ui/common/constants/action_types.ts index 8c44d08a7b89..d87c24da95a6 100644 --- a/components/brave_wallet_ui/common/constants/action_types.ts +++ b/components/brave_wallet_ui/common/constants/action_types.ts @@ -89,10 +89,6 @@ export type RemoveSitePermissionPayloadType = { accountId: BraveWallet.AccountId } -export type AddSitePermissionPayloadType = { - accountId: BraveWallet.AccountId -} - export type GetCoinMarketPayload = { vsAsset: string limit: number diff --git a/components/brave_wallet_ui/common/slices/wallet.slice.ts b/components/brave_wallet_ui/common/slices/wallet.slice.ts index 0ea0cec2402d..deeb2d50ee74 100644 --- a/components/brave_wallet_ui/common/slices/wallet.slice.ts +++ b/components/brave_wallet_ui/common/slices/wallet.slice.ts @@ -15,7 +15,6 @@ import { ImportAccountErrorType } from '../../constants/types' import { - AddSitePermissionPayloadType, DefaultBaseCryptocurrencyChanged, DefaultBaseCurrencyChanged, DefaultEthereumWalletChanged, @@ -197,8 +196,6 @@ export const WalletAsyncActions = { removeSitePermission: createAction( 'removeSitePermission' ), - addSitePermission: - createAction('addSitePermission'), refreshNetworksAndTokens: createAction('refreshNetworksAndTokens'), expandWalletNetworks: createAction('expandWalletNetworks'), // replace with chrome.tabs.create helper diff --git a/components/brave_wallet_ui/components/extension/connected-account-item/index.tsx b/components/brave_wallet_ui/components/extension/connected-account-item/index.tsx index a330780b859b..544a49ffc55b 100644 --- a/components/brave_wallet_ui/components/extension/connected-account-item/index.tsx +++ b/components/brave_wallet_ui/components/extension/connected-account-item/index.tsx @@ -7,6 +7,7 @@ import * as React from 'react' import { useDispatch } from 'react-redux' // Actions +import { PanelActions } from '../../../panel/actions' import { WalletActions } from '../../../common/actions' // Types @@ -83,7 +84,8 @@ export const ConnectedAccountItem = (props: Props) => { // methods const onClickConnect = React.useCallback(() => { - dispatch(WalletActions.addSitePermission({ accountId: account.accountId })) + dispatch(PanelActions + .requestSitePermission({ accountId: account.accountId })) if (selectedCoin !== BraveWallet.CoinType.SOL) { setSelectedAccount(account.accountId) } diff --git a/components/brave_wallet_ui/components/extension/dapp-connection-settings/change-account-button.tsx b/components/brave_wallet_ui/components/extension/dapp-connection-settings/change-account-button.tsx index 6386d117a755..84a7b94d0473 100644 --- a/components/brave_wallet_ui/components/extension/dapp-connection-settings/change-account-button.tsx +++ b/components/brave_wallet_ui/components/extension/dapp-connection-settings/change-account-button.tsx @@ -8,6 +8,8 @@ import Button from '@brave/leo/react/button' import { useDispatch } from 'react-redux' // Actions +import { PanelActions } from '../../../panel/actions' + import { WalletActions } from '../../../common/actions' @@ -120,8 +122,8 @@ export const ChangeAccountButton = (props: Props) => { // Methods const onClickConnect = React.useCallback(() => { dispatch( - WalletActions - .addSitePermission({ accountId: account.accountId }) + PanelActions + .requestSitePermission({ accountId: account.accountId }) ) if (selectedCoin !== BraveWallet.CoinType.SOL) { setSelectedAccount(account.accountId) diff --git a/components/brave_wallet_ui/components/extension/dapp-connection-settings/dapp-connection-main.tsx b/components/brave_wallet_ui/components/extension/dapp-connection-settings/dapp-connection-main.tsx index fb5d35514b82..59ea87f6be20 100644 --- a/components/brave_wallet_ui/components/extension/dapp-connection-settings/dapp-connection-main.tsx +++ b/components/brave_wallet_ui/components/extension/dapp-connection-settings/dapp-connection-main.tsx @@ -8,6 +8,8 @@ import Button from '@brave/leo/react/button' import { useDispatch } from 'react-redux' // Actions +import { PanelActions } from '../../../panel/actions' + import { WalletActions } from '../../../common/actions' @@ -124,8 +126,8 @@ export const DAppConnectionMain = (props: Props) => { return } dispatch( - WalletActions - .addSitePermission( + PanelActions + .requestSitePermission( { accountId: selectedAccount.accountId } ) ) diff --git a/components/brave_wallet_ui/panel/actions/wallet_panel_actions.ts b/components/brave_wallet_ui/panel/actions/wallet_panel_actions.ts index e67e2a3f4e1b..9ad76a536fa4 100644 --- a/components/brave_wallet_ui/panel/actions/wallet_panel_actions.ts +++ b/components/brave_wallet_ui/panel/actions/wallet_panel_actions.ts @@ -10,6 +10,7 @@ import { DecryptProcessedPayload, ShowConnectToSitePayload, EthereumChainRequestPayload, + RequestSitePermissionPayloadType, SignMessageProcessedPayload, SignAllTransactionsProcessedPayload, SwitchEthereumChainProcessedPayload, @@ -25,6 +26,8 @@ import { HardwareWalletResponseCodeType } from '../../common/hardware/types' export const connectToSite = createAction('connectToSite') export const cancelConnectToSite = createAction('cancelConnectToSite') +export const requestSitePermission + = createAction('requestSitePermission') export const visibilityChanged = createAction('visibilityChanged') export const showConnectToSite = createAction('showConnectToSite') export const addEthereumChain = createAction('addEthereumChain') diff --git a/components/brave_wallet_ui/panel/async/wallet_panel_async_handler.ts b/components/brave_wallet_ui/panel/async/wallet_panel_async_handler.ts index 85ad48e3874d..f3a8fab6b364 100644 --- a/components/brave_wallet_ui/panel/async/wallet_panel_async_handler.ts +++ b/components/brave_wallet_ui/panel/async/wallet_panel_async_handler.ts @@ -18,6 +18,7 @@ import { ConnectWithSitePayloadType, ShowConnectToSitePayload, EthereumChainRequestPayload, + RequestSitePermissionPayloadType, SignMessageProcessedPayload, SignAllTransactionsProcessedPayload, SwitchEthereumChainProcessedPayload, @@ -175,6 +176,13 @@ handler.on(PanelActions.connectToSite.type, async (store: Store, payload: Connec apiProxy.panelHandler.closeUI() }) +handler.on(PanelActions.requestSitePermission.type, + async(store: Store, payload: RequestSitePermissionPayloadType) => { + const apiProxy = getWalletPanelApiProxy() + await apiProxy.panelHandler.requestPermission(payload.accountId) + // TODO(Douglashdaniel): Clear isConnectingOnMainPanel when result is false +}) + handler.on(PanelActions.visibilityChanged.type, async (store: Store, isVisible) => { if (!isVisible) { return diff --git a/components/brave_wallet_ui/panel/constants/action_types.ts b/components/brave_wallet_ui/panel/constants/action_types.ts index 696738591573..60ae754e7271 100644 --- a/components/brave_wallet_ui/panel/constants/action_types.ts +++ b/components/brave_wallet_ui/panel/constants/action_types.ts @@ -9,6 +9,10 @@ export type AccountPayloadType = { selectedAccounts: BraveWallet.AccountInfo[] } +export type RequestSitePermissionPayloadType = { + accountId: BraveWallet.AccountId, +} + export type ConnectWithSitePayloadType = { addressToConnect: string, duration: BraveWallet.PermissionLifetimeOption