remove most direct references to libstatus; document some common issues

This commit is contained in:
Iuri Matias 2021-06-08 10:48:56 -04:00
parent 36c25aaab9
commit e8de7e0c99
14 changed files with 76 additions and 56 deletions

View File

@ -88,6 +88,14 @@ or using typedesc param with `:` like:
`self.status.settings.getSetting[:string](Setting.SigningPhrase)`
### undeclared identifier: 'result'
Typically this means the method has no return type and so `result =` isn't necessary
### expression 'method(param)' has no type (or is ambiguous)
This usually means a method that has no return type is being discarded
## Warnings
### QML anchor warnings

View File

@ -3,8 +3,7 @@ import ../../status/chat as chat_model
import ../../status/messages as messages_model
import ../../status/signals/types
import ../../status/libstatus/types as status_types
import ../../status/libstatus/settings as status_settings
import ../../status/[chat, contacts, status, wallet, stickers]
import ../../status/[chat, contacts, status, wallet, stickers, settings]
import view, views/channels_list, views/message_list, views/reactions, views/stickers as stickers_view
import ../../eventemitter
@ -34,8 +33,8 @@ proc init*(self: ChatController) =
self.handleChatEvents()
self.handleSignals()
let pubKey = status_settings.getSetting[string](Setting.PublicKey, "0x0")
let messagesFromContactsOnly = status_settings.getSetting[bool](Setting.MessagesFromContactsOnly, false, true)
let pubKey = self.status.settings.getSetting[:string](Setting.PublicKey, "0x0")
let messagesFromContactsOnly = self.status.settings.getSetting[:bool](Setting.MessagesFromContactsOnly, false, true)
self.view.pubKey = pubKey
self.status.chat.init(pubKey, messagesFromContactsOnly)

View File

@ -1,7 +1,6 @@
import NimQml, Tables, std/wrapnils
import ../../../status/[chat/chat, status, ens, accounts]
import ../../../status/[chat/chat, status, ens, accounts, settings]
from ../../../status/libstatus/types import Setting
import ../../../status/libstatus/settings as status_settings
import ../../../status/libstatus/utils as status_utils
import chat_members
@ -151,7 +150,7 @@ QtObject:
proc isMember*(self: ChatItemView): bool {.slot.} =
if self.chatItem.isNil: return false
let pubKey = status_settings.getSetting[string](Setting.PublicKey, "0x0")
let pubKey = self.status.settings.getSetting[:string](Setting.PublicKey, "0x0")
return self.chatItem.isMember(pubKey)
QtProperty[bool] isMember:

View File

@ -1,7 +1,6 @@
import NimQml, tables, json, chronicles
import ../../../status/[status, chat/message, chat/chat]
import ../../../status/[status, chat/message, chat/chat, settings]
import message_list, chat_item
import ../../../status/libstatus/settings as status_settings
import ../../../status/libstatus/utils as status_utils
import ../../../status/libstatus/types
@ -30,7 +29,7 @@ QtObject:
result.setup
proc init*(self: ReactionView) =
self.pubKey = status_settings.getSetting[string](Setting.PublicKey, "0x0")
self.pubKey = self.status.settings.getSetting[:string](Setting.PublicKey, "0x0")
proc messageEmojiReactionId(self: ReactionView, chatId: string, messageId: string, emojiId: int): string =
let chat = self.status.chat.channels[chatId]

View File

@ -4,9 +4,8 @@ import ../../status/libstatus/mailservers as status_mailservers
import ../../status/signals/types
import ../../status/libstatus/accounts/constants
import ../../status/libstatus/types as status_types
import ../../status/libstatus/settings as status_settings
import ../../status/profile/[profile, mailserver]
import ../../status/status
import ../../status/[status, settings]
import ../../status/contacts as status_contacts
import ../../status/chat as status_chat
import ../../status/devices as status_devices
@ -37,10 +36,10 @@ proc delete*(self: ProfileController) =
proc init*(self: ProfileController, account: Account) =
let profile = account.toProfileModel()
let pubKey = status_settings.getSetting[string](Setting.PublicKey, "0x0")
let network = status_settings.getSetting[string](Setting.Networks_CurrentNetwork, constants.DEFAULT_NETWORK_NAME)
let appearance = status_settings.getSetting[int](Setting.Appearance)
let messagesFromContactsOnly = status_settings.getSetting[bool](Setting.MessagesFromContactsOnly)
let pubKey = self.status.settings.getSetting[:string](Setting.PublicKey, "0x0")
let network = self.status.settings.getSetting[:string](Setting.Networks_CurrentNetwork, constants.DEFAULT_NETWORK_NAME)
let appearance = self.status.settings.getSetting[:int](Setting.Appearance)
let messagesFromContactsOnly = self.status.settings.getSetting[:bool](Setting.MessagesFromContactsOnly)
profile.appearance = appearance
profile.id = pubKey
profile.address = account.keyUid
@ -58,11 +57,11 @@ proc init*(self: ProfileController, account: Account) =
self.view.ens.init()
self.view.initialized()
for name, endpoint in self.status.fleet.config.getMailservers(status_settings.getFleet()).pairs():
for name, endpoint in self.status.fleet.config.getMailservers(self.status.settings.getFleet()).pairs():
let mailserver = MailServer(name: name, endpoint: endpoint)
self.view.mailservers.add(mailserver)
for mailserver in status_settings.getMailservers().getElems():
for mailserver in self.status.settings.getMailservers().getElems():
let mailserver = MailServer(name: mailserver["name"].getStr(), endpoint: mailserver["address"].getStr())
self.view.mailservers.add(mailserver)

View File

@ -6,7 +6,6 @@ import ../../status/profile/profile
import ../../status/profile as status_profile
import ../../status/contacts as status_contacts
import ../../status/accounts as status_accounts
import ../../status/libstatus/settings as status_settings
import ../../status/status
import ../../status/ens as status_ens
import ../../status/chat/chat

View File

@ -8,7 +8,7 @@ import ../../../status/ens as status_ens
import ../../../status/libstatus/wallet as status_wallet
import ../../../status/libstatus/settings as status_settings
import ../../../status/libstatus/utils as libstatus_utils
import ../../../status/status
import ../../../status/[status, settings]
import ../../../status/wallet
import sets
import web3/ethtypes
@ -105,7 +105,7 @@ QtObject:
result.setup
proc init*(self: EnsManager) =
self.usernames = status_settings.getSetting[seq[string]](Setting.Usernames, @[])
self.usernames = getSetting[seq[string]](self.status.settings, Setting.Usernames, @[])
# Get pending ens names
let pendingTransactions = status_wallet.getPendingTransactions()
@ -131,7 +131,7 @@ QtObject:
self.endInsertRows()
proc getPreferredUsername(self: EnsManager): string {.slot.} =
result = status_settings.getSetting[string](Setting.PreferredUsername, "")
result = self.status.settings.getSetting[:string](Setting.PreferredUsername, "")
proc preferredUsernameChanged(self: EnsManager) {.signal.}
@ -143,7 +143,7 @@ QtObject:
proc setPreferredUsername(self: EnsManager, newENS: string) {.slot.} =
if not self.isPending(newENS):
discard status_settings.saveSetting(Setting.PreferredUsername, newENS)
discard self.status.settings.saveSetting(Setting.PreferredUsername, newENS)
self.preferredUsernameChanged()
QtProperty[string] preferredUsername:
@ -152,9 +152,9 @@ QtObject:
write = setPreferredUsername
proc connect(self: EnsManager, ensUsername: string) =
var usernames = status_settings.getSetting[seq[string]](Setting.Usernames, @[])
var usernames = getSetting[seq[string]](self.status.settings, Setting.Usernames, @[])
usernames.add ensUsername
discard status_settings.saveSetting(Setting.Usernames, %*usernames)
discard self.status.settings.saveSetting(Setting.Usernames, %*usernames)
proc loading(self: EnsManager, isLoading: bool) {.signal.}
@ -235,14 +235,14 @@ QtObject:
proc registerENSGasEstimate(self: EnsManager, ensUsername: string, address: string): int {.slot.} =
var success: bool
let pubKey = status_settings.getSetting[string](Setting.PublicKey, "0x0")
let pubKey = self.status.settings.getSetting[:string](Setting.PublicKey, "0x0")
result = registerUsernameEstimateGas(ensUsername, address, pubKey, success)
if not success:
result = 380000
proc registerENS*(self: EnsManager, username: string, address: string, gas: string, gasPrice: string, password: string): string {.slot.} =
var success: bool
let pubKey = status_settings.getSetting[string](Setting.PublicKey, "0x0")
let pubKey = self.status.settings.getSetting[:string](Setting.PublicKey, "0x0")
let response = registerUsername(username, pubKey, address, gas, gasPrice, password, success)
result = $(%* { "result": %response, "success": %success })
@ -254,14 +254,14 @@ QtObject:
proc setPubKeyGasEstimate(self: EnsManager, ensUsername: string, address: string): int {.slot.} =
var success: bool
let pubKey = status_settings.getSetting[string](Setting.PublicKey, "0x0")
let pubKey = self.status.settings.getSetting[:string](Setting.PublicKey, "0x0")
result = setPubKeyEstimateGas(ensUsername, address, pubKey, success)
if not success:
result = 80000
proc setPubKey(self: EnsManager, username: string, address: string, gas: string, gasPrice: string, password: string): string {.slot.} =
var success: bool
let pubKey = status_settings.getSetting[string](Setting.PublicKey, "0x0")
let pubKey = self.status.settings.getSetting[:string](Setting.PublicKey, "0x0")
let response = setPubKey(username, pubKey, address, gas, gasPrice, password, success)
result = $(%* { "result": %response, "success": %success })
if success:

View File

@ -1,9 +1,8 @@
import NimQml
import chronicles, strutils
import ../../../status/libstatus/types as status_types
import ../../../status/libstatus/settings as status_settings
import ../../../status/libstatus/accounts as status_accounts
import ../../../status/status
import ../../../status/[status, settings]
QtObject:
type Fleets * = ref object of QObject
@ -24,19 +23,19 @@ QtObject:
proc fleetChanged*(self: Fleets, newFleet: string) {.signal.}
proc triggerFleetChange*(self: Fleets) {.slot.} =
self.fleetChanged($status_settings.getFleet())
self.fleetChanged($self.status.settings.getFleet())
proc setFleet*(self: Fleets, newFleet: string) {.slot.} =
discard status_settings.saveSetting(Setting.Fleet, newFleet)
discard self.status.settings.saveSetting(Setting.Fleet, newFleet)
let fleet = parseEnum[Fleet](newFleet)
let installationId = status_settings.getSetting[string](Setting.InstallationId)
let updatedNodeConfig = status_accounts.getNodeConfig(self.status.fleet.config, installationId, $status_settings.getCurrentNetwork(), fleet)
discard status_settings.saveSetting(Setting.NodeConfig, updatedNodeConfig)
let installationId = self.status.settings.getSetting[:string](Setting.InstallationId)
let updatedNodeConfig = status_accounts.getNodeConfig(self.status.fleet.config, installationId, $self.status.settings.getCurrentNetwork(), fleet)
discard self.status.settings.saveSetting(Setting.NodeConfig, updatedNodeConfig)
self.fleetChanged(newFleet)
quit(QuitSuccess) # quits the app TODO: change this to logout instead when supported
proc getFleet*(self: Fleets): string {.slot.} = $status_settings.getFleet()
proc getFleet*(self: Fleets): string {.slot.} = $self.status.settings.getFleet()
QtProperty[string] fleet:
read = getFleet

View File

@ -1,8 +1,7 @@
import NimQml, chronicles
import ../../../status/status
import ../../../status/[status, settings]
import ../../../status/profile/mailserver
import mailservers_list
import ../../../status/libstatus/settings as status_settings
import ../../../status/tasks/marathon/mailserver/worker
logScope:
@ -51,18 +50,18 @@ QtObject:
self.activeMailserverChanged(activeMailserver)
proc getAutomaticSelection(self: MailserversView): bool {.slot.} =
status_settings.getPinnedMailserver() == ""
self.status.settings.getPinnedMailserver() == ""
QtProperty[bool] automaticSelection:
read = getAutomaticSelection
proc setMailserver(self: MailserversView, id: string) {.slot.} =
let enode = self.mailserversList.getMailserverEnode(id)
status_settings.pinMailserver(enode)
self.status.settings.pinMailserver(enode)
proc enableAutomaticSelection(self: MailserversView, value: bool) {.slot.} =
if value:
status_settings.pinMailserver()
self.status.settings.pinMailserver()
else:
let
mailserverWorker = self.status.tasks.marathon[MailserverWorker().name]
@ -74,8 +73,8 @@ QtObject:
mailserverWorker.start(task)
proc getActiveMailserverResult2(self: MailserversView, activeMailserver: string) {.slot.} =
status_settings.pinMailserver(activeMailserver)
self.status.settings.pinMailserver(activeMailserver)
proc save(self: MailserversView, name: string, address: string) {.slot.} =
status_settings.saveMailserver(name, address)
self.status.settings.saveMailserver(name, address)
self.mailserversList.add(Mailserver(name: name, endpoint: address))

View File

@ -1,6 +1,5 @@
import NimQml, chronicles, strutils
import ../../../status/status
import ../../../status/libstatus/settings as status_settings
import ../../../status/[status, settings]
import ../../../status/libstatus/types
import options
@ -25,7 +24,7 @@ QtObject:
proc isBackedUp*(self: MnemonicView): bool {.slot.} =
if self.isMnemonicBackedUp.isNone:
self.isMnemonicBackedUp = some(status_settings.getSetting[string](Setting.Mnemonic, "") == "")
self.isMnemonicBackedUp = some(self.status.settings.getSetting[:string](Setting.Mnemonic, "") == "")
self.isMnemonicBackedUp.get()
proc seedPhraseRemoved*(self: MnemonicView) {.signal.}
@ -36,7 +35,7 @@ QtObject:
proc getMnemonic*(self: MnemonicView): QVariant {.slot.} =
# Do not keep the mnemonic in memory, so fetch it when necessary
let mnemonic = status_settings.getSetting[string](Setting.Mnemonic, "")
let mnemonic = self.status.settings.getSetting[:string](Setting.Mnemonic, "")
return newQVariant(mnemonic)
QtProperty[QVariant] get:
@ -44,12 +43,12 @@ QtObject:
notify = seedPhraseRemoved
proc remove*(self: MnemonicView) {.slot.} =
discard status_settings.saveSetting(Setting.Mnemonic, "")
discard self.status.settings.saveSetting(Setting.Mnemonic, "")
self.isMnemonicBackedUp = some(true)
self.seedPhraseRemoved()
proc getWord*(self: MnemonicView, idx: int): string {.slot.} =
let mnemonics = status_settings.getSetting[string](Setting.Mnemonic, "").split(" ")
let mnemonics = self.status.settings.getSetting[:string](Setting.Mnemonic, "").split(" ")
return mnemonics[idx]

View File

@ -1,5 +1,5 @@
import NimQml
import ../../status/[status, ens, chat/stickers, wallet]
import ../../status/[status, ens, chat/stickers, wallet, settings]
import ../../status/libstatus/types
import ../../status/libstatus/accounts
import ../../status/libstatus/core

View File

@ -3,7 +3,6 @@ import NimQml, strformat, strutils, chronicles, sugar, sequtils
import view
import views/[asset_list, account_list, account_item]
import ../../status/libstatus/wallet as status_wallet
# import ../../status/libstatus/settings as status_settings
import ../../status/libstatus/types as status_types
import ../../status/signals/types
import ../../status/[status, wallet, settings]

View File

@ -6,11 +6,10 @@ import # vendor libs
NimQml, chronicles, stint
import # status-desktop libs
../../status/[status, wallet],
../../status/[status, wallet, settings],
../../status/wallet/collectibles as status_collectibles,
../../status/libstatus/accounts/constants,
../../status/libstatus/wallet as status_wallet,
../../status/libstatus/settings as status_settings,
../../status/libstatus/tokens, ../../status/libstatus/types,
../../status/libstatus/utils as status_utils,
../../status/libstatus/eth/contracts, ../../status/ens as status_ens,
@ -801,7 +800,7 @@ QtObject:
proc setDappBrowserAddress*(self: WalletView) {.slot.} =
if(self.accounts.rowCount() == 0): return
let dappAddress = status_settings.getSetting[string](Setting.DappsAddress)
let dappAddress = self.status.settings.getSetting[:string](Setting.DappsAddress)
var index = self.accounts.getAccountIndexByAddress(dappAddress)
if index == -1: index = 0
let selectedAccount = self.accounts.getAccount(index)

View File

@ -5,6 +5,7 @@ import
import libstatus/settings as status_settings
import ../eventemitter
import signals/types
#TODO: temporary?
import libstatus/types as LibStatusTypes
@ -17,6 +18,9 @@ proc newSettingsModel*(events: EventEmitter): SettingsModel =
result = SettingsModel()
result.events = events
proc saveSetting*(self: SettingsModel, key: Setting, value: string | JsonNode | bool): StatusGoError =
result = status_settings.saveSetting(key, value)
proc getSetting*[T](self: SettingsModel, name: Setting, defaultValue: T, useCached: bool = true): T =
result = status_settings.getSetting(name, defaultValue, useCached)
@ -25,3 +29,21 @@ proc getSetting*[T](self: SettingsModel, name: Setting, useCached: bool = true):
proc getCurrentNetworkDetails*(self: SettingsModel): LibStatusTypes.NetworkDetails =
result = status_settings.getCurrentNetworkDetails()
proc getMailservers*(self: SettingsModel):JsonNode =
result = status_settings.getMailservers()
proc getPinnedMailserver*(self: SettingsModel): string =
result = status_settings.getPinnedMailserver()
proc pinMailserver*(self: SettingsModel, enode: string = "") =
status_settings.pinMailserver(enode)
proc saveMailserver*(self: SettingsModel, name, enode: string) =
status_settings.saveMailserver(name, enode)
proc getFleet*(self: SettingsModel): Fleet =
result = status_settings.getFleet()
proc getCurrentNetwork*(self: SettingsModel): Network =
result = status_settings.getCurrentNetwork()