rename assetsView to walletView

This commit is contained in:
Iuri Matias 2020-05-15 17:40:05 -04:00
parent 5bff1f49a4
commit f6528ee476
7 changed files with 70 additions and 67 deletions

View File

@ -8,54 +8,53 @@ type
QtObject:
type
ChatsModel* = ref object of QAbstractListModel
ChatsView* = ref object of QAbstractListModel
names*: seq[string]
callResult: string
sendMessage: proc (msg: string): string
proc delete(self: ChatsModel) =
proc delete(self: ChatsView) =
self.QAbstractListModel.delete
proc setup(self: ChatsModel) =
proc setup(self: ChatsView) =
self.QAbstractListModel.setup
proc newChatsModel*(sendMessage: proc): ChatsModel =
proc newChatsView*(sendMessage: proc): ChatsView =
new(result, delete)
result.sendMessage = sendMessage
result.names = @[]
result.setup
proc addNameTolist*(self: ChatsModel, chatId: string) {.slot.} =
# chat.join(chatId)
proc addNameTolist*(self: ChatsView, chatId: string) {.slot.} =
self.beginInsertRows(newQModelIndex(), self.names.len, self.names.len)
self.names.add(chatId)
self.endInsertRows()
method rowCount(self: ChatsModel, index: QModelIndex = nil): int =
method rowCount(self: ChatsView, index: QModelIndex = nil): int =
return self.names.len
method data(self: ChatsModel, index: QModelIndex, role: int): QVariant =
method data(self: ChatsView, index: QModelIndex, role: int): QVariant =
if not index.isValid:
return
if index.row < 0 or index.row >= self.names.len:
return
return newQVariant(self.names[index.row])
method roleNames(self: ChatsModel): Table[int, string] =
method roleNames(self: ChatsView): Table[int, string] =
{ RoleNames.Name.int:"name"}.toTable
# Accesors
proc callResult*(self: ChatsModel): string {.slot.} =
proc callResult*(self: ChatsView): string {.slot.} =
result = self.callResult
proc callResultChanged*(self: ChatsModel, callResult: string) {.signal.}
proc callResultChanged*(self: ChatsView, callResult: string) {.signal.}
proc setCallResult(self: ChatsModel, callResult: string) {.slot.} =
proc setCallResult(self: ChatsView, callResult: string) {.slot.} =
if self.callResult == callResult: return
self.callResult = callResult
self.callResultChanged(callResult)
proc `callResult=`*(self: ChatsModel, callResult: string) = self.setCallResult(callResult)
proc `callResult=`*(self: ChatsView, callResult: string) = self.setCallResult(callResult)
# Binding between a QML variable and accesors is done here
QtProperty[string] callResult:
@ -63,10 +62,10 @@ QtObject:
write = setCallResult
notify = callResultChanged
proc onSend*(self: ChatsModel, inputJSON: string) {.slot.} =
proc onSend*(self: ChatsView, inputJSON: string) {.slot.} =
self.setCallResult(self.sendMessage(inputJSON))
echo "Done!: ", self.callResult
proc onMessage*(self: ChatsModel, message: string) {.slot.} =
proc onMessage*(self: ChatsView, message: string) {.slot.} =
self.setCallResult(message)
echo "Received message: ", message

View File

@ -6,24 +6,24 @@ var sendMessage = proc (msg: string): string =
echo "sending public message"
status_chat.sendPublicChatMessage("test", msg)
type Chat* = ref object
chatsModel*: ChatsModel
chatsVariant*: QVariant
type ChatController* = ref object
view*: ChatsView
variant*: QVariant
proc newChat*(): Chat =
result = Chat()
result.chatsModel = newChatsModel(sendMessage)
result.chatsModel.names = @[]
result.chatsVariant = newQVariant(result.chatsModel)
proc newController*(): ChatController =
result = ChatController()
result.view = newChatsView(sendMessage)
result.view.names = @[]
result.variant = newQVariant(result.view)
proc delete*(self: Chat) =
delete self.chatsModel
delete self.chatsVariant
proc delete*(self: ChatController) =
delete self.view
delete self.variant
proc init*(self: Chat) =
proc init*(self: ChatController) =
discard
proc join*(self: Chat, chatId: string) =
proc join*(self: ChatController, chatId: string) =
# TODO: check whether we have joined a chat already or not
# TODO: save chat list in the db
echo "Joining chat: ", chatId
@ -31,9 +31,9 @@ proc join*(self: Chat, chatId: string) =
status_chat.saveChat(chatId)
status_chat.chatMessages(chatId)
# self.chatsModel.addNameTolist(channel.name)
self.chatsModel.addNameTolist(chatId)
self.view.addNameTolist(chatId)
proc load*(self: Chat): seq[string] =
proc load*(self: ChatController): seq[string] =
# TODO: retrieve chats from DB
self.join("test")
result = @["test"]

View File

@ -36,17 +36,17 @@ proc mainProc() =
status.startMessenger()
var wallet = wallet.newWallet()
var wallet = wallet.newController()
wallet.init()
engine.setRootContextProperty("assetsModel", wallet.assetsVariant)
engine.setRootContextProperty("assetsModel", wallet.variant)
var chat = chat.newChat()
var chat = chat.newController()
chat.init()
engine.setRootContextProperty("chatsModel", chat.chatsVariant)
engine.setRootContextProperty("chatsModel", chat.variant)
var node = node.newNode()
var node = node.newController()
node.init()
engine.setRootContextProperty("nodeModel", node.nodeVariant)
engine.setRootContextProperty("nodeModel", node.variant)
engine.load("../ui/main.qml")

View File

@ -2,22 +2,22 @@ import NimQml
import "../status/core" as status
import nodeView
type Node* = ref object
nodeModel*: NodeView
nodeVariant*: QVariant
type NodeController* = ref object
view*: NodeView
variant*: QVariant
var sendRPCMessage = proc (msg: string): string =
echo "sending RPC message"
status.callPrivateRPC(msg)
proc newNode*(): Node =
result = Node()
result.nodeModel = newNodeView(sendRPCMessage)
result.nodeVariant = newQVariant(result.nodeModel)
proc newController*(): NodeController =
result = NodeController()
result.view = newNodeView(sendRPCMessage)
result.variant = newQVariant(result.view)
proc delete*(self: Node) =
delete self.nodeModel
delete self.nodeVariant
proc delete*(self: NodeController) =
delete self.view
delete self.variant
proc init*(self: Node) =
proc init*(self: NodeController) =
discard

View File

@ -1,6 +1,10 @@
import status/types
import tables
##########################################################
## warning: this section is still very much in flux
##########################################################
type
ChatChannel = object
name*: string

View File

@ -5,21 +5,21 @@ import strutils
import walletView
import ../status/wallet as status_wallet
type Wallet* = ref object
assetsModel*: AssetsModel
assetsVariant*: QVariant
type WalletController* = ref object
view*: WalletView
variant*: QVariant
proc newWallet*(): Wallet =
proc newController*(): WalletController =
echo "new wallet"
result = Wallet()
result.assetsModel = newAssetsModel()
result.assetsVariant = newQVariant(result.assetsModel)
result = WalletController()
result.view = newWalletView()
result.variant = newQVariant(result.view)
proc delete*(self: Wallet) =
delete self.assetsModel
delete self.assetsVariant
proc delete*(self: WalletController) =
delete self.view
delete self.variant
proc init*(self: Wallet) =
proc init*(self: WalletController) =
# 1. get balance of an address
var balance = status_wallet.getBalance("0x0000000000000000000000000000000000000000")
echo(fmt"balance in hex: {balance}")
@ -37,4 +37,4 @@ proc init*(self: Wallet) =
echo(fmt"balance in usd: {usd_balance}")
let symbol = "ETH"
self.assetsModel.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

@ -15,24 +15,24 @@ type
QtObject:
type
AssetsModel* = ref object of QAbstractListModel
WalletView* = ref object of QAbstractListModel
assets*: seq[Asset]
proc delete(self: AssetsModel) =
proc delete(self: WalletView) =
self.QAbstractListModel.delete
for asset in self.assets:
asset.delete
self.assets = @[]
proc setup(self: AssetsModel) =
proc setup(self: WalletView) =
self.QAbstractListModel.setup
proc newAssetsModel*(): AssetsModel =
proc newWalletView*(): WalletView =
new(result, delete)
result.assets = @[]
result.setup
proc addAssetToList*(self: AssetsModel, name: string, symbol: string, value: string, fiatValue: string, image: string) {.slot.} =
proc addAssetToList*(self: WalletView, name: string, symbol: string, value: string, fiatValue: string, image: string) {.slot.} =
self.beginInsertRows(newQModelIndex(), self.assets.len, self.assets.len)
self.assets.add(Asset(name : name,
symbol : symbol,
@ -41,10 +41,10 @@ QtObject:
image: image))
self.endInsertRows()
method rowCount(self: AssetsModel, index: QModelIndex = nil): int =
method rowCount(self: WalletView, index: QModelIndex = nil): int =
return self.assets.len
method data(self: AssetsModel, index: QModelIndex, role: int): QVariant =
method data(self: WalletView, index: QModelIndex, role: int): QVariant =
if not index.isValid:
return
if index.row < 0 or index.row >= self.assets.len:
@ -59,7 +59,7 @@ QtObject:
of AssetRoles.FiatValue: result = newQVariant(asset.fiatValue)
of AssetRoles.Image: result = newQVariant(asset.image)
method roleNames(self: AssetsModel): Table[int, string] =
method roleNames(self: WalletView): Table[int, string] =
{ AssetRoles.Name.int:"name",
AssetRoles.Symbol.int:"symbol",
AssetRoles.Value.int:"value",