Skip to content

Commit

Permalink
Fixes restore for new wallets
Browse files Browse the repository at this point in the history
  • Loading branch information
NejcZdovc committed Sep 10, 2020
1 parent c07fe20 commit d3bd49e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<base::Value> value = base::JSONReader::Read(body);
Expand All @@ -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;
}
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ namespace promotion {

using GetRecoverWalletCallback = std::function<void(
const type::Result result,
const std::string& payment_id)>;
const std::string& payment_id,
const bool old_wallet)>;

class GetRecoverWallet {
public:
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

using std::placeholders::_1;
using std::placeholders::_2;
using std::placeholders::_3;

namespace ledger {
namespace wallet {
Expand Down Expand Up @@ -72,6 +73,7 @@ void WalletRecover::Start(
this,
_1,
_2,
_3,
new_seed,
callback);

Expand All @@ -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<uint8_t>& new_seed,
ledger::ResultCallback callback) {
if (result != type::Result::LEDGER_OK) {
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class WalletRecover {
void OnRecover(
const type::Result result,
const std::string& payment_id,
const bool old_wallet,
const std::vector<uint8_t>& new_seed,
ledger::ResultCallback callback);

Expand Down

0 comments on commit d3bd49e

Please sign in to comment.