diff --git a/src/app/provider/view.nim b/src/app/provider/view.nim index af4cd9e83..3ea849a2f 100644 --- a/src/app/provider/view.nim +++ b/src/app/provider/view.nim @@ -113,15 +113,21 @@ QtObject: let request = data.request.parseJson let fromAddress = request["params"][0]["from"].getStr() let to = request["params"][0]["to"].getStr() - let value = request["params"][0]["value"].getStr() + let value = if (request["params"][0]["value"] != nil): + request["params"][0]["value"].getStr() + else: + "0" let password = request["password"].getStr() let selectedGasLimit = request["selectedGasLimit"].getStr() let selectedGasPrice = request["selectedGasPrice"].getStr() + let txData = if (request["params"][0]["data"] != nil): + request["params"][0]["data"].getStr() + else: + "" var success: bool # TODO make this async - let response = status.wallet.sendTransaction(fromAddress, to, value, selectedGasLimit, selectedGasPrice, password, success) - debug "Response", response, success + let response = status.wallet.sendTransaction(fromAddress, to, value, selectedGasLimit, selectedGasPrice, password, success, txData) let errorMessage = if not success: if response == "": "web3-response-error" @@ -134,7 +140,11 @@ QtObject: "type": ResponseTypes.Web3SendAsyncCallback, "messageId": data.messageId, "error": errorMessage, - "result": if (success): response else: "" + "result": { + "jsonrpc": "2.0", + "id": data.payload.id, + "result": if (success): response else: "" + } } except Exception as e: error "Error sending the transaction", msg = e.msg diff --git a/src/status/transactions.nim b/src/status/transactions.nim index cbfb101a5..c4f7e1f13 100644 --- a/src/status/transactions.nim +++ b/src/status/transactions.nim @@ -8,12 +8,13 @@ import libstatus/types from libstatus/utils as status_utils import toUInt64, gwei2Wei, parseAddress -proc buildTransaction*(source: Address, value: Uint256, gas = "", gasPrice = ""): EthSend = +proc buildTransaction*(source: Address, value: Uint256, gas = "", gasPrice = "", data = ""): EthSend = result = EthSend( source: source, value: value.some, gas: (if gas.isEmptyOrWhitespace: Quantity.none else: Quantity(cast[uint64](parseFloat(gas).toUInt64)).some), - gasPrice: (if gasPrice.isEmptyOrWhitespace: int.none else: gwei2Wei(parseFloat(gasPrice)).truncate(int).some) + gasPrice: (if gasPrice.isEmptyOrWhitespace: int.none else: gwei2Wei(parseFloat(gasPrice)).truncate(int).some), + data: data ) proc buildTokenTransaction*(source, contractAddress: Address, gas = "", gasPrice = ""): EthSend = diff --git a/src/status/wallet.nim b/src/status/wallet.nim index 876b39667..8de51ef42 100644 --- a/src/status/wallet.nim +++ b/src/status/wallet.nim @@ -118,10 +118,10 @@ proc estimateTokenGas*(self: WalletModel, source, to, assetAddress, value: strin let response = contract.methods["transfer"].estimateGas(tx, transfer, success) result = fromHex[int](response) -proc sendTransaction*(self: WalletModel, source, to, value, gas, gasPrice, password: string, success: var bool): string = +proc sendTransaction*(self: WalletModel, source, to, value, gas, gasPrice, password: string, success: var bool, data = ""): string = var tx = transactions.buildTransaction( parseAddress(source), - eth2Wei(parseFloat(value), 18), gas, gasPrice + eth2Wei(parseFloat(value), 18), gas, gasPrice, data ) tx.to = parseAddress(to).some diff --git a/ui/app/AppLayouts/Browser/BrowserLayout.qml b/ui/app/AppLayouts/Browser/BrowserLayout.qml index ca63f373c..bd1748ea4 100644 --- a/ui/app/AppLayouts/Browser/BrowserLayout.qml +++ b/ui/app/AppLayouts/Browser/BrowserLayout.qml @@ -193,7 +193,6 @@ Item { // TODO change sendTransaction function to the postMessage one sendDialog.sendTransaction = function (selectedGasLimit, selectedGasPrice, enteredPassword) { - console.log('OK', selectedGasLimit, selectedGasPrice, enteredPassword) request.payload.selectedGasLimit = selectedGasLimit request.payload.selectedGasPrice = selectedGasPrice request.payload.password = enteredPassword @@ -215,7 +214,7 @@ Item { toastMessage.source = "../../img/loading.svg" toastMessage.iconColor = Style.current.primary toastMessage.iconRotates = true - toastMessage.link = `${walletModel.etherscanLink}/${responseOnj.result}` + toastMessage.link = `${walletModel.etherscanLink}/${responseObj.result}` toastMessage.open() } catch (e) { if (e.message.includes("could not decrypt key with given password")){