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

View File

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

View File

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

View File

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

View File

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

View File

@ -5,21 +5,21 @@ import strutils
import walletView import walletView
import ../status/wallet as status_wallet import ../status/wallet as status_wallet
type Wallet* = ref object type WalletController* = ref object
assetsModel*: AssetsModel view*: WalletView
assetsVariant*: QVariant variant*: QVariant
proc newWallet*(): Wallet = proc newController*(): WalletController =
echo "new wallet" echo "new wallet"
result = Wallet() result = WalletController()
result.assetsModel = newAssetsModel() result.view = newWalletView()
result.assetsVariant = newQVariant(result.assetsModel) result.variant = newQVariant(result.view)
proc delete*(self: Wallet) = proc delete*(self: WalletController) =
delete self.assetsModel delete self.view
delete self.assetsVariant delete self.variant
proc init*(self: Wallet) = proc init*(self: WalletController) =
# 1. get balance of an address # 1. get balance of an address
var balance = status_wallet.getBalance("0x0000000000000000000000000000000000000000") var balance = status_wallet.getBalance("0x0000000000000000000000000000000000000000")
echo(fmt"balance in hex: {balance}") echo(fmt"balance in hex: {balance}")
@ -37,4 +37,4 @@ proc init*(self: Wallet) =
echo(fmt"balance in usd: {usd_balance}") echo(fmt"balance in usd: {usd_balance}")
let symbol = "ETH" 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: QtObject:
type type
AssetsModel* = ref object of QAbstractListModel WalletView* = ref object of QAbstractListModel
assets*: seq[Asset] assets*: seq[Asset]
proc delete(self: AssetsModel) = proc delete(self: WalletView) =
self.QAbstractListModel.delete self.QAbstractListModel.delete
for asset in self.assets: for asset in self.assets:
asset.delete asset.delete
self.assets = @[] self.assets = @[]
proc setup(self: AssetsModel) = proc setup(self: WalletView) =
self.QAbstractListModel.setup self.QAbstractListModel.setup
proc newAssetsModel*(): AssetsModel = proc newWalletView*(): WalletView =
new(result, delete) new(result, delete)
result.assets = @[] result.assets = @[]
result.setup 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.beginInsertRows(newQModelIndex(), self.assets.len, self.assets.len)
self.assets.add(Asset(name : name, self.assets.add(Asset(name : name,
symbol : symbol, symbol : symbol,
@ -41,10 +41,10 @@ QtObject:
image: image)) image: image))
self.endInsertRows() self.endInsertRows()
method rowCount(self: AssetsModel, index: QModelIndex = nil): int = method rowCount(self: WalletView, index: QModelIndex = nil): int =
return self.assets.len 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: 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:
@ -59,7 +59,7 @@ 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: AssetsModel): 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",
AssetRoles.Value.int:"value", AssetRoles.Value.int:"value",