Add node model; simplify more; simplify callRPC
Add node model; simplify more; simplify callRPC refactor wallet to use asset model move some of wallet logic away from the controller move ChatMessage to model move chatItem model organize models folder simplify chat message and chat item rename messageList to message_list simply addresses in the controller rename mailservers list refactor how profile is set refactor/simplify profile view refactor/simplify adding mailservers rename wallet view simplify wallet assets rename nodeView to view extract channel list view extract channel list view refactor channel list / chats view move signals out of app folder simplify callRPC add raw rpc method and make node section use it add node model move accounts model inside onboard controller (for now) make events usage consistent among models and controllers; separate model events from app events
This commit is contained in:
parent
6e14749904
commit
e6199fede6
|
@ -9,10 +9,12 @@ type ChatController* = ref object of SignalSubscriber
|
||||||
view*: ChatsView
|
view*: ChatsView
|
||||||
model*: ChatModel
|
model*: ChatModel
|
||||||
variant*: QVariant
|
variant*: QVariant
|
||||||
|
appEvents*: EventEmitter
|
||||||
|
|
||||||
proc newController*(events: EventEmitter): ChatController =
|
proc newController*(appEvents: EventEmitter): ChatController =
|
||||||
result = ChatController()
|
result = ChatController()
|
||||||
result.model = newChatModel(events)
|
result.appEvents = appEvents
|
||||||
|
result.model = newChatModel()
|
||||||
result.view = newChatsView(result.model)
|
result.view = newChatsView(result.model)
|
||||||
result.variant = newQVariant(result.view)
|
result.variant = newQVariant(result.view)
|
||||||
|
|
||||||
|
|
|
@ -1,23 +1,25 @@
|
||||||
import NimQml
|
import NimQml
|
||||||
import chronicles
|
import chronicles
|
||||||
|
import eventemitter
|
||||||
import "../../status/core" as status
|
import "../../status/core" as status
|
||||||
import ../../signals/types
|
import ../../signals/types
|
||||||
|
import ../../models/node
|
||||||
import view
|
import view
|
||||||
|
|
||||||
logScope:
|
logScope:
|
||||||
topics = "node"
|
topics = "node"
|
||||||
|
|
||||||
type NodeController* = ref object of SignalSubscriber
|
type NodeController* = ref object of SignalSubscriber
|
||||||
|
model*: NodeModel
|
||||||
view*: NodeView
|
view*: NodeView
|
||||||
variant*: QVariant
|
variant*: QVariant
|
||||||
|
appEvents*: EventEmitter
|
||||||
|
|
||||||
var sendRPCMessage = proc (msg: string): string =
|
proc newController*(appEvents: EventEmitter): NodeController =
|
||||||
echo "sending RPC message"
|
|
||||||
status.callPrivateRPC(msg)
|
|
||||||
|
|
||||||
proc newController*(): NodeController =
|
|
||||||
result = NodeController()
|
result = NodeController()
|
||||||
result.view = newNodeView(sendRPCMessage)
|
result.appEvents = appEvents
|
||||||
|
result.model = newNodeModel()
|
||||||
|
result.view = newNodeView(result.model)
|
||||||
result.variant = newQVariant(result.view)
|
result.variant = newQVariant(result.view)
|
||||||
|
|
||||||
proc delete*(self: NodeController) =
|
proc delete*(self: NodeController) =
|
||||||
|
|
|
@ -1,17 +1,18 @@
|
||||||
import NimQml
|
import NimQml
|
||||||
|
import ../../models/node
|
||||||
|
|
||||||
QtObject:
|
QtObject:
|
||||||
type NodeView* = ref object of QObject
|
type NodeView* = ref object of QObject
|
||||||
|
model: NodeModel
|
||||||
callResult: string
|
callResult: string
|
||||||
sendRPCMessage: proc (msg: string): string
|
|
||||||
lastMessage*: string
|
lastMessage*: string
|
||||||
|
|
||||||
proc setup(self: NodeView) =
|
proc setup(self: NodeView) =
|
||||||
self.QObject.setup
|
self.QObject.setup
|
||||||
|
|
||||||
proc newNodeView*(sendRPCMessage: proc): NodeView =
|
proc newNodeView*(model: NodeModel): NodeView =
|
||||||
new(result)
|
new(result)
|
||||||
result.sendRPCMessage = sendRPCMessage
|
result.model = model
|
||||||
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
|
||||||
|
@ -37,7 +38,7 @@ QtObject:
|
||||||
notify = callResultChanged
|
notify = callResultChanged
|
||||||
|
|
||||||
proc onSend*(self: NodeView, inputJSON: string) {.slot.} =
|
proc onSend*(self: NodeView, inputJSON: string) {.slot.} =
|
||||||
self.setCallResult(self.sendRPCMessage(inputJSON))
|
self.setCallResult(self.model.sendRPCMessageRaw(inputJSON))
|
||||||
echo "Done!: ", self.callResult
|
echo "Done!: ", self.callResult
|
||||||
|
|
||||||
proc onMessage*(self: NodeView, message: string) {.slot.} =
|
proc onMessage*(self: NodeView, message: string) {.slot.} =
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import NimQml
|
import NimQml
|
||||||
import ../../models/accounts as Models
|
import ../../models/accounts
|
||||||
import ../../signals/types
|
import ../../signals/types
|
||||||
import eventemitter
|
import eventemitter
|
||||||
import view
|
import view
|
||||||
|
@ -8,12 +8,16 @@ type OnboardingController* = ref object of SignalSubscriber
|
||||||
view*: OnboardingView
|
view*: OnboardingView
|
||||||
variant*: QVariant
|
variant*: QVariant
|
||||||
model*: AccountModel
|
model*: AccountModel
|
||||||
|
appEvents*: EventEmitter
|
||||||
|
|
||||||
proc newController*(model: AccountModel): OnboardingController =
|
proc newController*(appEvents: EventEmitter): OnboardingController =
|
||||||
result = OnboardingController()
|
result = OnboardingController()
|
||||||
result.model = model
|
result.appEvents = appEvents
|
||||||
|
result.model = newAccountModel()
|
||||||
result.view = newOnboardingView(result.model)
|
result.view = newOnboardingView(result.model)
|
||||||
result.variant = newQVariant(result.view)
|
result.variant = newQVariant(result.view)
|
||||||
|
result.model.events.on("accountsReady") do(a: Args):
|
||||||
|
appEvents.emit("accountsReady", a)
|
||||||
|
|
||||||
proc delete*(self: OnboardingController) =
|
proc delete*(self: OnboardingController) =
|
||||||
delete self.view
|
delete self.view
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import NimQml
|
import NimQml
|
||||||
|
import eventemitter
|
||||||
import strformat
|
import strformat
|
||||||
import json
|
import json
|
||||||
import "../../status/core" as status
|
import "../../status/core" as status
|
||||||
|
@ -11,9 +12,11 @@ import ../../models/profile
|
||||||
type ProfileController* = ref object of SignalSubscriber
|
type ProfileController* = ref object of SignalSubscriber
|
||||||
view*: ProfileView
|
view*: ProfileView
|
||||||
variant*: QVariant
|
variant*: QVariant
|
||||||
|
appEvents*: EventEmitter
|
||||||
|
|
||||||
proc newController*(): ProfileController =
|
proc newController*(appEvents: EventEmitter): ProfileController =
|
||||||
result = ProfileController()
|
result = ProfileController()
|
||||||
|
result.appEvents = appEvents
|
||||||
result.view = newProfileView()
|
result.view = newProfileView()
|
||||||
result.variant = newQVariant(result.view)
|
result.variant = newQVariant(result.view)
|
||||||
|
|
||||||
|
|
|
@ -12,10 +12,12 @@ type WalletController* = ref object of SignalSubscriber
|
||||||
model: WalletModel
|
model: WalletModel
|
||||||
view*: WalletView
|
view*: WalletView
|
||||||
variant*: QVariant
|
variant*: QVariant
|
||||||
|
appEvents*: EventEmitter
|
||||||
|
|
||||||
proc newController*(events: EventEmitter): WalletController =
|
proc newController*(appEvents: EventEmitter): WalletController =
|
||||||
result = WalletController()
|
result = WalletController()
|
||||||
result.model = newWalletModel(events)
|
result.appEvents = appEvents
|
||||||
|
result.model = newWalletModel()
|
||||||
result.view = newWalletView(result.model)
|
result.view = newWalletView(result.model)
|
||||||
result.variant = newQVariant(result.view)
|
result.variant = newQVariant(result.view)
|
||||||
|
|
||||||
|
|
|
@ -18,10 +18,10 @@ type
|
||||||
events*: EventEmitter
|
events*: EventEmitter
|
||||||
channels*: HashSet[string]
|
channels*: HashSet[string]
|
||||||
|
|
||||||
proc newChatModel*(events: EventEmitter): ChatModel =
|
proc newChatModel*(): ChatModel =
|
||||||
result = ChatModel()
|
result = ChatModel()
|
||||||
|
result.events = createEventEmitter()
|
||||||
result.channels = initHashSet[string]()
|
result.channels = initHashSet[string]()
|
||||||
result.events = events
|
|
||||||
|
|
||||||
proc delete*(self: ChatModel) =
|
proc delete*(self: ChatModel) =
|
||||||
discard
|
discard
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
import eventemitter
|
||||||
|
# import json
|
||||||
|
# import strformat
|
||||||
|
# import strutils
|
||||||
|
import "../status/core" as status
|
||||||
|
|
||||||
|
type NodeModel* = ref object
|
||||||
|
events*: EventEmitter
|
||||||
|
|
||||||
|
proc newNodeModel*(): NodeModel =
|
||||||
|
result = NodeModel()
|
||||||
|
result.events = createEventEmitter()
|
||||||
|
|
||||||
|
proc delete*(self: NodeModel) =
|
||||||
|
discard
|
||||||
|
|
||||||
|
proc sendRPCMessageRaw*(self: NodeModel, msg: string): string =
|
||||||
|
echo "sending RPC message"
|
||||||
|
status.callPrivateRPCRaw(msg)
|
|
@ -10,9 +10,9 @@ type Asset* = ref object
|
||||||
type WalletModel* = ref object
|
type WalletModel* = ref object
|
||||||
events*: EventEmitter
|
events*: EventEmitter
|
||||||
|
|
||||||
proc newWalletModel*(events: EventEmitter): WalletModel =
|
proc newWalletModel*(): WalletModel =
|
||||||
result = WalletModel()
|
result = WalletModel()
|
||||||
result.events = events
|
result.events = createEventEmitter()
|
||||||
|
|
||||||
proc delete*(self: WalletModel) =
|
proc delete*(self: WalletModel) =
|
||||||
discard
|
discard
|
||||||
|
|
|
@ -9,6 +9,7 @@ import app/onboarding/core as onboarding
|
||||||
import state
|
import state
|
||||||
import json
|
import json
|
||||||
import status/accounts as status_accounts
|
import status/accounts as status_accounts
|
||||||
|
import status/core as status_core
|
||||||
import status/chat as status_chat
|
import status/chat as status_chat
|
||||||
import status/types as types
|
import status/types as types
|
||||||
import status/libstatus
|
import status/libstatus
|
||||||
|
@ -27,7 +28,7 @@ proc mainProc() =
|
||||||
let app = newQApplication()
|
let app = newQApplication()
|
||||||
let engine = newQQmlApplicationEngine()
|
let engine = newQQmlApplicationEngine()
|
||||||
let signalController = signals.newController(app)
|
let signalController = signals.newController(app)
|
||||||
let events = createEventEmitter()
|
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()
|
||||||
|
@ -41,28 +42,29 @@ proc mainProc() =
|
||||||
var appState = state.newAppState()
|
var appState = state.newAppState()
|
||||||
debug "Application State", title=appState.title
|
debug "Application State", title=appState.title
|
||||||
|
|
||||||
var wallet = wallet.newController(events)
|
var wallet = wallet.newController(appEvents)
|
||||||
engine.setRootContextProperty("assetsModel", wallet.variant)
|
engine.setRootContextProperty("assetsModel", wallet.variant)
|
||||||
|
|
||||||
var chat = chat.newController(events)
|
var chat = chat.newController(appEvents)
|
||||||
chat.init()
|
chat.init()
|
||||||
engine.setRootContextProperty("chatsModel", chat.variant)
|
engine.setRootContextProperty("chatsModel", chat.variant)
|
||||||
|
|
||||||
var node = node.newController()
|
var node = node.newController(appEvents)
|
||||||
node.init()
|
node.init()
|
||||||
engine.setRootContextProperty("nodeModel", node.variant)
|
engine.setRootContextProperty("nodeModel", node.variant)
|
||||||
|
|
||||||
var profile = profile.newController()
|
var profile = profile.newController(appEvents)
|
||||||
engine.setRootContextProperty("profileModel", profile.variant)
|
engine.setRootContextProperty("profileModel", profile.variant)
|
||||||
|
|
||||||
var accountsModel = newAccountModel()
|
# var accountsModel = newAccountModel()
|
||||||
accountsModel.events.on("accountsReady") do(a: Args):
|
appEvents.on("accountsReady") do(a: Args):
|
||||||
var args = AccountArgs(a)
|
var args = AccountArgs(a)
|
||||||
status_chat.startMessenger()
|
status_core.startMessenger()
|
||||||
wallet.init()
|
wallet.init()
|
||||||
profile.init(args.account) # TODO: use correct account
|
profile.init(args.account) # TODO: use correct account
|
||||||
|
|
||||||
var onboarding = onboarding.newController(accountsModel)
|
# var onboarding = onboarding.newController(accountsModel)
|
||||||
|
var onboarding = onboarding.newController(appEvents)
|
||||||
onboarding.init()
|
onboarding.init()
|
||||||
engine.setRootContextProperty("onboardingModel", onboarding.variant)
|
engine.setRootContextProperty("onboardingModel", onboarding.variant)
|
||||||
|
|
||||||
|
@ -78,7 +80,8 @@ proc mainProc() =
|
||||||
chat.load(channel.name)
|
chat.load(channel.name)
|
||||||
)
|
)
|
||||||
|
|
||||||
accountsModel.events.on("accountsReady") do(a: Args):
|
# accountsModel.appEvents.on("accountsReady") do(a: Args):
|
||||||
|
appEvents.on("accountsReady") do(a: Args):
|
||||||
appState.addChannel("test")
|
appState.addChannel("test")
|
||||||
appState.addChannel("test2")
|
appState.addChannel("test2")
|
||||||
appState.addChannel("status")
|
appState.addChannel("status")
|
||||||
|
|
|
@ -8,15 +8,7 @@ import os
|
||||||
import uuids
|
import uuids
|
||||||
|
|
||||||
proc queryAccounts*(): string =
|
proc queryAccounts*(): string =
|
||||||
var payload = %* {
|
var response = callPrivateRPC("eth_accounts")
|
||||||
"jsonrpc": "2.0",
|
|
||||||
"method": "eth_accounts",
|
|
||||||
"params": [
|
|
||||||
[]
|
|
||||||
]
|
|
||||||
}
|
|
||||||
var response = callPrivateRPC($payload)
|
|
||||||
echo response
|
|
||||||
result = parseJson(response)["result"][0].getStr()
|
result = parseJson(response)["result"][0].getStr()
|
||||||
|
|
||||||
proc generateAddresses*(): string =
|
proc generateAddresses*(): string =
|
||||||
|
|
|
@ -1,37 +1,17 @@
|
||||||
import libstatus
|
import core
|
||||||
import json
|
import json
|
||||||
import utils
|
import utils
|
||||||
|
|
||||||
proc startMessenger*() =
|
|
||||||
let payload = %* {
|
|
||||||
"jsonrpc": "2.0",
|
|
||||||
"id": 3, #TODO:
|
|
||||||
"method": "startMessenger".prefix,
|
|
||||||
"params": []
|
|
||||||
}
|
|
||||||
discard $libstatus.callPrivateRPC($payload)
|
|
||||||
# TODO: create template for error handling
|
|
||||||
|
|
||||||
proc loadFilters*(chatId: string, oneToOne = false) =
|
proc loadFilters*(chatId: string, oneToOne = false) =
|
||||||
let payload = %* {
|
discard callPrivateRPC("loadFilters".prefix, %* [
|
||||||
"jsonrpc": "2.0",
|
|
||||||
"id": 3, #TODO:
|
|
||||||
"method": "loadFilters".prefix,
|
|
||||||
"params": [
|
|
||||||
[{
|
[{
|
||||||
"ChatID": chatId,
|
"ChatID": chatId,
|
||||||
"OneToOne": oneToOne
|
"OneToOne": oneToOne
|
||||||
}]
|
}]
|
||||||
]
|
])
|
||||||
}
|
|
||||||
discard $libstatus.callPrivateRPC($payload)
|
|
||||||
|
|
||||||
proc saveChat*(chatId: string, oneToOne = false) =
|
proc saveChat*(chatId: string, oneToOne = false) =
|
||||||
let payload = %* {
|
discard callPrivateRPC("saveChat".prefix, %* [
|
||||||
"jsonrpc": "2.0",
|
|
||||||
"id": 4,
|
|
||||||
"method": "saveChat".prefix,
|
|
||||||
"params": [ #TODO: determine where do these values come from
|
|
||||||
{
|
{
|
||||||
"lastClockValue": 0,
|
"lastClockValue": 0,
|
||||||
"color": "#51d0f0",
|
"color": "#51d0f0",
|
||||||
|
@ -43,29 +23,13 @@ proc saveChat*(chatId: string, oneToOne = false) =
|
||||||
"chatType": if oneToOne: 1 else: 2,
|
"chatType": if oneToOne: 1 else: 2,
|
||||||
"timestamp": 1588940692659
|
"timestamp": 1588940692659
|
||||||
}
|
}
|
||||||
]
|
])
|
||||||
}
|
|
||||||
discard $libstatus.callPrivateRPC($payload)
|
|
||||||
|
|
||||||
proc chatMessages*(chatId: string) =
|
proc chatMessages*(chatId: string) =
|
||||||
let payload = %* {
|
discard callPrivateRPC("chatMessages".prefix, %* [chatId, nil, 20])
|
||||||
"jsonrpc": "2.0",
|
|
||||||
"id": 3, #TODO:
|
|
||||||
"method": "chatMessages".prefix,
|
|
||||||
"params": [
|
|
||||||
chatId, nil, 20
|
|
||||||
]
|
|
||||||
}
|
|
||||||
discard $libstatus.callPrivateRPC($payload)
|
|
||||||
# TODO: create template for error handling
|
|
||||||
|
|
||||||
|
|
||||||
proc sendChatMessage*(chatId: string, msg: string): string =
|
proc sendChatMessage*(chatId: string, msg: string): string =
|
||||||
let payload = %* {
|
callPrivateRPC("sendChatMessage".prefix, %* [
|
||||||
"jsonrpc": "2.0",
|
|
||||||
"id": 40,
|
|
||||||
"method": "sendChatMessage".prefix,
|
|
||||||
"params": [
|
|
||||||
{
|
{
|
||||||
"chatId": chatId,
|
"chatId": chatId,
|
||||||
"text": msg,
|
"text": msg,
|
||||||
|
@ -74,6 +38,4 @@ proc sendChatMessage*(chatId: string, msg: string): string =
|
||||||
"sticker": nil,
|
"sticker": nil,
|
||||||
"contentType": 1
|
"contentType": 1
|
||||||
}
|
}
|
||||||
]
|
])
|
||||||
}
|
|
||||||
$libstatus.callPrivateRPC($payload)
|
|
||||||
|
|
|
@ -1,16 +1,30 @@
|
||||||
|
import json
|
||||||
import libstatus
|
import libstatus
|
||||||
import chat
|
|
||||||
import nimcrypto
|
import nimcrypto
|
||||||
|
import utils
|
||||||
proc startMessenger*() =
|
|
||||||
chat.startMessenger()
|
|
||||||
|
|
||||||
proc callRPC*(inputJSON: string): string =
|
proc callRPC*(inputJSON: string): string =
|
||||||
return $libstatus.callRPC(inputJSON)
|
return $libstatus.callRPC(inputJSON)
|
||||||
|
|
||||||
proc callPrivateRPC*(inputJSON: string): string =
|
proc callPrivateRPCRaw*(inputJSON: string): string =
|
||||||
return $libstatus.callPrivateRPC(inputJSON)
|
return $libstatus.callPrivateRPC(inputJSON)
|
||||||
|
|
||||||
|
proc callPrivateRPC*(methodName: string, payload = %* []): string =
|
||||||
|
try:
|
||||||
|
let inputJSON = %* {
|
||||||
|
"jsonrpc": "2.0",
|
||||||
|
"method": methodName,
|
||||||
|
"params": %payload
|
||||||
|
}
|
||||||
|
echo inputJSON
|
||||||
|
result = $libstatus.callPrivateRPC($inputJSON)
|
||||||
|
except:
|
||||||
|
echo "error doing rpc request"
|
||||||
|
echo methodName
|
||||||
|
|
||||||
proc sendTransaction*(inputJSON: string, password: string): string =
|
proc sendTransaction*(inputJSON: string, password: string): string =
|
||||||
var hashed_password = "0x" & $keccak_256.digest(password)
|
var hashed_password = "0x" & $keccak_256.digest(password)
|
||||||
return $libstatus.sendTransaction(inputJSON, hashed_password)
|
return $libstatus.sendTransaction(inputJSON, hashed_password)
|
||||||
|
|
||||||
|
proc startMessenger*() =
|
||||||
|
discard callPrivateRPC("startMessenger".prefix)
|
||||||
|
|
|
@ -7,14 +7,7 @@ import stint
|
||||||
import strutils
|
import strutils
|
||||||
|
|
||||||
proc getAccounts*(): seq[string] =
|
proc getAccounts*(): seq[string] =
|
||||||
var payload = %* {
|
var response = callPrivateRPC("eth_accounts")
|
||||||
"jsonrpc": "2.0",
|
|
||||||
"method": "eth_accounts",
|
|
||||||
"params": [
|
|
||||||
[]
|
|
||||||
]
|
|
||||||
}
|
|
||||||
var response = status.callPrivateRPC($payload)
|
|
||||||
result = parseJson(response)["result"].to(seq[string])
|
result = parseJson(response)["result"].to(seq[string])
|
||||||
|
|
||||||
proc getAccount*(): string =
|
proc getAccount*(): string =
|
||||||
|
@ -39,16 +32,8 @@ proc getPrice*(crypto: string, fiat: string): string =
|
||||||
$parseJson(response.body)["USD"]
|
$parseJson(response.body)["USD"]
|
||||||
|
|
||||||
proc getBalance*(address: string): string =
|
proc getBalance*(address: string): string =
|
||||||
let payload = %* {
|
let payload = %* [address, "latest"]
|
||||||
"jsonrpc": "2.0",
|
parseJson(status.callPrivateRPC("eth_getBalance", payload))["result"].str
|
||||||
"id": 50,
|
|
||||||
"method": "eth_getBalance",
|
|
||||||
"params": [
|
|
||||||
address,
|
|
||||||
"latest"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
parseJson(status.callPrivateRPC($payload))["result"].str
|
|
||||||
|
|
||||||
proc hex2Eth*(input: string): string =
|
proc hex2Eth*(input: string): string =
|
||||||
var value = fromHex(Stuint[256], input)
|
var value = fromHex(Stuint[256], input)
|
||||||
|
|
Loading…
Reference in New Issue