feat(@wallet): make activity respect networks selector

This commit is contained in:
Anthony Laibe 2023-03-06 16:52:20 +01:00 committed by Anthony Laibe
parent fb86d8745c
commit 52c01f1dd5
8 changed files with 73 additions and 16 deletions

View File

@ -85,6 +85,9 @@ proc init*(self: Controller) =
let args = TransactionsLoadedArgs(e)
self.delegate.setHistoryFetchState(args.address, args.allTxLoaded, isFetching = false)
self.events.on(SIGNAL_WALLET_ACCOUNT_NETWORK_ENABLED_UPDATED) do(e:Args):
self.delegate.refreshTransactions()
self.events.on(SIGNAL_CURRENCY_FORMATS_UPDATED) do(e:Args):
# TODO: Rebuild Transaction items
discard
@ -122,6 +125,9 @@ proc suggestedFees*(self: Controller, chainId: int): string =
let suggestedFees = self.transactionService.suggestedFees(chainId)
return suggestedFees.toJson()
proc getAllTransactions*(self: Controller, address: string): seq[TransactionDto] =
return self.transactionService.getAllTransactions(address)
proc suggestedRoutes*(self: Controller, account: string, amount: Uint256, token: string, disabledFromChainIDs, disabledToChainIDs, preferredChainIDs: seq[uint64], sendType: int, lockedInAmounts: string): string =
let suggestedRoutes = self.transactionService.suggestedRoutes(account, amount, token, disabledFromChainIDs, disabledToChainIDs, preferredChainIDs, sendType, lockedInAmounts)
return suggestedRoutes.toJson()
@ -138,6 +144,8 @@ proc getEstimatedTime*(self: Controller, chainId: int, maxFeePerGas: string): Es
proc getLastTxBlockNumber*(self: Controller): string =
return self.transactionService.getLastTxBlockNumber(self.networkService.getNetworkForBrowser().chainId)
proc getEnabledChainIds*(self: Controller): seq[int] =
return self.networkService.getNetworks().filter(n => n.enabled).map(n => n.chainId)
proc authenticateUser*(self: Controller, keyUid = "") =
let data = SharedKeycarModuleAuthenticationArgs(uniqueIdentifier: UNIQUE_WALLET_SECTION_TRANSACTION_MODULE_IDENTIFIER,

View File

@ -69,6 +69,9 @@ method getChainIdForBrowser*(self: AccessInterface): int =
method getEstimatedTime*(self: AccessInterface, chainId: int, maxFeePerGas: string): int {.base.} =
raise newException(ValueError, "No implementation available")
method refreshTransactions*(self: AccessInterface) {.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.

View File

@ -258,34 +258,34 @@ proc getMaxFeePerGas*(self: Item): CurrencyAmount =
proc getMaxPriorityFeePerGas*(self: Item): CurrencyAmount =
return self.maxPriorityFeePerGas
proc getInput*(self: Item): string =
proc getInput*(self: Item): string =
return self.input
proc getTxHash*(self: Item): string =
proc getTxHash*(self: Item): string =
return self.txHash
proc getMultiTransactionID*(self: Item): int =
proc getMultiTransactionID*(self: Item): int =
return self.multiTransactionID
proc getIsTimeStamp*(self: Item): bool =
proc getIsTimeStamp*(self: Item): bool =
return self.isTimeStamp
proc getIsNFT*(self: Item): bool =
proc getIsNFT*(self: Item): bool =
return self.isNFT
proc getBaseGasFees*(self: Item): CurrencyAmount =
proc getBaseGasFees*(self: Item): CurrencyAmount =
return self.baseGasFees
proc getTotalFees*(self: Item): CurrencyAmount =
proc getTotalFees*(self: Item): CurrencyAmount =
return self.totalFees
proc getMaxTotalFees*(self: Item): CurrencyAmount =
proc getMaxTotalFees*(self: Item): CurrencyAmount =
return self.maxTotalFees
proc getSymbol*(self: Item): string =
proc getSymbol*(self: Item): string =
return self.symbol
proc getLoadingTransaction*(self: Item): bool =
proc getLoadingTransaction*(self: Item): bool =
return self.loadingTransaction
proc getTokenID*(self: Item): UInt256 =

View File

@ -188,6 +188,12 @@ QtObject:
self.endResetModel()
self.countChanged()
proc resetItems*(self: Model) =
self.beginResetModel()
self.items = @[]
self.endResetModel()
self.countChanged()
proc getLastTxBlockNumber*(self: Model): string {.slot.} =
if (self.items.len == 0):
return "0x0"

View File

@ -107,12 +107,24 @@ proc transactionsToItems(self: Module, transactions: seq[TransactionDto], collec
proc setPendingTx(self: Module) =
self.view.setPendingTx(self.transactionsToItems(self.controller.watchPendingTransactions(), @[]))
method setEnabledChainIds*(self: Module) =
let enabledChainIds = self.controller.getEnabledChainIds()
self.view.setEnabledChainIds(enabledChainIds)
method refreshTransactions*(self: Module) =
self.setEnabledChainIds()
self.view.resetTrxHistory()
self.view.setPendingTx(self.transactionsToItems(self.controller.getPendingTransactions(), @[]))
for account in self.controller.getWalletAccounts():
let transactions = self.controller.getAllTransactions(account.address)
self.view.setTrxHistoryResult(self.transactionsToItems(transactions, @[]), account.address, wasFetchMore=false)
method viewDidLoad*(self: Module) =
let accounts = self.getWalletAccounts()
self.moduleLoaded = true
self.delegate.transactionsModuleDidLoad()
self.setEnabledChainIds()
self.setPendingTx()
method switchAccount*(self: Module, accountIndex: int) =

View File

@ -15,6 +15,7 @@ QtObject:
model: Model
modelVariant: QVariant
fetchingHistoryState: Table[string, bool]
enabledChainIds: seq[int]
isNonArchivalNode: bool
proc delete*(self: View) =
@ -72,14 +73,25 @@ QtObject:
self.models[address].addPageSizeBuffer(limit)
self.delegate.loadTransactions(address, toBlock, limit, loadMore)
proc resetTrxHistory*(self: View) =
for address in self.models.keys:
self.models[address].resetItems()
proc setTrxHistoryResult*(self: View, transactions: seq[Item], address: string, wasFetchMore: bool) =
var toAddTransactions: seq[Item] = @[]
for tx in transactions:
if not self.enabledChainIds.contains(tx.getChainId()):
continue
toAddTransactions.add(tx)
if not self.models.hasKey(address):
self.models[address] = newModel()
self.models[address].removePageSizeBuffer()
self.models[address].addNewTransactions(transactions, wasFetchMore)
self.models[address].addNewTransactions(toAddTransactions, wasFetchMore)
if self.fetchingHistoryState.hasKey(address) and self.fetchingHistoryState[address] and wasFetchMore:
self.models[address].addPageSizeBuffer(transactions.len)
self.models[address].addPageSizeBuffer(toAddTransactions.len)
proc setHistoryFetchStateForAccounts*(self: View, addresses: seq[string], isFetching: bool) =
for address in addresses:
@ -106,6 +118,9 @@ QtObject:
proc getIsNonArchivalNode(self: View): QVariant {.slot.} =
return newQVariant(self.isNonArchivalNode)
proc setEnabledChainIds*(self: View, chainIds: seq[int]) =
self.enabledChainIds = chainIds
proc isNonArchivalNodeChanged(self: View) {.signal.}
proc setIsNonArchivalNode*(self: View, isNonArchivalNode: bool) =
@ -158,7 +173,7 @@ QtObject:
discard
return self.delegate.suggestedRoutes(account, parsedAmount, token, seqDisabledFromChainIDs, seqDisabledToChainIDs, seqPreferredChainIDs, sendType, lockedInAmounts)
proc getChainIdForChat*(self: View): int {.slot.} =
return self.delegate.getChainIdForChat()
@ -175,6 +190,9 @@ QtObject:
proc setPendingTx*(self: View, pendingTx: seq[Item]) =
for tx in pendingTx:
if not self.enabledChainIds.contains(tx.getChainId()):
continue
let fromAddress = tx.getfrom()
if not self.models.hasKey(fromAddress):
self.models[fromAddress] = newModel()

View File

@ -105,6 +105,7 @@ QtObject:
tokenService: token_service.Service
txCounter: Table[string, seq[int]]
allTxLoaded: Table[string, bool]
allTransactions: Table[string, Table[string, TransactionDto]]
# Forward declaration
proc loadTransactions*(self: Service, address: string, toBlock: Uint256, limit: int = 20, loadMore: bool = false)
@ -128,6 +129,7 @@ QtObject:
result.tokenService = tokenService
result.txCounter = initTable[string, seq[int]]()
result.allTxLoaded = initTable[string, bool]()
result.allTransactions = initTable[string, Table[string, TransactionDto]]()
proc init*(self: Service) =
self.events.on(SignalType.Wallet.event) do(e:Args):
@ -167,6 +169,12 @@ QtObject:
error "error: ", errDescription
return
proc getAllTransactions*(self: Service, address: string): seq[TransactionDto] =
if not self.allTransactions.hasKey(address):
return @[]
return toSeq(self.allTransactions[address].values)
proc watchTransactionResult*(self: Service, watchTxResult: string) {.slot.} =
let watchTxResult = parseJson(watchTxResult)
let success = watchTxResult["isSuccessfull"].getBool
@ -224,7 +232,9 @@ QtObject:
var transactions: seq[TransactionDto] = @[]
var collectibles: seq[CollectibleDto] = @[]
for tx in historyData["history"].getElems():
transactions.add(tx.toTransactionDto())
let dto = tx.toTransactionDto()
self.allTransactions.mgetOrPut(address, initTable[string, TransactionDto]())[dto.txHash] = dto
transactions.add(dto)
let collectiblesContainerJson = historyData["collectibles"]
if collectiblesContainerJson.kind == JObject:

View File

@ -170,7 +170,7 @@ ColumnLayout {
}
}
}
onAtYEndChanged: if (atYEnd && RootStore.historyTransactions.hasMore) fetchHistory()
onAtYEndChanged: if(atYEnd && RootStore.historyTransactions.count > 0 && RootStore.historyTransactions.hasMore) fetchHistory()
}
Component {