move 'models' to status lib for clarity
move 'models' to status lib for clarity move chat model update login controller update wallet controller update onboarding and profile update
This commit is contained in:
parent
73069255cd
commit
2bc165bbc2
|
@ -6,21 +6,20 @@ import ../../status/libstatus/types as status_types
|
||||||
import views/channels_list
|
import views/channels_list
|
||||||
import view
|
import view
|
||||||
import chronicles
|
import chronicles
|
||||||
|
import ../../status/status
|
||||||
|
|
||||||
logScope:
|
logScope:
|
||||||
topics = "chat-controller"
|
topics = "chat-controller"
|
||||||
|
|
||||||
type ChatController* = ref object of SignalSubscriber
|
type ChatController* = ref object of SignalSubscriber
|
||||||
view*: ChatsView
|
view*: ChatsView
|
||||||
model*: ChatModel
|
status*: Status
|
||||||
variant*: QVariant
|
variant*: QVariant
|
||||||
appEvents*: EventEmitter
|
|
||||||
|
|
||||||
proc newController*(appEvents: EventEmitter): ChatController =
|
proc newController*(status: Status): ChatController =
|
||||||
result = ChatController()
|
result = ChatController()
|
||||||
result.appEvents = appEvents
|
result.status = status
|
||||||
result.model = newChatModel()
|
result.view = newChatsView(status)
|
||||||
result.view = newChatsView(result.model)
|
|
||||||
result.variant = newQVariant(result.view)
|
result.variant = newQVariant(result.view)
|
||||||
|
|
||||||
proc delete*(self: ChatController) =
|
proc delete*(self: ChatController) =
|
||||||
|
@ -28,25 +27,25 @@ proc delete*(self: ChatController) =
|
||||||
delete self.variant
|
delete self.variant
|
||||||
|
|
||||||
proc init*(self: ChatController) =
|
proc init*(self: ChatController) =
|
||||||
self.model.events.on("messageSent") do(e: Args):
|
self.status.events.on("messageSent") do(e: Args):
|
||||||
var sentMessage = MsgArgs(e)
|
var sentMessage = MsgArgs(e)
|
||||||
var chatMessage = sentMessage.payload.toChatMessage()
|
var chatMessage = sentMessage.payload.toChatMessage()
|
||||||
chatMessage.message = sentMessage.message
|
chatMessage.message = sentMessage.message
|
||||||
chatMessage.isCurrentUser = true
|
chatMessage.isCurrentUser = true
|
||||||
self.view.pushMessage(sentMessage.chatId, chatMessage)
|
self.view.pushMessage(sentMessage.chatId, chatMessage)
|
||||||
|
|
||||||
self.model.events.on("channelJoined") do(e: Args):
|
self.status.events.on("channelJoined") do(e: Args):
|
||||||
var channelMessage = ChannelArgs(e)
|
var channelMessage = ChannelArgs(e)
|
||||||
let chatItem = newChatItem(id = channelMessage.channel, channelMessage.chatTypeInt)
|
let chatItem = newChatItem(id = channelMessage.channel, channelMessage.chatTypeInt)
|
||||||
discard self.view.chats.addChatItemToList(chatItem)
|
discard self.view.chats.addChatItemToList(chatItem)
|
||||||
|
|
||||||
self.model.events.on("channelLeft") do(e: Args):
|
self.status.events.on("channelLeft") do(e: Args):
|
||||||
discard self.view.chats.removeChatItemFromList(self.view.activeChannel)
|
discard self.view.chats.removeChatItemFromList(self.view.activeChannel)
|
||||||
|
|
||||||
self.model.events.on("activeChannelChanged") do(e: Args):
|
self.status.events.on("activeChannelChanged") do(e: Args):
|
||||||
self.view.setActiveChannel(ChannelArgs(e).channel)
|
self.view.setActiveChannel(ChannelArgs(e).channel)
|
||||||
|
|
||||||
self.model.load()
|
self.status.chat.load()
|
||||||
self.view.setActiveChannelByIndex(0)
|
self.view.setActiveChannelByIndex(0)
|
||||||
|
|
||||||
proc handleMessage(self: ChatController, data: Signal) =
|
proc handleMessage(self: ChatController, data: Signal) =
|
||||||
|
|
|
@ -1,14 +1,17 @@
|
||||||
import NimQml
|
import NimQml
|
||||||
import Tables
|
import Tables
|
||||||
import views/channels_list
|
|
||||||
import views/message_list
|
|
||||||
import ../../signals/types
|
import ../../signals/types
|
||||||
import ../../status/chat
|
import ../../status/chat
|
||||||
|
import ../../status/status
|
||||||
|
|
||||||
|
import views/channels_list
|
||||||
|
import views/message_list
|
||||||
|
|
||||||
QtObject:
|
QtObject:
|
||||||
type
|
type
|
||||||
ChatsView* = ref object of QAbstractListModel
|
ChatsView* = ref object of QAbstractListModel
|
||||||
model: ChatModel
|
status: Status
|
||||||
chats*: ChannelsList
|
chats*: ChannelsList
|
||||||
callResult: string
|
callResult: string
|
||||||
messageList: Table[string, ChatMessageList]
|
messageList: Table[string, ChatMessageList]
|
||||||
|
@ -18,10 +21,10 @@ QtObject:
|
||||||
|
|
||||||
proc delete(self: ChatsView) = self.QAbstractListModel.delete
|
proc delete(self: ChatsView) = self.QAbstractListModel.delete
|
||||||
|
|
||||||
proc newChatsView*(model: ChatModel): ChatsView =
|
proc newChatsView*(status: Status): ChatsView =
|
||||||
new(result, delete)
|
new(result, delete)
|
||||||
result.model = model
|
result.status = status
|
||||||
result.chats = newChannelsList(result.model)
|
result.chats = newChannelsList()
|
||||||
result.activeChannel = ""
|
result.activeChannel = ""
|
||||||
result.messageList = initTable[string, ChatMessageList]()
|
result.messageList = initTable[string, ChatMessageList]()
|
||||||
result.setup()
|
result.setup()
|
||||||
|
@ -84,13 +87,13 @@ QtObject:
|
||||||
discard self.chats.addChatItemToList(chatItem)
|
discard self.chats.addChatItemToList(chatItem)
|
||||||
|
|
||||||
proc sendMessage*(self: ChatsView, message: string) {.slot.} =
|
proc sendMessage*(self: ChatsView, message: string) {.slot.} =
|
||||||
discard self.model.sendMessage(self.activeChannel, message)
|
discard self.status.chat.sendMessage(self.activeChannel, message)
|
||||||
|
|
||||||
proc joinChat*(self: ChatsView, channel: string, chatTypeInt: int): int {.slot.} =
|
proc joinChat*(self: ChatsView, channel: string, chatTypeInt: int): int {.slot.} =
|
||||||
self.model.join(channel, ChatType(chatTypeInt))
|
self.status.chat.join(channel, ChatType(chatTypeInt))
|
||||||
|
|
||||||
proc leaveActiveChat*(self: ChatsView) {.slot.} =
|
proc leaveActiveChat*(self: ChatsView) {.slot.} =
|
||||||
self.model.leave(self.activeChannel)
|
self.status.chat.leave(self.activeChannel)
|
||||||
|
|
||||||
proc updateChat*(self: ChatsView, chat: ChatItem) =
|
proc updateChat*(self: ChatsView, chat: ChatItem) =
|
||||||
self.chats.updateChat(chat)
|
self.chats.updateChat(chat)
|
||||||
|
|
|
@ -36,17 +36,15 @@ type
|
||||||
QtObject:
|
QtObject:
|
||||||
type
|
type
|
||||||
ChannelsList* = ref object of QAbstractListModel
|
ChannelsList* = ref object of QAbstractListModel
|
||||||
model*: ChatModel
|
|
||||||
chats*: seq[ChatItem]
|
chats*: seq[ChatItem]
|
||||||
|
|
||||||
proc setup(self: ChannelsList) = self.QAbstractListModel.setup
|
proc setup(self: ChannelsList) = self.QAbstractListModel.setup
|
||||||
|
|
||||||
proc delete(self: ChannelsList) = self.QAbstractListModel.delete
|
proc delete(self: ChannelsList) = self.QAbstractListModel.delete
|
||||||
|
|
||||||
proc newChannelsList*(model: ChatModel): ChannelsList =
|
proc newChannelsList*(): ChannelsList =
|
||||||
new(result, delete)
|
new(result, delete)
|
||||||
result.chats = @[]
|
result.chats = @[]
|
||||||
result.model = model
|
|
||||||
result.setup()
|
result.setup()
|
||||||
|
|
||||||
method rowCount(self: ChannelsList, index: QModelIndex = nil): int = self.chats.len
|
method rowCount(self: ChannelsList, index: QModelIndex = nil): int = self.chats.len
|
||||||
|
|
|
@ -1,24 +1,25 @@
|
||||||
import NimQml
|
import NimQml
|
||||||
import ../../status/libstatus/types as status_types
|
|
||||||
import ../../signals/types
|
|
||||||
import eventemitter
|
|
||||||
import view
|
|
||||||
import ../../status/accounts as AccountModel
|
|
||||||
import chronicles
|
import chronicles
|
||||||
import options
|
import options
|
||||||
import std/wrapnils
|
import std/wrapnils
|
||||||
|
import eventemitter
|
||||||
|
|
||||||
|
import ../../status/libstatus/types as status_types
|
||||||
|
import ../../signals/types
|
||||||
|
# import ../../status/accounts as AccountModel
|
||||||
|
import ../../status/status
|
||||||
|
|
||||||
|
import view
|
||||||
|
|
||||||
type LoginController* = ref object of SignalSubscriber
|
type LoginController* = ref object of SignalSubscriber
|
||||||
|
status*: Status
|
||||||
view*: LoginView
|
view*: LoginView
|
||||||
variant*: QVariant
|
variant*: QVariant
|
||||||
appEvents*: EventEmitter
|
|
||||||
model: AccountModel
|
|
||||||
|
|
||||||
proc newController*(appEvents: EventEmitter): LoginController =
|
proc newController*(status: Status): LoginController =
|
||||||
result = LoginController()
|
result = LoginController()
|
||||||
result.appEvents = appEvents
|
result.status = status
|
||||||
result.model = newAccountModel()
|
result.view = newLoginView(status)
|
||||||
result.view = newLoginView(result.model)
|
|
||||||
result.variant = newQVariant(result.view)
|
result.variant = newQVariant(result.view)
|
||||||
|
|
||||||
proc delete*(self: LoginController) =
|
proc delete*(self: LoginController) =
|
||||||
|
@ -26,18 +27,18 @@ proc delete*(self: LoginController) =
|
||||||
delete self.variant
|
delete self.variant
|
||||||
|
|
||||||
proc init*(self: LoginController, nodeAccounts: seq[NodeAccount]) =
|
proc init*(self: LoginController, nodeAccounts: seq[NodeAccount]) =
|
||||||
self.model.nodeAccounts = nodeAccounts
|
self.status.accounts.nodeAccounts = nodeAccounts
|
||||||
for nodeAccount in nodeAccounts:
|
for nodeAccount in nodeAccounts:
|
||||||
self.view.addAccountToList(nodeAccount)
|
self.view.addAccountToList(nodeAccount)
|
||||||
|
|
||||||
proc handleNodeLogin(self: LoginController, data: Signal) =
|
proc handleNodeLogin(self: LoginController, data: Signal) =
|
||||||
var response = NodeSignal(data)
|
var response = NodeSignal(data)
|
||||||
self.view.setLastLoginResponse($response.event.toJson)
|
self.view.setLastLoginResponse($response.event.toJson)
|
||||||
if ?.response.event.error == "" and self.model.currentAccount != nil:
|
if ?.response.event.error == "" and self.status.accounts.currentAccount != nil:
|
||||||
self.appEvents.emit("login", AccountArgs(account: self.model.currentAccount))
|
self.status.events.emit("login", AccountArgs(account: self.status.accounts.currentAccount))
|
||||||
|
|
||||||
method onSignal(self: LoginController, data: Signal) =
|
method onSignal(self: LoginController, data: Signal) =
|
||||||
if data.signalType == SignalType.NodeLogin:
|
if data.signalType == SignalType.NodeLogin:
|
||||||
self.handleNodeLogin(data)
|
self.handleNodeLogin(data)
|
||||||
else:
|
else:
|
||||||
discard
|
discard
|
||||||
|
|
|
@ -10,6 +10,8 @@ import json_serialization
|
||||||
import core
|
import core
|
||||||
import ../../status/accounts as AccountModel
|
import ../../status/accounts as AccountModel
|
||||||
|
|
||||||
|
import ../../status/status
|
||||||
|
|
||||||
type
|
type
|
||||||
AccountRoles {.pure.} = enum
|
AccountRoles {.pure.} = enum
|
||||||
Username = UserRole + 1,
|
Username = UserRole + 1,
|
||||||
|
@ -18,9 +20,9 @@ type
|
||||||
|
|
||||||
QtObject:
|
QtObject:
|
||||||
type LoginView* = ref object of QAbstractListModel
|
type LoginView* = ref object of QAbstractListModel
|
||||||
|
status: Status
|
||||||
accounts: seq[NodeAccount]
|
accounts: seq[NodeAccount]
|
||||||
lastLoginResponse: string
|
lastLoginResponse: string
|
||||||
model*: AccountModel
|
|
||||||
|
|
||||||
proc setup(self: LoginView) =
|
proc setup(self: LoginView) =
|
||||||
self.QAbstractListModel.setup
|
self.QAbstractListModel.setup
|
||||||
|
@ -29,11 +31,11 @@ QtObject:
|
||||||
self.QAbstractListModel.delete
|
self.QAbstractListModel.delete
|
||||||
self.accounts = @[]
|
self.accounts = @[]
|
||||||
|
|
||||||
proc newLoginView*(model: AccountModel): LoginView =
|
proc newLoginView*(status: Status): LoginView =
|
||||||
new(result, delete)
|
new(result, delete)
|
||||||
result.accounts = @[]
|
result.accounts = @[]
|
||||||
result.lastLoginResponse = ""
|
result.lastLoginResponse = ""
|
||||||
result.model = model
|
result.status = status
|
||||||
result.setup
|
result.setup
|
||||||
|
|
||||||
proc addAccountToList*(self: LoginView, account: NodeAccount) =
|
proc addAccountToList*(self: LoginView, account: NodeAccount) =
|
||||||
|
@ -64,7 +66,7 @@ QtObject:
|
||||||
|
|
||||||
proc login(self: LoginView, selectedAccountIndex: int, password: string): string {.slot.} =
|
proc login(self: LoginView, selectedAccountIndex: int, password: string): string {.slot.} =
|
||||||
try:
|
try:
|
||||||
result = self.model.login(selectedAccountIndex, password).toJson
|
result = self.status.accounts.login(selectedAccountIndex, password).toJson
|
||||||
except:
|
except:
|
||||||
let
|
let
|
||||||
e = getCurrentException()
|
e = getCurrentException()
|
||||||
|
|
|
@ -5,20 +5,20 @@ import ../../signals/types
|
||||||
import ../../status/node
|
import ../../status/node
|
||||||
import view
|
import view
|
||||||
|
|
||||||
|
import ../../status/status
|
||||||
|
|
||||||
logScope:
|
logScope:
|
||||||
topics = "node"
|
topics = "node"
|
||||||
|
|
||||||
type NodeController* = ref object of SignalSubscriber
|
type NodeController* = ref object of SignalSubscriber
|
||||||
model*: NodeModel
|
status*: Status
|
||||||
view*: NodeView
|
view*: NodeView
|
||||||
variant*: QVariant
|
variant*: QVariant
|
||||||
appEvents*: EventEmitter
|
|
||||||
|
|
||||||
proc newController*(appEvents: EventEmitter): NodeController =
|
proc newController*(status: Status): NodeController =
|
||||||
result = NodeController()
|
result = NodeController()
|
||||||
result.appEvents = appEvents
|
result.status = status
|
||||||
result.model = newNodeModel()
|
result.view = newNodeView(status)
|
||||||
result.view = newNodeView(result.model)
|
|
||||||
result.variant = newQVariant(result.view)
|
result.variant = newQVariant(result.view)
|
||||||
|
|
||||||
proc delete*(self: NodeController) =
|
proc delete*(self: NodeController) =
|
||||||
|
|
|
@ -1,18 +1,19 @@
|
||||||
import NimQml
|
import NimQml
|
||||||
import ../../status/node
|
import ../../status/node
|
||||||
|
import ../../status/status
|
||||||
|
|
||||||
QtObject:
|
QtObject:
|
||||||
type NodeView* = ref object of QObject
|
type NodeView* = ref object of QObject
|
||||||
model: NodeModel
|
status*: Status
|
||||||
callResult: string
|
callResult: string
|
||||||
lastMessage*: string
|
lastMessage*: string
|
||||||
|
|
||||||
proc setup(self: NodeView) =
|
proc setup(self: NodeView) =
|
||||||
self.QObject.setup
|
self.QObject.setup
|
||||||
|
|
||||||
proc newNodeView*(model: NodeModel): NodeView =
|
proc newNodeView*(status: Status): NodeView =
|
||||||
new(result)
|
new(result)
|
||||||
result.model = model
|
result.status = status
|
||||||
result.callResult = "Use this tool to call JSONRPC methods"
|
result.callResult = "Use this tool to call JSONRPC methods"
|
||||||
result.lastMessage = ""
|
result.lastMessage = ""
|
||||||
result.setup
|
result.setup
|
||||||
|
@ -38,7 +39,7 @@ QtObject:
|
||||||
notify = callResultChanged
|
notify = callResultChanged
|
||||||
|
|
||||||
proc onSend*(self: NodeView, inputJSON: string) {.slot.} =
|
proc onSend*(self: NodeView, inputJSON: string) {.slot.} =
|
||||||
self.setCallResult(self.model.sendRPCMessageRaw(inputJSON))
|
self.setCallResult(self.status.node.sendRPCMessageRaw(inputJSON))
|
||||||
echo "Done!: ", self.callResult
|
echo "Done!: ", self.callResult
|
||||||
|
|
||||||
proc onMessage*(self: NodeView, message: string) {.slot.} =
|
proc onMessage*(self: NodeView, message: string) {.slot.} =
|
||||||
|
|
|
@ -8,17 +8,17 @@ import chronicles
|
||||||
import ../../signals/types
|
import ../../signals/types
|
||||||
import std/wrapnils
|
import std/wrapnils
|
||||||
|
|
||||||
|
import ../../status/status
|
||||||
|
|
||||||
type OnboardingController* = ref object of SignalSubscriber
|
type OnboardingController* = ref object of SignalSubscriber
|
||||||
view*: OnboardingView
|
view*: OnboardingView
|
||||||
variant*: QVariant
|
variant*: QVariant
|
||||||
appEvents*: EventEmitter
|
status: Status
|
||||||
model: AccountModel
|
|
||||||
|
|
||||||
proc newController*(appEvents: EventEmitter): OnboardingController =
|
proc newController*(status: Status): OnboardingController =
|
||||||
result = OnboardingController()
|
result = OnboardingController()
|
||||||
result.appEvents = appEvents
|
result.status = status
|
||||||
result.model = newAccountModel()
|
result.view = newOnboardingView(status)
|
||||||
result.view = newOnboardingView(result.model)
|
|
||||||
result.variant = newQVariant(result.view)
|
result.variant = newQVariant(result.view)
|
||||||
|
|
||||||
proc delete*(self: OnboardingController) =
|
proc delete*(self: OnboardingController) =
|
||||||
|
@ -26,15 +26,15 @@ proc delete*(self: OnboardingController) =
|
||||||
delete self.variant
|
delete self.variant
|
||||||
|
|
||||||
proc init*(self: OnboardingController) =
|
proc init*(self: OnboardingController) =
|
||||||
let accounts = self.model.generateAddresses()
|
let accounts = self.status.accounts.generateAddresses()
|
||||||
for account in accounts:
|
for account in accounts:
|
||||||
self.view.addAccountToList(account)
|
self.view.addAccountToList(account)
|
||||||
|
|
||||||
proc handleNodeLogin(self: OnboardingController, data: Signal) =
|
proc handleNodeLogin(self: OnboardingController, data: Signal) =
|
||||||
var response = NodeSignal(data)
|
var response = NodeSignal(data)
|
||||||
self.view.setLastLoginResponse($response.event.toJson)
|
self.view.setLastLoginResponse($response.event.toJson)
|
||||||
if ?.response.event.error == "" and self.model.currentAccount != nil:
|
if ?.response.event.error == "" and self.status.accounts.currentAccount != nil:
|
||||||
self.appEvents.emit("login", AccountArgs(account: self.model.currentAccount))
|
self.status.events.emit("login", AccountArgs(account: self.status.accounts.currentAccount))
|
||||||
|
|
||||||
method onSignal(self: OnboardingController, data: Signal) =
|
method onSignal(self: OnboardingController, data: Signal) =
|
||||||
if data.signalType == SignalType.NodeLogin:
|
if data.signalType == SignalType.NodeLogin:
|
||||||
|
|
|
@ -7,6 +7,7 @@ import ../../signals/types
|
||||||
import strformat
|
import strformat
|
||||||
import json_serialization
|
import json_serialization
|
||||||
import ../../status/accounts as AccountModel
|
import ../../status/accounts as AccountModel
|
||||||
|
import ../../status/status
|
||||||
|
|
||||||
type
|
type
|
||||||
AccountRoles {.pure.} = enum
|
AccountRoles {.pure.} = enum
|
||||||
|
@ -18,7 +19,7 @@ QtObject:
|
||||||
type OnboardingView* = ref object of QAbstractListModel
|
type OnboardingView* = ref object of QAbstractListModel
|
||||||
accounts*: seq[GeneratedAccount]
|
accounts*: seq[GeneratedAccount]
|
||||||
lastLoginResponse: string
|
lastLoginResponse: string
|
||||||
model*: AccountModel
|
status*: Status
|
||||||
|
|
||||||
proc setup(self: OnboardingView) =
|
proc setup(self: OnboardingView) =
|
||||||
self.QAbstractListModel.setup
|
self.QAbstractListModel.setup
|
||||||
|
@ -27,11 +28,11 @@ QtObject:
|
||||||
self.QAbstractListModel.delete
|
self.QAbstractListModel.delete
|
||||||
self.accounts = @[]
|
self.accounts = @[]
|
||||||
|
|
||||||
proc newOnboardingView*(model: AccountModel): OnboardingView =
|
proc newOnboardingView*(status: Status): OnboardingView =
|
||||||
new(result, delete)
|
new(result, delete)
|
||||||
result.accounts = @[]
|
result.accounts = @[]
|
||||||
result.lastLoginResponse = ""
|
result.lastLoginResponse = ""
|
||||||
result.model = model
|
result.status = status
|
||||||
result.setup
|
result.setup
|
||||||
|
|
||||||
proc addAccountToList*(self: OnboardingView, account: GeneratedAccount) =
|
proc addAccountToList*(self: OnboardingView, account: GeneratedAccount) =
|
||||||
|
@ -62,7 +63,7 @@ QtObject:
|
||||||
|
|
||||||
proc storeAccountAndLogin(self: OnboardingView, selectedAccountIndex: int, password: string): string {.slot.} =
|
proc storeAccountAndLogin(self: OnboardingView, selectedAccountIndex: int, password: string): string {.slot.} =
|
||||||
try:
|
try:
|
||||||
result = self.model.storeAccountAndLogin(selectedAccountIndex, password).toJson
|
result = self.status.accounts.storeAccountAndLogin(selectedAccountIndex, password).toJson
|
||||||
except:
|
except:
|
||||||
let
|
let
|
||||||
e = getCurrentException()
|
e = getCurrentException()
|
||||||
|
|
|
@ -2,21 +2,23 @@ import NimQml
|
||||||
import eventemitter
|
import eventemitter
|
||||||
import strformat
|
import strformat
|
||||||
import json
|
import json
|
||||||
import "../../status/libstatus/core" as status
|
|
||||||
import ../../status/libstatus/mailservers as status_mailservers
|
import ../../status/libstatus/mailservers as status_mailservers
|
||||||
import ../../signals/types
|
import ../../signals/types
|
||||||
import view
|
import view
|
||||||
import "../../status/libstatus/types" as status_types
|
import "../../status/libstatus/types" as status_types
|
||||||
import ../../status/profile
|
import ../../status/profile
|
||||||
|
|
||||||
|
import ../../status/status
|
||||||
|
|
||||||
type ProfileController* = object
|
type ProfileController* = object
|
||||||
view*: ProfileView
|
view*: ProfileView
|
||||||
variant*: QVariant
|
variant*: QVariant
|
||||||
appEvents*: EventEmitter
|
status*: Status
|
||||||
|
|
||||||
proc newController*(appEvents: EventEmitter): ProfileController =
|
proc newController*(status: Status): ProfileController =
|
||||||
result = ProfileController()
|
result = ProfileController()
|
||||||
result.appEvents = appEvents
|
result.status = status
|
||||||
result.view = newProfileView()
|
result.view = newProfileView()
|
||||||
result.variant = newQVariant(result.view)
|
result.variant = newQVariant(result.view)
|
||||||
|
|
||||||
|
|
|
@ -9,17 +9,17 @@ import ../../status/libstatus/wallet as status_wallet
|
||||||
import ../../status/wallet
|
import ../../status/wallet
|
||||||
import ../../signals/types
|
import ../../signals/types
|
||||||
|
|
||||||
|
import ../../status/status
|
||||||
|
|
||||||
type WalletController* = ref object of SignalSubscriber
|
type WalletController* = ref object of SignalSubscriber
|
||||||
model: WalletModel
|
status: Status
|
||||||
view*: WalletView
|
view*: WalletView
|
||||||
variant*: QVariant
|
variant*: QVariant
|
||||||
appEvents*: EventEmitter
|
|
||||||
|
|
||||||
proc newController*(appEvents: EventEmitter): WalletController =
|
proc newController*(status: Status): WalletController =
|
||||||
result = WalletController()
|
result = WalletController()
|
||||||
result.appEvents = appEvents
|
result.status = status
|
||||||
result.model = newWalletModel()
|
result.view = newWalletView(status)
|
||||||
result.view = newWalletView(result.model)
|
|
||||||
result.variant = newQVariant(result.view)
|
result.variant = newQVariant(result.view)
|
||||||
|
|
||||||
proc delete*(self: WalletController) =
|
proc delete*(self: WalletController) =
|
||||||
|
@ -28,8 +28,8 @@ proc delete*(self: WalletController) =
|
||||||
|
|
||||||
proc init*(self: WalletController) =
|
proc init*(self: WalletController) =
|
||||||
var symbol = "ETH"
|
var symbol = "ETH"
|
||||||
var eth_balance = self.model.getEthBalance("0x0000000000000000000000000000000000000000")
|
var eth_balance = self.status.wallet.getEthBalance("0x0000000000000000000000000000000000000000")
|
||||||
var usd_balance = self.model.getFiatValue(eth_balance, symbol, "USD")
|
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 asset = Asset(name:"Ethereum", symbol: symbol, value: fmt"{eth_balance:.6}", fiatValue: "$" & fmt"{usd_balance:.6}", image: fmt"../../img/token-icons/{toLowerAscii(symbol)}.svg")
|
||||||
self.view.addAssetToList(asset)
|
self.view.addAssetToList(asset)
|
||||||
|
|
|
@ -2,13 +2,14 @@ import NimQml
|
||||||
import Tables
|
import Tables
|
||||||
import views/asset_list
|
import views/asset_list
|
||||||
import ../../status/wallet
|
import ../../status/wallet
|
||||||
|
import ../../status/status
|
||||||
|
|
||||||
QtObject:
|
QtObject:
|
||||||
type
|
type
|
||||||
WalletView* = ref object of QAbstractListModel
|
WalletView* = ref object of QAbstractListModel
|
||||||
assets*: AssetsList
|
assets*: AssetsList
|
||||||
defaultAccount: string
|
defaultAccount: string
|
||||||
model: WalletModel
|
status: Status
|
||||||
|
|
||||||
proc delete(self: WalletView) =
|
proc delete(self: WalletView) =
|
||||||
self.QAbstractListModel.delete
|
self.QAbstractListModel.delete
|
||||||
|
@ -16,9 +17,9 @@ QtObject:
|
||||||
proc setup(self: WalletView) =
|
proc setup(self: WalletView) =
|
||||||
self.QAbstractListModel.setup
|
self.QAbstractListModel.setup
|
||||||
|
|
||||||
proc newWalletView*(model: WalletModel): WalletView =
|
proc newWalletView*(status: Status): WalletView =
|
||||||
new(result, delete)
|
new(result, delete)
|
||||||
result.model = model
|
result.status = status
|
||||||
result.assets = newAssetsList()
|
result.assets = newAssetsList()
|
||||||
result.setup
|
result.setup
|
||||||
|
|
||||||
|
@ -32,7 +33,7 @@ QtObject:
|
||||||
read = getAssetsList
|
read = getAssetsList
|
||||||
|
|
||||||
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.model.sendTransaction(from_value, to, value, password)
|
result = self.status.wallet.sendTransaction(from_value, to, value, password)
|
||||||
|
|
||||||
proc setDefaultAccount*(self: WalletView, account: string) =
|
proc setDefaultAccount*(self: WalletView, account: string) =
|
||||||
self.defaultAccount = account
|
self.defaultAccount = account
|
||||||
|
|
|
@ -1,21 +1,19 @@
|
||||||
import NimQml
|
import NimQml
|
||||||
|
import eventemitter
|
||||||
import chronicles
|
import chronicles
|
||||||
|
import json_serialization
|
||||||
|
|
||||||
import app/chat/core as chat
|
import app/chat/core as chat
|
||||||
import app/wallet/core as wallet
|
import app/wallet/core as wallet
|
||||||
import app/node/core as node
|
import app/node/core as node
|
||||||
import app/profile/core as profile
|
import app/profile/core as profile
|
||||||
import signals/core as signals
|
|
||||||
import app/onboarding/core as onboarding
|
import app/onboarding/core as onboarding
|
||||||
import app/login/core as login
|
import app/login/core as login
|
||||||
import state
|
import signals/core as signals
|
||||||
import status/libstatus/accounts as status_accounts
|
|
||||||
import status/libstatus/core as status_core
|
|
||||||
import status/libstatus/types as types
|
|
||||||
import status/libstatus/libstatus
|
|
||||||
import status/libstatus/types
|
import status/libstatus/types
|
||||||
import state
|
import status/libstatus/libstatus
|
||||||
import eventemitter
|
import status/status as statuslib
|
||||||
import json_serialization
|
|
||||||
|
|
||||||
var signalsQObjPointer: pointer
|
var signalsQObjPointer: pointer
|
||||||
|
|
||||||
|
@ -23,11 +21,12 @@ logScope:
|
||||||
topics = "main"
|
topics = "main"
|
||||||
|
|
||||||
proc mainProc() =
|
proc mainProc() =
|
||||||
let nodeAccounts = status_accounts.initNodeAccounts()
|
let status = statuslib.newStatusInstance()
|
||||||
|
let nodeAccounts = status.initNodeAccounts()
|
||||||
|
|
||||||
let app = newQApplication()
|
let app = newQApplication()
|
||||||
let engine = newQQmlApplicationEngine()
|
let engine = newQQmlApplicationEngine()
|
||||||
let signalController = signals.newController(app)
|
let signalController = signals.newController(app)
|
||||||
let appEvents = createEventEmitter()
|
|
||||||
|
|
||||||
defer: # Defer will run this just before mainProc() function ends
|
defer: # Defer will run this just before mainProc() function ends
|
||||||
app.delete()
|
app.delete()
|
||||||
|
@ -38,31 +37,28 @@ proc mainProc() =
|
||||||
# from the non-closure callback passed to `libstatus.setSignalEventCallback`
|
# from the non-closure callback passed to `libstatus.setSignalEventCallback`
|
||||||
signalsQObjPointer = cast[pointer](signalController.vptr)
|
signalsQObjPointer = cast[pointer](signalController.vptr)
|
||||||
|
|
||||||
var appState = state.newAppState()
|
var wallet = wallet.newController(status)
|
||||||
debug "Application State", title=appState.title
|
|
||||||
|
|
||||||
var wallet = wallet.newController(appEvents)
|
|
||||||
engine.setRootContextProperty("assetsModel", wallet.variant)
|
engine.setRootContextProperty("assetsModel", wallet.variant)
|
||||||
|
|
||||||
var chat = chat.newController(appEvents)
|
var chat = chat.newController(status)
|
||||||
engine.setRootContextProperty("chatsModel", chat.variant)
|
engine.setRootContextProperty("chatsModel", chat.variant)
|
||||||
|
|
||||||
var node = node.newController(appEvents)
|
var node = node.newController(status)
|
||||||
node.init()
|
node.init()
|
||||||
engine.setRootContextProperty("nodeModel", node.variant)
|
engine.setRootContextProperty("nodeModel", node.variant)
|
||||||
|
|
||||||
var profile = profile.newController(appEvents)
|
var profile = profile.newController(status)
|
||||||
engine.setRootContextProperty("profileModel", profile.variant)
|
engine.setRootContextProperty("profileModel", profile.variant)
|
||||||
|
|
||||||
appEvents.once("login") do(a: Args):
|
status.events.once("login") do(a: Args):
|
||||||
var args = AccountArgs(a)
|
var args = AccountArgs(a)
|
||||||
status_core.startMessenger()
|
status.startMessenger()
|
||||||
chat.init()
|
chat.init()
|
||||||
wallet.init()
|
wallet.init()
|
||||||
profile.init(args.account)
|
profile.init(args.account)
|
||||||
|
|
||||||
var login = login.newController(appEvents)
|
var login = login.newController(status)
|
||||||
var onboarding = onboarding.newController(appEvents)
|
var onboarding = onboarding.newController(status)
|
||||||
|
|
||||||
# TODO: replace this with routing
|
# TODO: replace this with routing
|
||||||
let showLogin = nodeAccounts.len > 0
|
let showLogin = nodeAccounts.len > 0
|
||||||
|
|
|
@ -1,28 +0,0 @@
|
||||||
##########################################################
|
|
||||||
## warning: this file is still very much in flux
|
|
||||||
##########################################################
|
|
||||||
|
|
||||||
type
|
|
||||||
ChatChannel = object
|
|
||||||
name*: string
|
|
||||||
|
|
||||||
Subscriber* = proc ()
|
|
||||||
|
|
||||||
type AppState* = ref object
|
|
||||||
title*: string
|
|
||||||
channels*: seq[ChatChannel]
|
|
||||||
subscribers*: seq[Subscriber]
|
|
||||||
|
|
||||||
proc newAppState*(): AppState =
|
|
||||||
result = AppState(title: "hello")
|
|
||||||
|
|
||||||
proc subscribe*(self: AppState, subscriber: Subscriber) =
|
|
||||||
self.subscribers.add(subscriber)
|
|
||||||
|
|
||||||
proc dispatch*(self: AppState) =
|
|
||||||
for subscriber in self.subscribers:
|
|
||||||
subscriber()
|
|
||||||
|
|
||||||
proc addChannel*(self: AppState, name: string) =
|
|
||||||
self.channels.add(ChatChannel(name: name))
|
|
||||||
self.dispatch()
|
|
|
@ -28,9 +28,9 @@ type
|
||||||
channels*: HashSet[string]
|
channels*: HashSet[string]
|
||||||
filters*: Table[string, string]
|
filters*: Table[string, string]
|
||||||
|
|
||||||
proc newChatModel*(): ChatModel =
|
proc newChatModel*(events: EventEmitter): ChatModel =
|
||||||
result = ChatModel()
|
result = ChatModel()
|
||||||
result.events = createEventEmitter()
|
result.events = events
|
||||||
result.channels = initHashSet[string]()
|
result.channels = initHashSet[string]()
|
||||||
result.filters = initTable[string, string]()
|
result.filters = initTable[string, string]()
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
import eventemitter
|
||||||
|
|
||||||
|
import libstatus/types
|
||||||
|
import libstatus/accounts as libstatus_accounts
|
||||||
|
import libstatus/core as libstatus_core
|
||||||
|
|
||||||
|
import chat as chat
|
||||||
|
import accounts as accounts
|
||||||
|
import wallet as wallet
|
||||||
|
import node as node
|
||||||
|
|
||||||
|
type Status* = ref object
|
||||||
|
events*: EventEmitter
|
||||||
|
chat*: ChatModel
|
||||||
|
accounts*: AccountModel
|
||||||
|
wallet*: WalletModel
|
||||||
|
node*: NodeModel
|
||||||
|
|
||||||
|
proc newStatusInstance*(): Status =
|
||||||
|
result = Status()
|
||||||
|
result.events = createEventEmitter()
|
||||||
|
result.chat = chat.newChatModel(result.events)
|
||||||
|
result.accounts = accounts.newAccountModel()
|
||||||
|
result.wallet = wallet.newWalletModel()
|
||||||
|
result.node = node.newNodeModel()
|
||||||
|
|
||||||
|
proc initNodeAccounts*(self: Status): seq[NodeAccount] =
|
||||||
|
libstatus_accounts.initNodeAccounts()
|
||||||
|
|
||||||
|
proc startMessenger*(self: Status) =
|
||||||
|
libstatus_core.startMessenger()
|
Loading…
Reference in New Issue