From 21a73b2f3989a13fe3bd0e67d18732b9acf405cb Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Thu, 31 Aug 2017 13:15:22 -0700 Subject: [PATCH] Changes in what I think are the right direction --- .../qml/hifi/commerce/wallet/Wallet.qml | 43 +++++++++++++------ interface/src/commerce/QmlCommerce.cpp | 16 +++++-- interface/src/commerce/QmlCommerce.h | 3 +- interface/src/commerce/Wallet.cpp | 8 ++-- interface/src/commerce/Wallet.h | 4 +- 5 files changed, 50 insertions(+), 24 deletions(-) diff --git a/interface/resources/qml/hifi/commerce/wallet/Wallet.qml b/interface/resources/qml/hifi/commerce/wallet/Wallet.qml index 42760abacd..04278e85a9 100644 --- a/interface/resources/qml/hifi/commerce/wallet/Wallet.qml +++ b/interface/resources/qml/hifi/commerce/wallet/Wallet.qml @@ -40,8 +40,32 @@ Rectangle { root.activeView = "needsLogIn"; } else if (isLoggedIn) { root.activeView = "initialize"; - commerce.getSecurityImage(); - commerce.getKeyFilePathIfExists(); + commerce.getPassphraseSetupStatus(); + } + } + + onPassphraseSetupStatusResult: { + if (!passphraseIsSetup && root.activeView !== "notSetUp") { + root.activeView = "notSetUp"; + } else if (passphraseIsSetup && root.activeView === "initialize") { + commerce.getWalletAuthenticatedStatus(); + } + } + + onWalletAuthenticatedStatusResult: { + if (!isAuthenticated && !passphraseModal.visible) { + passphraseModal.visible = true; + } else if (isAuthenticated) { + if (passphraseModal.visible) { + passphraseModal.visible = false; + } + + if (!securityImageResultReceived) { + commerce.getSecurityImage(); + } + if (!keyFilePathIfExistsResultReceived) { + commerce.getKeyFilePathIfExists(); + } } } @@ -62,16 +86,6 @@ Rectangle { root.activeView = "walletHome"; } } - - onWalletAuthenticatedStatus: { - if (!isAuthenticated && !passphraseModal.visible) { - passphraseModal.visible = true; - } else if (isAuthenticated && passphraseModal.visible) { - passphraseModal.visible = false; - commerce.getSecurityImage(); - commerce.getKeyFilePathIfExists(); - } - } } SecurityImageModel { @@ -99,7 +113,8 @@ Rectangle { if (msg.method === 'walletSetup_cancelClicked') { walletSetupLightbox.visible = false; } else if (msg.method === 'walletSetup_finished') { - root.activeView = "walletHome"; + root.activeView = "initialize"; + commerce.getPassphraseSetupStatus(); } else if (msg.method === 'walletSetup_raiseKeyboard') { root.keyboardRaised = true; } else if (msg.method === 'walletSetup_lowerKeyboard') { @@ -231,7 +246,7 @@ Rectangle { PassphraseModal { id: passphraseModal; z: 998; - //visible: false; + visible: false; anchors.top: titleBarContainer.bottom; anchors.bottom: parent.bottom; anchors.left: parent.left; diff --git a/interface/src/commerce/QmlCommerce.cpp b/interface/src/commerce/QmlCommerce.cpp index 2f424b7cc8..ccbc37ed13 100644 --- a/interface/src/commerce/QmlCommerce.cpp +++ b/interface/src/commerce/QmlCommerce.cpp @@ -27,7 +27,6 @@ QmlCommerce::QmlCommerce(QQuickItem* parent) : OffscreenQmlDialog(parent) { connect(wallet.data(), &Wallet::securityImageResult, this, &QmlCommerce::securityImageResult); connect(ledger.data(), &Ledger::historyResult, this, &QmlCommerce::historyResult); connect(wallet.data(), &Wallet::keyFilePathIfExistsResult, this, &QmlCommerce::keyFilePathIfExistsResult); - connect(wallet.data(), &Wallet::walletAuthenticatedStatus, this, &QmlCommerce::walletAuthenticatedStatus); } void QmlCommerce::buy(const QString& assetId, int cost, const QString& buyerUsername) { @@ -76,12 +75,23 @@ void QmlCommerce::getLoginStatus() { } void QmlCommerce::setPassphrase(const QString& passphrase) { - emit passphraseSetupStatusResult(true); + auto wallet = DependencyManager::get(); + wallet->setPassphrase(passphrase); + getPassphraseSetupStatus(); } void QmlCommerce::getPassphraseSetupStatus() { - emit passphraseSetupStatusResult(false); + auto wallet = DependencyManager::get(); + // ????? WHAT DO I DO HERE + emit passphraseSetupStatusResult(wallet->getPassphraseIsCached()); } + +void QmlCommerce::getWalletAuthenticatedStatus() { + auto wallet = DependencyManager::get(); + // ????? WHAT DO I DO HERE + emit walletAuthenticatedStatusResult(wallet->getPassphraseIsCached()); +} + void QmlCommerce::getKeyFilePathIfExists() { auto wallet = DependencyManager::get(); wallet->sendKeyFilePathIfExists(); diff --git a/interface/src/commerce/QmlCommerce.h b/interface/src/commerce/QmlCommerce.h index a9eca34242..5561f331f9 100644 --- a/interface/src/commerce/QmlCommerce.h +++ b/interface/src/commerce/QmlCommerce.h @@ -38,7 +38,7 @@ signals: void passphraseSetupStatusResult(bool passphraseIsSetup); void historyResult(QJsonObject result); void keyFilePathIfExistsResult(const QString& path); - void walletAuthenticatedStatus(bool isAuthenticated); + void walletAuthenticatedStatusResult(bool isAuthenticated); protected: Q_INVOKABLE void buy(const QString& assetId, int cost, const QString& buyerUsername = ""); @@ -50,6 +50,7 @@ protected: Q_INVOKABLE void getLoginStatus(); Q_INVOKABLE void setPassphrase(const QString& passphrase); Q_INVOKABLE void getPassphraseSetupStatus(); + Q_INVOKABLE void getWalletAuthenticatedStatus(); Q_INVOKABLE void getKeyFilePathIfExists(); Q_INVOKABLE void reset(); }; diff --git a/interface/src/commerce/Wallet.cpp b/interface/src/commerce/Wallet.cpp index 569e0f9110..cfd5b6baa5 100644 --- a/interface/src/commerce/Wallet.cpp +++ b/interface/src/commerce/Wallet.cpp @@ -55,14 +55,14 @@ QString imageFilePath() { // use the cached _passphrase if it exists, otherwise we need to prompt int passwordCallback(char* password, int maxPasswordSize, int rwFlag, void* u) { // just return a hardcoded pwd for now - auto wallet = DependencyManager::get(); - auto passphrase = wallet->getPassphrase(); + auto passphrase = DependencyManager::get()->getPassphrase(); if (passphrase) { strcpy(password, passphrase->toLocal8Bit().constData()); - emit wallet->walletAuthenticatedStatus(true); return static_cast(passphrase->size()); } else { - emit wallet->walletAuthenticatedStatus(false); + // Old comment below...this should never happen once we're here...what if it does? + // ok gotta bring up modal dialog... But right now lets just + // just keep it empty return 0; } } diff --git a/interface/src/commerce/Wallet.h b/interface/src/commerce/Wallet.h index 24575c5ca4..cb0e318598 100644 --- a/interface/src/commerce/Wallet.h +++ b/interface/src/commerce/Wallet.h @@ -39,19 +39,19 @@ public: void setPassphrase(const QString& passphrase); QString* getPassphrase() { return _passphrase; } + bool getPassphraseIsCached() { return !(_passphrase->isEmpty()); } void reset(); signals: void securityImageResult(bool exists); void keyFilePathIfExistsResult(const QString& path); - void walletAuthenticatedStatus(bool isAuthenticated); private: QStringList _publicKeys{}; QPixmap* _securityImage { nullptr }; QByteArray _salt {"iamsalt!"}; - QString* _passphrase { new QString("pwd") }; + QString* _passphrase { new QString("") }; void updateImageProvider(); bool encryptFile(const QString& inputFilePath, const QString& outputFilePath);