-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(@desktop/wallet): Create a new send module to clear out old logi…
…c and switch the old one to the new one later, once the old sendModal is not used anymore fixes #16919
- Loading branch information
1 parent
7f5fe66
commit 1dec9f8
Showing
18 changed files
with
1,290 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
148 changes: 148 additions & 0 deletions
148
src/app/modules/main/wallet_section/send_new/controller.nim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
66
src/app/modules/main/wallet_section/send_new/io_interface.nim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
50 changes: 50 additions & 0 deletions
50
src/app/modules/main/wallet_section/send_new/max_fee_levels_item.nim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.