Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes restore for new wallets #6610

Merged
merged 1 commit into from
Sep 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ type::Result GetRecoverWallet::CheckStatusCode(const int status_code) {

type::Result GetRecoverWallet::ParseBody(
const std::string& body,
std::string* payment_id) {
DCHECK(payment_id);
std::string* payment_id,
bool* legacy_wallet) {
DCHECK(payment_id && legacy_wallet);

base::Optional<base::Value> value = base::JSONReader::Read(body);
if (!value || !value->is_dict()) {
Expand All @@ -74,6 +75,14 @@ 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;
}

*legacy_wallet = *wallet_name == "uphold";
*payment_id = *payment_id_string;
return type::Result::LEDGER_OK;
}
Expand All @@ -97,15 +106,16 @@ void GetRecoverWallet::OnRequest(
ledger::LogUrlResponse(__func__, response);

std::string payment_id;
bool legacy_wallet = false;
type::Result result = CheckStatusCode(response.status_code);

if (result != type::Result::LEDGER_OK) {
callback(result, payment_id);
callback(result, payment_id, legacy_wallet);
return;
}

result = ParseBody(response.body, &payment_id);
callback(result, payment_id);
result = ParseBody(response.body, &payment_id, &legacy_wallet);
callback(result, payment_id, legacy_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 legacy_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* legacy_wallet);

void OnRequest(
const type::UrlResponse& response,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,13 @@ TEST_F(GetRecoverWalletTest, ServerOK) {

wallet_->Request(
"79d7da2a756cc8d9403d0353a64fae5698e01b44a2c2745",
[](const type::Result result, const std::string& payment_id) {
[](
const type::Result result,
const std::string& payment_id,
const bool legacy_wallet) {
EXPECT_EQ(result, type::Result::LEDGER_OK);
EXPECT_EQ(payment_id, "d59d4b69-f66e-4ee8-9c88-1c522e02ffd3");
EXPECT_EQ(legacy_wallet, true);
});
}

Expand All @@ -85,7 +89,10 @@ TEST_F(GetRecoverWalletTest, ServerError400) {

wallet_->Request(
"79d7da2a756cc8d9403d0353a64fae5698e01b44a2c2745",
[](const type::Result result, const std::string& payment_id) {
[](
const type::Result result,
const std::string& payment_id,
const bool legacy_wallet) {
EXPECT_EQ(result, type::Result::LEDGER_ERROR);
EXPECT_EQ(payment_id, "");
});
Expand All @@ -106,7 +113,10 @@ TEST_F(GetRecoverWalletTest, ServerError404) {

wallet_->Request(
"79d7da2a756cc8d9403d0353a64fae5698e01b44a2c2745",
[](const type::Result result, const std::string& payment_id) {
[](
const type::Result result,
const std::string& payment_id,
const bool legacy_wallet) {
EXPECT_EQ(result, type::Result::NOT_FOUND);
EXPECT_EQ(payment_id, "");
});
Expand All @@ -127,7 +137,10 @@ TEST_F(GetRecoverWalletTest, ServerErrorRandom) {

wallet_->Request(
"79d7da2a756cc8d9403d0353a64fae5698e01b44a2c2745",
[](const type::Result result, const std::string& payment_id) {
[](
const type::Result result,
const std::string& payment_id,
const bool legacy_wallet) {
EXPECT_EQ(result, type::Result::LEDGER_ERROR);
EXPECT_EQ(payment_id, "");
});
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 legacy_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 (legacy_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 legacy_wallet,
const std::vector<uint8_t>& new_seed,
ledger::ResultCallback callback);

Expand Down