diff --git a/src/app/modules/main/wallet_section/transactions/controller.nim b/src/app/modules/main/wallet_section/transactions/controller.nim index 78f5ff85bb..427819f445 100644 --- a/src/app/modules/main/wallet_section/transactions/controller.nim +++ b/src/app/modules/main/wallet_section/transactions/controller.nim @@ -86,6 +86,10 @@ proc init*(self: Controller) = # TODO: Refresh collectible data in Transaction items discard + self.events.on(SIGNAL_TRANSACTION_DECODED) do(e: Args): + let args = TransactionDecodedArgs(e) + self.delegate.txDecoded(args.txHash, args.dataDecoded) + proc watchPendingTransactions*(self: Controller): seq[TransactionDto] = return self.transactionService.watchPendingTransactions() @@ -124,3 +128,6 @@ proc findTokenSymbolByAddress*(self: Controller, address: string): string = proc getMultiTransactions*(self: Controller, transactionIDs: seq[int]): seq[MultiTransactionDto] = return transaction_service.getMultiTransactions(transactionIDs) + +proc fetchDecodedTxData*(self: Controller, txHash: string, data: string) = + self.transactionService.fetchDecodedTxData(txHash, data) \ No newline at end of file diff --git a/src/app/modules/main/wallet_section/transactions/io_interface.nim b/src/app/modules/main/wallet_section/transactions/io_interface.nim index f8170ca9d8..cbd3d2a8a5 100644 --- a/src/app/modules/main/wallet_section/transactions/io_interface.nim +++ b/src/app/modules/main/wallet_section/transactions/io_interface.nim @@ -54,6 +54,12 @@ method getChainIdForBrowser*(self: AccessInterface): int {.base.} = method refreshTransactions*(self: AccessInterface) {.base.} = raise newException(ValueError, "No implementation available") +method fetchDecodedTxData*(self: AccessInterface, txHash: string, data: string) {.base.} = + raise newException(ValueError, "No implementation available") + +method txDecoded*(self: AccessInterface, txHash: string, dataDecoded: 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. diff --git a/src/app/modules/main/wallet_section/transactions/module.nim b/src/app/modules/main/wallet_section/transactions/module.nim index 747fe71b1f..a18b9ecfbc 100644 --- a/src/app/modules/main/wallet_section/transactions/module.nim +++ b/src/app/modules/main/wallet_section/transactions/module.nim @@ -136,4 +136,10 @@ method getLatestBlockNumber*(self: Module, chainId: int): string = return self.controller.getLatestBlockNumber(chainId) method transactionWasSent*(self: Module, result: string) = - self.view.setPendingTx(self.transactionsToItems(self.controller.getPendingTransactions(), @[])) \ No newline at end of file + self.view.setPendingTx(self.transactionsToItems(self.controller.getPendingTransactions(), @[])) + +method fetchDecodedTxData*(self: Module, txHash: string, data: string) = + self.controller.fetchDecodedTxData(txHash, data) + +method txDecoded*(self: Module, txHash: string, dataDecoded: string) = + self.view.txDecoded(txHash, dataDecoded) diff --git a/src/app/modules/main/wallet_section/transactions/view.nim b/src/app/modules/main/wallet_section/transactions/view.nim index b2c2c268f4..90a0558b41 100644 --- a/src/app/modules/main/wallet_section/transactions/view.nim +++ b/src/app/modules/main/wallet_section/transactions/view.nim @@ -159,3 +159,8 @@ QtObject: return newQVariant(self.models[self.tempAddress]) else: return newQVariant() + + proc fetchDecodedTxData*(self: View, txHash: string, data: string) {.slot.} = + self.delegate.fetchDecodedTxData(txHash, data) + + proc txDecoded*(self: View, txHash: string, dataDecoded: string) {.signal.} \ No newline at end of file diff --git a/src/app_service/service/transaction/async_tasks.nim b/src/app_service/service/transaction/async_tasks.nim index a622894fd8..22edaf649d 100644 --- a/src/app_service/service/transaction/async_tasks.nim +++ b/src/app_service/service/transaction/async_tasks.nim @@ -3,6 +3,7 @@ ################################################# import stint +import ../../../backend/backend as backend import ../../common/conversion as service_conversion import ../../common/wallet_constants @@ -221,3 +222,24 @@ const getCryptoServicesTask*: Task = proc(argEncoded: string) {.gcsafe, nimcall. arg.finish(%* { "result": @[], }) + +type + FetchDecodedTxDataTaskArg* = ref object of QObjectTaskArg + txHash: string + data: string + +const fetchDecodedTxDataTask*: Task = proc(argEncoded: string) {.gcsafe, nimcall.} = + let arg = decode[FetchDecodedTxDataTaskArg](argEncoded) + + try: + let response = backend.fetchDecodedTxData(arg.data) + arg.finish(%* { + "txHash": arg.txHash, + "result": $response.result, + }) + except Exception as e: + error "Error decoding tx input", message = e.msg + arg.finish(%* { + "txHash": arg.txHash, + "result": "", + }) diff --git a/src/app_service/service/transaction/service.nim b/src/app_service/service/transaction/service.nim index e9b060eb57..d6324d37b3 100644 --- a/src/app_service/service/transaction/service.nim +++ b/src/app_service/service/transaction/service.nim @@ -48,6 +48,7 @@ const SIGNAL_HISTORY_NON_ARCHIVAL_NODE* = "historyNonArchivalNode" const SIGNAL_HISTORY_ERROR* = "historyError" const SIGNAL_NEW_TRANSFERS* = "newTransfers" const SIGNAL_CRYPTO_SERVICES_READY* = "cryptoServicesReady" +const SIGNAL_TRANSACTION_DECODED* = "transactionDecoded" const SIMPLE_TX_BRIDGE_NAME = "Simple" const HOP_TX_BRIDGE_NAME = "Hop" @@ -95,6 +96,10 @@ type type CryptoServicesArgs* = ref object of Args data*: seq[CryptoRampDto] +type + TransactionDecodedArgs* = ref object of Args + dataDecoded*: string + txHash*: string QtObject: type Service* = ref object of QObject @@ -220,6 +225,21 @@ QtObject: ) self.threadpool.start(arg) + + proc onFetchDecodedTxData*(self: Service, response: string) {.slot.} = + let data = parseJson(response) + self.events.emit(SIGNAL_TRANSACTION_DECODED, TransactionDecodedArgs(dataDecoded: data["result"].getStr, txHash: data["txHash"].getStr)) + + proc fetchDecodedTxData*(self: Service, txHash: string, data: string) = + let arg = FetchDecodedTxDataTaskArg( + tptr: cast[ByteAddress](fetchDecodedTxDataTask), + vptr: cast[ByteAddress](self.vptr), + data: data, + txHash: txHash, + slot: "onFetchDecodedTxData", + ) + self.threadpool.start(arg) + proc watchPendingTransactions*(self: Service): seq[TransactionDto] = let pendingTransactions = self.getPendingTransactions() for tx in pendingTransactions: @@ -234,6 +254,7 @@ QtObject: let allTxLoaded = historyData["allTxLoaded"].getBool var transactions: seq[TransactionDto] = @[] var collectibles: seq[CollectibleDto] = @[] + for tx in historyData["history"].getElems(): let dto = tx.toTransactionDto() self.allTransactions.mgetOrPut(address, initTable[string, TransactionDto]())[dto.txHash] = dto @@ -523,9 +544,6 @@ QtObject: self.events.emit(SIGNAL_CRYPTO_SERVICES_READY, CryptoServicesArgs(data: cryptoServices)) proc fetchCryptoServices*(self: Service) = - if(not main_constants.WALLET_ENABLED): - return - let arg = GetCryptoServicesTaskArg( tptr: cast[ByteAddress](getCryptoServicesTask), vptr: cast[ByteAddress](self.vptr), diff --git a/src/backend/backend.nim b/src/backend/backend.nim index 79795fe7b9..32ab72468e 100644 --- a/src/backend/backend.nim +++ b/src/backend/backend.nim @@ -143,6 +143,9 @@ rpc(fetchPrices, "wallet"): symbols: seq[string] currencies: seq[string] +rpc(fetchDecodedTxData, "wallet"): + data: string + rpc(activityCenterNotifications, "wakuext"): request: ActivityCenterNotificationsRequest