Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: improvements of the sending route generated by the router process #16330

Merged
merged 2 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion src/app/modules/main/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ proc newModule*[T](
networkService, keycardService, keychainService, tokenService, nodeService
)
result.stickersModule = stickers_module.newModule(result, events, stickersService, settingsService, walletAccountService,
networkService, tokenService, keycardService)
networkService, tokenService)
result.gifsModule = gifs_module.newModule(result, events, gifService)
result.activityCenterModule = activity_center_module.newModule(result, events, activityCenterService, contactsService,
messageService, chatService, communityService)
Expand Down
73 changes: 4 additions & 69 deletions src/app/modules/main/stickers/controller.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Tables, uuids, stint, json
import Tables, uuids, stint

import ./io_interface

Expand All @@ -7,14 +7,8 @@ import app_service/service/stickers/service as stickers_service
import app_service/service/token/service
import app_service/service/settings/service as settings_service
import app_service/service/network/service as network_service
import app_service/service/eth/utils as eth_utils
import app_service/service/wallet_account/service as wallet_account_service
import app_service/service/token/service as token_service
import app_service/service/keycard/service as keycard_service
import app/modules/shared_modules/keycard_popup/io_interface as keycard_shared_module
import app_service/service/network/network_item

const UNIQUE_BUY_STICKER_TRANSACTION_MODULE_IDENTIFIER* = "StickersSection-TransactionModule"

type
Controller* = ref object of RootObj
Expand All @@ -25,7 +19,6 @@ type
networkService: network_service.Service
walletAccountService: wallet_account_service.Service
tokenService: token_service.Service
keycardService: keycard_service.Service
connectionKeycardResponse: UUID
disconnected: bool

Expand All @@ -37,7 +30,6 @@ proc newController*(
walletAccountService: wallet_account_service.Service,
networkService: network_service.Service,
tokenService: token_service.Service,
keycardService: keycard_service.Service
): Controller =
result = Controller()
result.delegate = delegate
Expand All @@ -47,7 +39,6 @@ proc newController*(
result.networkService = networkService
result.walletAccountService = walletAccountService
result.tokenService = tokenService
result.keycardService = keycardService
result.disconnected = false

proc delete*(self: Controller) =
Expand Down Expand Up @@ -81,9 +72,9 @@ proc init*(self: Controller) =
self.events.on(SIGNAL_ALL_STICKER_PACKS_LOAD_FAILED) do(e: Args):
self.delegate.allPacksLoadFailed()

self.events.on(SIGNAL_STICKER_GAS_ESTIMATED) do(e: Args):
let args = StickerGasEstimatedArgs(e)
self.delegate.gasEstimateReturned(args.estimate, args.uuid)
self.events.on(SIGNAL_STICKER_TRANSACTION_SENT) do(e:Args):
let args = StickerBuyResultArgs(e)
self.delegate.stickerTransactionSent(args.chainId, args.packId, args.txHash, args.error)

self.events.on(SIGNAL_STICKER_TRANSACTION_CONFIRMED) do(e:Args):
let args = StickerTransactionArgs(e)
Expand All @@ -93,28 +84,10 @@ proc init*(self: Controller) =
let args = StickerTransactionArgs(e)
self.delegate.stickerTransactionReverted(args.transactionType, args.packID, args.transactionHash)

self.events.on(SIGNAL_SHARED_KEYCARD_MODULE_USER_AUTHENTICATED) do(e: Args):
let args = SharedKeycarModuleArgs(e)
if args.uniqueIdentifier != UNIQUE_BUY_STICKER_TRANSACTION_MODULE_IDENTIFIER:
return
self.delegate.onKeypairAuthenticated(args.password, args.pin)

self.events.on(SIGNAL_STICKER_PACK_INSTALLED) do(e: Args):
let args = StickerPackInstalledArgs(e)
self.delegate.onStickerPackInstalled(args.packId)

proc prepareTxForBuyingStickers*(self: Controller, chainId: int, packId: string, address: string, gas: string, gasPrice: string,
maxPriorityFeePerGas: string, maxFeePerGas: string, eip1559Enabled: bool): JsonNode =
return self.stickerService.prepareTxForBuyingStickers(chainId, packId, address, gas, gasPrice, maxPriorityFeePerGas,
maxFeePerGas, eip1559Enabled)

proc signBuyingStickersTxLocally*(self: Controller, data, account, hashedPasssword: string): string =
return self.stickerService.signBuyingStickersTxLocally(data, account, hashedPasssword)

proc sendBuyingStickersTxWithSignatureAndWatch*(self: Controller, chainId: int, txData: JsonNode, packId: string,
signature: string): StickerBuyResultArgs =
return self.stickerService.sendBuyingStickersTxWithSignatureAndWatch(chainId, txData, packId, signature)

proc getRecentStickers*(self: Controller): seq[StickerDto] =
return self.stickerService.getRecentStickers()

Expand All @@ -124,9 +97,6 @@ proc loadRecentStickers*(self: Controller) =
proc loadInstalledStickerPacks*(self: Controller) =
self.stickerService.asyncLoadInstalledStickerPacks()

proc estimate*(self: Controller, packId: string, address: string, price: string, uuid: string) =
self.stickerService.estimate(packId, address, price, uuid)

proc getInstalledStickerPacks*(self: Controller): Table[string, StickerPackDto] =
self.stickerService.getInstalledStickerPacks()

Expand All @@ -153,9 +123,6 @@ proc sendSticker*(
preferredUsername: string) =
self.stickerService.asyncSendSticker(channelId, replyTo, sticker, preferredUsername)

proc wei2Eth*(self: Controller, price: Stuint[256]): string =
eth_utils.wei2Eth(price)

proc getSigningPhrase*(self: Controller): string =
return self.settingsService.getSigningPhrase()

Expand All @@ -165,40 +132,8 @@ proc getStickerMarketAddress*(self: Controller): string =
proc getWalletDefaultAddress*(self: Controller): string =
return self.walletAccountService.getWalletAccount(0).address

proc getKeypairByAccountAddress*(self: Controller, address: string): KeypairDto =
return self.walletAccountService.getKeypairByAccountAddress(address)

proc getCurrentCurrency*(self: Controller): string =
return self.settingsService.getCurrency()

proc getAppNetwork*(self: Controller): NetworkItem =
return self.networkService.getAppNetwork()

proc getStatusTokenKey*(self: Controller): string =
return self.tokenService.getStatusTokenKey()

proc authenticate*(self: Controller, keyUid = "") =
let data = SharedKeycarModuleAuthenticationArgs(uniqueIdentifier: UNIQUE_BUY_STICKER_TRANSACTION_MODULE_IDENTIFIER,
keyUid: keyUid)
self.events.emit(SIGNAL_SHARED_KEYCARD_MODULE_AUTHENTICATE_USER, data)

proc disconnectKeycardReponseSignal(self: Controller) =
self.events.disconnect(self.connectionKeycardResponse)

proc connectKeycardReponseSignal(self: Controller) =
self.connectionKeycardResponse = self.events.onWithUUID(SIGNAL_KEYCARD_RESPONSE) do(e: Args):
let args = KeycardLibArgs(e)
self.disconnectKeycardReponseSignal()
let currentFlow = self.keycardService.getCurrentFlow()
if currentFlow != KCSFlowType.Sign:
self.delegate.onTransactionSigned("", KeycardEvent())
return
self.delegate.onTransactionSigned(args.flowType, args.flowEvent)

proc cancelCurrentFlow*(self: Controller) =
self.keycardService.cancelCurrentFlow()

proc runSignFlow*(self: Controller, pin, bip44Path, txHash: string) =
self.cancelCurrentFlow()
self.connectKeycardReponseSignal()
self.keycardService.startSignFlow(bip44Path, txHash, pin)
24 changes: 5 additions & 19 deletions src/app/modules/main/stickers/io_interface.nim
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import Tables, stint
import Tables
import ./item

import app_service/service/stickers/service as stickers_service
from app_service/service/keycard/service import KeycardEvent

type
AccessInterface* {.pure inheritable.} = ref object of RootObj
Expand All @@ -20,9 +19,6 @@ method isLoaded*(self: AccessInterface): bool {.base.} =
method viewDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

method authenticateAndBuy*(self: AccessInterface, packId: string, address: string, gas: string, gasPrice: string, maxPriorityFeePerGas: string, maxFeePerGas: string, eip1559Enabled: bool){.base.} =
raise newException(ValueError, "No implementation available")

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

Expand Down Expand Up @@ -68,8 +64,6 @@ method onStickerPackInstalled*(self: AccessInterface, packId: string) {.base.} =
method uninstallStickerPack*(self: AccessInterface, packId: string) {.base.} =
raise newException(ValueError, "No implementation available")

method wei2Eth*(self: AccessInterface, price: Stuint[256]): string {.base.} =
raise newException(ValueError, "No implementation available")

method removeRecentStickers*(self: AccessInterface, packId: string) {.base.} =
raise newException(ValueError, "No implementation available")
Expand All @@ -80,9 +74,6 @@ method sendSticker*(self: AccessInterface, channelId: string, replyTo: string, s
method populateInstalledStickerPacks*(self: AccessInterface, stickers: Table[string, StickerPackDto]) {.base.} =
raise newException(ValueError, "No implementation available")

method gasEstimateReturned*(self: AccessInterface, estimate: int, uuid: string) {.base.} =
raise newException(ValueError, "No implementation available")

method addStickerPackToList*(self: AccessInterface, stickerPack: StickerPackDto, isInstalled: bool, isBought: bool, isPending: bool) {.base.} =
raise newException(ValueError, "No implementation available")

Expand All @@ -92,20 +83,15 @@ method getWalletDefaultAddress*(self: AccessInterface): string {.base.} =
method getCurrentCurrency*(self: AccessInterface): string {.base.} =
raise newException(ValueError, "No implementation available")

method getGasEthValue*(self: AccessInterface, gweiValue: string, gasLimit: string): string {.base.} =
raise newException(ValueError, "No implementation available")

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

method stickerTransactionConfirmed*(self: AccessInterface, trxType: string, packID: string, transactionHash: string) {.base.} =
method stickerTransactionSent*(self: AccessInterface, chainId: int, packId: string, txHash: string, error: string) {.base.} =
raise newException(ValueError, "No implementation available")

method stickerTransactionReverted*(self: AccessInterface, trxType: string, packID: string, transactionHash: string) {.base.} =
raise newException(ValueError, "No implementation available")

method onKeypairAuthenticated*(self: AccessInterface, password: string, pin: string) {.base.} =
method stickerTransactionConfirmed*(self: AccessInterface, trxType: string, packID: string, transactionHash: string) {.base.} =
raise newException(ValueError, "No implementation available")

method onTransactionSigned*(self: AccessInterface, keycardFlowType: string, keycardEvent: KeycardEvent) {.base.} =
raise newException(ValueError, "No implementation available")
method stickerTransactionReverted*(self: AccessInterface, trxType: string, packID: string, transactionHash: string) {.base.} =
raise newException(ValueError, "No implementation available")
6 changes: 4 additions & 2 deletions src/app/modules/main/stickers/models/sticker_pack_list.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import NimQml, Tables, sequtils, sugar
import ./sticker_list
import ../io_interface, ../item
# TODO remove those uses of services stuff
import ../../../../../app_service/service/eth/utils as eth_utils
import app_service/service/eth/utils as eth_utils
import app_service/common/conversion as service_conversion


type
StickerPackRoles {.pure.} = enum
Expand Down Expand Up @@ -57,7 +59,7 @@ QtObject:
of StickerPackRoles.Author: result = newQVariant(stickerPack.author)
of StickerPackRoles.Id: result = newQVariant(stickerPack.id)
of StickerPackRoles.Name: result = newQVariant(stickerPack.name)
of StickerPackRoles.Price: result = newQVariant(self.delegate.wei2Eth(stickerPack.price))
of StickerPackRoles.Price: result = newQVariant(service_conversion.wei2Eth(stickerPack.price))
of StickerPackRoles.Preview: result = newQVariant(stickerPack.preview)
of StickerPackRoles.Stickers: result = newQVariant(packInfo.stickers)
of StickerPackRoles.Thumbnail: result = newQVariant(stickerPack.thumbnail)
Expand Down
Loading