chore(@desktop/wallet): intergrate uuid to Swap

Part of #15330
This commit is contained in:
Dario Gabriel Lipicar 2024-06-30 19:08:08 -03:00 committed by dlipicar
parent 273858bc81
commit 25127bfd63
10 changed files with 47 additions and 20 deletions

View File

@ -69,7 +69,8 @@ proc init*(self: Controller) =
self.delegate.onUserAuthenticated(args.password, args.pin) self.delegate.onUserAuthenticated(args.password, args.pin)
self.events.on(SIGNAL_SUGGESTED_ROUTES_READY) do(e:Args): self.events.on(SIGNAL_SUGGESTED_ROUTES_READY) do(e:Args):
self.delegate.suggestedRoutesReady(SuggestedRoutesArgs(e).suggestedRoutes) let args = SuggestedRoutesArgs(e)
self.delegate.suggestedRoutesReady(args.uuid, args.suggestedRoutes)
self.events.on(SignalType.WalletSignTransactions.event) do(e:Args): self.events.on(SignalType.WalletSignTransactions.event) do(e:Args):
var data = WalletSignal(e) var data = WalletSignal(e)
@ -108,6 +109,7 @@ proc authenticate*(self: Controller, keyUid = "") =
self.events.emit(SIGNAL_SHARED_KEYCARD_MODULE_AUTHENTICATE_USER, data) self.events.emit(SIGNAL_SHARED_KEYCARD_MODULE_AUTHENTICATE_USER, data)
proc suggestedRoutes*(self: Controller, proc suggestedRoutes*(self: Controller,
uuid: string,
sendType: SendType, sendType: SendType,
accountFrom: string, accountFrom: string,
accountTo: string, accountTo: string,
@ -119,7 +121,7 @@ proc suggestedRoutes*(self: Controller,
disabledToChainIDs: seq[int] = @[], disabledToChainIDs: seq[int] = @[],
lockedInAmounts: Table[string, string] = initTable[string, string](), lockedInAmounts: Table[string, string] = initTable[string, string](),
extraParamsTable: Table[string, string] = initTable[string, string]()) = extraParamsTable: Table[string, string] = initTable[string, string]()) =
self.transactionService.suggestedRoutes(sendType, accountFrom, accountTo, token, amountIn, toToken, amountOut, self.transactionService.suggestedRoutes(uuid, sendType, accountFrom, accountTo, token, amountIn, toToken, amountOut,
disabledFromChainIDs, disabledToChainIDs, lockedInAmounts, extraParamsTable) disabledFromChainIDs, disabledToChainIDs, lockedInAmounts, extraParamsTable)
proc transfer*(self: Controller, from_addr: string, to_addr: string, assetKey: string, toAssetKey: string, proc transfer*(self: Controller, from_addr: string, to_addr: string, assetKey: string, toAssetKey: string,

View File

@ -25,6 +25,7 @@ method getTokenBalance*(self: AccessInterface, address: string, chainId: int, to
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method suggestedRoutes*(self: AccessInterface, method suggestedRoutes*(self: AccessInterface,
uuid: string,
sendType: SendType, sendType: SendType,
accountFrom: string, accountFrom: string,
accountTo: string, accountTo: string,
@ -38,7 +39,7 @@ method suggestedRoutes*(self: AccessInterface,
extraParamsTable: Table[string, string] = initTable[string, string]()) {.base.} = extraParamsTable: Table[string, string] = initTable[string, string]()) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method suggestedRoutesReady*(self: AccessInterface, suggestedRoutes: SuggestedRoutesDto) {.base.} = method suggestedRoutesReady*(self: AccessInterface, uuid: string, suggestedRoutes: SuggestedRoutesDto) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method authenticateAndTransfer*(self: AccessInterface, from_addr: string, to_addr: string, assetKey: string, method authenticateAndTransfer*(self: AccessInterface, from_addr: string, to_addr: string, assetKey: string,

View File

@ -345,7 +345,7 @@ method transactionWasSent*(self: Module, chainId: int, txHash, uuid, error: stri
return return
self.view.sendTransactionSentSignal(chainId, txHash, uuid, error) self.view.sendTransactionSentSignal(chainId, txHash, uuid, error)
method suggestedRoutesReady*(self: Module, suggestedRoutes: SuggestedRoutesDto) = method suggestedRoutesReady*(self: Module, uuid: string, suggestedRoutes: SuggestedRoutesDto) =
self.tmpSendTransactionDetails.paths = suggestedRoutes.best self.tmpSendTransactionDetails.paths = suggestedRoutes.best
self.tmpSendTransactionDetails.slippagePercentage = none(float) self.tmpSendTransactionDetails.slippagePercentage = none(float)
let paths = suggestedRoutes.best.map(x => self.convertTransactionPathDtoToSuggestedRouteItem(x)) let paths = suggestedRoutes.best.map(x => self.convertTransactionPathDtoToSuggestedRouteItem(x))
@ -357,6 +357,7 @@ method suggestedRoutesReady*(self: Module, suggestedRoutes: SuggestedRoutesDto)
toNetworksModel.setItems(networks) toNetworksModel.setItems(networks)
self.view.updatedNetworksWithRoutes(paths, gasTimeEstimate.getTotalFeesInEth()) self.view.updatedNetworksWithRoutes(paths, gasTimeEstimate.getTotalFeesInEth())
let transactionRoutes = newTransactionRoutes( let transactionRoutes = newTransactionRoutes(
uuid = uuid,
suggestedRoutes = suggestedRouteModel, suggestedRoutes = suggestedRouteModel,
gasTimeEstimate = gasTimeEstimate, gasTimeEstimate = gasTimeEstimate,
amountToReceive = suggestedRoutes.amountToReceive, amountToReceive = suggestedRoutes.amountToReceive,
@ -365,6 +366,7 @@ method suggestedRoutesReady*(self: Module, suggestedRoutes: SuggestedRoutesDto)
self.view.setTransactionRoute(transactionRoutes) self.view.setTransactionRoute(transactionRoutes)
method suggestedRoutes*(self: Module, method suggestedRoutes*(self: Module,
uuid: string,
sendType: SendType, sendType: SendType,
accountFrom: string, accountFrom: string,
accountTo: string, accountTo: string,
@ -377,6 +379,7 @@ method suggestedRoutes*(self: Module,
lockedInAmounts: Table[string, string] = initTable[string, string](), lockedInAmounts: Table[string, string] = initTable[string, string](),
extraParamsTable: Table[string, string] = initTable[string, string]()) = extraParamsTable: Table[string, string] = initTable[string, string]()) =
self.controller.suggestedRoutes( self.controller.suggestedRoutes(
uuid,
sendType, sendType,
accountFrom, accountFrom,
accountTo, accountTo,

View File

@ -4,6 +4,7 @@ import ./gas_estimate_item, ./suggested_route_model, ./network_model
QtObject: QtObject:
type TransactionRoutes* = ref object of QObject type TransactionRoutes* = ref object of QObject
uuid: string
suggestedRoutes: SuggestedRouteModel suggestedRoutes: SuggestedRouteModel
gasTimeEstimate: GasEstimateItem gasTimeEstimate: GasEstimateItem
amountToReceive: UInt256 amountToReceive: UInt256
@ -11,6 +12,7 @@ QtObject:
rawPaths: string rawPaths: string
proc setup*(self: TransactionRoutes, proc setup*(self: TransactionRoutes,
uuid: string,
suggestedRoutes: SuggestedRouteModel, suggestedRoutes: SuggestedRouteModel,
gasTimeEstimate: GasEstimateItem, gasTimeEstimate: GasEstimateItem,
amountToReceive: UInt256, amountToReceive: UInt256,
@ -18,6 +20,7 @@ QtObject:
rawPaths: string rawPaths: string
) = ) =
self.QObject.setup self.QObject.setup
self.uuid = uuid
self.suggestedRoutes = suggestedRoutes self.suggestedRoutes = suggestedRoutes
self.gasTimeEstimate = gasTimeEstimate self.gasTimeEstimate = gasTimeEstimate
self.amountToReceive = amountToReceive self.amountToReceive = amountToReceive
@ -28,6 +31,7 @@ QtObject:
self.QObject.delete self.QObject.delete
proc newTransactionRoutes*( proc newTransactionRoutes*(
uuid: string = "",
suggestedRoutes: SuggestedRouteModel = newSuggestedRouteModel(), suggestedRoutes: SuggestedRouteModel = newSuggestedRouteModel(),
gasTimeEstimate: GasEstimateItem = newGasEstimateItem(), gasTimeEstimate: GasEstimateItem = newGasEstimateItem(),
amountToReceive: UInt256 = stint.u256(0), amountToReceive: UInt256 = stint.u256(0),
@ -35,10 +39,11 @@ QtObject:
rawPaths: string = "" rawPaths: string = ""
): TransactionRoutes = ): TransactionRoutes =
new(result, delete) new(result, delete)
result.setup(suggestedRoutes, gasTimeEstimate, amountToReceive, toNetworksModel, rawPaths) result.setup(uuid, suggestedRoutes, gasTimeEstimate, amountToReceive, toNetworksModel, rawPaths)
proc `$`*(self: TransactionRoutes): string = proc `$`*(self: TransactionRoutes): string =
result = fmt"""TransactionRoutes( result = fmt"""TransactionRoutes(
uuid: {self.uuid},
suggestedRoutes: {self.suggestedRoutes}, suggestedRoutes: {self.suggestedRoutes},
gasTimeEstimate: {self.gasTimeEstimate}, gasTimeEstimate: {self.gasTimeEstimate},
amountToReceive: {self.amountToReceive}, amountToReceive: {self.amountToReceive},
@ -46,6 +51,13 @@ QtObject:
rawPaths: {self.rawPaths}, rawPaths: {self.rawPaths},
]""" ]"""
proc uuidChanged*(self: TransactionRoutes) {.signal.}
proc getUuid*(self: TransactionRoutes): string {.slot.} =
return self.uuid
QtProperty[string] uuid:
read = getUuid
notify = uuidChanged
proc suggestedRoutesChanged*(self: TransactionRoutes) {.signal.} proc suggestedRoutesChanged*(self: TransactionRoutes) {.signal.}
proc getSuggestedRoutes*(self: TransactionRoutes): QVariant {.slot.} = proc getSuggestedRoutes*(self: TransactionRoutes): QVariant {.slot.} =
return newQVariant(self.suggestedRoutes) return newQVariant(self.suggestedRoutes)

View File

@ -1,4 +1,5 @@
import NimQml, Tables, json, sequtils, strutils, stint, sugar, options, chronicles import NimQml, Tables, json, sequtils, strutils, stint, sugar, options, chronicles
import uuids
import ./io_interface, ./accounts_model, ./account_item, ./network_model, ./network_item, ./suggested_route_item, ./transaction_routes import ./io_interface, ./accounts_model, ./account_item, ./network_model, ./network_item, ./suggested_route_item, ./transaction_routes
import app/modules/shared_models/collectibles_model as collectibles import app/modules/shared_models/collectibles_model as collectibles
@ -243,6 +244,7 @@ QtObject:
error "Error parsing extraParamsJson: ", msg=e.msg error "Error parsing extraParamsJson: ", msg=e.msg
self.delegate.suggestedRoutes( self.delegate.suggestedRoutes(
$genUUID(),
self.sendType, self.sendType,
self.selectedSenderAccount.address(), self.selectedSenderAccount.address(),
self.selectedRecipient, self.selectedRecipient,
@ -342,6 +344,7 @@ QtObject:
# "Stateless" methods # "Stateless" methods
proc fetchSuggestedRoutesWithParameters*(self: View, proc fetchSuggestedRoutesWithParameters*(self: View,
uuid: string,
accountFrom: string, accountFrom: string,
accountTo: string, accountTo: string,
amountIn: string, amountIn: string,
@ -361,6 +364,7 @@ QtObject:
discard discard
# Resolve the best route # Resolve the best route
self.delegate.suggestedRoutes( self.delegate.suggestedRoutes(
uuid,
SendType(sendType), SendType(sendType),
accountFrom, accountFrom,
accountTo, accountTo,

View File

@ -1,4 +1,4 @@
import Tables, NimQml, chronicles, sequtils, sugar, stint, strutils, json, uuids, stew/shims/strformat import Tables, NimQml, chronicles, sequtils, sugar, stint, strutils, json, stew/shims/strformat
import backend/collectibles as collectibles import backend/collectibles as collectibles
import backend/transactions as transactions import backend/transactions as transactions
@ -110,6 +110,7 @@ type
type type
SuggestedRoutesArgs* = ref object of Args SuggestedRoutesArgs* = ref object of Args
uuid*: string
suggestedRoutes*: SuggestedRoutesDto suggestedRoutes*: SuggestedRoutesDto
type type
@ -583,9 +584,10 @@ QtObject:
amountToReceive: getTotalAmountToReceive(oldRoute), amountToReceive: getTotalAmountToReceive(oldRoute),
toNetworks: getToNetworksList(oldRoute), toNetworks: getToNetworksList(oldRoute),
) )
self.events.emit(SIGNAL_SUGGESTED_ROUTES_READY, SuggestedRoutesArgs(suggestedRoutes: suggestedDto)) self.events.emit(SIGNAL_SUGGESTED_ROUTES_READY, SuggestedRoutesArgs(uuid: uuid, suggestedRoutes: suggestedDto))
proc suggestedRoutes*(self: Service, proc suggestedRoutes*(self: Service,
uuid: string,
sendType: SendType, sendType: SendType,
accountFrom: string, accountFrom: string,
accountTo: string, accountTo: string,
@ -605,7 +607,6 @@ QtObject:
amountOutHex = "0x" & eth_utils.stripLeadingZeros(bigAmountOut.toHex) amountOutHex = "0x" & eth_utils.stripLeadingZeros(bigAmountOut.toHex)
try: try:
let uuid = $genUUID()
let res = eth.suggestedRoutesV2Async(uuid, ord(sendType), accountFrom, accountTo, amountInHex, amountOutHex, token, let res = eth.suggestedRoutesV2Async(uuid, ord(sendType), accountFrom, accountTo, amountInHex, amountOutHex, token,
toToken, disabledFromChainIDs, disabledToChainIDs, lockedInAmounts, extraParamsTable) toToken, disabledFromChainIDs, disabledToChainIDs, lockedInAmounts, extraParamsTable)
except CatchableError as e: except CatchableError as e:

View File

@ -58,12 +58,12 @@ SplitView {
readonly property var flatNetworks: NetworksModel.flatNetworks readonly property var flatNetworks: NetworksModel.flatNetworks
readonly property bool areTestNetworksEnabled: areTestNetworksEnabledCheckbox.checked readonly property bool areTestNetworksEnabled: areTestNetworksEnabledCheckbox.checked
function fetchSuggestedRoutes(accountFrom, accountTo, amount, tokenFrom, tokenTo, function fetchSuggestedRoutes(uuid, accountFrom, accountTo, amount, tokenFrom, tokenTo,
disabledFromChainIDs, disabledToChainIDs, preferredChainIDs, sendType, lockedInAmounts) { disabledFromChainIDs, disabledToChainIDs, preferredChainIDs, sendType, lockedInAmounts) {
console.debug("fetchSuggestedRoutes called >> accountFrom = ",accountFrom, " accountTo =", console.debug("fetchSuggestedRoutes called >> uuid = ", uuid, " accountFrom = ", accountFrom, " accountTo =",
accountTo, "amount = ",amount, " tokenFrom = ",tokenFrom, " tokenTo = ", tokenTo, accountTo, "amount = ", amount, " tokenFrom = ", tokenFrom, " tokenTo = ", tokenTo,
" disabledFromChainIDs = ",disabledFromChainIDs, " disabledToChainIDs = ",disabledToChainIDs, " disabledFromChainIDs = ", disabledFromChainIDs, " disabledToChainIDs = ", disabledToChainIDs,
" preferredChainIDs = ",preferredChainIDs, " sendType =", sendType, " lockedInAmounts = ",lockedInAmounts) " preferredChainIDs = ", preferredChainIDs, " sendType =", sendType, " lockedInAmounts = ", lockedInAmounts)
} }
function authenticateAndTransfer(uuid, accountFrom, accountTo, tokenFrom, function authenticateAndTransfer(uuid, accountFrom, accountTo, tokenFrom,
tokenTo, sendType, tokenName, tokenIsOwnerToken, paths) { tokenTo, sendType, tokenName, tokenIsOwnerToken, paths) {

View File

@ -34,7 +34,7 @@ Item {
function getWei2Eth(wei, decimals) { function getWei2Eth(wei, decimals) {
return wei/(10**decimals) return wei/(10**decimals)
} }
function fetchSuggestedRoutes(accountFrom, accountTo, amount, tokenFrom, tokenTo, function fetchSuggestedRoutes(uuid, accountFrom, accountTo, amount, tokenFrom, tokenTo,
disabledFromChainIDs, disabledToChainIDs, preferredChainIDs, sendType, lockedInAmounts) {} disabledFromChainIDs, disabledToChainIDs, preferredChainIDs, sendType, lockedInAmounts) {}
} }

View File

@ -144,6 +144,10 @@ QObject {
Connections { Connections {
target: root.swapStore target: root.swapStore
function onSuggestedRoutesReady(txRoutes) { function onSuggestedRoutesReady(txRoutes) {
if (txRoutes.uuid !== d.uuid) {
// Suggested routes for a different fetch, ignore
return
}
root.swapOutputData.reset() root.swapOutputData.reset()
root.validSwapProposalReceived = false root.validSwapProposalReceived = false
root.swapProposalLoading = false root.swapProposalLoading = false
@ -207,17 +211,17 @@ QObject {
function fetchSuggestedRoutes(cryptoValueInRaw) { function fetchSuggestedRoutes(cryptoValueInRaw) {
if (root.swapFormData.isFormFilledCorrectly() && !!cryptoValueInRaw) { if (root.swapFormData.isFormFilledCorrectly() && !!cryptoValueInRaw) {
root.swapProposalLoading = true
root.swapOutputData.reset()
// Identify new swap with a different uuid // Identify new swap with a different uuid
d.uuid = Utils.uuid() d.uuid = Utils.uuid()
root.swapProposalLoading = true
root.swapOutputData.reset()
let account = selectedAccountEntry.item let account = selectedAccountEntry.item
let accountAddress = account.address let accountAddress = account.address
let disabledChainIds = getDisabledChainIds(root.swapFormData.selectedNetworkChainId) let disabledChainIds = getDisabledChainIds(root.swapFormData.selectedNetworkChainId)
root.swapStore.fetchSuggestedRoutes(accountAddress, accountAddress, root.swapStore.fetchSuggestedRoutes(d.uuid, accountAddress, accountAddress,
cryptoValueInRaw, "0", root.swapFormData.fromTokensKey, root.swapFormData.toTokenKey, cryptoValueInRaw, "0", root.swapFormData.fromTokensKey, root.swapFormData.toTokenKey,
disabledChainIds, disabledChainIds, Constants.SendType.Swap, "") disabledChainIds, disabledChainIds, Constants.SendType.Swap, "")
} else { } else {

View File

@ -25,11 +25,11 @@ QtObject {
} }
} }
function fetchSuggestedRoutes(accountFrom, accountTo, amountIn, amountOut, tokenFrom, tokenTo, function fetchSuggestedRoutes(uuid, accountFrom, accountTo, amountIn, amountOut, tokenFrom, tokenTo,
disabledFromChainIDs, disabledToChainIDs, sendType, lockedInAmounts) { disabledFromChainIDs, disabledToChainIDs, sendType, lockedInAmounts) {
const valueIn = AmountsArithmetic.fromNumber(amountIn) const valueIn = AmountsArithmetic.fromNumber(amountIn)
const valueOut = AmountsArithmetic.fromNumber(amountOut) const valueOut = AmountsArithmetic.fromNumber(amountOut)
root.walletSectionSendInst.fetchSuggestedRoutesWithParameters(accountFrom, accountTo, valueIn.toFixed(), valueOut.toFixed(), root.walletSectionSendInst.fetchSuggestedRoutesWithParameters(uuid, accountFrom, accountTo, valueIn.toFixed(), valueOut.toFixed(),
tokenFrom, tokenTo, disabledFromChainIDs, disabledToChainIDs, sendType, lockedInAmounts) tokenFrom, tokenTo, disabledFromChainIDs, disabledToChainIDs, sendType, lockedInAmounts)
} }