mirror of
https://github.com/status-im/status-desktop.git
synced 2025-01-18 10:32:53 +00:00
feat: Add transaction modal when changing the pubkey
This commit is contained in:
parent
9ae739a8ce
commit
346e98c81a
@ -209,9 +209,10 @@ QtObject:
|
||||
proc registerENSGasEstimate(self: EnsManager, ensUsername: string, address: string): int {.slot.} =
|
||||
var success: bool
|
||||
let pubKey = status_settings.getSetting[string](Setting.PublicKey, "0x0")
|
||||
result = registerUsernameEstimateGas(ensUsername, address, pubKey, success)
|
||||
if not success:
|
||||
result = 325000
|
||||
try:
|
||||
result = registerUsernameEstimateGas(ensUsername, address, pubKey)
|
||||
except:
|
||||
result = 380000
|
||||
|
||||
proc registerENS*(self: EnsManager, username: string, address: string, gas: string, gasPrice: string, password: string): string {.slot.} =
|
||||
var success: bool
|
||||
@ -226,15 +227,25 @@ QtObject:
|
||||
self.pendingUsernames.incl(ensUsername)
|
||||
self.add ensUsername
|
||||
|
||||
proc setPubKey(self: EnsManager, username: string, password: string) {.slot.} =
|
||||
let pubKey = status_settings.getSetting[string](Setting.PublicKey, "0x0")
|
||||
let address = status_wallet.getWalletAccounts()[0].address
|
||||
let walletAddress = parseAddress(address)
|
||||
let trxHash = setPubKey(username, walletAddress, pubKey, password)
|
||||
except RpcException as e:
|
||||
result = $(%* { "error": %* { "message": %e.msg }})
|
||||
|
||||
self.transactionWasSent(trxHash)
|
||||
proc setPubKeyGasEstimate(self: EnsManager, ensUsername: string, address: string): int {.slot.} =
|
||||
let pubKey = status_settings.getSetting[string](Setting.PublicKey, "0x0")
|
||||
try:
|
||||
result = setPubKeyEstimateGas(ensUsername, address, pubKey)
|
||||
except:
|
||||
result = 80000
|
||||
|
||||
proc setPubKey(self: EnsManager, username: string, address: string, gas: string, gasPrice: string, password: string): string {.slot.} =
|
||||
try:
|
||||
let pubKey = status_settings.getSetting[string](Setting.PublicKey, "0x0")
|
||||
let response = setPubKey(username, pubKey, address, gas, gasPrice, password)
|
||||
result = $(%* { "result": %response })
|
||||
self.transactionWasSent(response)
|
||||
|
||||
# TODO: handle transaction failure
|
||||
self.pendingUsernames.incl(username)
|
||||
self.add username
|
||||
|
||||
except RpcException as e:
|
||||
result = $(%* { "error": %* { "message": %e.msg }})
|
||||
|
@ -190,7 +190,7 @@ proc registerUsername*(username, pubKey, address, gas, gasPrice, password: stri
|
||||
if success:
|
||||
trackPendingTransaction(result, address, $sntContract.address, PendingTransactionType.RegisterENS, username & domain)
|
||||
|
||||
proc setPubKey*(username:string, address: EthAddress, pubKey: string, password: string): string =
|
||||
proc setPubKeyEstimateGas*(username: string, address: string, pubKey: string): int =
|
||||
var hash = namehash(username)
|
||||
hash.removePrefix("0x")
|
||||
|
||||
@ -199,28 +199,36 @@ proc setPubKey*(username:string, address: EthAddress, pubKey: string, password:
|
||||
x = fromHex(FixedBytes[32], "0x" & pubkey[4..67])
|
||||
y = fromHex(FixedBytes[32], "0x" & pubkey[68..131])
|
||||
resolverContract = contracts.getContract("ens-resolver")
|
||||
setPubkey = SetPubkey(label: label, x: x, y: y)
|
||||
resolverAddress = resolver(hash)
|
||||
|
||||
var tx = transactions.buildTokenTransaction(parseAddress(address), parseAddress(resolverAddress), "", "")
|
||||
|
||||
try:
|
||||
let response = resolverContract.methods["setPubkey"].estimateGas(tx, setPubkey)
|
||||
result = fromHex[int](response)
|
||||
except RpcException as e:
|
||||
raise
|
||||
|
||||
proc setPubKey*(username, pubKey, address, gas, gasPrice, password: string): string =
|
||||
var hash = namehash(username)
|
||||
hash.removePrefix("0x")
|
||||
|
||||
let
|
||||
label = fromHex(FixedBytes[32], "0x" & hash)
|
||||
x = fromHex(FixedBytes[32], "0x" & pubkey[4..67])
|
||||
y = fromHex(FixedBytes[32], "0x" & pubkey[68..131])
|
||||
resolverContract = contracts.getContract("ens-resolver")
|
||||
setPubkey = SetPubkey(label: label, x: x, y: y)
|
||||
setPubkeyAbiEncoded = resolverContract.methods["setPubkey"].encodeAbi(setPubkey)
|
||||
resolverAddress = resolver(hash)
|
||||
|
||||
let resolverAddress = resolver(hash)
|
||||
var tx = transactions.buildTokenTransaction(parseAddress(address), parseAddress(resolverAddress), gas, gasPrice)
|
||||
|
||||
let payload = %* {
|
||||
"from": $address,
|
||||
"to": resolverAddress,
|
||||
# "gas": 200000, # TODO: obtain gas price?
|
||||
"data": setPubkeyAbiEncoded
|
||||
}
|
||||
|
||||
let responseStr = sendTransaction($payload, password)
|
||||
let response = Json.decode(responseStr, RpcResponse)
|
||||
if not response.error.isNil:
|
||||
raise newException(RpcException, "Error setting the pubkey: " & response.error.message)
|
||||
|
||||
trackPendingTransaction(response.result, $address, resolverAddress, PendingTransactionType.SetPubKey, username)
|
||||
|
||||
result = response.result
|
||||
try:
|
||||
result = resolverContract.methods["setPubkey"].send(tx, setPubkey, password)
|
||||
trackPendingTransaction(result, $address, resolverAddress, PendingTransactionType.SetPubKey, username)
|
||||
except RpcException as e:
|
||||
raise
|
||||
|
||||
proc statusRegistrarAddress*():string =
|
||||
result = $contracts.getContract("ens-usernames").address
|
||||
|
@ -46,34 +46,11 @@ Item {
|
||||
Qt.callLater(validateENS, ensUsername, isStatus)
|
||||
}
|
||||
|
||||
ModalPopup {
|
||||
SetPubKeyModal {
|
||||
id: transactionDialog
|
||||
//% "TODO: replace this for the transaction dialog"
|
||||
title: qsTrId("todo--replace-this-for-the-transaction-dialog")
|
||||
|
||||
Input {
|
||||
id: passwd
|
||||
placeholderText: "Password"
|
||||
anchors.top: parent.textToCopy
|
||||
anchors.topMargin: 24
|
||||
anchors.left: parent.left
|
||||
anchors.leftMargin: 24
|
||||
}
|
||||
|
||||
StyledButton {
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.bottomMargin: Style.current.padding
|
||||
anchors.left: parent.left
|
||||
anchors.leftMargin: Style.current.padding
|
||||
//% "Ok"
|
||||
label: qsTrId("ok")
|
||||
onClicked: {
|
||||
profileModel.ens.setPubKey(ensUsername.text, passwd.text)
|
||||
passwd.text = "";
|
||||
usernameUpdated(ensUsername.text);
|
||||
transactionDialog.close();
|
||||
}
|
||||
}
|
||||
ensUsername: ensUsername.text
|
||||
width: 400
|
||||
height: 400
|
||||
}
|
||||
|
||||
StyledText {
|
||||
|
202
ui/app/AppLayouts/Profile/Sections/Ens/SetPubKeyModal.qml
Normal file
202
ui/app/AppLayouts/Profile/Sections/Ens/SetPubKeyModal.qml
Normal file
@ -0,0 +1,202 @@
|
||||
import QtQuick 2.13
|
||||
import QtQuick.Controls 2.13
|
||||
import QtQuick.Layouts 1.13
|
||||
import QtQuick.Dialogs 1.3
|
||||
import "../../../../../imports"
|
||||
import "../../../../../shared"
|
||||
|
||||
ModalPopup {
|
||||
id: root
|
||||
readonly property var asset: {"name": "Ethereum", "symbol": "ETH"}
|
||||
property string ensUsername: ""
|
||||
|
||||
title: qsTr("Connect username with your pubkey")
|
||||
|
||||
property MessageDialog sendingError: MessageDialog {
|
||||
id: sendingError
|
||||
title: qsTr("Error sending the transaction")
|
||||
icon: StandardIcon.Critical
|
||||
standardButtons: StandardButton.Ok
|
||||
}
|
||||
|
||||
onClosed: {
|
||||
stack.reset()
|
||||
}
|
||||
|
||||
function sendTransaction() {
|
||||
let responseStr = profileModel.ens.setPubKey(root.ensUsername,
|
||||
selectFromAccount.selectedAccount.address,
|
||||
gasSelector.selectedGasLimit,
|
||||
gasSelector.selectedGasPrice,
|
||||
transactionSigner.enteredPassword)
|
||||
let response = JSON.parse(responseStr)
|
||||
|
||||
if (response.error) {
|
||||
if (response.error.message.includes("could not decrypt key with given password")){
|
||||
transactionSigner.validationError = qsTr("Wrong password")
|
||||
return
|
||||
}
|
||||
sendingError.text = response.error.message
|
||||
return sendingError.open()
|
||||
}
|
||||
|
||||
usernameUpdated(root.ensUsername);
|
||||
}
|
||||
|
||||
TransactionStackView {
|
||||
id: stack
|
||||
height: parent.height
|
||||
anchors.fill: parent
|
||||
anchors.leftMargin: Style.current.padding
|
||||
anchors.rightMargin: Style.current.padding
|
||||
onGroupActivated: {
|
||||
root.title = group.headerText
|
||||
btnNext.label = group.footerText
|
||||
}
|
||||
TransactionFormGroup {
|
||||
id: group1
|
||||
headerText: qsTr("Connect username with your pubkey")
|
||||
footerText: qsTr("Continue")
|
||||
|
||||
AccountSelector {
|
||||
id: selectFromAccount
|
||||
accounts: walletModel.accounts
|
||||
selectedAccount: walletModel.currentAccount
|
||||
currency: walletModel.defaultCurrency
|
||||
width: stack.width
|
||||
label: qsTr("Choose account")
|
||||
showBalanceForAssetSymbol: "ETH"
|
||||
minRequiredAssetBalance: 0
|
||||
reset: function() {
|
||||
accounts = Qt.binding(function() { return walletModel.accounts })
|
||||
selectedAccount = Qt.binding(function() { return walletModel.currentAccount })
|
||||
showBalanceForAssetSymbol = Qt.binding(function() { return "ETH" })
|
||||
minRequiredAssetBalance = Qt.binding(function() { return 0 })
|
||||
}
|
||||
onSelectedAccountChanged: gasSelector.estimateGas()
|
||||
}
|
||||
RecipientSelector {
|
||||
id: selectRecipient
|
||||
visible: false
|
||||
accounts: walletModel.accounts
|
||||
contacts: profileModel.addedContacts
|
||||
selectedRecipient: { "address": profileModel.ens.ensRegisterAddress, "type": RecipientSelector.Type.Address }
|
||||
readOnly: true
|
||||
onSelectedRecipientChanged: gasSelector.estimateGas()
|
||||
}
|
||||
GasSelector {
|
||||
id: gasSelector
|
||||
visible: false
|
||||
slowestGasPrice: parseFloat(walletModel.safeLowGasPrice)
|
||||
fastestGasPrice: parseFloat(walletModel.fastestGasPrice)
|
||||
getGasEthValue: walletModel.getGasEthValue
|
||||
getFiatValue: walletModel.getFiatValue
|
||||
defaultCurrency: walletModel.defaultCurrency
|
||||
reset: function() {
|
||||
slowestGasPrice = Qt.binding(function(){ return parseFloat(walletModel.safeLowGasPrice) })
|
||||
fastestGasPrice = Qt.binding(function(){ return parseFloat(walletModel.fastestGasPrice) })
|
||||
}
|
||||
property var estimateGas: Backpressure.debounce(gasSelector, 600, function() {
|
||||
if (!(root.ensUsername !== "" && selectFromAccount.selectedAccount)) {
|
||||
selectedGasLimit = 80000;
|
||||
return;
|
||||
}
|
||||
selectedGasLimit = profileModel.ens.setPubKeyGasEstimate(root.ensUsername, selectFromAccount.selectedAccount.address)
|
||||
})
|
||||
}
|
||||
GasValidator {
|
||||
id: gasValidator
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.bottomMargin: 8
|
||||
selectedAccount: selectFromAccount.selectedAccount
|
||||
selectedAsset: root.asset
|
||||
selectedAmount: 0
|
||||
selectedGasEthValue: gasSelector.selectedGasEthValue
|
||||
reset: function() {
|
||||
selectedAccount = Qt.binding(function() { return selectFromAccount.selectedAccount })
|
||||
selectedAsset = Qt.binding(function() { return root.asset })
|
||||
selectedAmount = Qt.binding(function() { return 0 })
|
||||
selectedGasEthValue = Qt.binding(function() { return gasSelector.selectedGasEthValue })
|
||||
}
|
||||
}
|
||||
}
|
||||
TransactionFormGroup {
|
||||
id: group3
|
||||
headerText: qsTr("Connect username with your pubkey")
|
||||
footerText: qsTr("Sign with password")
|
||||
|
||||
TransactionPreview {
|
||||
id: pvwTransaction
|
||||
width: stack.width
|
||||
fromAccount: selectFromAccount.selectedAccount
|
||||
gas: {
|
||||
"value": gasSelector.selectedGasEthValue,
|
||||
"symbol": "ETH",
|
||||
"fiatValue": gasSelector.selectedGasFiatValue
|
||||
}
|
||||
toAccount: selectRecipient.selectedRecipient
|
||||
asset: root.asset
|
||||
currency: walletModel.defaultCurrency
|
||||
amount: {
|
||||
const fiatValue = walletModel.getFiatValue(0, root.asset.symbol, currency)
|
||||
return { "value": 0, "fiatValue": fiatValue }
|
||||
}
|
||||
reset: function() {
|
||||
fromAccount = Qt.binding(function() { return selectFromAccount.selectedAccount })
|
||||
toAccount = Qt.binding(function() { return selectRecipient.selectedRecipient })
|
||||
asset = Qt.binding(function() { return root.asset })
|
||||
amount = Qt.binding(function() { return { "value": 0, "fiatValue": walletModel.getFiatValue(0, root.asset.symbol, currency) } })
|
||||
gas = Qt.binding(function() {
|
||||
return {
|
||||
"value": gasSelector.selectedGasEthValue,
|
||||
"symbol": "ETH",
|
||||
"fiatValue": gasSelector.selectedGasFiatValue
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
TransactionFormGroup {
|
||||
id: group4
|
||||
headerText: qsTr("Connect username with your pubkey")
|
||||
footerText: qsTr("Sign with password")
|
||||
|
||||
TransactionSigner {
|
||||
id: transactionSigner
|
||||
width: stack.width
|
||||
signingPhrase: walletModel.signingPhrase
|
||||
reset: function() {
|
||||
signingPhrase = Qt.binding(function() { return walletModel.signingPhrase })
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
footer: Item {
|
||||
anchors.top: parent.top
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
|
||||
StyledButton {
|
||||
id: btnNext
|
||||
anchors.right: parent.right
|
||||
label: qsTr("Next")
|
||||
disabled: !stack.currentGroup.isValid
|
||||
onClicked: {
|
||||
const validity = stack.currentGroup.validate()
|
||||
if (validity.isValid && !validity.isPending) {
|
||||
if (stack.isLastGroup) {
|
||||
return root.sendTransaction()
|
||||
}
|
||||
stack.next()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*##^##
|
||||
Designer {
|
||||
D{i:0;autoSize:true;height:480;width:640}
|
||||
}
|
||||
##^##*/
|
Loading…
x
Reference in New Issue
Block a user