chore(wallet) lookup symbols for wallet activity filter

Updates #11597
This commit is contained in:
Stefan 2023-08-29 12:59:23 +01:00 committed by Stefan Dunca
parent 2c769602f4
commit 600793e0de
3 changed files with 28 additions and 16 deletions

View File

@ -33,7 +33,6 @@ proc toRef*[T](obj: T): ref T =
const FETCH_BATCH_COUNT_DEFAULT = 10
const FETCH_RECIPIENTS_BATCH_COUNT_DEFAULT = 2000
# TODO: implement passing of collectibles
QtObject:
type
Controller* = ref object of QObject
@ -76,18 +75,16 @@ QtObject:
read = getRecipientsModel
proc buildMultiTransactionExtraData(self: Controller, metadata: backend_activity.ActivityEntry, item: MultiTransactionDto): ExtraData =
# TODO: Use symbols from backendEntry when they're available
result.inSymbol = item.toAsset
result.inAmount = self.currencyService.parseCurrencyValue(result.inSymbol, metadata.amountIn)
result.outSymbol = item.fromAsset
result.outAmount = self.currencyService.parseCurrencyValue(result.outSymbol, metadata.amountOut)
if metadata.symbolIn.isSome():
result.inAmount = self.currencyService.parseCurrencyValue(metadata.symbolIn.get(), metadata.amountIn)
if metadata.symbolOut.isSome():
result.outAmount = self.currencyService.parseCurrencyValue(metadata.symbolOut.get(), metadata.amountOut)
proc buildTransactionExtraData(self: Controller, metadata: backend_activity.ActivityEntry, item: ref TransactionDto): ExtraData =
# TODO: Use symbols from backendEntry when they're available
result.inSymbol = item[].symbol
result.inAmount = self.currencyService.parseCurrencyValue(result.inSymbol, metadata.amountIn)
result.outSymbol = item[].symbol
result.outAmount = self.currencyService.parseCurrencyValue(result.outSymbol, metadata.amountOut)
if metadata.symbolIn.isSome():
result.inAmount = self.currencyService.parseCurrencyValue(metadata.symbolIn.get(), metadata.amountIn)
if metadata.symbolOut.isSome():
result.outAmount = self.currencyService.parseCurrencyValue(metadata.symbolOut.get(), metadata.amountOut)
proc getResolvedSymbol(self: Controller, transaction: TransactionDto): string =
if transaction.symbol != "":

View File

@ -19,9 +19,6 @@ type
ExtraData* = object
inAmount*: float64
outAmount*: float64
# TODO: Fields below should come from the metadata. see #11597
inSymbol*: string
outSymbol*: string
AmountToCurrencyConvertor* = proc (amount: UInt256, symbol: string): CurrencyAmount
@ -147,13 +144,13 @@ QtObject:
read = getRecipient
proc getInSymbol*(self: ActivityEntry): string {.slot.} =
return self.extradata.inSymbol
return self.metadata.symbolIn.get("")
QtProperty[string] inSymbol:
read = getInSymbol
proc getOutSymbol*(self: ActivityEntry): string {.slot.} =
return self.extradata.outSymbol
return self.metadata.symbolOut.get("")
QtProperty[string] outSymbol:
read = getOutSymbol

View File

@ -272,6 +272,8 @@ type
tokenOut*: Option[Token]
tokenIn*: Option[Token]
symbolOut*: Option[string]
symbolIn*: Option[string]
sender*: Option[eth.Address]
recipient*: Option[eth.Address]
@ -295,6 +297,8 @@ type
tokenOut*: Option[Token]
tokenIn*: Option[Token]
symbolOut*: Option[string]
symbolIn*: Option[string]
sender*: Option[eth.Address]
recipient*: Option[eth.Address]
@ -331,6 +335,8 @@ proc fromJson*(e: JsonNode, T: typedesc[Data]): Data {.inline.} =
const amountInField = "amountIn"
const tokenOutField = "tokenOut"
const tokenInField = "tokenIn"
const symbolOutField = "symbolOut"
const symbolInField = "symbolIn"
const senderField = "sender"
const recipientField = "recipient"
const chainIdOutField = "chainIdOut"
@ -364,6 +370,14 @@ proc fromJson*(e: JsonNode, T: typedesc[Data]): Data {.inline.} =
some(fromJson(e[tokenInField], Token))
else:
none(Token),
symbolOut: if e.contains(symbolOutField):
some(e[symbolOutField].getStr())
else:
none(string),
symbolIn: if e.contains(symbolInField):
some(e[symbolInField].getStr())
else:
none(string),
nftName: if e.contains(nftNameField): some(e[nftNameField].getStr()) else: none(string),
nftUrl: if e.contains(nftUrlField): some(e[nftUrlField].getStr()) else: none(string),
@ -396,6 +410,8 @@ proc fromJson*(e: JsonNode, T: typedesc[ActivityEntry]): ActivityEntry {.inline.
amountIn: data.amountIn.get(),
tokenOut: data.tokenOut,
tokenIn: data.tokenIn,
symbolOut: data.symbolOut,
symbolIn: data.symbolIn,
sender: data.sender,
recipient: data.recipient,
chainIdOut: data.chainIdOut,
@ -417,6 +433,8 @@ proc `$`*(self: ActivityEntry): string =
amountIn* {$self.amountIn},
tokenOut* {$self.tokenOut},
tokenIn* {$self.tokenIn}
symbolOut* {$self.symbolOut}
symbolIn* {$self.symbolIn}
sender* {$self.sender}
recipient* {$self.recipient}
chainIdOut* {$self.chainIdOut}