Skip to content

Commit

Permalink
kBraveWalletDefaultHiddenNetworksVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
supermassive committed Jan 10, 2025
1 parent a42a12a commit 8415738
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 84 deletions.
49 changes: 0 additions & 49 deletions browser/brave_wallet/brave_wallet_service_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1946,55 +1946,6 @@ TEST_F(BraveWalletServiceUnitTest, MigrateEip1559ForCustomNetworks) {
GetPrefs()->GetBoolean(kBraveWalletEip1559ForCustomNetworksMigrated));
}

TEST_F(BraveWalletServiceUnitTest, MigrateDefaultHiddenNetworks) {
// Note: The testing profile has already performed the prefs migration by the
// time this test runs, so undo its effects here for testing purposes
ASSERT_EQ(GetPrefs()->GetInteger(kBraveWalletDefaultHiddenNetworksVersion),
1);
GetPrefs()->SetInteger(kBraveWalletDefaultHiddenNetworksVersion, 0);

BraveWalletService::MigrateHiddenNetworks(GetPrefs());
{
auto* list =
GetPrefs()->GetDict(kBraveWalletHiddenNetworks).FindList("ethereum");
ASSERT_NE(std::find_if(list->begin(), list->end(),
[](const auto& v) { return v == "0x4cb2f"; }),
list->end());
}
ASSERT_EQ(GetPrefs()->GetInteger(kBraveWalletDefaultHiddenNetworksVersion),
1);
network_manager_->RemoveHiddenNetwork(mojom::CoinType::ETH, "0x4cb2f");
BraveWalletService::MigrateHiddenNetworks(GetPrefs());
{
auto* list =
GetPrefs()->GetDict(kBraveWalletHiddenNetworks).FindList("ethereum");
ASSERT_EQ(std::find_if(list->begin(), list->end(),
[](const auto& v) { return v == "0x4cb2f"; }),
list->end());
}
}

TEST_F(BraveWalletServiceUnitTest, MigrateDefaultHiddenNetworks_NoList) {
// Note: The testing profile has already performed the prefs migration by the
// time this test runs, so undo its effects here for testing purposes
ASSERT_EQ(GetPrefs()->GetInteger(kBraveWalletDefaultHiddenNetworksVersion),
1);
GetPrefs()->SetInteger(kBraveWalletDefaultHiddenNetworksVersion, 0);

{
ScopedDictPrefUpdate update(GetPrefs(), kBraveWalletHiddenNetworks);
update.Get().Remove("ethereum");
}
BraveWalletService::MigrateHiddenNetworks(GetPrefs());
{
auto* list =
GetPrefs()->GetDict(kBraveWalletHiddenNetworks).FindList("ethereum");
EXPECT_NE(std::find_if(list->begin(), list->end(),
[](const auto& v) { return v == "0x4cb2f"; }),
list->end());
}
}

TEST_F(BraveWalletServiceUnitTest, MigrateFantomMainnetAsCustomNetwork) {
// Note: The testing profile has already performed the prefs migration by the
// time this test runs, so undo its effects here for testing purposes
Expand Down
13 changes: 7 additions & 6 deletions components/brave_wallet/browser/brave_wallet_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ constexpr char kBraveWalletTransactionsChainIdMigrated[] =
constexpr char kPinnedNFTAssetsMigrated[] = "brave.wallet.user_pin_data";
// Deprecated 07/2024
constexpr char kAutoPinEnabledMigrated[] = "brave.wallet.auto_pin_enabled";
// Deprecated 01/2025
constexpr char kBraveWalletDefaultHiddenNetworksVersion[] =
"brave.wallet.user.assets.default_hidden_networks_version";

base::Value::Dict GetDefaultSelectedNetworks() {
base::Value::Dict selected_networks;
Expand Down Expand Up @@ -138,6 +141,8 @@ void RegisterProfilePrefsDeprecatedMigrationFlags(
false);
// Deprecated 06/2024.
registry->RegisterBooleanPref(kBraveWalletTransactionsChainIdMigrated, false);
// Deprecated 01/2025.
registry->RegisterIntegerPref(kBraveWalletDefaultHiddenNetworksVersion, 0);
}

void RegisterDeprecatedIpfsPrefs(user_prefs::PrefRegistrySyncable* registry) {
Expand All @@ -164,6 +169,8 @@ void ClearDeprecatedProfilePrefsMigrationFlags(PrefService* prefs) {
prefs->ClearPref(kBraveWalletUserAssetsAddIsERC1155Migrated);
// Deprecated 06/2024.
prefs->ClearPref(kBraveWalletTransactionsChainIdMigrated);
// Deprecated 01/2025.
prefs->ClearPref(kBraveWalletDefaultHiddenNetworksVersion);
}

void ClearDeprecatedIpfsPrefs(PrefService* prefs) {
Expand Down Expand Up @@ -262,9 +269,6 @@ void RegisterProfilePrefsForMigration(
base::Time());
registry->RegisterListPref(kBraveWalletP3AWeeklyStorageDeprecated);

// Added 03/2023
registry->RegisterIntegerPref(kBraveWalletDefaultHiddenNetworksVersion, 0);

// Added 06/2023
registry->RegisterIntegerPref(
kBraveWalletSelectedCoinDeprecated,
Expand Down Expand Up @@ -341,9 +345,6 @@ void ClearBraveWalletServicePrefs(PrefService* prefs) {
void MigrateObsoleteProfilePrefs(PrefService* prefs) {
ClearDeprecatedProfilePrefsMigrationFlags(prefs);

// Added 03/2023 to add filecoin evm support.
BraveWalletService::MigrateHiddenNetworks(prefs);

// Added 08/2023 to add Fantom as a custom network if selected for the default
// or custom origins.
BraveWalletService::MigrateFantomMainnetAsCustomNetwork(prefs);
Expand Down
25 changes: 0 additions & 25 deletions components/brave_wallet/browser/brave_wallet_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -728,31 +728,6 @@ void BraveWalletService::ResetWebSitePermission(
delegate_->ResetWebSitePermission(coin, formed_website, std::move(callback));
}

// static
void BraveWalletService::MigrateHiddenNetworks(PrefService* prefs) {
auto previous_version_code =
prefs->GetInteger(kBraveWalletDefaultHiddenNetworksVersion);
if (previous_version_code >= 1) {
return;
}
{
// Default hidden networks
ScopedDictPrefUpdate update(prefs, kBraveWalletHiddenNetworks);
auto& hidden_networks_pref = update.Get();
base::Value::List* hidden_eth_networks =
hidden_networks_pref.EnsureList(kEthereumPrefKey);

auto value = base::Value(mojom::kFilecoinEthereumTestnetChainId);
if (std::find_if(hidden_eth_networks->begin(), hidden_eth_networks->end(),
[&value](auto& v) { return value == v; }) ==
hidden_eth_networks->end()) {
hidden_eth_networks->Append(std::move(value));
}
}

prefs->SetInteger(kBraveWalletDefaultHiddenNetworksVersion, 1);
}

bool ShouldMigrateRemovedPreloadedNetwork(PrefService* prefs,
mojom::CoinType coin,
const std::string& chain_id) {
Expand Down
1 change: 0 additions & 1 deletion components/brave_wallet/browser/brave_wallet_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ class BraveWalletService : public KeyedService,
template <class T>
void Bind(mojo::PendingReceiver<T> receiver);

static void MigrateHiddenNetworks(PrefService* profile_prefs);
static void MigrateDeadNetwork(PrefService* prefs,
const std::string& chain_id,
const std::string& fallback_chain_id,
Expand Down
3 changes: 0 additions & 3 deletions components/brave_wallet/browser/pref_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ inline constexpr char kBraveWalletUserAssetsList[] =
"brave.wallet.wallet_user_assets_list";
inline constexpr char kBraveWalletEthAllowancesCache[] =
"brave.wallet.eth_allowances_cache";
// Added 03/2023 to add networks hidden by default
inline constexpr char kBraveWalletDefaultHiddenNetworksVersion[] =
"brave.wallet.user.assets.default_hidden_networks_version";
inline constexpr char kBraveWalletAutoLockMinutes[] =
"brave.wallet.auto_lock_minutes";
inline constexpr char kBraveWalletP3AFirstUnlockTime[] =
Expand Down

0 comments on commit 8415738

Please sign in to comment.