Skip to content

Commit

Permalink
feat(@desktop/wallet): Create a new send module to clear out old logi…
Browse files Browse the repository at this point in the history
…c and switch the old one to the new one later, once the old sendModal is not used anymore

fixes #16919
  • Loading branch information
Khushboo-dev-cpp committed Jan 6, 2025
1 parent 7f5fe66 commit 1dec9f8
Show file tree
Hide file tree
Showing 18 changed files with 1,290 additions and 65 deletions.
3 changes: 3 additions & 0 deletions src/app/modules/main/wallet_section/io_interface.nim
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ method buySellCryptoModuleDidLoad*(self: AccessInterface) {.base.} =
method sendModuleDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

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

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

Expand Down
12 changes: 12 additions & 0 deletions src/app/modules/main/wallet_section/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import ./buy_sell_crypto/module as buy_sell_crypto_module
import ./networks/module as networks_module
import ./overview/module as overview_module
import ./send/module as send_module
import ./send_new/module as new_send_module

import ./activity/controller as activityc

Expand Down Expand Up @@ -70,6 +71,8 @@ type
allCollectiblesModule: all_collectibles_module.AccessInterface
assetsModule: assets_module.AccessInterface
sendModule: send_module.AccessInterface
# TODO: replace this with sendModule when old one is removed
newSendModule: new_send_module.AccessInterface
savedAddressesModule: saved_addresses_module.AccessInterface
buySellCryptoModule: buy_sell_crypto_module.AccessInterface
overviewModule: overview_module.AccessInterface
Expand Down Expand Up @@ -141,6 +144,7 @@ proc newModule*(
currencyService)
result.sendModule = send_module.newModule(result, events, walletAccountService, networkService, currencyService,
transactionService, keycardService)
result.newSendModule = newSendModule.newModule(result, events, walletAccountService, networkService, transactionService, keycardService)
result.savedAddressesModule = saved_addresses_module.newModule(result, events, savedAddressService)
result.buySellCryptoModule = buy_sell_crypto_module.newModule(result, events, rampService)
result.overviewModule = overview_module.newModule(result, events, walletAccountService, currencyService)
Expand Down Expand Up @@ -185,6 +189,7 @@ method delete*(self: Module) =
self.savedAddressesModule.delete
self.buySellCryptoModule.delete
self.sendModule.delete
self.newSendModule.delete
self.controller.delete
self.viewVariant.delete
self.view.delete
Expand Down Expand Up @@ -351,6 +356,7 @@ method load*(self: Module) =
self.buySellCryptoModule.load()
self.overviewModule.load()
self.sendModule.load()
self.newSendModule.load()
self.networksModule.load()
self.walletConnectService.init()
self.walletConnectController.init()
Expand Down Expand Up @@ -384,6 +390,9 @@ proc checkIfModuleDidLoad(self: Module) =
if(not self.sendModule.isLoaded()):
return

if(not self.newSendModule.isLoaded()):
return

if(not self.networksModule.isLoaded()):
return

Expand Down Expand Up @@ -432,6 +441,9 @@ method overviewModuleDidLoad*(self: Module) =
method sendModuleDidLoad*(self: Module) =
self.checkIfModuleDidLoad()

method newSendModuleDidLoad*(self: Module) =
self.checkIfModuleDidLoad()

method networksModuleDidLoad*(self: Module) =
self.checkIfModuleDidLoad()

Expand Down
148 changes: 148 additions & 0 deletions src/app/modules/main/wallet_section/send_new/controller.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
import Tables
import uuids, chronicles

import io_interface

import app/modules/shared_modules/keycard_popup/io_interface as keycard_shared_module
import app_service/service/wallet_account/service as wallet_account_service
import app_service/service/network/service as network_service
import app_service/service/transaction/service as transaction_service
import app_service/service/keycard/service as keycard_service
import app_service/service/network/network_item

import app/core/eventemitter

logScope:
topics = "wallet-send-controller"

const UNIQUE_WALLET_SECTION_SEND_MODULE_IDENTIFIER* = "WalletSection-NewSendModule"

type
Controller* = ref object of RootObj
delegate: io_interface.AccessInterface
events: EventEmitter
walletAccountService: wallet_account_service.Service
networkService: network_service.Service
transactionService: transaction_service.Service
keycardService: keycard_service.Service
connectionKeycardResponse: UUID

proc newController*(
delegate: io_interface.AccessInterface,
events: EventEmitter,
walletAccountService: wallet_account_service.Service,
networkService: network_service.Service,
transactionService: transaction_service.Service,
keycardService: keycard_service.Service
): Controller =
result = Controller()
result.delegate = delegate
result.events = events
result.walletAccountService = walletAccountService
result.networkService = networkService
result.transactionService = transactionService
result.keycardService = keycardService

proc delete*(self: Controller) =
discard

proc init*(self: Controller) =
self.events.on(SIGNAL_TRANSACTION_SENT) do(e:Args):
let args = TransactionArgs(e)
var
txHash = ""
isApprovalTx = false
if not args.sentTransaction.isNil:
txHash = args.sentTransaction.hash
isApprovalTx = args.sentTransaction.approvalTx
self.delegate.transactionWasSent(
args.sendDetails.uuid,
args.sendDetails.fromChain,
isApprovalTx,
txHash,
if not args.sendDetails.errorResponse.isNil: args.sendDetails.errorResponse.details else: ""
)

self.events.on(SIGNAL_OWNER_TOKEN_SENT) do(e:Args):
let args = OwnerTokenSentArgs(e)
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)
if args.uniqueIdentifier != UNIQUE_WALLET_SECTION_SEND_MODULE_IDENTIFIER:
return
self.delegate.onUserAuthenticated(args.password, args.pin)

self.events.on(SIGNAL_SUGGESTED_ROUTES_READY) do(e:Args):
let args = SuggestedRoutesArgs(e)
self.delegate.suggestedRoutesReady(args.uuid, args.routes, args.errCode, args.errDescription)

self.events.on(SIGNAL_SIGN_ROUTER_TRANSACTIONS) do(e:Args):
var data = RouterTransactionsForSigningArgs(e)
self.delegate.prepareSignaturesForTransactions(data.data)

self.events.on(SIGNAL_TRANSACTION_STATUS_CHANGED) do(e:Args):
let args = TransactionArgs(e)
self.delegate.transactionSendingComplete(args.sentTransaction.hash, args.status)

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

proc suggestedRoutes*(self: Controller,
uuid: string,
sendType: SendType,
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, tokenIsOwnerToken, amountIn, toToken, amountOut,
disabledFromChainIDs, disabledToChainIDs, lockedInAmounts, extraParamsTable)

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

proc getCurrentNetworks*(self: Controller): seq[NetworkItem] =
return self.networkService.getCurrentNetworks()

proc buildTransactionsFromRoute*(self: Controller, uuid: string, slippagePercentage: float): string =
return self.transactionService.buildTransactionsFromRoute(uuid, slippagePercentage)

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 getKeypairByAccountAddress*(self: Controller, address: string): KeypairDto =
return self.walletAccountService.getKeypairByAccountAddress(address)

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:
error "trying to use keycard in the other than the signing a transaction flow"
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)

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)
66 changes: 66 additions & 0 deletions src/app/modules/main/wallet_section/send_new/io_interface.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import Tables

import app_service/service/transaction/dto
import app_service/service/transaction/router_transactions_dto
import app_service/service/transaction/dtoV2
from app_service/service/keycard/service import KeycardEvent

type
AccessInterface* {.pure inheritable.} = ref object of RootObj
## Abstract class for any input/interaction with this module.

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

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

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

method suggestedRoutes*(self: AccessInterface,
uuid: string,
sendType: SendType,
chainId: int,
accountFrom: string,
accountTo: string,
token: string,
tokenIsOwnerToken: bool,
amountIn: string,
toToken: string = "",
amountOut: string = "",
extraParamsTable: Table[string, string] = initTable[string, string]()) {.base.} =
raise newException(ValueError, "No implementation available")

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

method authenticateAndTransfer*(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 suggestedRoutesReady*(self: AccessInterface, uuid: string, routes: seq[TransactionPathDtoV2], errCode: string, errDescription: string) {.base.} =
raise newException(ValueError, "No implementation available")

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.} =
raise newException(ValueError, "No implementation available")

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

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

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

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

method transactionSendingComplete*(self: AccessInterface, txHash: string, status: string) {.base.} =
raise newException(ValueError, "No implementation available")
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import NimQml

QtObject:
type MaxFeeLevelsItem* = ref object of QObject
low: string
medium: string
high: string

proc setup*(self: MaxFeeLevelsItem,
low: string,
medium: string,
high: string
) =
self.QObject.setup
self.low = low
self.medium = medium
self.high = high

proc delete*(self: MaxFeeLevelsItem) =
self.QObject.delete

proc newMaxFeeLevelsItem*(
low: string,
medium: string,
high: string
): MaxFeeLevelsItem =
new(result, delete)
result.setup(low, medium, high)

proc `$`*(self: MaxFeeLevelsItem): string =
result = "MaxFeeLevelsItem("
result = result & "\low: " & $self.low
result = result & "\nmedium " & $self.medium
result = result & "\nhigh: " & $self.high
result = result & ")"

proc getLow*(self: MaxFeeLevelsItem): string {.slot.} =
return self.low
QtProperty[string] low:
read = getLow

proc getMedium*(self: MaxFeeLevelsItem): string {.slot.} =
return self.medium
QtProperty[string] medium:
read = getMedium

proc getHigh*(self: MaxFeeLevelsItem): string {.slot.} =
return self.high
QtProperty[string] high:
read = getHigh
Loading

0 comments on commit 1dec9f8

Please sign in to comment.