Skip to content

Commit

Permalink
chore: align buying/releasing/setting ens usernames with the new send…
Browse files Browse the repository at this point in the history
…ing flow

Based on changes done in this PR status-im/status-go#5807
we can simplify our client logic a lot.

This results in the removal of many lines of code that are no longer needed

Closes 2nd part of #16336
  • Loading branch information
saledjenic committed Oct 2, 2024
1 parent e351293 commit 100389a
Show file tree
Hide file tree
Showing 13 changed files with 162 additions and 705 deletions.
81 changes: 8 additions & 73 deletions src/app/modules/main/profile_section/ens_usernames/controller.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import uuids, chronicles, json
import uuids, chronicles
import io_interface

import app/global/global_singleton
Expand All @@ -8,16 +8,11 @@ import app_service/service/ens/service as ens_service
import app_service/service/network/service as network_service
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
from app_service/service/transaction/dto import PendingTransactionTypeDto
import app/modules/shared_modules/keycard_popup/io_interface as keycard_shared_module
import app_service/service/network/network_item

logScope:
topics = "profile-section-ens-usernames-module-controller"

const UNIQUE_ENS_SECTION_TRANSACTION_MODULE_IDENTIFIER* = "EnsSection-TransactionModule"

type
Controller* = ref object of RootObj
delegate: io_interface.AccessInterface
Expand All @@ -27,15 +22,13 @@ type
networkService: network_service.Service
walletAccountService: wallet_account_service.Service
tokenService: token_service.Service
keycardService: keycard_service.Service
connectionKeycardResponse: UUID

proc newController*(
delegate: io_interface.AccessInterface, events: EventEmitter,
settingsService: settings_service.Service, ensService: ens_service.Service,
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 @@ -45,7 +38,6 @@ proc newController*(
result.walletAccountService = walletAccountService
result.networkService = networkService
result.tokenService = tokenService
result.keycardService = keycardService

proc delete*(self: Controller) =
discard
Expand All @@ -59,19 +51,17 @@ proc init*(self: Controller) =
let args = EnsUsernameDetailsArgs(e)
self.delegate.onDetailsForEnsUsername(args.chainId, args.ensUsername, args.address, args.pubkey, args.isStatus, args.expirationTime)

self.events.on(SIGNAL_ENS_TRANSACTION_SENT) do(e:Args):
let args = EnsTxResultArgs(e)
self.delegate.ensTransactionSent(args.transactionType, args.chainId, args.ensUsername, args.txHash, args.error)

self.events.on(SIGNAL_ENS_TRANSACTION_CONFIRMED) do(e:Args):
let args = EnsTransactionArgs(e)
self.delegate.ensTransactionConfirmed(args.transactionType, args.ensUsername, args.transactionHash)
self.delegate.ensTransactionConfirmed(args.transactionType, args.ensUsername, args.txHash)

self.events.on(SIGNAL_ENS_TRANSACTION_REVERTED) do(e:Args):
let args = EnsTransactionArgs(e)
self.delegate.ensTransactionReverted(args.transactionType, args.ensUsername, args.transactionHash)

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

proc getAppNetwork*(self: Controller): NetworkItem =
return self.networkService.getAppNetwork()
Expand All @@ -88,13 +78,6 @@ proc getAllMyEnsUsernames*(self: Controller, includePendingEnsUsernames: bool):
proc fetchDetailsForEnsUsername*(self: Controller, chainId: int, ensUsername: string) =
self.ensService.fetchDetailsForEnsUsername(chainId, ensUsername)

proc setPubKeyGasEstimate*(self: Controller, chainId: int, ensUsername: string, address: string): int =
return self.ensService.setPubKeyGasEstimate(chainId, ensUsername, address)


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

proc addEnsUsername*(self: Controller, chainId: int, ensUsername: string): bool =
return self.ensService.add(chainId, ensUsername)

Expand All @@ -104,10 +87,6 @@ proc removeEnsUsername*(self: Controller, chainId: int, ensUsername: string): bo
proc getPreferredEnsUsername*(self: Controller): string =
return self.settingsService.getPreferredName()

proc releaseEnsEstimate*(self: Controller, chainId: int, ensUsername: string, address: string): int =
return self.ensService.releaseEnsEstimate(chainId, ensUsername, address)


proc setPreferredName*(self: Controller, preferredName: string) =
if(self.settingsService.savePreferredName(preferredName)):
singletonInstance.userProfile.setPreferredName(preferredName)
Expand All @@ -130,58 +109,14 @@ proc fixPreferredName*(self: Controller, ignoreCurrentValue: bool = false) =
proc getEnsRegisteredAddress*(self: Controller): string =
return self.ensService.getEnsRegisteredAddress()

proc registerEnsGasEstimate*(self: Controller, chainId: int, ensUsername: string, address: string): int =
return self.ensService.registerEnsGasEstimate(chainId, ensUsername, address)

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 getPriceBySymbol*(self: Controller, crypto: string): float64 =
return self.tokenService.getPriceBySymbol(crypto)

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

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

proc prepareEnsTx*(self: Controller, txType: PendingTransactionTypeDto, chainId: int, ensUsername: string, address: string,
gas: string, gasPrice: string, maxPriorityFeePerGas: string, maxFeePerGas: string, eip1559Enabled: bool): JsonNode =
return self.ensService.prepareEnsTx(txType, chainId, ensUsername, address, gas, gasPrice, maxPriorityFeePerGas,
maxFeePerGas, eip1559Enabled)

proc signEnsTxLocally*(self: Controller, data, account, hashedPasssword: string): string =
return self.ensService.signEnsTxLocally(data, account, hashedPasssword)

proc sendEnsTxWithSignatureAndWatch*(self: Controller, txType: PendingTransactionTypeDto, chainId: int,
txData: JsonNode, ensUsername: string, signature: string): EnsTxResultArgs =
return self.ensService.sendEnsTxWithSignatureAndWatch(txType, chainId, txData, ensUsername, signature)

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)
return self.tokenService.getStatusTokenKey()
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import NimQml
from app_service/service/keycard/service import KeycardEvent

type
AccessInterface* {.pure inheritable.} = ref object of RootObj
Expand All @@ -23,6 +22,9 @@ method onDetailsForEnsUsername*(self: AccessInterface, chainId: int, ensUsername
isStatus: bool, expirationTime: int) {.base.} =
raise newException(ValueError, "No implementation available")

method ensTransactionSent*(self: AccessInterface, trxType: string, chainId: int, ensUsername: string, txHash: string, err: string) {.base.} =
raise newException(ValueError, "No implementation available")

method ensTransactionConfirmed*(self: AccessInterface, trxType: string, ensUsername: string, transactionHash: string)
{.base.} =
raise newException(ValueError, "No implementation available")
Expand All @@ -42,36 +44,15 @@ method numOfPendingEnsUsernames*(self: AccessInterface): int {.base.} =
method fetchDetailsForEnsUsername*(self: AccessInterface, chainId: int, ensUsername: string) {.base.} =
raise newException(ValueError, "No implementation available")

method setPubKeyGasEstimate*(self: AccessInterface, chainId: int, ensUsername: string, address: string): int {.base.} =
raise newException(ValueError, "No implementation available")

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

method removeEnsUsername*(self: AccessInterface, chainId: int, ensUsername: string): bool {.base.} =
raise newException(ValueError, "No implementation available")

method releaseEnsEstimate*(self: AccessInterface, chainId: int, ensUsername: string, address: string): int {.base.} =
raise newException(ValueError, "No implementation available")

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

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

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

method registerEnsGasEstimate*(self: AccessInterface, chainId: int, ensUsername: string, address: string): int {.base.} =
raise newException(ValueError, "No implementation available")

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

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

Expand All @@ -93,10 +74,4 @@ method getStatusTokenKey*(self: AccessInterface): string {.base.} =
raise newException(ValueError, "No implementation available")

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

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

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

0 comments on commit 100389a

Please sign in to comment.