diff --git a/interface/src/commerce/Ledger.cpp b/interface/src/commerce/Ledger.cpp index f607c923ee..ed862384dc 100644 --- a/interface/src/commerce/Ledger.cpp +++ b/interface/src/commerce/Ledger.cpp @@ -90,6 +90,15 @@ void Ledger::buy(const QString& hfc_key, int cost, const QString& asset_id, cons signedSend("transaction", transactionString, hfc_key, "buy", "buySuccess", "buyFailure", controlled_failure); } +void Ledger::receiveAtSuccess(QNetworkReply& reply) { + auto wallet = DependencyManager::get(); + QByteArray response = reply.readAll(); + QJsonObject data = QJsonDocument::fromJson(response).object(); + + if (data["status"] == "fail") { // Not on "The List" for receiving HFC + wallet->setMustRegenerateKeypair(true); + } +} bool Ledger::receiveAt(const QString& hfc_key, const QString& old_key, const QString& machine_fingerprint) { auto accountManager = DependencyManager::get(); if (!accountManager->isLoggedIn()) { diff --git a/interface/src/commerce/Wallet.cpp b/interface/src/commerce/Wallet.cpp index 9bc8dc9e43..b746b58015 100644 --- a/interface/src/commerce/Wallet.cpp +++ b/interface/src/commerce/Wallet.cpp @@ -327,6 +327,12 @@ Wallet::Wallet() { auto walletScriptingInterface = DependencyManager::get(); uint status; + if (_mustRegenerateKeypair) { + _mustRegenerateKeypair = false; + resetKeysOnly(); + generateKeyPair(); + } + if (wallet->getKeyFilePath() == "" || !wallet->getSecurityImage()) { status = (uint)WalletStatus::WALLET_STATUS_NOT_SET_UP; } else if (!wallet->walletIsAuthenticatedWithPassphrase()) { @@ -661,9 +667,13 @@ QString Wallet::getKeyFilePath() { } } -void Wallet::reset() { +void Wallet::resetKeysOnly() { _publicKeys.clear(); + QFile keyFile(keyFilePath()); + keyFile.remove(); +} +void Wallet::reset() { delete _securityImage; _securityImage = nullptr; @@ -671,9 +681,7 @@ void Wallet::reset() { updateImageProvider(); _passphrase->clear(); - - QFile keyFile(keyFilePath()); - keyFile.remove(); + resetKeysOnly(); } bool Wallet::writeWallet(const QString& newPassphrase) { RSA* keys = readKeys(keyFilePath().toStdString().c_str()); diff --git a/interface/src/commerce/Wallet.h b/interface/src/commerce/Wallet.h index ed145df451..f0f13aaf6e 100644 --- a/interface/src/commerce/Wallet.h +++ b/interface/src/commerce/Wallet.h @@ -49,6 +49,7 @@ public: bool walletIsAuthenticatedWithPassphrase(); bool changePassphrase(const QString& newPassphrase); + void resetKeysOnly(); void reset(); void getWalletStatus(); @@ -59,6 +60,8 @@ public: WALLET_STATUS_READY }; + void setMustRegenerateKeypair(const bool& val) { _mustRegenerateKeypair = val; } + signals: void securityImageResult(bool exists); void keyFilePathIfExistsResult(const QString& path); @@ -83,6 +86,8 @@ private: bool writeBackupInstructions(); void account(); + + bool _mustRegenerateKeypair { false }; }; #endif // hifi_Wallet_h