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 ../../status/wallet as status_wallet
import ../signals/types 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 type WalletController* = ref object of SignalSubscriber
view*: WalletView view*: WalletView
variant*: QVariant variant*: QVariant
proc newController*(): WalletController = proc newController*(): WalletController =
echo "new wallet"
result = WalletController() result = WalletController()
result.view = newWalletView() result.view = newWalletView(sendTransaction)
result.variant = newQVariant(result.view) result.variant = newQVariant(result.view)
proc delete*(self: WalletController) = proc delete*(self: WalletController) =
@ -37,6 +39,8 @@ proc init*(self: WalletController) =
var usd_balance = parseFloat(eth_value) * parseFloat(usd_eth_price) var usd_balance = parseFloat(eth_value) * parseFloat(usd_eth_price)
echo(fmt"balance in usd: {usd_balance}") echo(fmt"balance in usd: {usd_balance}")
self.view.setDefaultAccount(status_wallet.getAccount())
let symbol = "ETH" let symbol = "ETH"
self.view.addAssetToList("Ethereum", symbol, fmt"{eth_value:.6}", "$" & fmt"{usd_balance:.6}", fmt"../../img/token-icons/{toLowerAscii(symbol)}.svg") 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 WalletView* = ref object of QAbstractListModel
assets*: seq[Asset] assets*: seq[Asset]
lastMessage*: string lastMessage*: string
defaultAccount: string
sendTransaction: proc(from_value: string, to: string, value: string, password: string): string
proc delete(self: WalletView) = proc delete(self: WalletView) =
self.QAbstractListModel.delete self.QAbstractListModel.delete
@ -28,8 +31,9 @@ QtObject:
proc setup(self: WalletView) = proc setup(self: WalletView) =
self.QAbstractListModel.setup self.QAbstractListModel.setup
proc newWalletView*(): WalletView = proc newWalletView*(sendTransaction: proc): WalletView =
new(result, delete) new(result, delete)
result.sendTransaction = sendTransaction
result.assets = @[] result.assets = @[]
result.lastMessage = "" result.lastMessage = ""
result.setup result.setup
@ -43,6 +47,12 @@ QtObject:
image: image)) image: image))
self.endInsertRows() 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 = method rowCount(self: WalletView, index: QModelIndex = nil): int =
return self.assets.len return self.assets.len
@ -61,6 +71,9 @@ QtObject:
of AssetRoles.FiatValue: result = newQVariant(asset.fiatValue) of AssetRoles.FiatValue: result = newQVariant(asset.fiatValue)
of AssetRoles.Image: result = newQVariant(asset.image) 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] = method roleNames(self: WalletView): Table[int, string] =
{ AssetRoles.Name.int:"name", { AssetRoles.Name.int:"name",
AssetRoles.Symbol.int:"symbol", AssetRoles.Symbol.int:"symbol",

View File

@ -4,6 +4,7 @@ import json
import httpclient, json import httpclient, json
import strformat import strformat
import stint import stint
import strutils
proc getAccounts*(): seq[string] = proc getAccounts*(): seq[string] =
var payload = %* { var payload = %* {
@ -20,6 +21,15 @@ proc getAccount*(): string =
var accounts = getAccounts() var accounts = getAccounts()
result = accounts[0] 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 = proc getPrice*(crypto: string, fiat: string): string =
var url: string = fmt"https://min-api.cryptocompare.com/data/price?fsym={crypto}&tsyms={fiat}" var url: string = fmt"https://min-api.cryptocompare.com/data/price?fsym={crypto}&tsyms={fiat}"
let client = newHttpClient() let client = newHttpClient()

View File

@ -43,15 +43,66 @@ Item {
Layout.fillHeight: true Layout.fillHeight: true
Layout.fillWidth: true Layout.fillWidth: true
Text { TextField {
id: element1 id: txtValue
text: qsTr("Send") x: 19
anchors.left: parent.left y: 41
placeholderText: qsTr("Enter ETH")
anchors.leftMargin: 24 anchors.leftMargin: 24
anchors.top: parent.top anchors.topMargin: 32
anchors.topMargin: 24 width: 239
font.weight: Font.Bold height: 40
font.pixelSize: 20 }
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);
}
} }
} }