fix(@browser): shared assets/history view

fixes #5129
This commit is contained in:
Anthony Laibe 2022-03-25 09:46:47 +01:00 committed by Anthony Laibe
parent dcab50fe09
commit 696e8aba29
29 changed files with 72 additions and 225 deletions

File diff suppressed because one or more lines are too long

View File

@ -2,8 +2,9 @@ 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
import ../../../shared_models/token_model as token_model
import ../../../shared_models/token_item as token_item
QtObject:
type
@ -17,7 +18,7 @@ QtObject:
walletType: string
isChat: bool
currencyBalance: float64
assets: account_tokens.Model
assets: token_model.Model
emoji: string
proc setup(self: View) =
@ -150,10 +151,10 @@ proc setData*(self: View, dto: wallet_account_service.WalletAccountDto) =
self.emoji = dto.emoji
self.emojiChanged()
let assets = account_tokens.newModel()
let assets = token_model.newModel()
assets.setItems(
dto.tokens.map(t => account_tokens_item.initItem(
dto.tokens.map(t => token_item.initItem(
t.name,
t.symbol,
t.balance,

View File

@ -1,24 +0,0 @@
import io_interface
import ../../../../../app_service/service/wallet_account/service as wallet_account_service
type
Controller* = ref object of RootObj
delegate: io_interface.AccessInterface
walletAccountService: wallet_account_service.Service
proc newController*(
delegate: io_interface.AccessInterface,
walletAccountService: wallet_account_service.Service
): Controller =
result = Controller()
result.delegate = delegate
result.walletAccountService = walletAccountService
proc delete*(self: Controller) =
discard
proc init*(self: Controller) =
discard
proc getWalletAccount*(self: Controller, accountIndex: int): wallet_account_service.WalletAccountDto =
return self.walletAccountService.getWalletAccount(accountIndex)

View File

@ -1,21 +0,0 @@
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 switchAccount*(self: AccessInterface, accountIndex: int) {.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

@ -1,69 +0,0 @@
import NimQml, sequtils, sugar
import ./io_interface, ./view, ./controller, ./item
import ../io_interface as delegate_interface
import ../../../../global/global_singleton
import ../../../../core/eventemitter
import ../../../../../app_service/service/wallet_account/service as wallet_account_service
export io_interface
type
Module* = ref object of io_interface.AccessInterface
delegate: delegate_interface.AccessInterface
events: EventEmitter
view: View
moduleLoaded: bool
controller: Controller
currentAccountIndex: int
proc newModule*(
delegate: delegate_interface.AccessInterface,
events: EventEmitter,
walletAccountService: wallet_account_service.Service
): Module =
result = Module()
result.delegate = delegate
result.events = events
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.setItems(
walletAccount.tokens.map(t => initItem(
t.name,
t.symbol,
t.balance,
t.address,
t.currencyBalance,
))
)
method load*(self: Module) =
singletonInstance.engine.setRootContextProperty("walletSectionAccountTokens", newQVariant(self.view))
# these connections should be part of the controller's init method
self.events.on(SIGNAL_WALLET_ACCOUNT_CURRENCY_UPDATED) do(e:Args):
self.switchAccount(self.currentAccountIndex)
self.events.on(SIGNAL_WALLET_ACCOUNT_TOKEN_VISIBILITY_UPDATED) do(e:Args):
self.switchAccount(self.currentAccountIndex)
self.events.on(SIGNAL_WALLET_ACCOUNT_NETWORK_ENABLED_UPDATED) do(e:Args):
self.switchAccount(self.currentAccountIndex)
self.controller.init()
self.view.load()
method isLoaded*(self: Module): bool =
return self.moduleLoaded
method viewDidLoad*(self: Module) =
self.moduleLoaded = true
self.delegate.accountTokensModuleDidLoad()

View File

@ -1,38 +0,0 @@
import NimQml
import ./model, ./item
import ./io_interface
QtObject:
type
View* = ref object of QObject
delegate: io_interface.AccessInterface
model: Model
modelVariant: QVariant
proc delete*(self: View) =
self.model.delete
self.modelVariant.delete
self.QObject.delete
proc newView*(delegate: io_interface.AccessInterface): View =
new(result, delete)
result.QObject.setup
result.delegate = delegate
result.model = newModel()
result.modelVariant = newQVariant(result.model)
proc load*(self: View) =
self.delegate.viewDidLoad()
proc modelChanged*(self: View) {.signal.}
proc getModel(self: View): QVariant {.slot.} =
return self.modelVariant
QtProperty[QVariant] model:
read = getModel
notify = modelChanged
proc setItems*(self: View, items: seq[Item]) =
self.model.setItems(items)

View File

@ -1,5 +1,5 @@
import strformat
import ../account_tokens/model as account_tokens
import ../../../shared_models/token_model as token_model
type
Item* = object
@ -12,7 +12,7 @@ type
isWallet: bool
isChat: bool
currencyBalance: float64
assets: account_tokens.Model
assets: token_model.Model
emoji: string
proc initItem*(
@ -25,7 +25,7 @@ proc initItem*(
isWallet: bool,
isChat: bool,
currencyBalance: float64,
assets: account_tokens.Model,
assets: token_model.Model,
emoji: string
): Item =
result.name = name
@ -85,5 +85,5 @@ proc getIsChat*(self: Item): bool =
proc getCurrencyBalance*(self: Item): float64 =
return self.currencyBalance
proc getAssets*(self: Item): account_tokens.Model =
proc getAssets*(self: Item): token_model.Model =
return self.assets

View File

@ -5,8 +5,8 @@ import ../io_interface as delegate_interface
import ../../../../global/global_singleton
import ../../../../core/eventemitter
import ../../../../../app_service/service/wallet_account/service as wallet_account_service
import ../account_tokens/model as account_tokens
import ../account_tokens/item as account_tokens_item
import ../../../shared_models/token_model as token_model
import ../../../shared_models/token_item as token_item
export io_interface
@ -39,11 +39,11 @@ method refreshWalletAccounts*(self: Module) =
let items = walletAccounts.map(proc (w: WalletAccountDto): item.Item =
let assets = account_tokens.newModel()
let assets = token_model.newModel()
assets.setItems(
w.tokens.map(t => account_tokens_item.initItem(
w.tokens.map(t => token_item.initItem(
t.name,
t.symbol,
t.balance,

View File

@ -2,8 +2,8 @@ import NimQml, sequtils, sugar
import ../../../../../app_service/service/wallet_account/service as wallet_account_service
import ./io_interface
import ../account_tokens/model as account_tokens
import ../account_tokens/item as account_tokens_item
import ../../../shared_models/token_model as token_model
import ../../../shared_models/token_item as token_item
QtObject:
type
@ -17,7 +17,7 @@ QtObject:
walletType: string
isChat: bool
currencyBalance: float64
assets: account_tokens.Model
assets: token_model.Model
emoji: string
proc setup(self: View) =
@ -147,10 +147,10 @@ proc setData*(self: View, dto: wallet_account_service.WalletAccountDto) =
self.emoji = dto.emoji
self.emojiChanged()
let assets = account_tokens.newModel()
let assets = token_model.newModel()
assets.setItems(
dto.tokens.map(t => account_tokens_item.initItem(
dto.tokens.map(t => token_item.initItem(
t.name,
t.symbol,
t.balance,

View File

@ -30,9 +30,6 @@ method viewDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
# Methods called by submodules of this module
method accountTokensModuleDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method accountsModuleDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -4,7 +4,6 @@ import ./controller, ./view
import ./io_interface as io_interface
import ../io_interface as delegate_interface
import ./account_tokens/module as account_tokens_module
import ./accounts/module as accountsModule
import ./all_tokens/module as all_tokens_module
import ./collectibles/module as collectibles_module
@ -34,7 +33,6 @@ type
controller: Controller
view: View
accountTokensModule: account_tokens_module.AccessInterface
accountsModule: accounts_module.AccessInterface
allTokensModule: all_tokens_module.AccessInterface
collectiblesModule: collectibles_module.AccessInterface
@ -61,7 +59,6 @@ proc newModule*(
result.controller = newController(result, settingsService, walletAccountService, networkService)
result.view = newView(result)
result.accountTokensModule = account_tokens_module.newModule(result, events, walletAccountService)
result.accountsModule = accounts_module.newModule(result, events, walletAccountService)
result.allTokensModule = all_tokens_module.newModule(result, events, tokenService, walletAccountService)
result.collectiblesModule = collectibles_module.newModule(result, events, collectibleService, walletAccountService)
@ -71,7 +68,6 @@ proc newModule*(
result.buySellCryptoModule = buy_sell_crypto_module.newModule(result, events, transactionService)
method delete*(self: Module) =
self.accountTokensModule.delete
self.accountsModule.delete
self.allTokensModule.delete
self.collectiblesModule.delete
@ -88,7 +84,6 @@ method updateCurrency*(self: Module, currency: string) =
method switchAccount*(self: Module, accountIndex: int) =
self.currentAccountModule.switchAccount(accountIndex)
self.collectiblesModule.switchAccount(accountIndex)
self.accountTokensModule.switchAccount(accountIndex)
self.transactionsModule.switchAccount(accountIndex)
method switchAccountByAddress*(self: Module, address: string) =
@ -118,7 +113,6 @@ method load*(self: Module) =
self.controller.init()
self.view.load()
self.accountTokensModule.load()
self.accountsModule.load()
self.allTokensModule.load()
self.collectiblesModule.load()
@ -131,9 +125,6 @@ method isLoaded*(self: Module): bool =
return self.moduleLoaded
proc checkIfModuleDidLoad(self: Module) =
if(not self.accountTokensModule.isLoaded()):
return
if(not self.accountsModule.isLoaded()):
return
@ -168,9 +159,6 @@ proc checkIfModuleDidLoad(self: Module) =
method viewDidLoad*(self: Module) =
self.checkIfModuleDidLoad()
method accountTokensModuleDidLoad*(self: Module) =
self.checkIfModuleDidLoad()
method accountsModuleDidLoad*(self: Module) =
self.checkIfModuleDidLoad()

View File

@ -84,13 +84,17 @@ QtObject:
for address in addresses:
self.setHistoryFetchState(address, isFetching)
proc switchAccount*(self: View, walletAccount: WalletAccountDto) =
if not self.models.hasKey(walletAccount.address):
self.models[walletAccount.address] = newModel()
self.model = self.models[walletAccount.address]
proc setModel*(self: View, address: string) {.slot.} =
if not self.models.hasKey(address):
self.models[address] = newModel()
self.model = self.models[address]
self.modelVariant = newQVariant(self.model)
self.modelChanged()
proc switchAccount*(self: View, walletAccount: WalletAccountDto) =
self.setModel(walletAccount.address)
proc getIsNonArchivalNode(self: View): QVariant {.slot.} =
return newQVariant(self.isNonArchivalNode)

View File

@ -1,6 +1,6 @@
import NimQml, Tables, strutils, strformat
import ./item
import ./token_item
type
ModelRole {.pure.} = enum

View File

@ -117,7 +117,6 @@ proc buildTokens(
): seq[WalletTokenDto] =
for network in self.networkService.getEnabledNetworks():
let balance = fetchNativeChainBalance(network, account.address)
result.add(WalletTokenDto(
name: network.chainName,
address: "0x0000000000000000000000000000000000000000",

View File

@ -7,10 +7,9 @@ import StatusQ.Controls 0.1
import StatusQ.Core 0.1
import shared.controls 1.0
import shared.views 1.0
import utils 1.0
import "../../Wallet/views"
import "../stores"
// TODO: replace with StatusPopupMenu
@ -218,9 +217,11 @@ Popup {
AssetsView {
id: assetsTab
account: WalletStore.dappBrowserAccount
}
HistoryView {
id: historyTab
account: WalletStore.dappBrowserAccount
}
}
}

View File

@ -17,6 +17,7 @@ QtObject {
function switchAccountByAddress(address) {
browserSectionCurrentAccount.switchAccountByAddress(address)
walletSectionTransactions.setModel(address)
}
function getGasPrice(){

View File

@ -22,15 +22,9 @@ QtObject {
property var walletTokensModule: walletSectionAllTokens
property var tokens: walletSectionAllTokens.all
property var assets: walletSectionAccountTokens.model
property CollectiblesStore collectiblesStore: CollectiblesStore { }
property var collectionList: walletSectionCollectiblesCollections.model
property var history: walletSectionTransactions
property var historyTransactions: walletSectionTransactions.model
property bool isNonArchivalNode: history.isNonArchivalNode
property var savedAddresses: walletSectionSavedAddresses.model
@ -141,25 +135,11 @@ QtObject {
return globalUtils.hex2Dec(value)
}
function hex2Eth(value) {
return globalUtils.hex2Eth(value)
}
function checkRecentHistory() {
history.checkRecentHistory()
}
function isFetchingHistory() {
return history.isFetchingHistory(currentAccount.address)
}
function loadTransactionsForAccount(pageSize) {
history.loadTransactionsForAccount(currentAccount.address,
historyTransactions.getLastTxBlockNumber(),
pageSize, true)
}
function fetchCollectionCollectiblesList(slug) {
function fetchCollectionCollectiblesList(slug) {
walletSectionCollectiblesCollectibles.fetch(slug)
}

View File

@ -7,6 +7,7 @@ import utils 1.0
import shared 1.0
import shared.controls 1.0
import shared.views 1.0
import "../controls"
import "../stores"
@ -85,12 +86,14 @@ Item {
AssetsView {
id: assetsTab
account: RootStore.currentAccount
}
CollectiblesView {
id: collectiblesTab
}
HistoryView {
id: historyTab
account: RootStore.currentAccount
}
}
}

View File

@ -45,7 +45,6 @@ QtObject {
property var messagingStore: profileSectionStore.messagingStore
property bool hasAddedContacts: contactStore.myContactsModel.count > 0
property var assets: walletSectionAccountTokens.model
// property MessageStore messageStore: MessageStore { }
property real volume: !!localAccountSensitiveSettings ? localAccountSensitiveSettings.volume * 0.1 : 0.2

View File

@ -1,6 +1,7 @@
AddressInput 1.0 AddressInput.qml
AddressSourceSelector 1.0 AddressSourceSelector.qml
AssetAndAmountInput 1.0 AssetAndAmountInput.qml
AssetDelegate 1.0 AssetDelegate.qml
ContactSelector 1.0 ContactSelector.qml
ContactsListAndSearch 1.0 ContactsListAndSearch.qml
CopyToClipBoardButton 1.0 CopyToClipBoardButton.qml
@ -22,5 +23,6 @@ StyledTextArea 1.0 StyledTextArea.qml
StyledTextEdit 1.0 StyledTextEdit.qml
StyledTextField 1.0 StyledTextField.qml
Timer 1.0 Timer.qml
TransactionDelegate 1.0 TransactionDelegate.qml
TransactionFormGroup 1.0 TransactionFormGroup.qml
EmojiHash 1.0 EmojiHash.qml

View File

@ -9,6 +9,7 @@ ModalPopup 1.0 ModalPopup.qml
PopupMenu 1.0 PopupMenu.qml
SendModal 1.0 SendModal.qml
ToastMessage 1.0 ToastMessage.qml
TransactionModal 1.0 TransactionModal.qml
TransactionSettingsConfirmationPopup 1.0 TransactionSettingsConfirmationPopup.qml
UnblockContactConfirmationDialog 1.0 UnblockContactConfirmationDialog.qml
UserStatusContextMenu 1.0 UserStatusContextMenu.qml

View File

@ -29,10 +29,18 @@ QtObject {
// property string signingPhrase: !!walletModelInst ? walletModelInst.utilsView.signingPhrase : ""
// property string gasPrice: !!walletModelInst ? walletModelInst.gasView.gasPrice : "0"
// property string gasEthValue: !!walletModelInst ? walletModelInst.gasView.getGasEthValue : "0"
// property string currentCurrency: !!walletSectionInst ? walletSectionInst.currentCurrency : ""
property string currentCurrency: walletSection.currentCurrency
// property string defaultCurrency: !!walletModelInst ? walletModelInst.balanceView.defaultCurrency : "0"
// property string fiatValue: !!walletModelInst ? walletModelInst.balanceView.getFiatValue : "0"
// property string cryptoValue: !!walletModelInst ? walletModelInst.balanceView.getCryptoValue : "0"
property var history: walletSectionTransactions
property var historyTransactions: walletSectionTransactions.model
property bool isNonArchivalNode: history.isNonArchivalNode
property var walletTokensModule: walletSectionAllTokens
property var tokens: walletSectionAllTokens.all
readonly property var formationChars: (["*", "`", "~"])
function getSelectedTextWithFormationChars(messageInputField) {
let i = 1
@ -109,4 +117,16 @@ QtObject {
return root.privacyModule.getPasswordStrengthScore(password);
}
}
function isFetchingHistory(address) {
return history.isFetchingHistory(address)
}
function loadTransactionsForAccount(address, pageSize) {
history.loadTransactionsForAccount(address, historyTransactions.getLastTxBlockNumber(), pageSize, true)
}
function hex2Eth(value) {
return globalUtils.hex2Eth(value)
}
}

View File

@ -9,6 +9,8 @@ import "../stores"
import "../controls"
Item {
property var account
height: assetListView.height
ScrollView {
@ -22,8 +24,7 @@ Item {
id: assetListView
spacing: Style.current.padding * 2
anchors.fill: parent
//model: RootStore.exampleAssetModel
model: RootStore.assets
model: account.assets
delegate: AssetDelegate {
locale: RootStore.locale
currency: RootStore.currentCurrency

View File

@ -7,7 +7,7 @@ import utils 1.0
import StatusQ.Components 0.1
import StatusQ.Controls 0.1
import shared.panels 1.0
import "../panels"
import "../popups"
import "../stores"
import "../controls"
@ -15,13 +15,14 @@ import "../controls"
Item {
id: historyView
property var account
property int pageSize: 20 // number of transactions per page
function fetchHistory() {
if (RootStore.isFetchingHistory()) {
if (RootStore.isFetchingHistory(historyView.account.address)) {
loadingImg.active = true
} else {
RootStore.loadTransactionsForAccount(pageSize)
RootStore.loadTransactionsForAccount(historyView.account.address, pageSize)
}
}
@ -41,8 +42,8 @@ Item {
Connections {
target: RootStore.history
onLoadingTrxHistoryChanged: {
if (RootStore.currentAccount.address.toLowerCase() === address.toLowerCase()) {
onLoadingTrxHistoryChanged: function(isLoading, address) {
if (historyView.account.address.toLowerCase() === address.toLowerCase()) {
loadingImg.active = isLoading
}
}
@ -82,7 +83,7 @@ Item {
delegate: TransactionDelegate {
tokens: RootStore.tokens
locale: RootStore.locale
currentAccountAddress: RootStore.currentAccount.address
currentAccountAddress: account.address
ethValue: RootStore.hex2Eth(value)
onLaunchTransactionModal: {
transactionModal.transaction = model

View File

@ -6,3 +6,5 @@ TransactionPreview 1.0 TransactionPreview.qml
TransactionSigner 1.0 TransactionSigner.qml
TransactionStackView 1.0 TransactionStackView.qml
PasswordView 1.0 PasswordView.qml
AssetsView 1.0 AssetsView.qml
HistoryView 1.0 HistoryView.qml