Skip to content

Commit

Permalink
chore: improvements of the sending route generated by the router process
Browse files Browse the repository at this point in the history
Closes #14636
  • Loading branch information
saledjenic committed Sep 13, 2024
1 parent 8dc067e commit 9b4e506
Show file tree
Hide file tree
Showing 26 changed files with 512 additions and 576 deletions.
4 changes: 4 additions & 0 deletions src/app/core/signals/remote_signals/signal_type.nim
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ type SignalType* {.pure.} = enum
## Wallet Signals
Wallet = "wallet"
WalletSignTransactions = "wallet.sign.transactions"
WalletRouterSendingTransactionsStarted = "wallet.router.sending-transactions-started"
WalletRouterSignTransactions = "wallet.router.sign-transactions"
WalletRouterTransactionsSent = "wallet.router.transactions-sent"
WalletTransactionStatusChanged = "wallet.transaction.status-changed"
WalletSuggestedRoutes = "wallet.suggested.routes"
NodeReady = "node.ready"
NodeCrashed = "node.crashed"
Expand Down
23 changes: 23 additions & 0 deletions src/app/core/signals/remote_signals/wallet.nim
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import base
import signal_type

import app_service/service/transaction/dtoV2
import app_service/service/transaction/router_transactions_dto

const SignTransactionsEventType* = "sing-transactions"

Expand All @@ -25,6 +26,10 @@ type WalletSignal* = ref object of Signal
error*: string
errorCode*: string
updatedPrices*: Table[string, float64]
routerTransactionsSendingDetails*: SendDetailsDto
routerTransactionsForSigning*: RouterTransactionsForSigningDto
routerSentTransactions*: RouterSentTransactionsDto
transactionStatusChange*: TransactionStatusChange

proc fromEvent*(T: type WalletSignal, signalType: SignalType, jsonSignal: JsonNode): WalletSignal =
result = WalletSignal()
Expand Down Expand Up @@ -54,6 +59,24 @@ proc fromEvent*(T: type WalletSignal, signalType: SignalType, jsonSignal: JsonNo
for tx in event:
result.txHashes.add(tx.getStr)
return
if signalType == SignalType.WalletRouterSignTransactions:
if event.kind != JObject:
return
result.routerTransactionsForSigning = toRouterTransactionsForSigningDto(event)
return
if signalType == SignalType.WalletRouterTransactionsSent:
if event.kind != JObject:
return
result.routerSentTransactions = toRouterSentTransactionsDto(event)
return
if signalType == SignalType.WalletRouterSendingTransactionsStarted:
result.routerTransactionsSendingDetails = toSendDetailsDto(event)
return
if signalType == SignalType.WalletTransactionStatusChanged:
if event.kind != JObject:
return
result.transactionStatusChange = toTransactionStatusChange(event)
return
if signalType == SignalType.WalletSuggestedRoutes:
try:
if event.contains("Uuid"):
Expand Down
6 changes: 5 additions & 1 deletion src/app/core/signals/signals_manager.nim
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,12 @@ QtObject:
of SignalType.WhisperFilterAdded: WhisperFilterSignal.fromEvent(jsonSignal)
of SignalType.Wallet,
SignalType.WalletSignTransactions,
SignalType.WalletRouterSendingTransactionsStarted,
SignalType.WalletRouterSignTransactions,
SignalType.WalletRouterTransactionsSent,
SignalType.WalletTransactionStatusChanged,
SignalType.WalletSuggestedRoutes:
WalletSignal.fromEvent(signalType, jsonSignal)
WalletSignal.fromEvent(signalType, jsonSignal)
of SignalType.NodeReady,
SignalType.NodeCrashed,
SignalType.NodeStarted,
Expand Down
43 changes: 20 additions & 23 deletions src/app/modules/main/wallet_section/send/controller.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Tables
import uuids, chronicles, options
import uuids, chronicles
import io_interface
import app_service/service/wallet_account/service as wallet_account_service
import app_service/service/network/service as network_service
Expand All @@ -13,7 +13,6 @@ import app/modules/shared_modules/keycard_popup/io_interface as keycard_shared_m
import app/modules/shared/wallet_utils
import app/modules/shared_models/currency_amount

import app/core/signals/types
import app/core/eventemitter

logScope:
Expand Down Expand Up @@ -56,11 +55,11 @@ proc delete*(self: Controller) =
proc init*(self: Controller) =
self.events.on(SIGNAL_TRANSACTION_SENT) do(e:Args):
let args = TransactionSentArgs(e)
self.delegate.transactionWasSent(args.chainId, args.txHash, args.uuid, args.error)
self.delegate.transactionWasSent(args.uuid, args.chainId, args.approvalTx, args.txHash, args.error)

self.events.on(SIGNAL_OWNER_TOKEN_SENT) do(e:Args):
let args = OwnerTokenSentArgs(e)
self.delegate.transactionWasSent(args.chainId, args.txHash, args.uuid, "")
self.delegate.transactionWasSent(args.uuid, args.chainId, approvalTx = false, args.txHash, error = "")

self.events.on(SIGNAL_SHARED_KEYCARD_MODULE_USER_AUTHENTICATED) do(e: Args):
let args = SharedKeycarModuleArgs(e)
Expand All @@ -72,13 +71,13 @@ proc init*(self: Controller) =
let args = SuggestedRoutesArgs(e)
self.delegate.suggestedRoutesReady(args.uuid, args.suggestedRoutes, args.errCode, args.errDescription)

self.events.on(SignalType.WalletSignTransactions.event) do(e:Args):
var data = WalletSignal(e)
self.delegate.prepareSignaturesForTransactions(data.txHashes)
self.events.on(SIGNAL_SIGN_ROUTER_TRANSACTIONS) do(e:Args):
var data = RouterTransactionsForSigningArgs(e)
self.delegate.prepareSignaturesForTransactionsV2(data.data)

self.events.on(SIGNAL_TRANSACTION_SENDING_COMPLETE) do(e:Args):
let args = TransactionMinedArgs(e)
self.delegate.transactionSendingComplete(args.transactionHash, args.success)
self.events.on(SIGNAL_TRANSACTION_STATUS_CHANGED) do(e:Args):
let args = TransactionStatusArgs(e)
self.delegate.transactionSendingComplete(args.data.hash, args.data.status)

proc getWalletAccounts*(self: Controller): seq[wallet_account_service.WalletAccountDto] =
return self.walletAccountService.getWalletAccounts()
Expand Down Expand Up @@ -115,30 +114,28 @@ proc suggestedRoutes*(self: Controller,
accountFrom: string,
accountTo: string,
token: string,
tokenIsOwnerToken: bool,
amountIn: string,
toToken: string = "",
amountOut: string = "",
disabledFromChainIDs: seq[int] = @[],
disabledToChainIDs: seq[int] = @[],
lockedInAmounts: Table[string, string] = initTable[string, string](),
extraParamsTable: Table[string, string] = initTable[string, string]()) =
self.transactionService.suggestedRoutes(uuid, sendType, accountFrom, accountTo, token, amountIn, toToken, amountOut,
self.transactionService.suggestedRoutes(uuid, sendType, accountFrom, accountTo, token, tokenIsOwnerToken, amountIn, toToken, amountOut,
disabledFromChainIDs, disabledToChainIDs, lockedInAmounts, extraParamsTable)

proc stopSuggestedRoutesAsyncCalculation*(self: Controller) =
self.transactionService.stopSuggestedRoutesAsyncCalculation()

proc transfer*(self: Controller, from_addr: string, to_addr: string, assetKey: string, toAssetKey: string,
uuid: string, selectedRoutes: seq[TransactionPathDto], password: string, sendType: SendType,
usePassword: bool, doHashing: bool, tokenName: string, isOwnerToken: bool,
slippagePercentage: Option[float]) =
self.transactionService.transfer(from_addr, to_addr, assetKey, toAssetKey, uuid, selectedRoutes, password, sendType,
usePassword, doHashing, tokenName, isOwnerToken, slippagePercentage)
proc buildTransactionsFromRoute*(self: Controller, uuid: string, slippagePercentage: float): string =
return self.transactionService.buildTransactionsFromRoute(uuid, slippagePercentage)

proc proceedWithTransactionsSignatures*(self: Controller, fromAddr: string, toAddr: string,
fromTokenKey: string, toTokenKey: string, uuid: string, signatures: TransactionsSignatures,
selectedRoutes: seq[TransactionPathDto], sendType: SendType) =
self.transactionService.proceedWithTransactionsSignatures(fromAddr, toAddr, fromTokenKey, toTokenKey, uuid, signatures, selectedRoutes, sendType)
proc signMessage*(self: Controller, address: string, hashedPassword: string, hashedMessage: string): tuple[res: string, err: string] =
return self.transactionService.signMessage(address, hashedPassword, hashedMessage)

proc sendRouterTransactionsWithSignatures*(self: Controller, uuid: string, signatures: TransactionsSignatures): string =
return self.transactionService.sendRouterTransactionsWithSignatures(uuid, signatures)

proc areTestNetworksEnabled*(self: Controller): bool =
return self.walletAccountService.areTestNetworksEnabled()
Expand All @@ -162,7 +159,7 @@ proc connectKeycardReponseSignal(self: Controller) =
let currentFlow = self.keycardService.getCurrentFlow()
if currentFlow != KCSFlowType.Sign:
error "trying to use keycard in the other than the signing a transaction flow"
self.delegate.transactionWasSent()
self.delegate.transactionWasSent(uuid = "", chainId = 0, approvalTx = false, txHash = "", error = "trying to use keycard in the other than the signing a transaction flow")
return
self.delegate.onTransactionSigned(args.flowType, args.flowEvent)

Expand All @@ -175,4 +172,4 @@ proc runSignFlow*(self: Controller, pin, bip44Path, txHash: string) =
self.keycardService.startSignFlow(bip44Path, txHash, pin)

proc getChainsWithNoGasFromError*(self: Controller, errCode: string, errDescription: string): Table[int, string] =
return self.walletAccountService.getChainsWithNoGasFromError(errCode, errDescription)
return self.walletAccountService.getChainsWithNoGasFromError(errCode, errDescription)
18 changes: 7 additions & 11 deletions src/app/modules/main/wallet_section/send/io_interface.nim
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Tables, options
import Tables
import app/modules/shared_models/currency_amount
import app_service/service/transaction/dto
import app_service/service/transaction/router_transactions_dto
import app_service/service/network/network_item
import app/modules/shared_models/collectibles_model as collectibles
import app/modules/shared_models/collectibles_nested_model as nested_collectibles
Expand Down Expand Up @@ -28,6 +29,7 @@ method suggestedRoutes*(self: AccessInterface,
accountFrom: string,
accountTo: string,
token: string,
tokenIsOwnerToken: bool,
amountIn: string,
toToken: string = "",
amountOut: string = "",
Expand All @@ -43,19 +45,13 @@ method stopUpdatesForSuggestedRoute*(self: AccessInterface) {.base.} =
method suggestedRoutesReady*(self: AccessInterface, uuid: string, suggestedRoutes: SuggestedRoutesDto, errCode: string, errDescription: string) {.base.} =
raise newException(ValueError, "No implementation available")

method authenticateAndTransfer*(self: AccessInterface, from_addr: string, to_addr: string, assetKey: string,
toAssetKey: string, uuid: string, sendType: SendType, selectedTokenName: string, selectedTokenIsOwnerToken: bool) {.base.} =
raise newException(ValueError, "No implementation available")

method authenticateAndTransferWithPaths*(self: AccessInterface, from_addr: string, to_addr: string, assetKey: string,
toAssetKey: string, uuid: string, sendType: SendType, selectedTokenName: string, selectedTokenIsOwnerToken: bool, rawPaths: string,
slippagePercentage: Option[float]) {.base.} =
method authenticateAndTransferV2*(self: AccessInterface, fromAddr: string, uuid: string, slippagePercentage: float) {.base.} =
raise newException(ValueError, "No implementation available")

method onUserAuthenticated*(self: AccessInterface, password: string, pin: string) {.base.} =
raise newException(ValueError, "No implementation available")

method transactionWasSent*(self: AccessInterface, chainId: int = 0, txHash, uuid, error: string = "") {.base.} =
method transactionWasSent*(self: AccessInterface, uuid: string, chainId: int = 0, approvalTx: bool = false, txHash: string = "", error: string = "") {.base.} =
raise newException(ValueError, "No implementation available")

method viewDidLoad*(self: AccessInterface) {.base.} =
Expand Down Expand Up @@ -85,7 +81,7 @@ method getNestedCollectiblesModel*(self: AccessInterface): nested_collectibles.M
method splitAndFormatAddressPrefix*(self: AccessInterface, text : string, updateInStore: bool): string {.base.} =
raise newException(ValueError, "No implementation available")

method prepareSignaturesForTransactions*(self: AccessInterface, txHashes: seq[string]) {.base.} =
method prepareSignaturesForTransactionsV2*(self:AccessInterface, txForSigning: RouterTransactionsForSigningDto) {.base.} =
raise newException(ValueError, "No implementation available")

method onTransactionSigned*(self: AccessInterface, keycardFlowType: string, keycardEvent: KeycardEvent) {.base.} =
Expand All @@ -94,7 +90,7 @@ method onTransactionSigned*(self: AccessInterface, keycardFlowType: string, keyc
method hasGas*(self: AccessInterface, accountAddress: string, chainId: int, nativeGasSymbol: string, requiredGas: float): bool {.base.} =
raise newException(ValueError, "No implementation available")

method transactionSendingComplete*(self: AccessInterface, txHash: string, success: bool) {.base.} =
method transactionSendingComplete*(self: AccessInterface, txHash: string, status: string) {.base.} =
raise newException(ValueError, "No implementation available")

method getNetworkItem*(self: AccessInterface, chainId: int): NetworkItem {.base.} =
Expand Down
Loading

0 comments on commit 9b4e506

Please sign in to comment.