Skip to content

Commit

Permalink
feat(@wallet): make activity respect networks selector
Browse files Browse the repository at this point in the history
  • Loading branch information
alaibe committed Apr 11, 2023
1 parent fb86d87 commit 52c01f1
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
20 changes: 10 additions & 10 deletions src/app/modules/main/wallet_section/transactions/item.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
6 changes: 6 additions & 0 deletions src/app/modules/main/wallet_section/transactions/model.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
14 changes: 13 additions & 1 deletion src/app/modules/main/wallet_section/transactions/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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) =
Expand Down
24 changes: 21 additions & 3 deletions src/app/modules/main/wallet_section/transactions/view.nim
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ QtObject:
model: Model
modelVariant: QVariant
fetchingHistoryState: Table[string, bool]
enabledChainIds: seq[int]
isNonArchivalNode: bool

proc delete*(self: View) =
Expand Down Expand Up @@ -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:
Expand All @@ -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) =
Expand Down Expand Up @@ -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()

Expand All @@ -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()
Expand Down
12 changes: 11 additions & 1 deletion src/app_service/service/transaction/service.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion ui/imports/shared/views/HistoryView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ ColumnLayout {
}
}
}
onAtYEndChanged: if (atYEnd && RootStore.historyTransactions.hasMore) fetchHistory()
onAtYEndChanged: if(atYEnd && RootStore.historyTransactions.count > 0 && RootStore.historyTransactions.hasMore) fetchHistory()
}

Component {
Expand Down

0 comments on commit 52c01f1

Please sign in to comment.