diff --git a/components/HistoryTable.qml b/components/HistoryTable.qml index c083ef3c..b7a32d41 100644 --- a/components/HistoryTable.qml +++ b/components/HistoryTable.qml @@ -30,6 +30,7 @@ import QtQuick 2.0 import moneroComponents.Clipboard 1.0 import moneroComponents.AddressBookModel 1.0 import "../components" as MoneroComponents +import "../js/TxUtils.js" as TxUtils import "." 1.0 ListView { @@ -196,19 +197,17 @@ ListView { font.pixelSize: 18 * scaleRatio font.bold: true text: { - // hack, removes trailing zeros - var amount = (displayAmount * 1); + var amount = (displayAmount * 1); // * 1 removes trailing zeros // sometimes, displayAmount is 0 - no idea why. // in that case, we try to get the amount from // the `destinations` string. if(amount === 0){ - amount = destinations.split(" ")[0].split(":")[0]; + amount = TxUtils.destinationsToAmount(destinations); amount = (amount *1); } - // sometimes this destinations string also shows 0, - // at which point we run out of options. + // sometimes this destinations string also shows 0 at which point we run out of options. return amount + " XMR"; } color: isOut ? "white" : "#2eb358" @@ -251,18 +250,15 @@ ListView { font.pixelSize: 16 * scaleRatio text: { if(isOut){ - var _address = destinations.split(" ")[1]; - if(_address === undefined) return "" - - if(_address){ - address = _address; - var address_truncated = address.substring(0, 6) + "..." + address.substring(address.length-6); - return "To " + address_truncated; + address = TxUtils.destinationsToAddress(destinations); + if(address){ + var truncated = TxUtils.addressTruncate(address); + return "To " + truncated; } else { return "Unknown recipient"; } } - return "" + return ""; } MouseArea{ @@ -414,6 +410,56 @@ ListView { } } + Rectangle { + id: proofButton + visible: isOut + color: "#404040" + height: 24 * scaleRatio + width: 24 * scaleRatio + anchors.right: parent.right + anchors.bottom: parent.bottom + anchors.bottomMargin: 36 + radius: 20 * scaleRatio + + MouseArea { + id: proofButtonMouseArea + anchors.fill: parent + hoverEnabled: true + cursorShape: Qt.PointingHandCursor + onClicked: { + var address = TxUtils.destinationsToAddress(destinations); + if(address === undefined){ + console.log('getProof: Error fetching address') + return; + } + + var checked = (TxUtils.checkTxID(hash) && TxUtils.checkAddress(address, appWindow.persistentSettings.testnet)); + if(!checked){ + console.log('getProof: Error checking TxId and/or address'); + } + + console.log("getProof: Generate clicked: txid " + hash + ", address " + address); + root.getProofClicked(hash, address, ''); + } + + onEntered: { + proofButton.color = "#656565"; + } + + onExited: { + proofButton.color = "#404040"; + } + } + + Text { + color: Style.defaultFontColor + text: "P" + anchors.horizontalCenter: parent.horizontalCenter + anchors.verticalCenter: parent.verticalCenter + font.pixelSize: 14 * scaleRatio + } + } + Rectangle { id: detailsButton color: "#404040" diff --git a/js/TxUtils.js b/js/TxUtils.js new file mode 100644 index 00000000..4a4b01c4 --- /dev/null +++ b/js/TxUtils.js @@ -0,0 +1,57 @@ +function destinationsToAmount(destinations){ + // Gets amount from destinations line + // input: "20.000000000000: 9tLGyK277MnYrDc7Vzi6TB1pJvstFoviziFwsqQNFbwA9rvg5RxYVYjEezFKDjvDHgAzTELJhJHVx6JAaWZKeVqSUZkXeKk" + // returns: 20.000000000000 + return destinations.split(" ")[0].split(":")[0]; +} + +function destinationsToAddress(destinations){ + var address = destinations.split(" ")[1]; + if(address === undefined) return "" + return address; +} + +function addressTruncate(address){ + return address.substring(0, 6) + "..." + address.substring(address.length-6); +} + +function check256(str, length) { + if (str.length != length) + return false; + for (var i = 0; i < length; ++i) { + if (str[i] >= '0' && str[i] <= '9') + continue; + if (str[i] >= 'a' && str[i] <= 'z') + continue; + if (str[i] >= 'A' && str[i] <= 'Z') + continue; + return false; + } + return true; +} + +function checkAddress(address, testnet) { + return walletManager.addressValid(address, testnet) +} + +function checkTxID(txid) { + return check256(txid, 64) +} + +function checkSignature(signature) { + if (signature.indexOf("OutProofV") === 0) { + if ((signature.length - 10) % 132 != 0) + return false; + return check256(signature, signature.length); + } else if (signature.indexOf("InProofV") === 0) { + if ((signature.length - 9) % 132 != 0) + return false; + return check256(signature, signature.length); + } else if (signature.indexOf("SpendProofV") === 0) { + if ((signature.length - 12) % 88 != 0) + return false; + return check256(signature, signature.length); + } + return false; +} + diff --git a/pages/History.qml b/pages/History.qml index 3a2c79ad..079373bc 100644 --- a/pages/History.qml +++ b/pages/History.qml @@ -38,7 +38,7 @@ import moneroComponents.TransactionHistoryModel 1.0 import "../components" Rectangle { - id: root + id: mainLayout property var model property int tableHeight: !isMobile ? table.contentHeight : tableMobile.contentHeight @@ -321,7 +321,7 @@ Rectangle { id: table visible: !isMobile onContentYChanged: flickableScroll.flickableContentYChanged() - model: !isMobile ? root.model : null + model: !isMobile ? mainLayout.model : null addressBookModel: null Layout.fillWidth: true @@ -332,7 +332,7 @@ Rectangle { id: tableMobile visible: isMobile onContentYChanged: flickableScroll.flickableContentYChanged() - model: isMobile ? root.model : null + model: isMobile ? mainLayout.model : null addressBookModel: null Layout.fillWidth: true diff --git a/pages/TxKey.qml b/pages/TxKey.qml index c4372b60..a9f571ba 100644 --- a/pages/TxKey.qml +++ b/pages/TxKey.qml @@ -34,52 +34,14 @@ import QtQuick.Layouts 1.1 import "../components" import moneroComponents.Clipboard 1.0 +import "../js/TxUtils.js" as TxUtils + Rectangle { color: "transparent" Clipboard { id: clipboard } - function checkAddress(address, nettype) { - return walletManager.addressValid(address, nettype) - } - - function check256(str, length) { - if (str.length != length) - return false; - for (var i = 0; i < length; ++i) { - if (str[i] >= '0' && str[i] <= '9') - continue; - if (str[i] >= 'a' && str[i] <= 'z') - continue; - if (str[i] >= 'A' && str[i] <= 'Z') - continue; - return false; - } - return true; - } - - function checkTxID(txid) { - return check256(txid, 64) - } - - function checkSignature(signature) { - if (signature.indexOf("OutProofV") === 0) { - if ((signature.length - 10) % 132 != 0) - return false; - return check256(signature, signature.length); - } else if (signature.indexOf("InProofV") === 0) { - if ((signature.length - 9) % 132 != 0) - return false; - return check256(signature, signature.length); - } else if (signature.indexOf("SpendProofV") === 0) { - if ((signature.length - 12) % 88 != 0) - return false; - return check256(signature, signature.length); - } - return false; - } - /* main layout */ ColumnLayout { id: mainLayout @@ -156,7 +118,7 @@ Rectangle { anchors.topMargin: 17 width: 60 text: qsTr("Generate") + translationManager.emptyString - enabled: checkTxID(getProofTxIdLine.text) && (getProofAddressLine.text.length == 0 || checkAddress(getProofAddressLine.text, appWindow.persistentSettings.testnet)) + enabled: TxUtils.checkTxID(getProofTxIdLine.text) && (getProofAddressLine.text.length == 0 || TxUtils.checkAddress(getProofAddressLine.text, appWindow.persistentSettings.testnet)) onClicked: { console.log("getProof: Generate clicked: txid " + getProofTxIdLine.text + ", address " + getProofAddressLine.text + ", message: " + getProofMessageLine.text); root.getProofClicked(getProofTxIdLine.text, getProofAddressLine.text, getProofMessageLine.text) @@ -246,7 +208,7 @@ Rectangle { anchors.topMargin: 17 width: 60 text: qsTr("Check") + translationManager.emptyString - enabled: checkTxID(checkProofTxIdLine.text) && checkSignature(checkProofSignatureLine.text) && ((checkProofSignatureLine.text.indexOf("SpendProofV") === 0 && checkProofAddressLine.text.length == 0) || (checkProofSignatureLine.text.indexOf("SpendProofV") !== 0 && checkAddress(checkProofAddressLine.text, appWindow.persistentSettings.testnet))) + enabled: TxUtils.checkTxID(checkProofTxIdLine.text) && TxUtils.checkSignature(checkProofSignatureLine.text) && ((checkProofSignatureLine.text.indexOf("SpendProofV") === 0 && checkProofAddressLine.text.length == 0) || (checkProofSignatureLine.text.indexOf("SpendProofV") !== 0 && TxUtils.checkAddress(checkProofAddressLine.text, appWindow.persistentSettings.testnet))) onClicked: { console.log("checkProof: Check clicked: txid " + checkProofTxIdLine.text + ", address " + checkProofAddressLine.text + ", message " + checkProofMessageLine.text + ", signature " + checkProofSignatureLine.text); root.checkProofClicked(checkProofTxIdLine.text, checkProofAddressLine.text, checkProofMessageLine.text, checkProofSignatureLine.text) @@ -278,5 +240,4 @@ Rectangle { console.log("TxKey page loaded"); } - } diff --git a/qml.qrc b/qml.qrc index 11d2d448..ad4f1f86 100644 --- a/qml.qrc +++ b/qml.qrc @@ -202,5 +202,6 @@ images/historyBorderRadius.png components/HistoryTableInnerColumn.qml components/CheckBox2.qml + js/TxUtils.js