chore: remove unused activity details code

This commit is contained in:
Dario Gabriel Lipicar 2024-11-29 12:09:39 -03:00 committed by dlipicar
parent a13349323b
commit 7c0eb01294
6 changed files with 2 additions and 346 deletions

View File

@ -10,8 +10,6 @@ import events_handler
import status
import utils
import details_controller as details_controller
import web3/conversions
import app/core/eventemitter
@ -49,8 +47,6 @@ QtObject:
tokenService: token_service.Service
savedAddressService: saved_address_service.Service
detailsController: details_controller.Controller
eventsHandler: EventsHandler
status: Status
@ -90,18 +86,6 @@ QtObject:
let ae = entry.newActivityEntry(backendEntry, self.addresses, self.currencyService)
result.add(ae)
proc fetchTxDetails*(self: Controller, txID: string) {.slot.} =
let index = self.model.getIndex(txID)
if index == -1:
error "entry index not found"
return
let entry = self.model.getEntry(index)
if entry == nil:
error "entry not found"
return
self.detailsController.setActivityEntry(entry)
proc processResponse(self: Controller, response: JsonNode) =
defer: self.status.setLoadingData(false)
@ -318,8 +302,7 @@ QtObject:
error "Error converting activity entries: ", e.msg
)
proc newController*(detailsController: details_controller.Controller,
currencyService: currency_service.Service,
proc newController*(currencyService: currency_service.Service,
tokenService: token_service.Service,
savedAddressService: saved_address_service.Service,
events: EventEmitter): Controller =
@ -336,7 +319,6 @@ QtObject:
result.status = newStatus()
result.currencyService = currencyService
result.detailsController = detailsController
result.filterTokenCodes = initHashSet[string]()

View File

@ -1,75 +0,0 @@
import NimQml, logging, stint
import entry
import entry_details
import app_service/service/currency/service as currency_service
import app/modules/shared/wallet_utils
import app/modules/shared_models/currency_amount
QtObject:
type
Controller* = ref object of QObject
activityEntry: ActivityEntry
activityDetails: ActivityDetails
currencyService: currency_service.Service
proc setup(self: Controller) =
self.QObject.setup
proc delete*(self: Controller) =
self.QObject.delete
proc newController*(currencyService: currency_service.Service): Controller =
new(result, delete)
result.currencyService = currencyService
result.setup()
proc activityEntryChanged*(self: Controller) {.signal.}
proc getActivityEntry(self: Controller): QVariant {.slot.} =
if self.activityEntry == nil:
return newQVariant()
return newQVariant(self.activityEntry)
QtProperty[QVariant] activityEntry:
read = getActivityEntry
notify = activityEntryChanged
proc activityDetailsChanged*(self: Controller) {.signal.}
proc getActivityDetails(self: Controller): QVariant {.slot.} =
if self.activityDetails == nil:
return newQVariant()
return newQVariant(self.activityDetails)
QtProperty[QVariant] activityDetails:
read = getActivityDetails
notify = activityDetailsChanged
proc setActivityEntry*(self: Controller, entry: ActivityEntry) =
if self.activityDetails != nil:
self.activityDetails = nil
self.activityDetailsChanged()
self.activityEntry = entry
self.activityEntryChanged()
proc resetActivityEntry*(self: Controller) {.slot.} =
self.setActivityEntry(nil)
proc fetchExtraTxDetails*(self: Controller) {.slot.} =
let amountToCurrencyConvertor = proc(amount: UInt256, symbol: string): CurrencyAmount =
return currencyAmountToItem(self.currencyService.parseCurrencyValue(symbol, amount),
self.currencyService.getCurrencyFormat(symbol))
if self.activityEntry == nil:
error "activity entry is not set"
return
try:
self.activityDetails = newActivityDetails(self.activityEntry.getMetadata(), amountToCurrencyConvertor)
self.activityDetailsChanged()
except Exception as e:
error "error: ", e.msg
return

View File

@ -1,225 +0,0 @@
import NimQml, json, stint, strutils, logging, options
import backend/activity as backend
import backend/backend as common_backend
import app/modules/shared_models/currency_amount
import web3/ethtypes as eth
import web3/conversions
type
AmountToCurrencyConvertor* = proc (amount: UInt256, symbol: string): CurrencyAmount
ActivityChainDetails = object
chainId: ChainId
blockNumber: int
txHash: string
contractAddress: Option[eth.Address]
QtObject:
type
ActivityDetails* = ref object of QObject
id*: string
metadata: backend.ActivityEntry
# TODO use medatada
multiTxId: int
nonce*: int
blockNumberOut*: int
blockNumberIn*: int
protocolType*: Option[backend.ProtocolType]
txHashOut*: string
txHashIn*: string
input*: string
contractAddressIn: Option[eth.Address]
contractAddressOut: Option[eth.Address]
maxTotalFees: CurrencyAmount
totalFees: CurrencyAmount
proc setup(self: ActivityDetails) =
self.QObject.setup
proc delete*(self: ActivityDetails) =
self.QObject.delete
proc getMaxTotalFees(maxFee: string, gasLimit: string): string =
return (stint.fromHex(Uint256, maxFee) * stint.fromHex(Uint256, gasLimit)).toHex
proc fromJson*(e: JsonNode, T: typedesc[ActivityChainDetails]): ActivityChainDetails {.inline.} =
const contractAddressField = "contractAddress"
result = T(
chainId: ChainId(e["chainId"].getInt()),
blockNumber: e["blockNumber"].getInt(),
txHash: e["hash"].getStr(),
)
if e.hasKey(contractAddressField) and e[contractAddressField].kind != JNull:
var contractAddress: eth.Address
fromJson(e[contractAddressField], contractAddressField, contractAddress)
result.contractAddress = some(contractAddress)
proc newActivityDetails*(metadata: backend.ActivityEntry, valueConvertor: AmountToCurrencyConvertor): ActivityDetails =
new(result, delete)
defer: result.setup()
result.maxTotalFees = newCurrencyAmount()
result.totalFees = newCurrencyAmount()
var e: JsonNode
case metadata.getPayloadType():
of PendingTransaction:
result.id = metadata.getTransactionIdentity().get().hash
return
of MultiTransaction:
result.multiTxId = metadata.getMultiTransactionId.get(0)
let res = backend.getMultiTxDetails(metadata.getMultiTransactionId().get(0))
if res.error != nil:
error "failed to fetch multi tx details: ", metadata.getMultiTransactionId()
return
e = res.result
of SimpleTransaction:
let res = backend.getTxDetails(metadata.getTransactionIdentity().get().hash)
if res.error != nil:
error "failed to fetch tx details: ", metadata.getTransactionIdentity().get().hash
return
e = res.result
const protocolTypeField = "protocolType"
const inputField = "input"
const totalFeesField = "totalFees"
const chainDetailsField = "chainDetails"
result.id = e["id"].getStr()
result.multiTxId = e["multiTxId"].getInt()
result.nonce = e["nonce"].getInt()
let chainIdOut = metadata.chainIdOut.get(ChainId(0))
let chainIdIn = metadata.chainIdIn.get(ChainId(0))
if e[chainDetailsField].kind == JArray:
for chainDetails in e[chainDetailsField].items:
let chainDetails = fromJson(chainDetails, ActivityChainDetails)
if chainDetails.chainId == chainIdOut:
result.blockNumberOut = chainDetails.blockNumber
result.txHashOut = chainDetails.txHash
result.contractAddressOut = chainDetails.contractAddress
elif chainDetails.chainId == chainIdIn:
result.blockNumberIn = chainDetails.blockNumber
result.txHashIn = chainDetails.txHash
result.contractAddressIn = chainDetails.contractAddress
let maxFeePerGas = e["maxFeePerGas"].getStr()
let gasLimit = e["gasLimit"].getStr()
const gweiSymbol = "Gwei"
if len(maxFeePerGas) > 0 and len(gasLimit) > 0:
let maxTotalFees = getMaxTotalFees(maxFeePerGas, gasLimit)
result.maxTotalFees = valueConvertor(stint.fromHex(UInt256, maxTotalFees), gweiSymbol)
if e.hasKey(totalFeesField) and e[totalFeesField].kind != JNull:
let totalFees = e[totalFeesField].getStr()
let resTotalFees = valueConvertor(stint.fromHex(UInt256, totalFees), gweiSymbol)
if resTotalFees != nil:
result.totalFees = resTotalFees
if e.hasKey(protocolTypeField) and e[protocolTypeField].kind != JNull:
result.protocolType = some(fromJson(e[protocolTypeField], backend.ProtocolType))
if e.hasKey(inputField) and e[inputField].kind != JNull:
result.input = e[inputField].getStr()
proc getNonce*(self: ActivityDetails): int {.slot.} =
return self.nonce
QtProperty[int] nonce:
read = getNonce
proc getBlockNumberIn*(self: ActivityDetails): int {.slot.} =
return self.blockNumberIn
QtProperty[int] blockNumberIn:
read = getBlockNumberIn
proc getBlockNumberOut*(self: ActivityDetails): int {.slot.} =
return self.blockNumberOut
QtProperty[int] blockNumberOut:
read = getBlockNumberOut
proc getBlockNumber*(self: ActivityDetails): int {.slot.} =
if self.blockNumberOut > 0:
return self.blockNumberOut
return self.blockNumberIn
QtProperty[int] blockNumber:
read = getBlockNumber
proc getProtocol*(self: ActivityDetails): string {.slot.} =
if self.protocolType.isSome():
return $self.protocolType.unsafeGet()
return ""
QtProperty[string] protocol:
read = getProtocol
proc getTxHashOut*(self: ActivityDetails): string {.slot.} =
return self.txHashOut
QtProperty[string] txHashOut:
read = getTxHashOut
proc getTxHashIn*(self: ActivityDetails): string {.slot.} =
return self.txHashIn
QtProperty[string] txHashIn:
read = getTxHashIn
proc getTxHash*(self: ActivityDetails): string {.slot.} =
if self.txHashOut.len > 0:
return self.txHashOut
return self.txHashIn
QtProperty[string] txHash:
read = getTxHash
proc getInput*(self: ActivityDetails): string {.slot.} =
return self.input
QtProperty[string] input:
read = getInput
proc getContractIn*(self: ActivityDetails): string {.slot.} =
return if self.contractAddressIn.isSome(): "0x" & self.contractAddressIn.unsafeGet().toHex() else: ""
QtProperty[string] contractIn:
read = getContractIn
proc getContractOut*(self: ActivityDetails): string {.slot.} =
return if self.contractAddressOut.isSome(): "0x" & self.contractAddressOut.unsafeGet().toHex() else: ""
QtProperty[string] contractOut:
read = getContractOut
proc getMaxTotalFees*(self: ActivityDetails): QVariant {.slot.} =
return newQVariant(self.maxTotalFees)
QtProperty[QVariant] maxTotalFees:
read = getMaxTotalFees
proc getTotalFees*(self: ActivityDetails): QVariant {.slot.} =
return newQVariant(self.totalFees)
QtProperty[QVariant] totalFees:
read = getTotalFees
proc getTokenType*(self: ActivityDetails): string {.slot.} =
if self.metadata.tokenIn.isSome:
return $self.metadata.tokenIn.get().tokenType
if self.metadata.tokenOut.isSome:
return $self.metadata.tokenOut.get().tokenType
return ""
QtProperty[string] tokenType:
read = getTokenType

View File

@ -15,7 +15,6 @@ import ./overview/module as overview_module
import ./send/module as send_module
import ./activity/controller as activityc
import ./activity/details_controller as activity_detailsc
import app/modules/shared_modules/collectible_details/controller as collectible_detailsc
import app/modules/shared_modules/wallet_connect/controller as wc_controller
@ -95,7 +94,6 @@ type
# We need one for each app "layer" that simultaneously needs to show a different list of activity
# entries (e.g. send popup is one "layer" above the collectible details activity tab)
tmpActivityControllers: ActivityControllerArray
activityDetailsController: activity_detailsc.Controller
threadpool: ThreadPool
@ -150,22 +148,18 @@ proc newModule*(
result.networksService = networkService
result.transactionService = transactionService
result.activityDetailsController = activity_detailsc.newController(currencyService)
result.activityController = activityc.newController(
result.activityDetailsController,
currencyService,
tokenService,
savedAddressService,
events)
result.tmpActivityControllers = [
activityc.newController(
result.activityDetailsController,
currencyService,
tokenService,
savedAddressService,
events),
activityc.newController(
result.activityDetailsController,
currencyService,
tokenService,
savedAddressService,
@ -180,7 +174,7 @@ proc newModule*(
result.dappsConnectorService = connector_service.newService(result.events)
result.dappsConnectorController = connector_controller.newController(result.dappsConnectorService, result.events)
result.view = newView(result, result.activityController, result.tmpActivityControllers, result.activityDetailsController, result.collectibleDetailsController, result.walletConnectController, result.dappsConnectorController)
result.view = newView(result, result.activityController, result.tmpActivityControllers, result.collectibleDetailsController, result.walletConnectController, result.dappsConnectorController)
result.viewVariant = newQVariant(result.view)
method delete*(self: Module) =
@ -197,7 +191,6 @@ method delete*(self: Module) =
self.activityController.delete
for i in 0..self.tmpActivityControllers.len-1:
self.tmpActivityControllers[i].delete
self.activityDetailsController.delete
self.collectibleDetailsController.delete
if not self.addAccountModule.isNil:

View File

@ -1,7 +1,6 @@
import NimQml, json
import ./activity/controller as activityc
import ./activity/details_controller as activity_detailsc
import app/modules/shared_modules/collectible_details/controller as collectible_detailsc
import ./io_interface
import app/modules/shared_models/currency_amount
@ -22,7 +21,6 @@ QtObject:
tmpSymbol: string # shouldn't be used anywhere except in prepare*/getPrepared* procs
activityController: activityc.Controller
tmpActivityControllers: ActivityControllerArray
activityDetailsController: activity_detailsc.Controller
collectibleDetailsController: collectible_detailsc.Controller
isNonArchivalNode: bool
keypairOperabilityForObservedAccount: string
@ -46,7 +44,6 @@ QtObject:
proc newView*(delegate: io_interface.AccessInterface,
activityController: activityc.Controller,
tmpActivityControllers: ActivityControllerArray,
activityDetailsController: activity_detailsc.Controller,
collectibleDetailsController: collectible_detailsc.Controller,
wcController: wc_controller.Controller,
dappsConnectorController: connector_controller.Controller): View =
@ -54,7 +51,6 @@ QtObject:
result.delegate = delegate
result.activityController = activityController
result.tmpActivityControllers = tmpActivityControllers
result.activityDetailsController = activityDetailsController
result.collectibleDetailsController = collectibleDetailsController
result.wcController = newQVariant(wcController)
result.dappsConnectorController = newQVariant(dappsConnectorController)
@ -181,11 +177,6 @@ QtObject:
QtProperty[QVariant] tmpActivityController1:
read = getTmpActivityController1
proc getActivityDetailsController(self: View): QVariant {.slot.} =
return newQVariant(self.activityDetailsController)
QtProperty[QVariant] activityDetailsController:
read = getActivityDetailsController
proc getLatestBlockNumber*(self: View, chainId: int): string {.slot.} =
return self.delegate.getLatestBlockNumber(chainId)

View File

@ -104,7 +104,6 @@ QtObject {
readonly property var activityController: walletSectionInst.activityController
readonly property var tmpActivityController0: walletSectionInst.tmpActivityController0
readonly property var tmpActivityController1: walletSectionInst.tmpActivityController1
readonly property var activityDetailsController: walletSectionInst.activityDetailsController
readonly property var walletConnectController: walletSectionInst.walletConnectController
readonly property var dappsConnectorController: walletSectionInst.dappsConnectorController
@ -540,15 +539,6 @@ QtObject {
root.walletSectionInst.activityController.updateFilter()
}
function getTxDetails() {
return root.walletSectionInst.activityDetailsController.activityDetails
}
function fetchTxDetails(txID) {
root.walletSectionInst.activityController.fetchTxDetails(txID)
root.walletSectionInst.activityDetailsController.fetchExtraTxDetails()
}
function fetchDecodedTxData(txHash, input) {
root.walletSectionInst.fetchDecodedTxData(txHash, input)
}