Skip to content

Commit

Permalink
added IsWalletCreated
Browse files Browse the repository at this point in the history
  • Loading branch information
supermassive committed Oct 19, 2023
1 parent bd0dc04 commit 6abc90a
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion browser/profiles/brave_renderer_updater.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ bool BraveRendererUpdater::CheckActiveWallet() {
if (!keyring_service_) {
return false;
}
bool is_wallet_created = keyring_service_->IsWalletSetup();
bool is_wallet_created = keyring_service_->IsWalletCreatedSync();
bool changed = is_wallet_created != is_wallet_created_;
is_wallet_created_ = is_wallet_created;
return changed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void WalletButtonNotificationSource::EnsureKeyringServiceConnected() {
keyring_service_->AddObserver(
keyring_service_observer_.BindNewPipeAndPassRemote());

wallet_created_ = keyring_service_->IsWalletSetup();
wallet_created_ = keyring_service_->IsWalletCreatedSync();
if (wallet_created_.value()) {
prefs_->SetBoolean(kShouldShowWalletSuggestionBadge, false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void WalletHandler::GetWalletInfo(GetWalletInfoCallback callback) {
}

std::move(callback).Run(mojom::WalletInfo::New(
keyring_service_->IsWalletSetup(), keyring_service_->IsLockedSync(),
keyring_service_->IsWalletCreatedSync(), keyring_service_->IsLockedSync(),
keyring_service_->IsWalletBackedUpSync(), IsFilecoinEnabled(),
IsSolanaEnabled(), IsBitcoinEnabled(), IsZCashEnabled(),
IsNftPinningEnabled(), IsPanelV2Enabled()));
Expand Down
4 changes: 2 additions & 2 deletions components/brave_wallet/browser/brave_wallet_p3a.cc
Original file line number Diff line number Diff line change
Expand Up @@ -425,12 +425,12 @@ void BraveWalletP3A::WriteUsageStatsToHistogram() {
}

void BraveWalletP3A::RecordInitialBraveWalletP3AState() {
RecordKeyringCreated(keyring_service_->IsWalletSetup());
RecordKeyringCreated(keyring_service_->IsWalletCreatedSync());
}

// KeyringServiceObserver
void BraveWalletP3A::WalletCreated() {
RecordKeyringCreated(keyring_service_->IsWalletSetup());
RecordKeyringCreated(keyring_service_->IsWalletCreatedSync());
}

} // namespace brave_wallet
16 changes: 10 additions & 6 deletions components/brave_wallet/browser/keyring_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1017,12 +1017,6 @@ HDKeyring* KeyringService::RestoreKeyring(mojom::KeyringId keyring_id,
return keyring;
}

bool KeyringService::IsWalletSetup() {
// Wallet is set up if there is at least one account as we don't allow
// removing derived accounts.
return GetAllAccountInfos().size() > 0;
}

void KeyringService::GetMnemonicForDefaultKeyring(
const std::string& password,
GetMnemonicForDefaultKeyringCallback callback) {
Expand All @@ -1047,6 +1041,16 @@ void KeyringService::MaybeCreateDefaultSolanaAccount() {
}
}

void KeyringService::IsWalletCreated(IsWalletCreatedCallback callback) {
std::move(callback).Run(IsWalletCreatedSync());
}

bool KeyringService::IsWalletCreatedSync() {
// Wallet is set up if there is at least one account as we don't allow
// removing derived accounts.
return GetAllAccountInfos().size() > 0;
}

void KeyringService::CreateWallet(const std::string& password,
CreateWalletCallback callback) {
const std::string mnemonic = GenerateMnemonic(16);
Expand Down
5 changes: 2 additions & 3 deletions components/brave_wallet/browser/keyring_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,14 @@ class KeyringService : public KeyedService, public mojom::KeyringService {
mojo::PendingRemote<mojom::KeyringService> MakeRemote();
void Bind(mojo::PendingReceiver<mojom::KeyringService> receiver);

// Returns true if wallet was created or restored by user.
bool IsWalletSetup();

// mojom::KeyringService
// Must unlock before using this API otherwise it will return empty string
void GetMnemonicForDefaultKeyring(
const std::string& password,
GetMnemonicForDefaultKeyringCallback callback) override;
void MaybeCreateDefaultSolanaAccount();
void IsWalletCreated(IsWalletCreatedCallback callback) override;
bool IsWalletCreatedSync();
void CreateWallet(const std::string& mnemonic,
const std::string& password,
CreateWalletCallback callback);
Expand Down
3 changes: 3 additions & 0 deletions components/brave_wallet/common/brave_wallet.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,9 @@ interface BlockchainRegistry {
// Implements the HD wallet, Ledger & Trezor integration, account management,
// and signing.
interface KeyringService {
// True if wallet was created or restored. Wallet needs onboarding when false.
IsWalletCreated() => (bool isCreated);

// Creates a new wallet and encrypts it using the specified password
CreateWallet(string password) => (string mnemonic);

Expand Down

0 comments on commit 6abc90a

Please sign in to comment.