Skip to content

Commit

Permalink
Disconnect existing external wallets when connecting a new wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
zenparsing committed Nov 10, 2021
1 parent 61d0f3d commit bd7dd8d
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 4 deletions.
22 changes: 18 additions & 4 deletions components/brave_rewards/browser/rewards_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2880,10 +2880,11 @@ void RewardsServiceImpl::OnExternalWalletAuthorization(
std::move(callback).Run(result, args);
}

void RewardsServiceImpl::ExternalWalletAuthorization(
const std::string& wallet_type,
const base::flat_map<std::string, std::string>& args,
ExternalWalletAuthorizationCallback callback) {
void RewardsServiceImpl::OnDisconnectWalletsForAuthorization(
const std::string& wallet_type,
const base::flat_map<std::string, std::string>& args,
ExternalWalletAuthorizationCallback callback,
ledger::type::Result result) {
if (!Connected()) {
return;
}
Expand All @@ -2897,6 +2898,19 @@ void RewardsServiceImpl::ExternalWalletAuthorization(
std::move(callback)));
}

void RewardsServiceImpl::ExternalWalletAuthorization(
const std::string& wallet_type,
const base::flat_map<std::string, std::string>& args,
ExternalWalletAuthorizationCallback callback) {
if (!Connected()) {
return;
}

bat_ledger_->DisconnectExternalWallets(base::BindOnce(
&RewardsServiceImpl::OnDisconnectWalletsForAuthorization, AsWeakPtr(),
wallet_type, std::move(args), std::move(callback)));
}

void RewardsServiceImpl::OnProcessExternalWalletAuthorization(
const std::string& wallet_type,
const std::string& action,
Expand Down
6 changes: 6 additions & 0 deletions components/brave_rewards/browser/rewards_service_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,12 @@ class RewardsServiceImpl : public RewardsService,
const ledger::type::Result result,
const base::flat_map<std::string, std::string>& args);

void OnDisconnectWalletsForAuthorization(
const std::string& wallet_type,
const base::flat_map<std::string, std::string>& args,
ExternalWalletAuthorizationCallback callback,
ledger::type::Result result);

void OnDisconnectWallet(
const std::string& wallet_type,
const ledger::type::Result result);
Expand Down
13 changes: 13 additions & 0 deletions components/services/bat_ledger/bat_ledger_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,19 @@ void BatLedgerImpl::DisconnectWallet(
_1));
}

void BatLedgerImpl::DisconnectExternalWallets(
DisconnectExternalWalletsCallback callback) {
auto weak_self = AsWeakPtr();
auto shared_callback =
std::make_shared<DisconnectExternalWalletsCallback>(std::move(callback));

ledger_->DisconnectExternalWallets(
[weak_self, shared_callback](ledger::type::Result result) {
if (weak_self)
std::move(*shared_callback).Run(result);
});
}

// static
void BatLedgerImpl::OnGetAnonWalletStatus(
CallbackHolder<GetAnonWalletStatusCallback>* holder,
Expand Down
3 changes: 3 additions & 0 deletions components/services/bat_ledger/bat_ledger_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ class BatLedgerImpl :
const std::string& wallet_type,
DisconnectWalletCallback callback) override;

void DisconnectExternalWallets(
DisconnectExternalWalletsCallback callback) override;

void GetAnonWalletStatus(GetAnonWalletStatusCallback callback) override;

void GetTransactionReport(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ interface BatLedger {

DisconnectWallet(string wallet_type) => (ledger.mojom.Result result);

DisconnectExternalWallets() => (ledger.mojom.Result result);

GetAnonWalletStatus() => (ledger.mojom.Result result);

GetTransactionReport(ledger.mojom.ActivityMonth month, int32 year) => (array<ledger.mojom.TransactionReportInfo> list);
Expand Down
2 changes: 2 additions & 0 deletions vendor/bat-native-ledger/include/bat/ledger/ledger.h
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,8 @@ class LEDGER_EXPORT Ledger {
virtual void DisconnectWallet(const std::string& wallet_type,
ResultCallback callback) = 0;

virtual void DisconnectExternalWallets(ResultCallback callback) = 0;

virtual void GetAllPromotions(GetAllPromotionsCallback callback) = 0;

virtual void GetAnonWalletStatus(ResultCallback callback) = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,10 @@ void LedgerImpl::DisconnectWallet(const std::string& wallet_type,
});
}

void LedgerImpl::DisconnectExternalWallets(ResultCallback callback) {
WhenReady([this, callback]() { wallet()->DisconnectAllWallets(callback); });
}

void LedgerImpl::GetAllPromotions(GetAllPromotionsCallback callback) {
WhenReady([this, callback]() { database()->GetAllPromotions(callback); });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@ class LedgerImpl : public Ledger {
void DisconnectWallet(const std::string& wallet_type,
ResultCallback callback) override;

void DisconnectExternalWallets(ResultCallback callback) override;

void GetAllPromotions(GetAllPromotionsCallback callback) override;

void GetAnonWalletStatus(ResultCallback callback) override;
Expand Down

0 comments on commit bd7dd8d

Please sign in to comment.