feat: show accounts in wallet and put assetList in Account
This commit is contained in:
parent
15bd1c3c2c
commit
cc85a42b5c
|
@ -2,7 +2,6 @@ import NimQml, Tables
|
||||||
import random
|
import random
|
||||||
import ../../../status/chat
|
import ../../../status/chat
|
||||||
|
|
||||||
const accountColors* = ["#9B832F", "#D37EF4", "#1D806F", "#FA6565", "#7CDA00", "#887af9", "#8B3131"]
|
|
||||||
const channelColors* = ["#fa6565", "#7cda00", "#887af9", "#51d0f0", "#FE8F59", "#d37ef4"]
|
const channelColors* = ["#fa6565", "#7cda00", "#887af9", "#51d0f0", "#FE8F59", "#d37ef4"]
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
|
@ -4,13 +4,15 @@ import strformat
|
||||||
import strutils
|
import strutils
|
||||||
import chronicles
|
import chronicles
|
||||||
|
|
||||||
|
import view
|
||||||
|
import views/asset_list
|
||||||
|
import views/account_list
|
||||||
import ../../status/libstatus/wallet as status_wallet
|
import ../../status/libstatus/wallet as status_wallet
|
||||||
import ../../signals/types
|
import ../../signals/types
|
||||||
|
|
||||||
import ../../status/wallet
|
import ../../status/wallet
|
||||||
import ../../status/status
|
import ../../status/status
|
||||||
|
|
||||||
import view
|
|
||||||
|
|
||||||
type WalletController* = ref object of SignalSubscriber
|
type WalletController* = ref object of SignalSubscriber
|
||||||
status: Status
|
status: Status
|
||||||
|
@ -28,14 +30,26 @@ proc delete*(self: WalletController) =
|
||||||
delete self.variant
|
delete self.variant
|
||||||
|
|
||||||
proc init*(self: WalletController) =
|
proc init*(self: WalletController) =
|
||||||
var symbol = "ETH"
|
let accounts = status_wallet.getAccounts()
|
||||||
var eth_balance = self.status.wallet.getEthBalance("0x0000000000000000000000000000000000000000")
|
|
||||||
var usd_balance = self.status.wallet.getFiatValue(eth_balance, symbol, "USD")
|
|
||||||
|
|
||||||
var asset = Asset(name:"Ethereum", symbol: symbol, value: fmt"{eth_balance:.6}", fiatValue: "$" & fmt"{usd_balance:.6}", image: fmt"../../img/token-icons/{toLowerAscii(symbol)}.svg")
|
var totalAccountBalance: float = 0
|
||||||
self.view.addAssetToList(asset)
|
|
||||||
|
|
||||||
self.view.setDefaultAccount(status_wallet.getAccount())
|
const symbol = "ETH"
|
||||||
|
for address in accounts:
|
||||||
|
let eth_balance = self.status.wallet.getEthBalance(address)
|
||||||
|
# TODO get all user assets and add them to balance
|
||||||
|
let usd_balance = self.status.wallet.getFiatValue(eth_balance, symbol, "USD")
|
||||||
|
|
||||||
|
totalAccountBalance = totalAccountBalance + usd_balance
|
||||||
|
|
||||||
|
let assetList = newAssetList()
|
||||||
|
let asset = Asset(name:"Ethereum", symbol: symbol, value: fmt"{eth_balance:.6}", fiatValue: "$" & fmt"{usd_balance:.2f}", image: fmt"../../img/token-icons/{toLowerAscii(symbol)}.svg")
|
||||||
|
assetList.addAssetToList(asset)
|
||||||
|
|
||||||
|
let account = Account(name: "Status Account", address: address, iconColor: "", balance: fmt"{totalAccountBalance:.2f} USD", assetList: assetList)
|
||||||
|
self.view.addAccountToList(account)
|
||||||
|
|
||||||
|
self.view.setDefaultAccount(accounts[0])
|
||||||
|
|
||||||
method onSignal(self: WalletController, data: Signal) =
|
method onSignal(self: WalletController, data: Signal) =
|
||||||
debug "New signal received"
|
debug "New signal received"
|
||||||
|
|
|
@ -1,14 +1,18 @@
|
||||||
import NimQml, Tables
|
import NimQml
|
||||||
|
import Tables
|
||||||
|
import views/asset_list
|
||||||
|
import views/account_list
|
||||||
import ../../status/wallet
|
import ../../status/wallet
|
||||||
import ../../status/status
|
import ../../status/status
|
||||||
import views/asset_list
|
|
||||||
|
|
||||||
QtObject:
|
QtObject:
|
||||||
type
|
type
|
||||||
WalletView* = ref object of QAbstractListModel
|
WalletView* = ref object of QAbstractListModel
|
||||||
assets*: AssetsList
|
accounts*: AccountList
|
||||||
|
currentAssetList*: AssetList
|
||||||
defaultAccount: string
|
defaultAccount: string
|
||||||
status: Status
|
status: Status
|
||||||
|
currentAccount: int8
|
||||||
|
|
||||||
proc delete(self: WalletView) =
|
proc delete(self: WalletView) =
|
||||||
self.QAbstractListModel.delete
|
self.QAbstractListModel.delete
|
||||||
|
@ -19,17 +23,36 @@ QtObject:
|
||||||
proc newWalletView*(status: Status): WalletView =
|
proc newWalletView*(status: Status): WalletView =
|
||||||
new(result, delete)
|
new(result, delete)
|
||||||
result.status = status
|
result.status = status
|
||||||
result.assets = newAssetsList()
|
result.accounts = newAccountList()
|
||||||
|
result.currentAccount = 0
|
||||||
|
result.currentAssetList = newAssetList() # Temporarily set to an empty list
|
||||||
result.setup
|
result.setup
|
||||||
|
|
||||||
proc addAssetToList*(self: WalletView, asset: Asset) =
|
proc currentAssetListChanged*(self: WalletView) {.signal.}
|
||||||
self.assets.addAssetToList(asset)
|
|
||||||
|
|
||||||
proc getAssetsList(self: WalletView): QVariant {.slot.} =
|
proc getCurrentAssetList(self: WalletView): QVariant {.slot.} =
|
||||||
return newQVariant(self.assets)
|
return newQVariant(self.currentAssetList)
|
||||||
|
|
||||||
|
proc setCurrentAssetList*(self: WalletView, assetList: AssetList) =
|
||||||
|
self.currentAssetList = assetList
|
||||||
|
self.currentAssetListChanged()
|
||||||
|
|
||||||
QtProperty[QVariant] assets:
|
QtProperty[QVariant] assets:
|
||||||
read = getAssetsList
|
read = getCurrentAssetList
|
||||||
|
write = setCurrentAssetList
|
||||||
|
notify = currentAssetListChanged
|
||||||
|
|
||||||
|
proc addAccountToList*(self: WalletView, account: Account) =
|
||||||
|
self.accounts.addAccountToList(account)
|
||||||
|
# If it's the first account we ever get, use its assetList as our currentAssetList
|
||||||
|
if (self.accounts.rowCount == 1):
|
||||||
|
self.setCurrentAssetList(account.assetList)
|
||||||
|
|
||||||
|
proc getAccountList(self: WalletView): QVariant {.slot.} =
|
||||||
|
return newQVariant(self.accounts)
|
||||||
|
|
||||||
|
QtProperty[QVariant] accounts:
|
||||||
|
read = getAccountList
|
||||||
|
|
||||||
proc onSendTransaction*(self: WalletView, from_value: string, to: string, value: string, password: string): string {.slot.} =
|
proc onSendTransaction*(self: WalletView, from_value: string, to: string, value: string, password: string): string {.slot.} =
|
||||||
result = self.status.wallet.sendTransaction(from_value, to, value, password)
|
result = self.status.wallet.sendTransaction(from_value, to, value, password)
|
||||||
|
|
|
@ -0,0 +1,77 @@
|
||||||
|
import NimQml
|
||||||
|
import Tables
|
||||||
|
import random
|
||||||
|
import ./asset_list
|
||||||
|
import ../../../status/wallet
|
||||||
|
|
||||||
|
# Need to put the definition here as putting it in status/wallet.nim would create a circular dep
|
||||||
|
type Account* = ref object
|
||||||
|
name*, address*, iconColor*, balance*: string
|
||||||
|
assetList*: AssetList
|
||||||
|
|
||||||
|
const accountColors* = [
|
||||||
|
"#9B832F",
|
||||||
|
"#D37EF4",
|
||||||
|
"#1D806F",
|
||||||
|
"#FA6565",
|
||||||
|
"#7CDA00",
|
||||||
|
"#887af9",
|
||||||
|
"#8B3131"
|
||||||
|
]
|
||||||
|
|
||||||
|
type
|
||||||
|
AccountRoles {.pure.} = enum
|
||||||
|
Name = UserRole + 1,
|
||||||
|
Address = UserRole + 2,
|
||||||
|
Color = UserRole + 3,
|
||||||
|
Balance = UserRole + 4
|
||||||
|
|
||||||
|
QtObject:
|
||||||
|
type AccountList* = ref object of QAbstractListModel
|
||||||
|
accounts*: seq[Account]
|
||||||
|
|
||||||
|
proc setup(self: AccountList) = self.QAbstractListModel.setup
|
||||||
|
|
||||||
|
proc delete(self: AccountList) =
|
||||||
|
self.QAbstractListModel.delete
|
||||||
|
self.accounts = @[]
|
||||||
|
|
||||||
|
proc newAccountList*(): AccountList =
|
||||||
|
new(result, delete)
|
||||||
|
result.accounts = @[]
|
||||||
|
result.setup
|
||||||
|
|
||||||
|
proc getAccountByIndex*(self: AccountList, index: int8): Account =
|
||||||
|
if (index >= self.accounts.len):
|
||||||
|
raise newException(ValueError, "Index out of bounds for accounts")
|
||||||
|
result = self.accounts[index]
|
||||||
|
|
||||||
|
method rowCount*(self: AccountList, index: QModelIndex = nil): int =
|
||||||
|
return self.accounts.len
|
||||||
|
|
||||||
|
method data(self: AccountList, index: QModelIndex, role: int): QVariant =
|
||||||
|
if not index.isValid:
|
||||||
|
return
|
||||||
|
if index.row < 0 or index.row >= self.accounts.len:
|
||||||
|
return
|
||||||
|
let account = self.accounts[index.row]
|
||||||
|
let accountRole = role.AccountRoles
|
||||||
|
case accountRole:
|
||||||
|
of AccountRoles.Name: result = newQVariant(account.name)
|
||||||
|
of AccountRoles.Address: result = newQVariant(account.address)
|
||||||
|
of AccountRoles.Color: result = newQVariant(account.iconColor)
|
||||||
|
of AccountRoles.Balance: result = newQVariant(account.balance)
|
||||||
|
|
||||||
|
method roleNames(self: AccountList): Table[int, string] =
|
||||||
|
{ AccountRoles.Name.int:"name",
|
||||||
|
AccountRoles.Address.int:"address",
|
||||||
|
AccountRoles.Color.int:"iconColor",
|
||||||
|
AccountRoles.Balance.int:"balance" }.toTable
|
||||||
|
|
||||||
|
proc addAccountToList*(self: AccountList, account: Account) =
|
||||||
|
if account.iconColor == "":
|
||||||
|
randomize()
|
||||||
|
account.iconColor = accountColors[rand(accountColors.len - 1)]
|
||||||
|
self.beginInsertRows(newQModelIndex(), self.accounts.len, self.accounts.len)
|
||||||
|
self.accounts.add(account)
|
||||||
|
self.endInsertRows()
|
|
@ -1,6 +1,5 @@
|
||||||
import NimQml
|
import NimQml
|
||||||
import Tables
|
import tables
|
||||||
import strformat
|
|
||||||
import ../../../status/wallet
|
import ../../../status/wallet
|
||||||
|
|
||||||
type
|
type
|
||||||
|
@ -12,24 +11,24 @@ type
|
||||||
Image = UserRole + 5
|
Image = UserRole + 5
|
||||||
|
|
||||||
QtObject:
|
QtObject:
|
||||||
type AssetsList* = ref object of QAbstractListModel
|
type AssetList* = ref object of QAbstractListModel
|
||||||
assets*: seq[Asset]
|
assets*: seq[Asset]
|
||||||
|
|
||||||
proc setup(self: AssetsList) = self.QAbstractListModel.setup
|
proc setup(self: AssetList) = self.QAbstractListModel.setup
|
||||||
|
|
||||||
proc delete(self: AssetsList) =
|
proc delete(self: AssetList) =
|
||||||
self.QAbstractListModel.delete
|
self.QAbstractListModel.delete
|
||||||
self.assets = @[]
|
self.assets = @[]
|
||||||
|
|
||||||
proc newAssetsList*(): AssetsList =
|
proc newAssetList*(): AssetList =
|
||||||
new(result, delete)
|
new(result, delete)
|
||||||
result.assets = @[]
|
result.assets = @[]
|
||||||
result.setup
|
result.setup
|
||||||
|
|
||||||
method rowCount(self: AssetsList, index: QModelIndex = nil): int =
|
method rowCount(self: AssetList, index: QModelIndex = nil): int =
|
||||||
return self.assets.len
|
return self.assets.len
|
||||||
|
|
||||||
method data(self: AssetsList, index: QModelIndex, role: int): QVariant =
|
method data(self: AssetList, index: QModelIndex, role: int): QVariant =
|
||||||
if not index.isValid:
|
if not index.isValid:
|
||||||
return
|
return
|
||||||
if index.row < 0 or index.row >= self.assets.len:
|
if index.row < 0 or index.row >= self.assets.len:
|
||||||
|
@ -43,14 +42,14 @@ 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)
|
||||||
|
|
||||||
method roleNames(self: AssetsList): Table[int, string] =
|
method roleNames(self: AssetList): Table[int, string] =
|
||||||
{ AssetRoles.Name.int:"name",
|
{ AssetRoles.Name.int:"name",
|
||||||
AssetRoles.Symbol.int:"symbol",
|
AssetRoles.Symbol.int:"symbol",
|
||||||
AssetRoles.Value.int:"value",
|
AssetRoles.Value.int:"value",
|
||||||
AssetRoles.FiatValue.int:"fiatValue",
|
AssetRoles.FiatValue.int:"fiatValue",
|
||||||
AssetRoles.Image.int:"image" }.toTable
|
AssetRoles.Image.int:"image" }.toTable
|
||||||
|
|
||||||
proc addAssetToList*(self: AssetsList, asset: Asset) =
|
proc addAssetToList*(self: AssetList, asset: Asset) =
|
||||||
self.beginInsertRows(newQModelIndex(), self.assets.len, self.assets.len)
|
self.beginInsertRows(newQModelIndex(), self.assets.len, self.assets.len)
|
||||||
self.assets.add(asset)
|
self.assets.add(asset)
|
||||||
self.endInsertRows()
|
self.endInsertRows()
|
||||||
|
|
|
@ -38,7 +38,7 @@ proc mainProc() =
|
||||||
signalsQObjPointer = cast[pointer](signalController.vptr)
|
signalsQObjPointer = cast[pointer](signalController.vptr)
|
||||||
|
|
||||||
var wallet = wallet.newController(status)
|
var wallet = wallet.newController(status)
|
||||||
engine.setRootContextProperty("assetsModel", wallet.variant)
|
engine.setRootContextProperty("walletModel", wallet.variant)
|
||||||
|
|
||||||
var chat = chat.newController(status)
|
var chat = chat.newController(status)
|
||||||
engine.setRootContextProperty("chatsModel", chat.variant)
|
engine.setRootContextProperty("chatsModel", chat.variant)
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import eventemitter
|
import eventemitter
|
||||||
import json
|
|
||||||
import strformat
|
import strformat
|
||||||
import strutils
|
import strutils
|
||||||
import libstatus/wallet as status_wallet
|
import libstatus/wallet as status_wallet
|
||||||
|
|
|
@ -31,7 +31,7 @@ Item {
|
||||||
onDataChanged: {
|
onDataChanged: {
|
||||||
// If the current active channel receives messages and changes its position,
|
// If the current active channel receives messages and changes its position,
|
||||||
// refresh the currentIndex accordingly
|
// refresh the currentIndex accordingly
|
||||||
if(chatsModel.activeChannelIndex != chatGroupsListView.currentIndex){
|
if(chatsModel.activeChannelIndex !== chatGroupsListView.currentIndex){
|
||||||
chatGroupsListView.currentIndex = chatsModel.activeChannelIndex
|
chatGroupsListView.currentIndex = chatsModel.activeChannelIndex
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ Item {
|
||||||
}
|
}
|
||||||
Text {
|
Text {
|
||||||
id: assetFullTokenName
|
id: assetFullTokenName
|
||||||
text: fullTokenName
|
text: name
|
||||||
anchors.bottom: parent.bottom
|
anchors.bottom: parent.bottom
|
||||||
anchors.bottomMargin: 0
|
anchors.bottomMargin: 0
|
||||||
anchors.left: assetInfoImage.right
|
anchors.left: assetInfoImage.right
|
||||||
|
@ -80,7 +80,7 @@ Item {
|
||||||
anchors.topMargin: 20
|
anchors.topMargin: 20
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
// model: exampleModel
|
// model: exampleModel
|
||||||
model: assetsModel.assets
|
model: walletModel.assets
|
||||||
delegate: assetViewDelegate
|
delegate: assetViewDelegate
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,7 +119,7 @@ Item {
|
||||||
anchors.bottom: parent.bottom
|
anchors.bottom: parent.bottom
|
||||||
anchors.bottomMargin: Theme.padding
|
anchors.bottomMargin: Theme.padding
|
||||||
onClicked: {
|
onClicked: {
|
||||||
let result = assetsModel.onSendTransaction(txtFrom.text,
|
let result = walletModel.onSendTransaction(txtFrom.text,
|
||||||
txtTo.text,
|
txtTo.text,
|
||||||
txtValue.text,
|
txtValue.text,
|
||||||
txtPassword.text)
|
txtPassword.text)
|
||||||
|
|
|
@ -89,7 +89,7 @@ Item {
|
||||||
ColorOverlay {
|
ColorOverlay {
|
||||||
anchors.fill: walletIcon
|
anchors.fill: walletIcon
|
||||||
source: walletIcon
|
source: walletIcon
|
||||||
color: selected ? Theme.transparent : "#7CDA00" // change image color
|
color: selected ? Theme.transparent : iconColor // change image color
|
||||||
}
|
}
|
||||||
Text {
|
Text {
|
||||||
id: walletName
|
id: walletName
|
||||||
|
@ -105,6 +105,9 @@ Item {
|
||||||
Text {
|
Text {
|
||||||
id: walletAddress
|
id: walletAddress
|
||||||
text: address
|
text: address
|
||||||
|
anchors.right: parent.right
|
||||||
|
anchors.rightMargin: parent.width/2
|
||||||
|
elide: Text.ElideMiddle
|
||||||
anchors.bottom: parent.bottom
|
anchors.bottom: parent.bottom
|
||||||
anchors.bottomMargin: Theme.smallPadding
|
anchors.bottomMargin: Theme.smallPadding
|
||||||
anchors.left: walletName.left
|
anchors.left: walletName.left
|
||||||
|
@ -148,24 +151,31 @@ Item {
|
||||||
|
|
||||||
delegate: walletDelegate
|
delegate: walletDelegate
|
||||||
|
|
||||||
model: ListModel {
|
ListModel {
|
||||||
|
id: exampleWalletModel
|
||||||
ListElement {
|
ListElement {
|
||||||
name: "Status account"
|
name: "Status account"
|
||||||
address: "0x2Ef1...E0Ba"
|
address: "0xcfc9f08bbcbcb80760e8cb9a3c1232d19662fc6f"
|
||||||
balance: "12.00 USD"
|
balance: "12.00 USD"
|
||||||
|
iconColor: "#7CDA00"
|
||||||
}
|
}
|
||||||
|
|
||||||
ListElement {
|
ListElement {
|
||||||
name: "Test account 1"
|
name: "Test account 1"
|
||||||
address: "0x2Ef1...E0Ba"
|
address: "0x2Ef1...E0Ba"
|
||||||
balance: "12.00 USD"
|
balance: "12.00 USD"
|
||||||
|
iconColor: "#FA6565"
|
||||||
}
|
}
|
||||||
ListElement {
|
ListElement {
|
||||||
name: "Status account"
|
name: "Status account"
|
||||||
address: "0x2Ef1...E0Ba"
|
address: "0x2Ef1...E0Ba"
|
||||||
balance: "12.00 USD"
|
balance: "12.00 USD"
|
||||||
|
iconColor: "#7CDA00"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
model: walletModel.getAccountList()
|
||||||
|
// model: exampleWalletModel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ Item {
|
||||||
popup.open()
|
popup.open()
|
||||||
sendModalContent.valueInput.text = ""
|
sendModalContent.valueInput.text = ""
|
||||||
sendModalContent.valueInput.forceActiveFocus(Qt.MouseFocusReason)
|
sendModalContent.valueInput.forceActiveFocus(Qt.MouseFocusReason)
|
||||||
sendModalContent.defaultAccount = assetsModel.getDefaultAccount()
|
sendModalContent.defaultAccount = walletModel.getDefaultAccount()
|
||||||
}
|
}
|
||||||
|
|
||||||
function close() {
|
function close() {
|
||||||
|
|
|
@ -8,6 +8,7 @@ Item {
|
||||||
property string placeholderText: "My placeholder"
|
property string placeholderText: "My placeholder"
|
||||||
property string text: ""
|
property string text: ""
|
||||||
property string label: ""
|
property string label: ""
|
||||||
|
|
||||||
// property string label: "My Label"
|
// property string label: "My Label"
|
||||||
// property url icon: "../app/img/hash.svg"
|
// property url icon: "../app/img/hash.svg"
|
||||||
property url icon: ""
|
property url icon: ""
|
||||||
|
|
Loading…
Reference in New Issue