mirror of
https://github.com/status-im/status-desktop.git
synced 2025-01-10 14:26:34 +00:00
feat(@wallet): make activity respect networks selector
This commit is contained in:
parent
fb86d8745c
commit
52c01f1dd5
@ -85,6 +85,9 @@ proc init*(self: Controller) =
|
|||||||
let args = TransactionsLoadedArgs(e)
|
let args = TransactionsLoadedArgs(e)
|
||||||
self.delegate.setHistoryFetchState(args.address, args.allTxLoaded, isFetching = false)
|
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):
|
self.events.on(SIGNAL_CURRENCY_FORMATS_UPDATED) do(e:Args):
|
||||||
# TODO: Rebuild Transaction items
|
# TODO: Rebuild Transaction items
|
||||||
discard
|
discard
|
||||||
@ -122,6 +125,9 @@ proc suggestedFees*(self: Controller, chainId: int): string =
|
|||||||
let suggestedFees = self.transactionService.suggestedFees(chainId)
|
let suggestedFees = self.transactionService.suggestedFees(chainId)
|
||||||
return suggestedFees.toJson()
|
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 =
|
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)
|
let suggestedRoutes = self.transactionService.suggestedRoutes(account, amount, token, disabledFromChainIDs, disabledToChainIDs, preferredChainIDs, sendType, lockedInAmounts)
|
||||||
return suggestedRoutes.toJson()
|
return suggestedRoutes.toJson()
|
||||||
@ -138,6 +144,8 @@ proc getEstimatedTime*(self: Controller, chainId: int, maxFeePerGas: string): Es
|
|||||||
proc getLastTxBlockNumber*(self: Controller): string =
|
proc getLastTxBlockNumber*(self: Controller): string =
|
||||||
return self.transactionService.getLastTxBlockNumber(self.networkService.getNetworkForBrowser().chainId)
|
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 = "") =
|
proc authenticateUser*(self: Controller, keyUid = "") =
|
||||||
let data = SharedKeycarModuleAuthenticationArgs(uniqueIdentifier: UNIQUE_WALLET_SECTION_TRANSACTION_MODULE_IDENTIFIER,
|
let data = SharedKeycarModuleAuthenticationArgs(uniqueIdentifier: UNIQUE_WALLET_SECTION_TRANSACTION_MODULE_IDENTIFIER,
|
||||||
|
@ -69,6 +69,9 @@ method getChainIdForBrowser*(self: AccessInterface): int =
|
|||||||
method getEstimatedTime*(self: AccessInterface, chainId: int, maxFeePerGas: string): int {.base.} =
|
method getEstimatedTime*(self: AccessInterface, chainId: int, maxFeePerGas: string): int {.base.} =
|
||||||
raise newException(ValueError, "No implementation available")
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
|
method refreshTransactions*(self: AccessInterface) {.base.} =
|
||||||
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
# View Delegate Interface
|
# View Delegate Interface
|
||||||
# Delegate for the view must be declared here due to use of QtObject and multi
|
# Delegate for the view must be declared here due to use of QtObject and multi
|
||||||
# inheritance, which is not well supported in Nim.
|
# inheritance, which is not well supported in Nim.
|
||||||
|
@ -258,34 +258,34 @@ proc getMaxFeePerGas*(self: Item): CurrencyAmount =
|
|||||||
proc getMaxPriorityFeePerGas*(self: Item): CurrencyAmount =
|
proc getMaxPriorityFeePerGas*(self: Item): CurrencyAmount =
|
||||||
return self.maxPriorityFeePerGas
|
return self.maxPriorityFeePerGas
|
||||||
|
|
||||||
proc getInput*(self: Item): string =
|
proc getInput*(self: Item): string =
|
||||||
return self.input
|
return self.input
|
||||||
|
|
||||||
proc getTxHash*(self: Item): string =
|
proc getTxHash*(self: Item): string =
|
||||||
return self.txHash
|
return self.txHash
|
||||||
|
|
||||||
proc getMultiTransactionID*(self: Item): int =
|
proc getMultiTransactionID*(self: Item): int =
|
||||||
return self.multiTransactionID
|
return self.multiTransactionID
|
||||||
|
|
||||||
proc getIsTimeStamp*(self: Item): bool =
|
proc getIsTimeStamp*(self: Item): bool =
|
||||||
return self.isTimeStamp
|
return self.isTimeStamp
|
||||||
|
|
||||||
proc getIsNFT*(self: Item): bool =
|
proc getIsNFT*(self: Item): bool =
|
||||||
return self.isNFT
|
return self.isNFT
|
||||||
|
|
||||||
proc getBaseGasFees*(self: Item): CurrencyAmount =
|
proc getBaseGasFees*(self: Item): CurrencyAmount =
|
||||||
return self.baseGasFees
|
return self.baseGasFees
|
||||||
|
|
||||||
proc getTotalFees*(self: Item): CurrencyAmount =
|
proc getTotalFees*(self: Item): CurrencyAmount =
|
||||||
return self.totalFees
|
return self.totalFees
|
||||||
|
|
||||||
proc getMaxTotalFees*(self: Item): CurrencyAmount =
|
proc getMaxTotalFees*(self: Item): CurrencyAmount =
|
||||||
return self.maxTotalFees
|
return self.maxTotalFees
|
||||||
|
|
||||||
proc getSymbol*(self: Item): string =
|
proc getSymbol*(self: Item): string =
|
||||||
return self.symbol
|
return self.symbol
|
||||||
|
|
||||||
proc getLoadingTransaction*(self: Item): bool =
|
proc getLoadingTransaction*(self: Item): bool =
|
||||||
return self.loadingTransaction
|
return self.loadingTransaction
|
||||||
|
|
||||||
proc getTokenID*(self: Item): UInt256 =
|
proc getTokenID*(self: Item): UInt256 =
|
||||||
|
@ -188,6 +188,12 @@ QtObject:
|
|||||||
self.endResetModel()
|
self.endResetModel()
|
||||||
self.countChanged()
|
self.countChanged()
|
||||||
|
|
||||||
|
proc resetItems*(self: Model) =
|
||||||
|
self.beginResetModel()
|
||||||
|
self.items = @[]
|
||||||
|
self.endResetModel()
|
||||||
|
self.countChanged()
|
||||||
|
|
||||||
proc getLastTxBlockNumber*(self: Model): string {.slot.} =
|
proc getLastTxBlockNumber*(self: Model): string {.slot.} =
|
||||||
if (self.items.len == 0):
|
if (self.items.len == 0):
|
||||||
return "0x0"
|
return "0x0"
|
||||||
|
@ -107,12 +107,24 @@ proc transactionsToItems(self: Module, transactions: seq[TransactionDto], collec
|
|||||||
proc setPendingTx(self: Module) =
|
proc setPendingTx(self: Module) =
|
||||||
self.view.setPendingTx(self.transactionsToItems(self.controller.watchPendingTransactions(), @[]))
|
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) =
|
method viewDidLoad*(self: Module) =
|
||||||
let accounts = self.getWalletAccounts()
|
let accounts = self.getWalletAccounts()
|
||||||
|
|
||||||
self.moduleLoaded = true
|
self.moduleLoaded = true
|
||||||
self.delegate.transactionsModuleDidLoad()
|
self.delegate.transactionsModuleDidLoad()
|
||||||
|
self.setEnabledChainIds()
|
||||||
self.setPendingTx()
|
self.setPendingTx()
|
||||||
|
|
||||||
method switchAccount*(self: Module, accountIndex: int) =
|
method switchAccount*(self: Module, accountIndex: int) =
|
||||||
|
@ -15,6 +15,7 @@ QtObject:
|
|||||||
model: Model
|
model: Model
|
||||||
modelVariant: QVariant
|
modelVariant: QVariant
|
||||||
fetchingHistoryState: Table[string, bool]
|
fetchingHistoryState: Table[string, bool]
|
||||||
|
enabledChainIds: seq[int]
|
||||||
isNonArchivalNode: bool
|
isNonArchivalNode: bool
|
||||||
|
|
||||||
proc delete*(self: View) =
|
proc delete*(self: View) =
|
||||||
@ -72,14 +73,25 @@ QtObject:
|
|||||||
self.models[address].addPageSizeBuffer(limit)
|
self.models[address].addPageSizeBuffer(limit)
|
||||||
self.delegate.loadTransactions(address, toBlock, limit, loadMore)
|
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) =
|
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):
|
if not self.models.hasKey(address):
|
||||||
self.models[address] = newModel()
|
self.models[address] = newModel()
|
||||||
|
|
||||||
self.models[address].removePageSizeBuffer()
|
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:
|
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) =
|
proc setHistoryFetchStateForAccounts*(self: View, addresses: seq[string], isFetching: bool) =
|
||||||
for address in addresses:
|
for address in addresses:
|
||||||
@ -106,6 +118,9 @@ QtObject:
|
|||||||
proc getIsNonArchivalNode(self: View): QVariant {.slot.} =
|
proc getIsNonArchivalNode(self: View): QVariant {.slot.} =
|
||||||
return newQVariant(self.isNonArchivalNode)
|
return newQVariant(self.isNonArchivalNode)
|
||||||
|
|
||||||
|
proc setEnabledChainIds*(self: View, chainIds: seq[int]) =
|
||||||
|
self.enabledChainIds = chainIds
|
||||||
|
|
||||||
proc isNonArchivalNodeChanged(self: View) {.signal.}
|
proc isNonArchivalNodeChanged(self: View) {.signal.}
|
||||||
|
|
||||||
proc setIsNonArchivalNode*(self: View, isNonArchivalNode: bool) =
|
proc setIsNonArchivalNode*(self: View, isNonArchivalNode: bool) =
|
||||||
@ -158,7 +173,7 @@ QtObject:
|
|||||||
discard
|
discard
|
||||||
|
|
||||||
return self.delegate.suggestedRoutes(account, parsedAmount, token, seqDisabledFromChainIDs, seqDisabledToChainIDs, seqPreferredChainIDs, sendType, lockedInAmounts)
|
return self.delegate.suggestedRoutes(account, parsedAmount, token, seqDisabledFromChainIDs, seqDisabledToChainIDs, seqPreferredChainIDs, sendType, lockedInAmounts)
|
||||||
|
|
||||||
proc getChainIdForChat*(self: View): int {.slot.} =
|
proc getChainIdForChat*(self: View): int {.slot.} =
|
||||||
return self.delegate.getChainIdForChat()
|
return self.delegate.getChainIdForChat()
|
||||||
|
|
||||||
@ -175,6 +190,9 @@ QtObject:
|
|||||||
|
|
||||||
proc setPendingTx*(self: View, pendingTx: seq[Item]) =
|
proc setPendingTx*(self: View, pendingTx: seq[Item]) =
|
||||||
for tx in pendingTx:
|
for tx in pendingTx:
|
||||||
|
if not self.enabledChainIds.contains(tx.getChainId()):
|
||||||
|
continue
|
||||||
|
|
||||||
let fromAddress = tx.getfrom()
|
let fromAddress = tx.getfrom()
|
||||||
if not self.models.hasKey(fromAddress):
|
if not self.models.hasKey(fromAddress):
|
||||||
self.models[fromAddress] = newModel()
|
self.models[fromAddress] = newModel()
|
||||||
|
@ -105,6 +105,7 @@ QtObject:
|
|||||||
tokenService: token_service.Service
|
tokenService: token_service.Service
|
||||||
txCounter: Table[string, seq[int]]
|
txCounter: Table[string, seq[int]]
|
||||||
allTxLoaded: Table[string, bool]
|
allTxLoaded: Table[string, bool]
|
||||||
|
allTransactions: Table[string, Table[string, TransactionDto]]
|
||||||
|
|
||||||
# Forward declaration
|
# Forward declaration
|
||||||
proc loadTransactions*(self: Service, address: string, toBlock: Uint256, limit: int = 20, loadMore: bool = false)
|
proc loadTransactions*(self: Service, address: string, toBlock: Uint256, limit: int = 20, loadMore: bool = false)
|
||||||
@ -128,6 +129,7 @@ QtObject:
|
|||||||
result.tokenService = tokenService
|
result.tokenService = tokenService
|
||||||
result.txCounter = initTable[string, seq[int]]()
|
result.txCounter = initTable[string, seq[int]]()
|
||||||
result.allTxLoaded = initTable[string, bool]()
|
result.allTxLoaded = initTable[string, bool]()
|
||||||
|
result.allTransactions = initTable[string, Table[string, TransactionDto]]()
|
||||||
|
|
||||||
proc init*(self: Service) =
|
proc init*(self: Service) =
|
||||||
self.events.on(SignalType.Wallet.event) do(e:Args):
|
self.events.on(SignalType.Wallet.event) do(e:Args):
|
||||||
@ -167,6 +169,12 @@ QtObject:
|
|||||||
error "error: ", errDescription
|
error "error: ", errDescription
|
||||||
return
|
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.} =
|
proc watchTransactionResult*(self: Service, watchTxResult: string) {.slot.} =
|
||||||
let watchTxResult = parseJson(watchTxResult)
|
let watchTxResult = parseJson(watchTxResult)
|
||||||
let success = watchTxResult["isSuccessfull"].getBool
|
let success = watchTxResult["isSuccessfull"].getBool
|
||||||
@ -224,7 +232,9 @@ QtObject:
|
|||||||
var transactions: seq[TransactionDto] = @[]
|
var transactions: seq[TransactionDto] = @[]
|
||||||
var collectibles: seq[CollectibleDto] = @[]
|
var collectibles: seq[CollectibleDto] = @[]
|
||||||
for tx in historyData["history"].getElems():
|
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"]
|
let collectiblesContainerJson = historyData["collectibles"]
|
||||||
if collectiblesContainerJson.kind == JObject:
|
if collectiblesContainerJson.kind == JObject:
|
||||||
|
@ -170,7 +170,7 @@ ColumnLayout {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onAtYEndChanged: if (atYEnd && RootStore.historyTransactions.hasMore) fetchHistory()
|
onAtYEndChanged: if(atYEnd && RootStore.historyTransactions.count > 0 && RootStore.historyTransactions.hasMore) fetchHistory()
|
||||||
}
|
}
|
||||||
|
|
||||||
Component {
|
Component {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user