From e83fafe7d7ea488e20638fd38c732801d046fc92 Mon Sep 17 00:00:00 2001 From: Szilard Szaloki Date: Wed, 11 Aug 2021 23:57:17 +0200 Subject: [PATCH] Don't show "Your wallet is verified!" when reconnecting after a natural disconnect. --- .../src/bat/ledger/internal/uphold/uphold.cc | 2 +- .../internal/uphold/uphold_authorization.cc | 2 +- .../bat/ledger/internal/uphold/uphold_util.cc | 19 ++++++++++++++++--- .../bat/ledger/internal/uphold/uphold_util.h | 8 +++++--- .../ledger/internal/uphold/uphold_wallet.cc | 12 +++++++----- 5 files changed, 30 insertions(+), 13 deletions(-) diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold.cc b/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold.cc index 6233f3e35a98..8127519c5106 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold.cc +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold.cc @@ -202,7 +202,7 @@ void Uphold::DisconnectWallet(const std::string& notification) { } const auto to = wallet->status; - LogWalletStatusChange(ledger_, from, to); + OnWalletStatusChange(ledger_, from, to); const bool shutting_down = ledger_->IsShuttingDown(); diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold_authorization.cc b/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold_authorization.cc index 722184b9cad4..5379348c16ed 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold_authorization.cc +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold_authorization.cc @@ -138,7 +138,7 @@ void UpholdAuthorization::OnAuthorize( return callback(type::Result::LEDGER_ERROR, {}); } - LogWalletStatusChange(ledger_, from, to); + OnWalletStatusChange(ledger_, from, to); callback(type::Result::LEDGER_OK, {}); } diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold_util.cc b/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold_util.cc index 860b9e7b2916..0b034eb022ea 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold_util.cc +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold_util.cc @@ -20,6 +20,10 @@ namespace ledger { namespace uphold { +namespace { +bool g_show_newly_verified_wallet = true; +} // namespace + std::string GetClientId() { return ledger::_environment == type::Environment::PRODUCTION ? UPHOLD_CLIENT_ID @@ -187,9 +191,9 @@ bool one_of(T&& t, Ts&&... ts) { return match; } -void LogWalletStatusChange(LedgerImpl* ledger, - absl::optional from, - type::WalletStatus to) { +void OnWalletStatusChange(LedgerImpl* ledger, + absl::optional from, + type::WalletStatus to) { DCHECK(ledger); DCHECK(!from || one_of(*from, type::WalletStatus::NOT_CONNECTED, @@ -206,6 +210,15 @@ void LogWalletStatusChange(LedgerImpl* ledger, oss << "==> " << to; ledger->database()->SaveEventLog(log::kWalletStatusChange, oss.str()); + + if (to == type::WalletStatus::PENDING) { + DCHECK(from); + g_show_newly_verified_wallet = *from == type::WalletStatus::NOT_CONNECTED; + } +} + +bool ShouldShowNewlyVerifiedWallet() { + return g_show_newly_verified_wallet; } } // namespace uphold diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold_util.h b/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold_util.h index 3b236a89112c..9cfd8ea27320 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold_util.h +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold_util.h @@ -55,9 +55,11 @@ type::ExternalWalletPtr GenerateLinks(type::ExternalWalletPtr wallet); std::string GenerateVerifyLink(type::ExternalWalletPtr wallet); -void LogWalletStatusChange(LedgerImpl* ledger, - absl::optional from, - type::WalletStatus to); +void OnWalletStatusChange(LedgerImpl* ledger, + absl::optional from, + type::WalletStatus to); + +bool ShouldShowNewlyVerifiedWallet(); } // namespace uphold } // namespace ledger diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold_wallet.cc b/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold_wallet.cc index 32ff7a68e52c..ced6408b744d 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold_wallet.cc +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold_wallet.cc @@ -56,7 +56,7 @@ void UpholdWallet::Generate(ledger::ResultCallback callback) const { return callback(type::Result::LEDGER_ERROR); } - LogWalletStatusChange(ledger_, {}, uphold_wallet->status); + OnWalletStatusChange(ledger_, {}, uphold_wallet->status); } if (uphold_wallet->one_time_string.empty()) { @@ -297,15 +297,17 @@ void UpholdWallet::OnLinkWallet(const type::Result result, return callback(type::Result::LEDGER_ERROR); } - LogWalletStatusChange(ledger_, from, to); + OnWalletStatusChange(ledger_, from, to); ledger_->database()->SaveEventLog( log::kWalletVerified, constant::kWalletUphold + std::string("/") + id.substr(0, 5)); - ledger_->ledger_client()->ShowNotification( - ledger::notifications::kWalletNewVerified, {"Uphold"}, - [](type::Result) {}); + if (ShouldShowNewlyVerifiedWallet()) { + ledger_->ledger_client()->ShowNotification( + ledger::notifications::kWalletNewVerified, {"Uphold"}, + [](type::Result) {}); + } ledger_->promotion()->TransferTokens( std::bind(&UpholdWallet::OnTransferTokens, this, _1, _2, callback));