status-desktop/ui/app/AppLayouts/Browser/SignMessageModal.qml
emizzle e0e1487643 refactor: replace transaction modal reset functionality
The transaction component's `reset` functionality was meant ot reset a form when the modal was closed. It was difficult to manage and added extra overhead for each additional transaction modal created.

Instead of using reset functions, we can use Loaders to load and destroy the modal's as they are opened and closed. We do not need to keep them in memory and then also reset their functions. It creates a smaller memory footprint to destroy the object and reload on open.

feat: load gas prediction prices asynchronously
2020-11-26 11:17:24 -05:00

106 lines
2.8 KiB
QML

import QtQuick 2.13
import QtQuick.Controls 2.13
import QtQuick.Layouts 1.13
import QtQuick.Dialogs 1.3
import "../../../imports"
import "../../../shared"
import "../../../shared/status"
ModalPopup {
property var request
readonly property int bytes32Length: 66
property bool interactedWith: false
property alias transactionSigner: transactionSigner
property var signMessage: function(enteredPassword) {}
property var web3Response
id: root
title: qsTr("Signing a message")
height: 504
onClosed: {
if(!interactedWith){
web3Response(JSON.stringify({
"type": "web3-send-async-callback",
"messageId": request.messageId,
"error": {
"code": 4100
}
}));
}
}
function displayValue(input){
if(Utils.isHex(input) && Utils.startsWith0x(input)){
if (input.length === bytes32Length){
return input;
}
return utilsModel.hex2Ascii(input)
}
return input;
}
Item {
anchors.fill: parent
anchors.leftMargin: Style.current.padding
anchors.rightMargin: Style.current.padding
ScrollView {
id: messageToSign
width: parent.width
height: 100
TextArea {
wrapMode: TextEdit.Wrap
readOnly: true
text: {
switch(request.payload.method){
case Constants.personal_sign:
return displayValue(request.payload.params[0]);
case Constants.eth_sign:
return displayValue(request.payload.params[1]);
case Constants.eth_signTypedData:
case Constants.eth_signTypedData_v3:
return JSON.stringify(request.payload.params[1]); // TODO: requires design
default:
return JSON.stringify(request.payload.params); // support for any unhandled sign method
}
}
}
}
TransactionSigner {
id: transactionSigner
width: parent.width
anchors.top: messageToSign.bottom
anchors.topMargin: Style.current.padding * 3
signingPhrase: walletModel.signingPhrase
}
}
footer: Item {
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
StatusButton {
id: btnNext
anchors.right: parent.right
text: qsTr("Sign")
onClicked: root.signMessage(transactionSigner.enteredPassword)
}
}
}
/*##^##
Designer {
D{i:0;autoSize:true;height:480;width:640}
}
##^##*/