diff --git a/browser/brave_wallet/BUILD.gn b/browser/brave_wallet/BUILD.gn index f91bc6479ebf..88ff628bd01e 100644 --- a/browser/brave_wallet/BUILD.gn +++ b/browser/brave_wallet/BUILD.gn @@ -56,7 +56,7 @@ source_set("brave_wallet_delegate") { "//brave/browser/brave_wallet", "//brave/components/brave_wallet/browser", "//brave/components/brave_wallet/browser:constants", - "//brave/components/brave_wallet/browser:ethereum_permission_utils", + "//brave/components/brave_wallet/browser:utils", "//brave/components/brave_wallet/common:mojom", "//brave/components/resources:strings_grit", "//components/content_settings/core/common", diff --git a/browser/brave_wallet/brave_wallet_service_browsertest.cc b/browser/brave_wallet/brave_wallet_service_browsertest.cc index 3f79676c7e3b..4278bda34cee 100644 --- a/browser/brave_wallet/brave_wallet_service_browsertest.cc +++ b/browser/brave_wallet/brave_wallet_service_browsertest.cc @@ -9,7 +9,7 @@ #include "brave/browser/brave_wallet/brave_wallet_service_factory.h" #include "brave/common/brave_paths.h" #include "brave/components/brave_wallet/browser/brave_wallet_service.h" -#include "brave/components/brave_wallet/browser/ethereum_permission_utils.h" +#include "brave/components/brave_wallet/browser/brave_wallet_utils.h" #include "brave/components/brave_wallet/common/brave_wallet.mojom.h" #include "brave/components/brave_wallet/common/features.h" #include "chrome/browser/profiles/profile.h" diff --git a/browser/brave_wallet/brave_wallet_service_delegate_impl.cc b/browser/brave_wallet/brave_wallet_service_delegate_impl.cc index 1aeadca471a9..c5c416dfabb8 100644 --- a/browser/brave_wallet/brave_wallet_service_delegate_impl.cc +++ b/browser/brave_wallet/brave_wallet_service_delegate_impl.cc @@ -7,7 +7,7 @@ #include -#include "brave/components/brave_wallet/browser/ethereum_permission_utils.h" +#include "brave/components/brave_wallet/browser/brave_wallet_utils.h" #include "brave/components/permissions/contexts/brave_ethereum_permission_context.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/browser.h" @@ -163,8 +163,9 @@ void BraveWalletServiceDelegateImpl::TabChangedAt( void BraveWalletServiceDelegateImpl::FireActiveOriginChanged() { const std::string origin = GetActiveOriginInternal(); + const std::string etld_plus_one = eTLDPlusOne(GURL(origin)); for (auto& observer : observer_list_) - observer.OnActiveOriginChanged(origin, eTLDPlusOne(GURL(origin))); + observer.OnActiveOriginChanged(origin, etld_plus_one); } std::string BraveWalletServiceDelegateImpl::GetActiveOriginInternal() { diff --git a/components/brave_wallet/browser/BUILD.gn b/components/brave_wallet/browser/BUILD.gn index 67d753dd745c..99075caa3b80 100644 --- a/components/brave_wallet/browser/BUILD.gn +++ b/components/brave_wallet/browser/BUILD.gn @@ -119,7 +119,6 @@ static_library("browser") { "//brave/components/bls/rs:cxx", "//brave/components/brave_component_updater/browser", "//brave/components/brave_stats/browser", - "//brave/components/brave_wallet/browser:ethereum_permission_utils", "//brave/components/brave_wallet/common", "//brave/components/brave_wallet/common:common_constants", "//brave/components/brave_wallet/common:mojom", @@ -154,8 +153,8 @@ static_library("ethereum_permission_utils") { ] deps = [ + ":utils", "//base", - "//net", "//third_party/re2", "//url", ] @@ -200,6 +199,7 @@ source_set("utils") { "//brave/vendor/bip39wally-core-native:bip39wally-core", "//components/prefs", "//crypto", + "//net", "//third_party/abseil-cpp:absl", "//third_party/boringssl", "//url", diff --git a/components/brave_wallet/browser/brave_wallet_utils.cc b/components/brave_wallet/browser/brave_wallet_utils.cc index 990d22dd672e..6e2d15466700 100644 --- a/components/brave_wallet/browser/brave_wallet_utils.cc +++ b/components/brave_wallet/browser/brave_wallet_utils.cc @@ -29,6 +29,7 @@ #include "components/prefs/pref_service.h" #include "components/prefs/scoped_user_pref_update.h" #include "crypto/random.h" +#include "net/base/registry_controlled_domains/registry_controlled_domain.h" #include "third_party/abseil-cpp/absl/types/optional.h" #include "third_party/boringssl/src/include/openssl/evp.h" #include "url/gurl.h" @@ -948,4 +949,9 @@ absl::optional GetPrefKeyForCoinType(mojom::CoinType coin) { return absl::nullopt; } +std::string eTLDPlusOne(const GURL& url) { + return net::registry_controlled_domains::GetDomainAndRegistry( + url, net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); +} + } // namespace brave_wallet diff --git a/components/brave_wallet/browser/brave_wallet_utils.h b/components/brave_wallet/browser/brave_wallet_utils.h index aa722ff6fbd3..2a148cf3e830 100644 --- a/components/brave_wallet/browser/brave_wallet_utils.h +++ b/components/brave_wallet/browser/brave_wallet_utils.h @@ -124,6 +124,11 @@ GURL GetFirstValidChainURL(const std::vector& chain_urls); absl::optional GetPrefKeyForCoinType(mojom::CoinType coin); +/** + * Given an url, return eTLD + 1 for that URL + */ +std::string eTLDPlusOne(const GURL& url); + } // namespace brave_wallet #endif // BRAVE_COMPONENTS_BRAVE_WALLET_BROWSER_BRAVE_WALLET_UTILS_H_ diff --git a/components/brave_wallet/browser/brave_wallet_utils_unittest.cc b/components/brave_wallet/browser/brave_wallet_utils_unittest.cc index f3edd079c573..ea251d690e47 100644 --- a/components/brave_wallet/browser/brave_wallet_utils_unittest.cc +++ b/components/brave_wallet/browser/brave_wallet_utils_unittest.cc @@ -1036,4 +1036,14 @@ TEST(BraveWalletUtilsUnitTest, GetCurrentChainId) { mojom::kFilecoinMainnet); } +TEST(BraveWalletUtilsUnitTest, eTLDPlusOne) { + EXPECT_EQ("", eTLDPlusOne(GURL())); + EXPECT_EQ("brave.com", eTLDPlusOne(GURL("https://blog.brave.com"))); + EXPECT_EQ("brave.com", eTLDPlusOne(GURL("https://...brave.com"))); + EXPECT_EQ("brave.com", eTLDPlusOne(GURL("https://a.b.c.d.brave.com/1"))); + EXPECT_EQ("brave.github.io", + eTLDPlusOne(GURL("https://a.b.brave.github.io/example"))); + EXPECT_EQ("", eTLDPlusOne(GURL("https://github.io"))); +} + } // namespace brave_wallet diff --git a/components/brave_wallet/browser/ethereum_permission_utils.cc b/components/brave_wallet/browser/ethereum_permission_utils.cc index 4a6c8311730e..8e5f20d006f4 100644 --- a/components/brave_wallet/browser/ethereum_permission_utils.cc +++ b/components/brave_wallet/browser/ethereum_permission_utils.cc @@ -9,7 +9,7 @@ #include "base/strings/strcat.h" #include "base/strings/string_util.h" #include "base/strings/stringprintf.h" -#include "net/base/registry_controlled_domains/registry_controlled_domain.h" +#include "brave/components/brave_wallet/browser/brave_wallet_utils.h" #include "third_party/re2/src/re2/re2.h" #include "url/gurl.h" #include "url/origin.h" @@ -136,11 +136,6 @@ bool GetSubRequestOrigin(const GURL& old_origin, return AddAccountToHost(old_origin, account, new_origin); } -std::string eTLDPlusOne(const GURL& url) { - return net::registry_controlled_domains::GetDomainAndRegistry( - url, net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); -} - GURL GetConnectWithSiteWebUIURL(const GURL& webui_base_url, const std::vector& accounts, const std::string& origin) { diff --git a/components/brave_wallet/browser/ethereum_permission_utils.h b/components/brave_wallet/browser/ethereum_permission_utils.h index 9b2e4f85544d..38b84778b7ae 100644 --- a/components/brave_wallet/browser/ethereum_permission_utils.h +++ b/components/brave_wallet/browser/ethereum_permission_utils.h @@ -57,11 +57,6 @@ bool GetSubRequestOrigin(const GURL& old_origin, const std::string& account, GURL* new_origin); -/** - * Given an url, return eTLD + 1 for that URL - */ -std::string eTLDPlusOne(const GURL& url); - /** * Given accounts, and origin, return the WebUI URL for connecting with site * (ethereum permission) request. diff --git a/components/brave_wallet/browser/ethereum_permission_utils_unittest.cc b/components/brave_wallet/browser/ethereum_permission_utils_unittest.cc index 47e42927c48c..53f8c81cb8dc 100644 --- a/components/brave_wallet/browser/ethereum_permission_utils_unittest.cc +++ b/components/brave_wallet/browser/ethereum_permission_utils_unittest.cc @@ -141,16 +141,6 @@ TEST(EthereumPermissionUtilsUnitTest, GetSubRequestOrigin) { EXPECT_EQ(new_origin, expected_new_origin_with_port); } -TEST(EthereumPermissionUtilsUnitTest, eTLDPlusOne) { - EXPECT_EQ("", eTLDPlusOne(GURL())); - EXPECT_EQ("brave.com", eTLDPlusOne(GURL("https://blog.brave.com"))); - EXPECT_EQ("brave.com", eTLDPlusOne(GURL("https://...brave.com"))); - EXPECT_EQ("brave.com", eTLDPlusOne(GURL("https://a.b.c.d.brave.com/1"))); - EXPECT_EQ("brave.github.io", - eTLDPlusOne(GURL("https://a.b.brave.github.io/example"))); - EXPECT_EQ("", eTLDPlusOne(GURL("https://github.io"))); -} - TEST(EthereumPermissionUtilsUnitTest, GetConnectWithSiteWebUIURL) { GURL base_url("chrome://wallet-panel.top-chrome/"); std::vector addrs = { diff --git a/components/brave_wallet_ui/common/actions/wallet_actions.ts b/components/brave_wallet_ui/common/actions/wallet_actions.ts index 578bd05eafa5..2686d1b87f6f 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 @@ import { NewUnapprovedTxAdded, UnapprovedTxUpdated, TransactionStatusChanged, - ActiveOriginChanged, DefaultWalletChanged, DefaultBaseCurrencyChanged, DefaultBaseCryptocurrencyChanged, @@ -38,7 +37,8 @@ import { WalletInfoBase, WalletInfo, DefaultCurrencies, - GetPriceReturnInfo + GetPriceReturnInfo, + OriginInfo } from '../../constants/types' export const initialize = createAction('initialize') @@ -89,7 +89,7 @@ export const rejectAllTransactions = createAction('rejectAllTransactions') export const setAccountTransactions = createAction('setAccountTransactions') export const defaultWalletUpdated = createAction('defaultWalletUpdated') export const setSelectedAccount = createAction('setSelectedAccount') -export const activeOriginChanged = createAction('activeOriginChanged') +export const activeOriginChanged = createAction('activeOriginChanged') export const refreshGasEstimates = createAction('refreshGasEstimates') export const setGasEstimates = createAction('setGasEstimates') export const updateUnapprovedTransactionGasFields = createAction('updateUnapprovedTransactionGasFields') diff --git a/components/brave_wallet_ui/common/constants/action_types.ts b/components/brave_wallet_ui/common/constants/action_types.ts index 47906f6b4328..6fa0675a2430 100644 --- a/components/brave_wallet_ui/common/constants/action_types.ts +++ b/components/brave_wallet_ui/common/constants/action_types.ts @@ -52,11 +52,6 @@ export type SwapParamsPayloadType = { full: boolean } -export type ActiveOriginChanged = { - origin: string - eTldPlusOne: string -} - export type UpdateUnapprovedTransactionGasFieldsType = { txMetaId: string gasLimit: string diff --git a/components/brave_wallet_ui/common/reducers/wallet_reducer.ts b/components/brave_wallet_ui/common/reducers/wallet_reducer.ts index 9962e569c5c4..ce7663e30ecb 100644 --- a/components/brave_wallet_ui/common/reducers/wallet_reducer.ts +++ b/components/brave_wallet_ui/common/reducers/wallet_reducer.ts @@ -17,10 +17,10 @@ import { WalletInfo, DefaultCurrencies, GetPriceReturnInfo, - GetNativeAssetBalancesPayload + GetNativeAssetBalancesPayload, + OriginInfo } from '../../constants/types' import { - ActiveOriginChanged, IsEip1559Changed, NewUnapprovedTxAdded, SetTransactionProviderErrorType, @@ -370,7 +370,7 @@ export const createWalletReducer = (initialState: WalletState) => { } }) - reducer.on(WalletActions.activeOriginChanged, (state: WalletState, payload: ActiveOriginChanged): WalletState => { + reducer.on(WalletActions.activeOriginChanged, (state: WalletState, payload: OriginInfo): WalletState => { return { ...state, activeOrigin: payload