fix(@browser): unlink wallet account and browser account

fixes #5034
This commit is contained in:
Anthony Laibe 2022-03-16 12:36:04 +01:00 committed by Iuri Matias
parent 738a3ba93e
commit 4b48bc69bd
9 changed files with 304 additions and 7 deletions

View File

@ -0,0 +1,30 @@
import ./controller_interface
import io_interface
import ../../../../../app_service/service/wallet_account/service as wallet_account_service
export controller_interface
type
Controller* = ref object of controller_interface.AccessInterface
delegate: io_interface.AccessInterface
walletAccountService: wallet_account_service.ServiceInterface
proc newController*(
delegate: io_interface.AccessInterface,
walletAccountService: wallet_account_service.ServiceInterface
): Controller =
result = Controller()
result.delegate = delegate
result.walletAccountService = walletAccountService
method delete*(self: Controller) =
discard
method init*(self: Controller) =
discard
method getWalletAccount*(self: Controller, accountIndex: int): wallet_account_service.WalletAccountDto =
return self.walletAccountService.getWalletAccount(accountIndex)
method getIndex*(self: Controller, address: string): int =
return self.walletAccountService.getIndex(address)

View File

@ -0,0 +1,22 @@
import ../../../../../app_service/service/wallet_account/service_interface as wallet_account_service
type
AccessInterface* {.pure inheritable.} = ref object of RootObj
## Abstract class for any input/interaction with this module.
method delete*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method init*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method getWalletAccount*(self: AccessInterface, accountIndex: int): wallet_account_service.WalletAccountDto {.base.} =
raise newException(ValueError, "No implementation available")
method getIndex*(self: AccessInterface, address: string): int {.base.} =
raise newException(ValueError, "No implementation available")
type
## Abstract class (concept) which must be implemented by object/s used in this
## module.
DelegateInterface* = concept c

View File

@ -0,0 +1,21 @@
type
AccessInterface* {.pure inheritable.} = ref object of RootObj
## Abstract class for any input/interaction with this module.
method delete*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method load*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method isLoaded*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available")
method switchAccountByAddress*(self: AccessInterface, address: string) {.base.} =
raise newException(ValueError, "No implementation available")
# View Delegate Interface
# Delegate for the view must be declared here due to use of QtObject and multi
# inheritance, which is not well supported in Nim.
method viewDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -0,0 +1,53 @@
import NimQml
import ../../../../global/global_singleton
import ../../../../../app_service/service/wallet_account/service as wallet_account_service
import ./io_interface, ./view, ./controller
import ../io_interface as delegate_interface
export io_interface
type
Module* = ref object of io_interface.AccessInterface
delegate: delegate_interface.AccessInterface
view: View
controller: controller.AccessInterface
moduleLoaded: bool
currentAccountIndex: int
proc newModule*(
delegate: delegate_interface.AccessInterface,
walletAccountService: wallet_account_service.ServiceInterface,
): Module =
result = Module()
result.delegate = delegate
result.currentAccountIndex = 0
result.view = newView(result)
result.controller = newController(result, walletAccountService)
result.moduleLoaded = false
method delete*(self: Module) =
self.view.delete
method switchAccount*(self: Module, accountIndex: int) =
self.currentAccountIndex = accountIndex
let walletAccount = self.controller.getWalletAccount(accountIndex)
self.view.setData(walletAccount)
method load*(self: Module) =
singletonInstance.engine.setRootContextProperty("browserSectionCurrentAccount", newQVariant(self.view))
self.controller.init()
self.view.load()
self.switchAccount(0)
method isLoaded*(self: Module): bool =
return self.moduleLoaded
method viewDidLoad*(self: Module) =
self.moduleLoaded = true
method switchAccountByAddress*(self: Module, address: string) =
let accountIndex = self.controller.getIndex(address)
self.switchAccount(accountIndex)

View File

@ -0,0 +1,165 @@
import NimQml, sequtils, sugar
import ../../../../../app_service/service/wallet_account/service as wallet_account_service
import ./io_interface
import ../../wallet_section/account_tokens/model as account_tokens
import ../../wallet_section/account_tokens/item as account_tokens_item
QtObject:
type
View* = ref object of QObject
delegate: io_interface.AccessInterface
name: string
address: string
path: string
color: string
publicKey: string
walletType: string
isChat: bool
currencyBalance: float64
assets: account_tokens.Model
emoji: string
proc setup(self: View) =
self.QObject.setup
proc delete*(self: View) =
self.QObject.delete
proc newView*(delegate: io_interface.AccessInterface): View =
new(result, delete)
result.delegate = delegate
result.setup()
proc load*(self: View) =
self.delegate.viewDidLoad()
proc getName(self: View): QVariant {.slot.} =
return newQVariant(self.name)
proc nameChanged(self: View) {.signal.}
QtProperty[QVariant] name:
read = getName
notify = nameChanged
proc getAddress(self: View): QVariant {.slot.} =
return newQVariant(self.address)
proc addressChanged(self: View) {.signal.}
QtProperty[QVariant] address:
read = getAddress
notify = addressChanged
proc getPath(self: View): QVariant {.slot.} =
return newQVariant(self.path)
proc pathChanged(self: View) {.signal.}
QtProperty[QVariant] path:
read = getPath
notify = pathChanged
proc getColor(self: View): QVariant {.slot.} =
return newQVariant(self.color)
proc colorChanged(self: View) {.signal.}
QtProperty[QVariant] color:
read = getColor
notify = colorChanged
proc getPublicKey(self: View): QVariant {.slot.} =
return newQVariant(self.publicKey)
proc publicKeyChanged(self: View) {.signal.}
QtProperty[QVariant] publicKey:
read = getPublicKey
notify = publicKeyChanged
proc getWalletType(self: View): QVariant {.slot.} =
return newQVariant(self.walletType)
proc walletTypeChanged(self: View) {.signal.}
QtProperty[QVariant] walletType:
read = getWalletType
notify = walletTypeChanged
proc getIsChat(self: View): QVariant {.slot.} =
return newQVariant(self.isChat)
proc isChatChanged(self: View) {.signal.}
QtProperty[QVariant] isChat:
read = getIsChat
notify = isChatChanged
proc getCurrencyBalance(self: View): QVariant {.slot.} =
return newQVariant(self.currencyBalance)
proc currencyBalanceChanged(self: View) {.signal.}
QtProperty[QVariant] currencyBalance:
read = getCurrencyBalance
notify = currencyBalanceChanged
proc getAssets(self: View): QVariant {.slot.} =
return newQVariant(self.assets)
proc assetsChanged(self: View) {.signal.}
QtProperty[QVariant] assets:
read = getAssets
notify = assetsChanged
proc getEmoji(self: View): QVariant {.slot.} =
return newQVariant(self.emoji)
proc emojiChanged(self: View) {.signal.}
QtProperty[QVariant] emoji:
read = getEmoji
notify = emojiChanged
proc switchAccountByAddress*(self: View, address: string) {.slot.} =
self.delegate.switchAccountByAddress(address)
proc setData*(self: View, dto: wallet_account_service.WalletAccountDto) =
self.name = dto.name
self.nameChanged()
self.address = dto.address
self.addressChanged()
self.path = dto.path
self.pathChanged()
self.color = dto.color
self.colorChanged()
self.publicKey = dto.publicKey
self.publicKeyChanged()
self.walletType = dto.walletType
self.walletTypeChanged()
self.isChat = dto.isChat
self.isChatChanged()
self.currencyBalance = dto.getCurrencyBalance()
self.currencyBalanceChanged()
self.emoji = dto.emoji
self.emojiChanged()
let assets = account_tokens.newModel()
assets.setItems(
dto.tokens.map(t => account_tokens_item.initItem(
t.name,
t.symbol,
t.balance,
t.address,
t.currencyBalance,
))
)
self.assets = assets
self.assetsChanged()

View File

@ -6,6 +6,7 @@ import ../../../global/global_singleton
import provider/module as provider_module
import bookmark/module as bookmark_module
import dapps/module as dapps_module
import current_account/module as current_account_module
import ../../../../app_service/service/bookmarks/service as bookmark_service
import ../../../../app_service/service/settings/service as settings_service
import ../../../../app_service/service/dapp_permissions/service as dapp_permissions_service
@ -23,6 +24,7 @@ type
providerModule: provider_module.AccessInterface
bookmarkModule: bookmark_module.AccessInterface
dappsModule: dapps_module.AccessInterface
currentAccountModule: current_account_module.AccessInterface
proc newModule*(delegate: delegate_interface.AccessInterface,
bookmarkService: bookmark_service.ServiceInterface,
@ -38,6 +40,7 @@ proc newModule*(delegate: delegate_interface.AccessInterface,
result.providerModule = provider_module.newModule(result, settingsService, providerService)
result.bookmarkModule = bookmark_module.newModule(result, bookmarkService)
result.dappsModule = dapps_module.newModule(result, dappPermissionsService, walletAccountService)
result.currentAccountModule = current_account_module.newModule(result, walletAccountService)
method delete*(self: Module) =
self.view.delete
@ -45,9 +48,11 @@ method delete*(self: Module) =
self.providerModule.delete
self.bookmarkModule.delete
self.dappsModule.delete
self.currentAccountModule.delete
method load*(self: Module) =
singletonInstance.engine.setRootContextProperty("browserSection", self.viewVariant)
self.currentAccountModule.load()
self.providerModule.load()
self.bookmarkModule.load()
self.dappsModule.load()
@ -66,6 +71,9 @@ proc checkIfModuleDidLoad(self: Module) =
if(not self.dappsModule.isLoaded()):
return
if(not self.currentAccountModule.isLoaded()):
return
self.moduleLoaded = true
self.delegate.browserSectionDidLoad()

View File

@ -131,7 +131,7 @@ StatusModal {
if (selectedAccount.address) {
Web3ProviderStore.web3ProviderInst.dappsAddress = selectedAccount.address;
WalletStore.setDappBrowserAddress()
WalletStore.switchAccountByAddress(selectedAccount.address)
}
}
}

View File

@ -133,7 +133,7 @@ Popup {
accountSelectorRow.currentAddress = selectedAccount.address
Web3ProviderStore.web3ProviderInst.dappsAddress = selectedAccount.address;
WalletStore.setDappBrowserAddress()
WalletStore.switchAccountByAddress(selectedAccount.address)
reload()
}
}

View File

@ -5,20 +5,18 @@ import QtQuick 2.13
QtObject {
id: root
property var dappBrowserAccount: walletSectionCurrent
property var dappBrowserAccount: browserSectionCurrentAccount
property var accounts: walletSectionAccounts.model
property string defaultCurrency: walletSection.currentCurrency
property string signingPhrase: walletSection.signingPhrase
// Not Refactored Yet
function getEtherscanLink() {
return profileSectionModule.ensUsernamesModule.getEtherscanLink()
}
function setDappBrowserAddress() {
// Not Refactored Yet
// walletModel.setDappBrowserAddress()
function switchAccountByAddress(address) {
browserSectionCurrentAccount.switchAccountByAddress(address)
}
function getGasPrice(){