Skip to content

Commit

Permalink
Don't show "Your wallet is verified!" when reconnecting after a natur…
Browse files Browse the repository at this point in the history
…al disconnect.
  • Loading branch information
szilardszaloki committed Aug 12, 2021
1 parent 6dfab0a commit e83fafe
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, {});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -187,9 +191,9 @@ bool one_of(T&& t, Ts&&... ts) {
return match;
}

void LogWalletStatusChange(LedgerImpl* ledger,
absl::optional<type::WalletStatus> from,
type::WalletStatus to) {
void OnWalletStatusChange(LedgerImpl* ledger,
absl::optional<type::WalletStatus> from,
type::WalletStatus to) {
DCHECK(ledger);
DCHECK(!from ||
one_of(*from, type::WalletStatus::NOT_CONNECTED,
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ type::ExternalWalletPtr GenerateLinks(type::ExternalWalletPtr wallet);

std::string GenerateVerifyLink(type::ExternalWalletPtr wallet);

void LogWalletStatusChange(LedgerImpl* ledger,
absl::optional<type::WalletStatus> from,
type::WalletStatus to);
void OnWalletStatusChange(LedgerImpl* ledger,
absl::optional<type::WalletStatus> from,
type::WalletStatus to);

bool ShouldShowNewlyVerifiedWallet();

} // namespace uphold
} // namespace ledger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit e83fafe

Please sign in to comment.