feat(ui/wallet): add basic form to send transaction

Closes #49
This commit is contained in:
Pascal Precht 2020-05-19 17:03:33 +02:00 committed by Iuri Matias
parent 407577c247
commit 76a0b55d47
4 changed files with 89 additions and 11 deletions

View File

@ -6,14 +6,16 @@ import walletView
import ../../status/wallet as status_wallet
import ../signals/types
var sendTransaction = proc(from_value: string, to: string, value: string, password: string): string =
status_wallet.sendTransaction(from_value, to, value, password)
type WalletController* = ref object of SignalSubscriber
view*: WalletView
variant*: QVariant
proc newController*(): WalletController =
echo "new wallet"
result = WalletController()
result.view = newWalletView()
result.view = newWalletView(sendTransaction)
result.variant = newQVariant(result.view)
proc delete*(self: WalletController) =
@ -37,6 +39,8 @@ proc init*(self: WalletController) =
var usd_balance = parseFloat(eth_value) * parseFloat(usd_eth_price)
echo(fmt"balance in usd: {usd_balance}")
self.view.setDefaultAccount(status_wallet.getAccount())
let symbol = "ETH"
self.view.addAssetToList("Ethereum", symbol, fmt"{eth_value:.6}", "$" & fmt"{usd_balance:.6}", fmt"../../img/token-icons/{toLowerAscii(symbol)}.svg")

View File

@ -18,6 +18,9 @@ QtObject:
WalletView* = ref object of QAbstractListModel
assets*: seq[Asset]
lastMessage*: string
defaultAccount: string
sendTransaction: proc(from_value: string, to: string, value: string, password: string): string
proc delete(self: WalletView) =
self.QAbstractListModel.delete
@ -28,8 +31,9 @@ QtObject:
proc setup(self: WalletView) =
self.QAbstractListModel.setup
proc newWalletView*(): WalletView =
proc newWalletView*(sendTransaction: proc): WalletView =
new(result, delete)
result.sendTransaction = sendTransaction
result.assets = @[]
result.lastMessage = ""
result.setup
@ -43,6 +47,12 @@ QtObject:
image: image))
self.endInsertRows()
proc setDefaultAccount*(self: WalletView, account: string) =
self.defaultAccount = account
method getDefaultAccount*(self: WalletView): string {.slot.} =
return self.defaultAccount
method rowCount(self: WalletView, index: QModelIndex = nil): int =
return self.assets.len
@ -61,6 +71,9 @@ QtObject:
of AssetRoles.FiatValue: result = newQVariant(asset.fiatValue)
of AssetRoles.Image: result = newQVariant(asset.image)
proc onSendTransaction*(self: WalletView, from_value: string, to: string, value: string, password: string): string {.slot.} =
result = self.sendTransaction(from_value, to, value, password)
method roleNames(self: WalletView): Table[int, string] =
{ AssetRoles.Name.int:"name",
AssetRoles.Symbol.int:"symbol",

View File

@ -4,6 +4,7 @@ import json
import httpclient, json
import strformat
import stint
import strutils
proc getAccounts*(): seq[string] =
var payload = %* {
@ -20,6 +21,15 @@ proc getAccount*(): string =
var accounts = getAccounts()
result = accounts[0]
proc sendTransaction*(from_address: string, to: string, value: string, password: string): string =
var args = %* {
"value": fmt"0x{toHex(value)}",
"from": from_address,
"to": to
}
var response = status.sendTransaction($args, password)
result = response
proc getPrice*(crypto: string, fiat: string): string =
var url: string = fmt"https://min-api.cryptocompare.com/data/price?fsym={crypto}&tsyms={fiat}"
let client = newHttpClient()

View File

@ -43,15 +43,66 @@ Item {
Layout.fillHeight: true
Layout.fillWidth: true
Text {
id: element1
text: qsTr("Send")
anchors.left: parent.left
TextField {
id: txtValue
x: 19
y: 41
placeholderText: qsTr("Enter ETH")
anchors.leftMargin: 24
anchors.top: parent.top
anchors.topMargin: 24
font.weight: Font.Bold
font.pixelSize: 20
anchors.topMargin: 32
width: 239
height: 40
}
TextField {
id: txtFrom
x: 340
y: 41
width: 239
height: 40
text: assetsModel.getDefaultAccount()
placeholderText: qsTr("Send from (account)")
anchors.topMargin: 32
anchors.leftMargin: 24
}
TextField {
id: txtTo
x: 340
y: 99
width: 239
height: 40
text: assetsModel.getDefaultAccount()
placeholderText: qsTr("Send to")
anchors.topMargin: 32
anchors.leftMargin: 24
}
TextField {
id: txtPassword
x: 19
y: 99
width: 239
height: 40
text: "0x2cd9bf92c5e20b1b410f5ace94d963a96e89156fbe65b70365e8596b37f1f165"
placeholderText: "Enter Password"
anchors.topMargin: 32
anchors.leftMargin: 24
}
Button {
x: 19
y: 159
text: "Send"
onClicked: {
let result = assetsModel.onSendTransaction(
txtFrom.text,
txtTo.text,
txtValue.text,
txtPassword.text
);
console.log(result);
}
}
}