Skip to content

Commit

Permalink
Merge pull request #42 from brave-intl/recover
Browse files Browse the repository at this point in the history
Saves new paymentId; Uses result instead of boolean
  • Loading branch information
NejcZdovc authored Aug 13, 2018
2 parents 2d9b7f6 + bf2ec96 commit 2bfcc97
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion include/bat/ledger/ledger_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class LEDGER_EXPORT LedgerClient {
virtual void OnPromotion(ledger::Promo) = 0;
virtual void GetPromotionCaptcha() = 0;
virtual void OnPromotionCaptcha(const std::string& image) = 0;
virtual void OnRecoverWallet(bool error, double balance) = 0;
virtual void OnRecoverWallet(Result result, double balance) = 0;

virtual std::unique_ptr<ledger::LedgerURLLoader> LoadURL(
const std::string& url,
Expand Down
14 changes: 8 additions & 6 deletions src/bat_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ void BatClient::recoverWallet(const std::string& passPhrase) {
int result = bip39_mnemonic_to_bytes(nullptr, passPhrase.c_str(), &newSeed.front(), newSeed.size(), &written);
LOG(ERROR) << "!!!recoverWallet result == " << result << "!!!result size == " << written;
if (0 != result || 0 == written) {
ledger_->OnRecoverWallet(true, 0);
ledger_->OnRecoverWallet(ledger::Result::ERROR, 0);
return;
}
state_->walletInfo_.keyInfoSeed_ = newSeed;
Expand All @@ -918,7 +918,7 @@ void BatClient::recoverWalletPublicKeyCallback(bool result, const std::string& r
LOG(ERROR) << "!!!recoverWalletPublicKeyCallback == " << response;

if (!result) {
ledger_->OnRecoverWallet(true, 0);
ledger_->OnRecoverWallet(ledger::Result::ERROR, 0);
return;
}

Expand All @@ -931,21 +931,23 @@ void BatClient::recoverWalletPublicKeyCallback(bool result, const std::string& r
std::bind(&BatClient::recoverWalletCallback,
this,
_1,
_2));
_2,
recoveryId));
}

void BatClient::recoverWalletCallback(bool result, const std::string& response) {
void BatClient::recoverWalletCallback(bool result, const std::string& response, const std::string& recoveryId) {
LOG(ERROR) << "!!!recoverWalletCallback == " << response;

if (!result) {
ledger_->OnRecoverWallet(true, 0);
ledger_->OnRecoverWallet(ledger::Result::ERROR, 0);
return;
}

braveledger_bat_helper::getJSONWalletInfo(response, state_->walletInfo_, state_->fee_currency_, state_->fee_amount_, state_->days_);
braveledger_bat_helper::getJSONRecoverWallet(response, state_->walletProperties_.balance_, state_->walletProperties_.probi_);
state_->walletInfo_.paymentId_ = recoveryId;
saveState();
ledger_->OnRecoverWallet(false, state_->walletProperties_.balance_);
ledger_->OnRecoverWallet(ledger::Result::OK, state_->walletProperties_.balance_);
}

void BatClient::getPromotion(const std::string& lang, const std::string& forPaymentId) {
Expand Down
2 changes: 1 addition & 1 deletion src/bat_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class BatClient {
void getPromotionCallback(bool result, const std::string& response);
void setPromotionCallback(bool result, const std::string& response);
void recoverWalletPublicKeyCallback(bool result, const std::string& response);
void recoverWalletCallback(bool result, const std::string& response);
void recoverWalletCallback(bool result, const std::string& response, const std::string& paymentId);
void prepareBatch(const braveledger_bat_helper::BALLOT_ST& ballot, const braveledger_bat_helper::TRANSACTION_ST& transaction);
void prepareBatchCallback(bool result, const std::string& response);
void proofBatch(const std::vector<braveledger_bat_helper::BATCH_PROOF>& batchProof);
Expand Down
4 changes: 2 additions & 2 deletions src/ledger_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,8 @@ void LedgerImpl::RecoverWallet(const std::string& passPhrase) const {
bat_client_->recoverWallet(passPhrase);
}

void LedgerImpl::OnRecoverWallet(bool error, double balance) {
ledger_client_->OnRecoverWallet(error ? ledger::Result::ERROR :
void LedgerImpl::OnRecoverWallet(ledger::Result result, double balance) {
ledger_client_->OnRecoverWallet(result ? ledger::Result::ERROR :
ledger::Result::OK,
balance);
}
Expand Down
2 changes: 1 addition & 1 deletion src/ledger_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class LedgerImpl : public ledger::Ledger,

std::string GetWalletPassphrase() const override;
void RecoverWallet(const std::string& passPhrase) const override;
void OnRecoverWallet(bool error, double balance);
void OnRecoverWallet(ledger::Result result, double balance);

std::unique_ptr<ledger::LedgerURLLoader> LoadURL(const std::string& url,
const std::vector<std::string>& headers,
Expand Down

0 comments on commit 2bfcc97

Please sign in to comment.