-
Notifications
You must be signed in to change notification settings - Fork 868
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement ZCash account creation & balance resolution
Resolves brave/brave-browser#32305
- Loading branch information
Showing
50 changed files
with
1,038 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* Copyright (c) 2023 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 https://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "brave/browser/brave_wallet/zcash_wallet_service_factory.h" | ||
|
||
#include <utility> | ||
|
||
#include "base/no_destructor.h" | ||
#include "brave/browser/brave_wallet/brave_wallet_context_utils.h" | ||
#include "brave/browser/brave_wallet/keyring_service_factory.h" | ||
#include "brave/components/brave_wallet/browser/zcash/zcash_wallet_service.h" | ||
#include "brave/components/brave_wallet/common/common_utils.h" | ||
#include "chrome/browser/profiles/incognito_helpers.h" | ||
#include "components/keyed_service/content/browser_context_dependency_manager.h" | ||
#include "components/user_prefs/user_prefs.h" | ||
#include "content/public/browser/storage_partition.h" | ||
#include "services/network/public/cpp/shared_url_loader_factory.h" | ||
|
||
namespace brave_wallet { | ||
|
||
// static | ||
ZCashWalletServiceFactory* ZCashWalletServiceFactory::GetInstance() { | ||
static base::NoDestructor<ZCashWalletServiceFactory> instance; | ||
return instance.get(); | ||
} | ||
|
||
// static | ||
mojo::PendingRemote<mojom::ZCashWalletService> | ||
ZCashWalletServiceFactory::GetForContext(content::BrowserContext* context) { | ||
if (!IsAllowedForContext(context)) { | ||
return mojo::PendingRemote<mojom::ZCashWalletService>(); | ||
} | ||
|
||
if (!IsZCashEnabled()) { | ||
return mojo::PendingRemote<mojom::ZCashWalletService>(); | ||
} | ||
|
||
return static_cast<ZCashWalletService*>( | ||
GetInstance()->GetServiceForBrowserContext(context, true)) | ||
->MakeRemote(); | ||
} | ||
|
||
// static | ||
ZCashWalletService* ZCashWalletServiceFactory::GetServiceForContext( | ||
content::BrowserContext* context) { | ||
if (!IsAllowedForContext(context)) { | ||
return nullptr; | ||
} | ||
if (!IsZCashEnabled()) { | ||
return nullptr; | ||
} | ||
return static_cast<ZCashWalletService*>( | ||
GetInstance()->GetServiceForBrowserContext(context, true)); | ||
} | ||
|
||
// static | ||
void ZCashWalletServiceFactory::BindForContext( | ||
content::BrowserContext* context, | ||
mojo::PendingReceiver<mojom::ZCashWalletService> receiver) { | ||
auto* zcash_service = | ||
ZCashWalletServiceFactory::GetServiceForContext(context); | ||
if (zcash_service) { | ||
zcash_service->Bind(std::move(receiver)); | ||
} | ||
} | ||
|
||
ZCashWalletServiceFactory::ZCashWalletServiceFactory() | ||
: BrowserContextKeyedServiceFactory( | ||
"ZCashWalletService", | ||
BrowserContextDependencyManager::GetInstance()) { | ||
DependsOn(KeyringServiceFactory::GetInstance()); | ||
} | ||
|
||
ZCashWalletServiceFactory::~ZCashWalletServiceFactory() = default; | ||
|
||
KeyedService* ZCashWalletServiceFactory::BuildServiceInstanceFor( | ||
content::BrowserContext* context) const { | ||
auto* default_storage_partition = context->GetDefaultStoragePartition(); | ||
auto shared_url_loader_factory = | ||
default_storage_partition->GetURLLoaderFactoryForBrowserProcess(); | ||
return new ZCashWalletService( | ||
KeyringServiceFactory::GetServiceForContext(context), | ||
user_prefs::UserPrefs::Get(context), shared_url_loader_factory); | ||
} | ||
|
||
content::BrowserContext* ZCashWalletServiceFactory::GetBrowserContextToUse( | ||
content::BrowserContext* context) const { | ||
return chrome::GetBrowserContextRedirectedInIncognito(context); | ||
} | ||
|
||
} // namespace brave_wallet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* Copyright (c) 2023 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 https://mozilla.org/MPL/2.0/. */ | ||
|
||
#ifndef BRAVE_BROWSER_BRAVE_WALLET_ZCASH_WALLET_SERVICE_FACTORY_H_ | ||
#define BRAVE_BROWSER_BRAVE_WALLET_ZCASH_WALLET_SERVICE_FACTORY_H_ | ||
|
||
#include "brave/components/brave_wallet/common/brave_wallet.mojom.h" | ||
#include "components/keyed_service/content/browser_context_keyed_service_factory.h" | ||
#include "components/keyed_service/core/keyed_service.h" | ||
#include "content/public/browser/browser_context.h" | ||
#include "mojo/public/cpp/bindings/pending_receiver.h" | ||
#include "mojo/public/cpp/bindings/pending_remote.h" | ||
|
||
namespace base { | ||
template <typename T> | ||
class NoDestructor; | ||
} // namespace base | ||
|
||
namespace brave_wallet { | ||
|
||
class ZCashWalletService; | ||
|
||
class ZCashWalletServiceFactory : public BrowserContextKeyedServiceFactory { | ||
public: | ||
ZCashWalletServiceFactory(const ZCashWalletServiceFactory&) = delete; | ||
ZCashWalletServiceFactory& operator=(const ZCashWalletServiceFactory&) = | ||
delete; | ||
|
||
static mojo::PendingRemote<mojom::ZCashWalletService> GetForContext( | ||
content::BrowserContext* context); | ||
static ZCashWalletService* GetServiceForContext( | ||
content::BrowserContext* context); | ||
static ZCashWalletServiceFactory* GetInstance(); | ||
static void BindForContext( | ||
content::BrowserContext* context, | ||
mojo::PendingReceiver<mojom::ZCashWalletService> receiver); | ||
|
||
private: | ||
friend base::NoDestructor<ZCashWalletServiceFactory>; | ||
|
||
ZCashWalletServiceFactory(); | ||
~ZCashWalletServiceFactory() override; | ||
|
||
KeyedService* BuildServiceInstanceFor( | ||
content::BrowserContext* context) const override; | ||
content::BrowserContext* GetBrowserContextToUse( | ||
content::BrowserContext* context) const override; | ||
}; | ||
|
||
} // namespace brave_wallet | ||
|
||
#endif // BRAVE_BROWSER_BRAVE_WALLET_ZCASH_WALLET_SERVICE_FACTORY_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.