From d3bd49e86e899981b7c43561a1188763f80eb820 Mon Sep 17 00:00:00 2001 From: NejcZdovc Date: Thu, 10 Sep 2020 08:16:49 +0200 Subject: [PATCH] Fixes restore for new wallets Resolves https://github.com/brave/brave-browser/issues/11647 --- .../get_recover_wallet/get_recover_wallet.cc | 19 +++++++++++++++---- .../get_recover_wallet/get_recover_wallet.h | 6 ++++-- .../ledger/internal/wallet/wallet_recover.cc | 7 ++++++- .../ledger/internal/wallet/wallet_recover.h | 1 + 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/promotion/get_recover_wallet/get_recover_wallet.cc b/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/promotion/get_recover_wallet/get_recover_wallet.cc index a84945e7883a..70d7632c55a0 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/promotion/get_recover_wallet/get_recover_wallet.cc +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/promotion/get_recover_wallet/get_recover_wallet.cc @@ -53,7 +53,8 @@ type::Result GetRecoverWallet::CheckStatusCode(const int status_code) { type::Result GetRecoverWallet::ParseBody( const std::string& body, - std::string* payment_id) { + std::string* payment_id, + bool* old_wallet) { DCHECK(payment_id); base::Optional value = base::JSONReader::Read(body); @@ -74,6 +75,15 @@ type::Result GetRecoverWallet::ParseBody( return type::Result::LEDGER_ERROR; } + + const auto* wallet_name = + dictionary->FindStringPath("walletProvider.name"); + if (!wallet_name) { + BLOG(0, "Wallet name is missing"); + return type::Result::LEDGER_ERROR; + } + + *old_wallet = *wallet_name == "uphold"; *payment_id = *payment_id_string; return type::Result::LEDGER_OK; } @@ -97,15 +107,16 @@ void GetRecoverWallet::OnRequest( ledger::LogUrlResponse(__func__, response); std::string payment_id; + bool old_wallet = false; type::Result result = CheckStatusCode(response.status_code); if (result != type::Result::LEDGER_OK) { - callback(result, payment_id); + callback(result, payment_id, old_wallet); return; } - result = ParseBody(response.body, &payment_id); - callback(result, payment_id); + result = ParseBody(response.body, &payment_id, &old_wallet); + callback(result, payment_id, old_wallet); } } // namespace promotion diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/promotion/get_recover_wallet/get_recover_wallet.h b/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/promotion/get_recover_wallet/get_recover_wallet.h index 511e440b1024..bbfacdd36739 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/promotion/get_recover_wallet/get_recover_wallet.h +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/promotion/get_recover_wallet/get_recover_wallet.h @@ -40,7 +40,8 @@ namespace promotion { using GetRecoverWalletCallback = std::function; + const std::string& payment_id, + const bool old_wallet)>; class GetRecoverWallet { public: @@ -58,7 +59,8 @@ class GetRecoverWallet { type::Result ParseBody( const std::string& body, - std::string* payment_id); + std::string* payment_id, + bool* old_wallet); void OnRequest( const type::UrlResponse& response, diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/wallet/wallet_recover.cc b/vendor/bat-native-ledger/src/bat/ledger/internal/wallet/wallet_recover.cc index 4e05e4c594fc..bfa49703eba7 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/wallet/wallet_recover.cc +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/wallet/wallet_recover.cc @@ -16,6 +16,7 @@ using std::placeholders::_1; using std::placeholders::_2; +using std::placeholders::_3; namespace ledger { namespace wallet { @@ -72,6 +73,7 @@ void WalletRecover::Start( this, _1, _2, + _3, new_seed, callback); @@ -83,6 +85,7 @@ void WalletRecover::Start( void WalletRecover::OnRecover( const type::Result result, const std::string& payment_id, + const bool old_wallet, const std::vector& new_seed, ledger::ResultCallback callback) { if (result != type::Result::LEDGER_OK) { @@ -92,9 +95,11 @@ void WalletRecover::OnRecover( ledger_->state()->SetRecoverySeed(new_seed); ledger_->state()->SetPaymentId(payment_id); - ledger_->state()->SetFetchOldBalanceEnabled(true); ledger_->state()->SetAnonTransferChecked(false); ledger_->state()->SetPromotionLastFetchStamp(0); + if (old_wallet) { + ledger_->state()->SetFetchOldBalanceEnabled(true); + } callback(type::Result::LEDGER_OK); } diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/wallet/wallet_recover.h b/vendor/bat-native-ledger/src/bat/ledger/internal/wallet/wallet_recover.h index f236aa358cca..d9e05358906d 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/wallet/wallet_recover.h +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/wallet/wallet_recover.h @@ -33,6 +33,7 @@ class WalletRecover { void OnRecover( const type::Result result, const std::string& payment_id, + const bool old_wallet, const std::vector& new_seed, ledger::ResultCallback callback);