diff --git a/interface/resources/qml/hifi/commerce/wallet/Security.qml b/interface/resources/qml/hifi/commerce/wallet/Security.qml index 3f3d00b401..d0a96db3f2 100644 --- a/interface/resources/qml/hifi/commerce/wallet/Security.qml +++ b/interface/resources/qml/hifi/commerce/wallet/Security.qml @@ -40,10 +40,8 @@ Item { } } - onKeyFilePathResult: { - if (path !== "") { - keyFilePath.text = path; - } + onKeyFilePathIfExistsResult: { + keyFilePath.text = path; } } @@ -264,7 +262,7 @@ Item { onVisibleChanged: { if (visible) { - commerce.getKeyFilePath(); + commerce.getKeyFilePathIfExists(); } } } diff --git a/interface/resources/qml/hifi/commerce/wallet/Wallet.qml b/interface/resources/qml/hifi/commerce/wallet/Wallet.qml index ac5d851bbc..ae2606c0f6 100644 --- a/interface/resources/qml/hifi/commerce/wallet/Wallet.qml +++ b/interface/resources/qml/hifi/commerce/wallet/Wallet.qml @@ -25,7 +25,9 @@ Rectangle { id: root; - property string activeView: "walletHome"; + property string activeView: "initialize"; + property bool securityImageResultReceived: false; + property bool keyFilePathIfExistsResultReceived: false; // Style color: hifi.colors.baseGray; @@ -33,16 +35,20 @@ Rectangle { id: commerce; onSecurityImageResult: { - if (!exists) { // "If security image is not set up" - if (root.activeView !== "notSetUp") { - root.activeView = "notSetUp"; - } + securityImageResultReceived = true; + if (!exists && root.activeView !== "notSetUp") { // "If security image is not set up" + root.activeView = "notSetUp"; + } else if (root.securityImageResultReceived && exists && root.keyFilePathIfExistsResultReceived && root.activeView === "initialize") { + root.activeView = "walletHome"; } } - onKeyFilePathResult: { + onKeyFilePathIfExistsResult: { + keyFilePathIfExistsResultReceived = true; if (path === "" && root.activeView !== "notSetUp") { root.activeView = "notSetUp"; + } else if (root.securityImageResultReceived && root.keyFilePathIfExistsResultReceived && path !== "" && root.activeView === "initialize") { + root.activeView = "walletHome"; } } } @@ -151,6 +157,22 @@ Rectangle { // // TAB CONTENTS START // + + Rectangle { + id: initialize; + visible: root.activeView === "initialize"; + anchors.top: titleBarContainer.bottom; + anchors.bottom: parent.top; + anchors.left: parent.left; + anchors.right: parent.right; + color: hifi.colors.baseGray; + + Component.onCompleted: { + commerce.getSecurityImage(); + commerce.getKeyFilePathIfExists(); + } + } + NotSetUp { id: notSetUp; visible: root.activeView === "notSetUp"; @@ -283,13 +305,6 @@ Rectangle { onEntered: parent.color = hifi.colors.blueHighlight; onExited: parent.color = root.activeView === "walletHome" ? hifi.colors.blueAccent : hifi.colors.black; } - - onVisibleChanged: { - if (visible) { - commerce.getSecurityImage(); - commerce.balance(); - } - } } // "SEND MONEY" tab button @@ -382,13 +397,6 @@ Rectangle { onEntered: parent.color = hifi.colors.blueHighlight; onExited: parent.color = root.activeView === "security" ? hifi.colors.blueAccent : hifi.colors.black; } - - onVisibleChanged: { - if (visible) { - commerce.getSecurityImage(); - commerce.getKeyFilePath(); - } - } } // "HELP" tab button diff --git a/interface/resources/qml/hifi/commerce/wallet/WalletSetupLightbox.qml b/interface/resources/qml/hifi/commerce/wallet/WalletSetupLightbox.qml index 474322062e..bbeb77f6fa 100644 --- a/interface/resources/qml/hifi/commerce/wallet/WalletSetupLightbox.qml +++ b/interface/resources/qml/hifi/commerce/wallet/WalletSetupLightbox.qml @@ -56,10 +56,8 @@ Rectangle { } } - onKeyFilePathResult: { - if (path !== "") { - keyFilePath.text = path; - } + onKeyFilePathIfExistsResult: { + keyFilePath.text = path; } } @@ -455,10 +453,10 @@ Rectangle { text: "Next"; onClicked: { if (passphraseSelection.validateAndSubmitPassphrase()) { - root.lastPage = "passphrase"; + root.lastPage = "choosePassphrase"; + commerce.balance(); // Do this here so that keys are generated. Order might change as backend changes? choosePassphraseContainer.visible = false; privateKeysReadyContainer.visible = true; - commerce.balance(); // Do this here so that keys are generated. Order might change as backend changes? } } } @@ -562,7 +560,7 @@ Rectangle { onVisibleChanged: { if (visible) { - commerce.getKeyFilePath(); + commerce.getKeyFilePathIfExists(); } } } diff --git a/interface/src/commerce/QmlCommerce.cpp b/interface/src/commerce/QmlCommerce.cpp index f1e9fa139e..a5ae008a36 100644 --- a/interface/src/commerce/QmlCommerce.cpp +++ b/interface/src/commerce/QmlCommerce.cpp @@ -25,7 +25,7 @@ QmlCommerce::QmlCommerce(QQuickItem* parent) : OffscreenQmlDialog(parent) { connect(ledger.data(), &Ledger::balanceResult, this, &QmlCommerce::balanceResult); connect(ledger.data(), &Ledger::inventoryResult, this, &QmlCommerce::inventoryResult); connect(wallet.data(), &Wallet::securityImageResult, this, &QmlCommerce::securityImageResult); - connect(wallet.data(), &Wallet::keyFilePathResult, this, &QmlCommerce::keyFilePathResult); + connect(wallet.data(), &Wallet::keyFilePathIfExistsResult, this, &QmlCommerce::keyFilePathIfExistsResult); } void QmlCommerce::buy(const QString& assetId, int cost, const QString& buyerUsername) { @@ -69,7 +69,7 @@ void QmlCommerce::setPassphrase(const QString& passphrase) { void QmlCommerce::getPassphraseSetupStatus() { emit passphraseSetupStatusResult(false); } -void QmlCommerce::getKeyFilePath() { +void QmlCommerce::getKeyFilePathIfExists() { auto wallet = DependencyManager::get(); - wallet->getKeyFilePath(); + wallet->sendKeyFilePathIfExists(); } diff --git a/interface/src/commerce/QmlCommerce.h b/interface/src/commerce/QmlCommerce.h index d7a892cf1f..0c3ed64c81 100644 --- a/interface/src/commerce/QmlCommerce.h +++ b/interface/src/commerce/QmlCommerce.h @@ -36,7 +36,7 @@ signals: void securityImageResult(bool exists); void loginStatusResult(bool isLoggedIn); void passphraseSetupStatusResult(bool passphraseIsSetup); - void keyFilePathResult(const QString& path); + void keyFilePathIfExistsResult(const QString& path); protected: Q_INVOKABLE void buy(const QString& assetId, int cost, const QString& buyerUsername = ""); @@ -47,7 +47,7 @@ protected: Q_INVOKABLE void getLoginStatus(); Q_INVOKABLE void setPassphrase(const QString& passphrase); Q_INVOKABLE void getPassphraseSetupStatus(); - Q_INVOKABLE void getKeyFilePath(); + Q_INVOKABLE void getKeyFilePathIfExists(); }; #endif // hifi_QmlCommerce_h diff --git a/interface/src/commerce/Wallet.cpp b/interface/src/commerce/Wallet.cpp index 5fefd0c43b..210aa62a0d 100644 --- a/interface/src/commerce/Wallet.cpp +++ b/interface/src/commerce/Wallet.cpp @@ -359,6 +359,7 @@ bool Wallet::createIfNeeded() { bool Wallet::generateKeyPair() { qCInfo(commerce) << "Generating keypair."; auto keyPair = generateRSAKeypair(); + sendKeyFilePathIfExists(); QString oldKey = _publicKeys.count() == 0 ? "" : _publicKeys.last(); QString key = keyPair.first->toBase64(); _publicKeys.push_back(key); @@ -471,6 +472,12 @@ void Wallet::getSecurityImage() { emit securityImageResult(false); } } -void Wallet::getKeyFilePath() { - emit keyFilePathResult(keyFilePath()); +void Wallet::sendKeyFilePathIfExists() { + QString filePath(keyFilePath()); + QFileInfo fileInfo(filePath); + if (fileInfo.exists()) { + emit keyFilePathIfExistsResult(filePath); + } else { + emit keyFilePathIfExistsResult(""); + } } diff --git a/interface/src/commerce/Wallet.h b/interface/src/commerce/Wallet.h index 4c0d7190bb..b13d4368d9 100644 --- a/interface/src/commerce/Wallet.h +++ b/interface/src/commerce/Wallet.h @@ -30,7 +30,7 @@ public: QString signWithKey(const QByteArray& text, const QString& key); void chooseSecurityImage(const QString& imageFile); void getSecurityImage(); - void getKeyFilePath(); + void sendKeyFilePathIfExists(); void setSalt(const QByteArray& salt) { _salt = salt; } QByteArray getSalt() { return _salt; } @@ -40,7 +40,7 @@ public: signals: void securityImageResult(bool exists) ; - void keyFilePathResult(const QString& path); + void keyFilePathIfExistsResult(const QString& path); protected: enum SecurityImage { diff --git a/scripts/defaultScripts.js b/scripts/defaultScripts.js index 2285337f41..f892a5ec78 100644 --- a/scripts/defaultScripts.js +++ b/scripts/defaultScripts.js @@ -24,12 +24,12 @@ var DEFAULT_SCRIPTS_COMBINED = [ "system/makeUserConnection.js", "system/tablet-goto.js", "system/marketplaces/marketplaces.js", + "system/commerce/wallet.js", "system/edit.js", "system/notifications.js", "system/dialTone.js", "system/firstPersonHMD.js", - "system/tablet-ui/tabletUI.js", - "system/commerce/wallet.js" + "system/tablet-ui/tabletUI.js" ]; var DEFAULT_SCRIPTS_SEPARATE = [ "system/controllers/controllerScripts.js", diff --git a/scripts/system/commerce/wallet.js b/scripts/system/commerce/wallet.js index 14954e5df6..4b758f0add 100644 --- a/scripts/system/commerce/wallet.js +++ b/scripts/system/commerce/wallet.js @@ -126,7 +126,8 @@ button = tablet.addButton({ text: buttonName, icon: "icons/tablet-icons/wallet-i.svg", - activeIcon: "icons/tablet-icons/wallet-a.svg" + activeIcon: "icons/tablet-icons/wallet-a.svg", + sortOrder: 10 }); button.clicked.connect(onButtonClicked); tablet.screenChanged.connect(onTabletScreenChanged);