feat(@wallet): parse input data of tx

This commit is contained in:
Anthony Laibe 2023-05-30 11:20:16 +02:00 committed by Anthony Laibe
parent c4e9f8dba0
commit c7ab998ea8
7 changed files with 71 additions and 4 deletions

View File

@ -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)

View File

@ -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.

View File

@ -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(), @[]))
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)

View File

@ -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.}

View File

@ -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": "",
})

View File

@ -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),

View File

@ -143,6 +143,9 @@ rpc(fetchPrices, "wallet"):
symbols: seq[string]
currencies: seq[string]
rpc(fetchDecodedTxData, "wallet"):
data: string
rpc(activityCenterNotifications, "wakuext"):
request: ActivityCenterNotificationsRequest