feat: Added `chainId` to ens usernames

This commit is contained in:
Igor Sirotin 2023-01-11 19:10:13 +03:00 committed by Igor Sirotin
parent 0bd957e71a
commit 1523c9f2a0
19 changed files with 329 additions and 216 deletions

View File

@ -422,8 +422,6 @@ proc buildAndRegisterUserProfile(self: AppController) =
let alias = self.settingsService.getName()
var preferredName = self.settingsService.getPreferredName()
let displayName = self.settingsService.getDisplayName()
let ensUsernames = self.settingsService.getEnsUsernames()
let firstEnsName = if (ensUsernames.len > 0): ensUsernames[0] else: ""
let currentUserStatus = self.settingsService.getCurrentUserStatus()
let loggedInAccount = self.accountsService.getLoggedInAccount()

View File

@ -50,7 +50,7 @@ proc init*(self: Controller) =
self.events.on(SIGNAL_ENS_USERNAME_DETAILS_FETCHED) do(e:Args):
let args = EnsUsernameDetailsArgs(e)
self.delegate.onDetailsForEnsUsername(args.ensUsername, args.address, args.pubkey, args.isStatus, args.expirationTime)
self.delegate.onDetailsForEnsUsername(args.chainId, args.ensUsername, args.address, args.pubkey, args.isStatus, args.expirationTime)
self.events.on(SIGNAL_ENS_TRANSACTION_CONFIRMED) do(e:Args):
let args = EnsTransactionArgs(e)
@ -66,44 +66,50 @@ proc init*(self: Controller) =
return
self.delegate.onUserAuthenticated(args.password)
proc getChainId*(self: Controller): int =
return self.networkService.getChainIdForEns()
proc getNetwork*(self: Controller): NetworkDto =
return self.networkService.getNetworkForEns()
proc checkEnsUsernameAvailability*(self: Controller, desiredEnsUsername: string, statusDomain: bool) =
self.ensService.checkEnsUsernameAvailability(desiredEnsUsername, statusDomain)
proc getMyPendingEnsUsernames*(self: Controller): seq[string] =
proc getMyPendingEnsUsernames*(self: Controller): seq[EnsUsernameDto] =
return self.ensService.getMyPendingEnsUsernames()
proc getAllMyEnsUsernames*(self: Controller, includePendingEnsUsernames: bool): seq[string] =
proc getAllMyEnsUsernames*(self: Controller, includePendingEnsUsernames: bool): seq[EnsUsernameDto] =
return self.ensService.getAllMyEnsUsernames(includePendingEnsUsernames)
proc fetchDetailsForEnsUsername*(self: Controller, ensUsername: string) =
self.ensService.fetchDetailsForEnsUsername(ensUsername)
proc fetchDetailsForEnsUsername*(self: Controller, chainId: int, ensUsername: string) =
self.ensService.fetchDetailsForEnsUsername(chainId, ensUsername)
proc setPubKeyGasEstimate*(self: Controller, ensUsername: string, address: string): int =
return self.ensService.setPubKeyGasEstimate(ensUsername, address)
proc setPubKeyGasEstimate*(self: Controller, chainId: int, ensUsername: string, address: string): int =
return self.ensService.setPubKeyGasEstimate(chainId, ensUsername, address)
proc setPubKey*(self: Controller, ensUsername: string, address: string, gas: string, gasPrice: string,
proc setPubKey*(self: Controller, chainId: int, ensUsername: string, address: string, gas: string, gasPrice: string,
maxPriorityFeePerGas: string, maxFeePerGas: string, password: string, eip1559Enabled: bool): string =
return self.ensService.setPubKey(ensUsername, address, gas, gasPrice, maxPriorityFeePerGas, maxFeePerGas, password, eip1559Enabled)
return self.ensService.setPubKey(chainId, ensUsername, address, gas, gasPrice, maxPriorityFeePerGas, maxFeePerGas, password, eip1559Enabled)
proc getSigningPhrase*(self: Controller): string =
return self.settingsService.getSigningPhrase()
proc saveNewEnsUsername*(self: Controller, ensUsername: string): bool =
return self.settingsService.saveNewEnsUsername(ensUsername)
proc addEnsUsername*(self: Controller, chainId: int, ensUsername: string): bool =
return self.ensService.add(chainId, ensUsername)
proc removeEnsUsername*(self: Controller, ensUsername: string): bool =
return self.settingsService.removeEnsUsername(ensUsername)
proc removeEnsUsername*(self: Controller, chainId: int, ensUsername: string): bool =
return self.ensService.remove(chainId, ensUsername)
proc getPreferredEnsUsername*(self: Controller): string =
return self.settingsService.getPreferredName()
proc releaseEnsEstimate*(self: Controller, ensUsername: string, address: string): int =
return self.ensService.releaseEnsEstimate(ensUsername, address)
proc releaseEnsEstimate*(self: Controller, chainId: int, ensUsername: string, address: string): int =
return self.ensService.releaseEnsEstimate(chainId, ensUsername, address)
proc release*(self: Controller, ensUsername: string, address: string, gas: string, gasPrice: string,
proc release*(self: Controller, chainId: int, ensUsername: string, address: string, gas: string, gasPrice: string,
maxPriorityFeePerGas: string, maxFeePerGas: string, password: string, eip1559Enabled: bool):
string =
return self.ensService.release(ensUsername, address, gas, gasPrice, maxPriorityFeePerGas, maxFeePerGas, password, eip1559Enabled)
return self.ensService.release(chainId, ensUsername, address, gas, gasPrice, maxPriorityFeePerGas, maxFeePerGas, password, eip1559Enabled)
proc setPreferredName*(self: Controller, preferredName: string) =
if(self.settingsService.savePreferredName(preferredName)):
@ -112,21 +118,27 @@ proc setPreferredName*(self: Controller, preferredName: string) =
info "an error occurred saving prefered ens username", methodName="setPreferredName"
proc fixPreferredName*(self: Controller, ignoreCurrentValue: bool = false) =
# TODO: Remove this workaround and make proper prefferedName-chainId database storage
if (not ignoreCurrentValue and singletonInstance.userProfile.getPreferredName().len > 0):
return
let ensUsernames = self.settingsService.getEnsUsernames()
let firstEnsName = if (ensUsernames.len > 0): ensUsernames[0] else: ""
let ensUsernames = self.getAllMyEnsUsernames(false)
let currentChainId = self.getNetwork().chainId
var firstEnsName = ""
for ensUsername in ensUsernames:
if ensUsername.chainId == currentChainId:
firstEnsName = ensUsername.username
break
self.setPreferredName(firstEnsName)
proc getEnsRegisteredAddress*(self: Controller): string =
return self.ensService.getEnsRegisteredAddress()
proc registerEnsGasEstimate*(self: Controller, ensUsername: string, address: string): int =
return self.ensService.registerEnsGasEstimate(ensUsername, address)
proc registerEnsGasEstimate*(self: Controller, chainId: int, ensUsername: string, address: string): int =
return self.ensService.registerEnsGasEstimate(chainId, ensUsername, address)
proc registerEns*(self: Controller, ensUsername: string, address: string, gas: string, gasPrice: string,
proc registerEns*(self: Controller, chainId: int, ensUsername: string, address: string, gas: string, gasPrice: string,
maxPriorityFeePerGas: string, maxFeePerGas: string, password: string, eip1559Enabled: bool): string =
return self.ensService.registerEns(ensUsername, address, gas, gasPrice, maxPriorityFeePerGas, maxFeePerGas, password, eip1559Enabled)
return self.ensService.registerEns(chainId, ensUsername, address, gas, gasPrice, maxPriorityFeePerGas, maxFeePerGas, password, eip1559Enabled)
proc getSNTBalance*(self: Controller): string =
return self.ensService.getSNTBalance()
@ -150,9 +162,6 @@ proc getStatusToken*(self: Controller): string =
}
return $jsonObj
proc getNetwork*(self: Controller): NetworkDto =
return self.networkService.getNetworkForEns()
proc authenticateUser*(self: Controller, keyUid = "") =
let data = SharedKeycarModuleAuthenticationArgs(uniqueIdentifier: UNIQUE_ENS_SECTION_TRANSACTION_MODULE_IDENTIFIER,
keyUid: keyUid)

View File

@ -18,7 +18,7 @@ method getModuleAsVariant*(self: AccessInterface): QVariant {.base.} =
method ensUsernameAvailabilityChecked*(self: AccessInterface, availabilityStatus: string) {.base.} =
raise newException(ValueError, "No implementation available")
method onDetailsForEnsUsername*(self: AccessInterface, ensUsername: string, address: string, pubkey: string,
method onDetailsForEnsUsername*(self: AccessInterface, chainId: int, ensUsername: string, address: string, pubkey: string,
isStatus: bool, expirationTime: int) {.base.} =
raise newException(ValueError, "No implementation available")
@ -39,23 +39,23 @@ method checkEnsUsernameAvailability*(self: AccessInterface, desiredEnsUsername:
method numOfPendingEnsUsernames*(self: AccessInterface): int {.base.} =
raise newException(ValueError, "No implementation available")
method fetchDetailsForEnsUsername*(self: AccessInterface, ensUsername: string) {.base.} =
method fetchDetailsForEnsUsername*(self: AccessInterface, chainId: int, ensUsername: string) {.base.} =
raise newException(ValueError, "No implementation available")
method setPubKeyGasEstimate*(self: AccessInterface, ensUsername: string, address: string): int {.base.} =
method setPubKeyGasEstimate*(self: AccessInterface, chainId: int, ensUsername: string, address: string): int {.base.} =
raise newException(ValueError, "No implementation available")
method authenticateAndSetPubKey*(self: AccessInterface, ensUsername: string, address: string, gas: string, gasPrice: string,
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, ensUsername: string): bool {.base.} =
method removeEnsUsername*(self: AccessInterface, chainId: int, ensUsername: string): bool {.base.} =
raise newException(ValueError, "No implementation available")
method releaseEnsEstimate*(self: AccessInterface, ensUsername: string, address: string): int {.base.} =
method releaseEnsEstimate*(self: AccessInterface, chainId: int, ensUsername: string, address: string): int {.base.} =
raise newException(ValueError, "No implementation available")
method authenticateAndReleaseEns*(self: AccessInterface, ensUsername: string, address: string, gas: string, gasPrice: string,
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")
@ -65,10 +65,10 @@ method connectOwnedUsername*(self: AccessInterface, ensUsername: string, isStatu
method getEnsRegisteredAddress*(self: AccessInterface): string {.base.} =
raise newException(ValueError, "No implementation available")
method registerEnsGasEstimate*(self: AccessInterface, ensUsername: string, address: string): int {.base.} =
method registerEnsGasEstimate*(self: AccessInterface, chainId: int, ensUsername: string, address: string): int {.base.} =
raise newException(ValueError, "No implementation available")
method authenticateAndRegisterEns*(self: AccessInterface, ensUsername: string, address: string, gas: string, gasPrice: string,
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")

View File

@ -3,11 +3,13 @@ import NimQml, Tables
type Item* = object
ensUsername*: string
isPending*: bool
chainId*: int
type
ModelRole {.pure.} = enum
EnsUsername = UserRole + 1
IsPending
ChainId
QtObject:
type
@ -38,7 +40,8 @@ QtObject:
method roleNames(self: Model): Table[int, string] =
{
ModelRole.EnsUsername.int:"ensUsername",
ModelRole.IsPending.int:"isPending"
ModelRole.IsPending.int:"isPending",
ModelRole.ChainId.int:"chainId"
}.toTable
method data(self: Model, index: QModelIndex, role: int): QVariant =
@ -56,18 +59,22 @@ QtObject:
result = newQVariant(item.ensUsername)
of ModelRole.IsPending:
result = newQVariant(item.isPending)
of ModelRole.ChainId:
result = newQVariant(item.chainId)
proc findIndexForItemWithEnsUsername(self: Model, ensUsername: string): int =
proc findIndex(self: Model, chainId: int, ensUsername: string): int =
for i in 0 ..< self.items.len:
if(self.items[i].ensUsername == ensUsername):
let item = self.items[i]
if (item.chainId == chainId and
item.ensUsername == ensUsername):
return i
return -1
proc containsEnsUsername*(self: Model, ensUsername: string): bool =
return self.findIndexForItemWithEnsUsername(ensUsername) != -1
proc containsEnsUsername*(self: Model, chainId: int, ensUsername: string): bool =
return self.findIndex(chainId, ensUsername) != -1
proc addItem*(self: Model, item: Item) =
if(self.containsEnsUsername(item.ensUsername)):
if(self.containsEnsUsername(item.chainId, item.ensUsername)):
return
let parentModelIndex = newQModelIndex()
@ -78,8 +85,8 @@ QtObject:
self.endInsertRows()
self.countChanged()
proc removeItemByEnsUsername*(self: Model, ensUsername: string) =
let index = self.findIndexForItemWithEnsUsername(ensUsername)
proc removeItemByEnsUsername*(self: Model, chainId: int, ensUsername: string) =
let index = self.findIndex(chainId, ensUsername)
if(index == -1):
return
@ -91,8 +98,8 @@ QtObject:
self.endRemoveRows()
self.countChanged()
proc updatePendingStatus*(self: Model, ensUsername: string, pendingStatus: bool) =
let ind = self.findIndexForItemWithEnsUsername(ensUsername)
proc updatePendingStatus*(self: Model, chainId: int, ensUsername: string, pendingStatus: bool) =
let ind = self.findIndex(chainId, ensUsername)
if(ind == -1):
return

View File

@ -25,6 +25,7 @@ const cancelledRequest* = "cancelled"
# Shouldn't be public ever, use only within this module.
type TmpSendEnsTransactionDetails = object
chainId: int
ensUsername: string
address: string
gas: string
@ -44,6 +45,7 @@ type
controller: Controller
moduleLoaded: bool
tmpSendEnsTransactionDetails: TmpSendEnsTransactionDetails
events: EventEmitter
proc newModule*(
delegate: delegate_interface.AccessInterface, events: EventEmitter,
@ -58,6 +60,7 @@ proc newModule*(
result.viewVariant = newQVariant(result.view)
result.controller = controller.newController(result, events, settingsService, ensService, walletAccountService, networkService, tokenService)
result.moduleLoaded = false
result.events = events
method delete*(self: Module) =
self.view.delete
@ -70,6 +73,10 @@ method load*(self: Module) =
let signingPhrase = self.controller.getSigningPhrase()
let link = self.controller.getNetwork().blockExplorerUrl & "/tx/"
self.view.load(link, signingPhrase)
self.events.on(SIGNAL_WALLET_ACCOUNT_NETWORK_ENABLED_UPDATED) do(e: Args):
self.view.emitChainIdChanged()
self.controller.fixPreferredName(true)
method isLoaded*(self: Module): bool =
return self.moduleLoaded
@ -77,12 +84,18 @@ method isLoaded*(self: Module): bool =
method viewDidLoad*(self: Module) =
# add registered ens usernames
let registeredEnsUsernames = self.controller.getAllMyEnsUsernames(includePendingEnsUsernames = false)
for u in registeredEnsUsernames:
self.view.model().addItem(Item(ensUsername: u, isPending: false))
for dto in registeredEnsUsernames:
let item = Item(chainId: dto.chainId,
ensUsername: dto.username,
isPending: false)
self.view.model().addItem(item)
# add pending ens usernames
let pendingEnsUsernames = self.controller.getMyPendingEnsUsernames()
for u in pendingEnsUsernames:
self.view.model().addItem(Item(ensUsername: u, isPending: true))
for dto in pendingEnsUsernames:
let item = Item(chainId: dto.chainId,
ensUsername: dto.username,
isPending: true)
self.view.model().addItem(item)
self.moduleLoaded = true
self.delegate.ensUsernamesModuleDidLoad()
@ -99,18 +112,20 @@ method ensUsernameAvailabilityChecked*(self: Module, availabilityStatus: string)
method numOfPendingEnsUsernames*(self: Module): int =
return self.controller.getMyPendingEnsUsernames().len
method fetchDetailsForEnsUsername*(self: Module, ensUsername: string) =
self.controller.fetchDetailsForEnsUsername(ensUsername)
method fetchDetailsForEnsUsername*(self: Module, chainId: int, ensUsername: string) =
self.controller.fetchDetailsForEnsUsername(chainId, ensUsername)
method onDetailsForEnsUsername*(self: Module, ensUsername: string, address: string, pubkey: string, isStatus: bool,
method onDetailsForEnsUsername*(self: Module, chainId: int, ensUsername: string, address: string, pubkey: string, isStatus: bool,
expirationTime: int) =
self.view.setDetailsForEnsUsername(ensUsername, address, pubkey, isStatus, expirationTime)
self.view.processObtainedEnsUsermesDetails(chainId, ensUsername, address, pubkey, isStatus, expirationTime)
method setPubKeyGasEstimate*(self: Module, ensUsername: string, address: string): int =
return self.controller.setPubKeyGasEstimate(ensUsername, address)
method setPubKeyGasEstimate*(self: Module, chainId: int, ensUsername: string, address: string): int =
return self.controller.setPubKeyGasEstimate(chainId, ensUsername, address)
method authenticateAndSetPubKey*(self: Module, ensUsername: string, address: string, gas: string, gasPrice: string,
method authenticateAndSetPubKey*(self: Module, chainId: int, ensUsername: string, address: string, gas: string, gasPrice: string,
maxPriorityFeePerGas: string, maxFeePerGas: string, eip1559Enabled: bool) =
self.tmpSendEnsTransactionDetails.chainId = chainId
self.tmpSendEnsTransactionDetails.ensUsername = ensUsername
self.tmpSendEnsTransactionDetails.address = address
self.tmpSendEnsTransactionDetails.gas = gas
@ -130,6 +145,7 @@ method authenticateAndSetPubKey*(self: Module, ensUsername: string, address: str
method setPubKey*(self: Module, password: string) =
let response = self.controller.setPubKey(
self.tmpSendEnsTransactionDetails.chainId,
self.tmpSendEnsTransactionDetails.ensUsername,
self.tmpSendEnsTransactionDetails.address,
self.tmpSendEnsTransactionDetails.gas,
@ -154,14 +170,19 @@ method setPubKey*(self: Module, password: string) =
var respResult: string
if(responseObj.getProp("result", respResult)):
self.view.model().addItem(Item(ensUsername: self.tmpSendEnsTransactionDetails.ensUsername, isPending: true))
let item = Item(chainId: self.tmpSendEnsTransactionDetails.chainId,
ensUsername: self.tmpSendEnsTransactionDetails.ensUsername,
isPending: true)
self.view.model().addItem(item)
self.view.emitTransactionWasSentSignal(response)
method releaseEnsEstimate*(self: Module, ensUsername: string, address: string): int =
return self.controller.releaseEnsEstimate(ensUsername, address)
method releaseEnsEstimate*(self: Module, chainId: int, ensUsername: string, address: string): int =
return self.controller.releaseEnsEstimate(chainId, ensUsername, address)
method authenticateAndReleaseEns*(self: Module, ensUsername: string, address: string, gas: string, gasPrice: string,
method authenticateAndReleaseEns*(self: Module, chainId: int, ensUsername: string, address: string, gas: string, gasPrice: string,
maxPriorityFeePerGas: string, maxFeePerGas: string, eip1559Enabled: bool) =
self.tmpSendEnsTransactionDetails.chainId = chainId
self.tmpSendEnsTransactionDetails.ensUsername = ensUsername
self.tmpSendEnsTransactionDetails.address = address
self.tmpSendEnsTransactionDetails.gas = gas
@ -179,17 +200,21 @@ method authenticateAndReleaseEns*(self: Module, ensUsername: string, address: st
else:
self.controller.authenticateUser()
method removeEnsUsername*(self: Module, ensUsername: string): bool =
if (not self.controller.removeEnsUsername(ensUsername)):
info "an error occurred removing ens username", methodName="removeEnsUsername"
return false
method onEnsUsernameRemoved(self: Module, chainId: int, ensUsername: string) =
if (self.controller.getPreferredEnsUsername() == ensUsername):
self.controller.fixPreferredName(true)
self.view.model().removeItemByEnsUsername(ensUsername)
self.view.model().removeItemByEnsUsername(chainId, ensUsername)
method removeEnsUsername*(self: Module, chainId: int, ensUsername: string): bool =
if (not self.controller.removeEnsUsername(chainId, ensUsername)):
info "an error occurred removing ens username", methodName="removeEnsUsername", ensUsername, chainId
return false
self.onEnsUsernameRemoved(chainId, ensUsername)
return true
method releaseEns*(self: Module, password: string) =
let response = self.controller.release(
self.tmpSendEnsTransactionDetails.chainId,
self.tmpSendEnsTransactionDetails.ensUsername,
self.tmpSendEnsTransactionDetails.address,
self.tmpSendEnsTransactionDetails.gas,
@ -216,7 +241,7 @@ method releaseEns*(self: Module, password: string) =
var result: string
if(responseObj.getProp("result", result)):
let removed = self.removeEnsUsername(self.tmpSendEnsTransactionDetails.ensUsername)
self.onEnsUsernameRemoved(self.tmpSendEnsTransactionDetails.chainId, self.tmpSendEnsTransactionDetails.ensUsername)
self.view.emitTransactionWasSentSignal(response)
proc formatUsername(self: Module, ensUsername: string, isStatus: bool): string =
@ -225,38 +250,40 @@ proc formatUsername(self: Module, ensUsername: string, isStatus: bool): string =
result = ensUsername & ens_utils.STATUS_DOMAIN
method connectOwnedUsername*(self: Module, ensUsername: string, isStatus: bool) =
let chainId = self.getChainIdForEns()
var ensUsername = self.formatUsername(ensUsername, isStatus)
if(not self.controller.saveNewEnsUsername(ensUsername)):
if(not self.controller.addEnsUsername(chainId, ensUsername)):
info "an error occurred saving ens username", methodName="connectOwnedUsername"
return
self.controller.fixPreferredName()
self.view.model().addItem(Item(ensUsername: ensUsername, isPending: false))
self.view.model().addItem(Item(chainId: chainId, ensUsername: ensUsername, isPending: false))
method ensTransactionConfirmed*(self: Module, trxType: string, ensUsername: string, transactionHash: string) =
if(not self.controller.saveNewEnsUsername(ensUsername)):
info "an error occurred saving ens username", methodName="ensTransactionConfirmed"
return
let chainId = self.getChainIdForEns()
self.controller.fixPreferredName()
if(self.view.model().containsEnsUsername(ensUsername)):
self.view.model().updatePendingStatus(ensUsername, false)
if(self.view.model().containsEnsUsername(chainId, ensUsername)):
self.view.model().updatePendingStatus(chainId, ensUsername, false)
else:
self.view.model().addItem(Item(ensUsername: ensUsername, isPending: false))
self.view.model().addItem(Item(chainId: chainId, ensUsername: ensUsername, isPending: false))
self.view.emitTransactionCompletedSignal(true, transactionHash, ensUsername, trxType, "")
method ensTransactionReverted*(self: Module, trxType: string, ensUsername: string, transactionHash: string,
revertReason: string) =
self.view.model().removeItemByEnsUsername(ensUsername)
revertReason: string) =
let chainId = self.getChainIdForEns()
self.view.model().removeItemByEnsUsername(chainId, ensUsername)
self.view.emitTransactionCompletedSignal(false, transactionHash, ensUsername, trxType, revertReason)
method getEnsRegisteredAddress*(self: Module): string =
return self.controller.getEnsRegisteredAddress()
method registerEnsGasEstimate*(self: Module, ensUsername: string, address: string): int =
return self.controller.registerEnsGasEstimate(ensUsername, address)
method registerEnsGasEstimate*(self: Module, chainId: int, ensUsername: string, address: string): int =
return self.controller.registerEnsGasEstimate(chainId, ensUsername, address)
method authenticateAndRegisterEns*(self: Module, ensUsername: string, address: string, gas: string, gasPrice: string,
method authenticateAndRegisterEns*(self: Module, chainId: int, ensUsername: string, address: string, gas: string, gasPrice: string,
maxPriorityFeePerGas: string, maxFeePerGas: string, eip1559Enabled: bool) =
self.tmpSendEnsTransactionDetails.chainId = chainId
self.tmpSendEnsTransactionDetails.ensUsername = ensUsername
self.tmpSendEnsTransactionDetails.address = address
self.tmpSendEnsTransactionDetails.gas = gas
@ -297,6 +324,7 @@ method authenticateAndRegisterEns*(self: Module, ensUsername: string, address: s
method registerEns(self: Module, password: string) =
let response = self.controller.registerEns(
self.tmpSendEnsTransactionDetails.chainId,
self.tmpSendEnsTransactionDetails.ensUsername,
self.tmpSendEnsTransactionDetails.address,
self.tmpSendEnsTransactionDetails.gas,
@ -314,8 +342,10 @@ method registerEns(self: Module, password: string) =
var respResult: string
if(responseObj.getProp("result", respResult) and responseObj{"success"}.getBool == true):
let ensUsername = self.formatUsername(self.tmpSendEnsTransactionDetails.ensUsername, true)
let item = Item(chainId: self.tmpSendEnsTransactionDetails.chainId, ensUsername: ensUsername, isPending: true)
self.controller.fixPreferredName()
self.view.model().addItem(Item(ensUsername: self.formatUsername(self.tmpSendEnsTransactionDetails.ensUsername, true), isPending: true))
self.view.model().addItem(item)
self.view.emitTransactionWasSentSignal(response)
method getSNTBalance*(self: Module): string =
@ -380,7 +410,7 @@ method getStatusToken*(self: Module): string =
return self.controller.getStatusToken()
method getChainIdForEns*(self: Module): int =
return self.controller.getNetwork().chainId
return self.controller.getChainId()
method setPrefferedEnsUsername*(self: Module, ensUsername: string) =
self.controller.setPreferredName(ensUsername)

View File

@ -39,6 +39,16 @@ QtObject:
read = getModel
notify = modelChanged
proc chainIdChanged*(self: View) {.signal.}
proc chainId(self: View): int {.slot.} =
return self.delegate.getChainIdForEns()
QtProperty[int] chainId:
read = chainId
notify = chainIdChanged
proc emitChainIdChanged*(self: View) =
self.chainIdChanged()
proc getEnsRegistry(self: View): string {.slot.} =
return ENS_REGISTRY
@ -53,27 +63,27 @@ QtObject:
return self.delegate.numOfPendingEnsUsernames()
proc loading(self: View, isLoading: bool) {.signal.}
proc detailsObtained(self: View, ensName: string, address: string, pubkey: string, isStatus: bool, expirationTime: int) {.signal.}
proc detailsObtained(self: View, chainId: int, ensName: string, address: string, pubkey: string, isStatus: bool, expirationTime: int) {.signal.}
proc fetchDetailsForEnsUsername*(self: View, ensUsername: string) {.slot.} =
proc fetchDetailsForEnsUsername*(self: View, chainId: int, ensUsername: string) {.slot.} =
self.loading(true)
self.delegate.fetchDetailsForEnsUsername(ensUsername)
self.delegate.fetchDetailsForEnsUsername(chainId, ensUsername)
proc setDetailsForEnsUsername*(self: View, ensUsername: string, address: string, pubkey: string, isStatus: bool,
proc processObtainedEnsUsermesDetails*(self: View, chainId: int, ensUsername: string, address: string, pubkey: string, isStatus: bool,
expirationTime: int) =
self.loading(false)
self.detailsObtained(ensUsername, address, pubkey, isStatus, expirationTime)
self.detailsObtained(chainId, ensUsername, address, pubkey, isStatus, expirationTime)
proc transactionWasSent(self: View, txResult: string) {.signal.}
proc emitTransactionWasSentSignal*(self: View, txResult: string) =
self.transactionWasSent(txResult)
proc setPubKeyGasEstimate*(self: View, ensUsername: string, address: string): int {.slot.} =
return self.delegate.setPubKeyGasEstimate(ensUsername, address)
proc setPubKeyGasEstimate*(self: View, chainId: int, ensUsername: string, address: string): int {.slot.} =
return self.delegate.setPubKeyGasEstimate(chainId, ensUsername, address)
proc authenticateAndSetPubKey*(self: View, ensUsername: string, address: string, gas: string, gasPrice: string,
proc authenticateAndSetPubKey*(self: View, chainId: int, ensUsername: string, address: string, gas: string, gasPrice: string,
maxPriorityFeePerGas: string, maxFeePerGas: string, eip1559Enabled: bool) {.slot.} =
self.delegate.authenticateAndSetPubKey(ensUsername, address, gas, gasPrice, maxPriorityFeePerGas, maxFeePerGas, eip1559Enabled)
self.delegate.authenticateAndSetPubKey(chainId, ensUsername, address, gas, gasPrice, maxPriorityFeePerGas, maxFeePerGas, eip1559Enabled)
proc getEtherscanLink*(self: View): string {.slot.} =
return self.etherscanLink
@ -91,15 +101,15 @@ QtObject:
revertReason: string) =
self.transactionCompleted(success, txHash, username, trxType, revertReason)
proc removeEnsUsername*(self: View, ensUsername: string): bool {.slot.} =
return self.delegate.removeEnsUsername(ensUsername)
proc removeEnsUsername*(self: View, chainId: int, ensUsername: string): bool {.slot.} =
return self.delegate.removeEnsUsername(chainId, ensUsername)
proc releaseEnsEstimate*(self: View, ensUsername: string, address: string): int {.slot.} =
return self.delegate.releaseEnsEstimate(ensUsername, address)
proc releaseEnsEstimate*(self: View, chainId: int, ensUsername: string, address: string): int {.slot.} =
return self.delegate.releaseEnsEstimate(chainId, ensUsername, address)
proc authenticateAndReleaseEns*(self: View, ensUsername: string, address: string, gas: string, gasPrice: string,
proc authenticateAndReleaseEns*(self: View, chainId: int, ensUsername: string, address: string, gas: string, gasPrice: string,
maxPriorityFeePerGas: string, maxFeePerGas: string, eip1559Enabled: bool) {.slot.} =
self.delegate.authenticateAndReleaseEns(ensUsername, address, gas, gasPrice, maxPriorityFeePerGas, maxFeePerGas, eip1559Enabled)
self.delegate.authenticateAndReleaseEns(chainId, ensUsername, address, gas, gasPrice, maxPriorityFeePerGas, maxFeePerGas, eip1559Enabled)
proc connectOwnedUsername*(self: View, ensUsername: string, isStatus: bool) {.slot.} =
self.delegate.connectOwnedUsername(ensUsername, isStatus)
@ -107,12 +117,12 @@ QtObject:
proc getEnsRegisteredAddress*(self: View): string {.slot.} =
return self.delegate.getEnsRegisteredAddress()
proc registerEnsGasEstimate*(self: View, ensUsername: string, address: string): int {.slot.} =
return self.delegate.registerEnsGasEstimate(ensUsername, address)
proc registerEnsGasEstimate*(self: View, chainId: int, ensUsername: string, address: string): int {.slot.} =
return self.delegate.registerEnsGasEstimate(chainId, ensUsername, address)
proc authenticateAndRegisterEns*(self: View, ensUsername: string, address: string, gas: string, gasPrice: string,
proc authenticateAndRegisterEns*(self: View, chainId: int, ensUsername: string, address: string, gas: string, gasPrice: string,
maxPriorityFeePerGas: string, maxFeePerGas: string, eip1559Enabled: bool) {.slot.} =
self.delegate.authenticateAndRegisterEns(ensUsername, address, gas, gasPrice, maxPriorityFeePerGas, maxFeePerGas, eip1559Enabled)
self.delegate.authenticateAndRegisterEns(chainId, ensUsername, address, gas, gasPrice, maxPriorityFeePerGas, maxFeePerGas, eip1559Enabled)
proc getSNTBalance*(self: View): string {.slot.} =
return self.delegate.getSNTBalance()

View File

@ -59,6 +59,7 @@ const ensUsernameDetailsTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.
expirationTime = ens_utils.getExpirationTime(arg.chainId, arg.ensUsername)
let responseJson = %* {
"chainId": arg.chainId,
"ensUsername": arg.ensUsername,
"address": address,
"pubkey": pubkey,

View File

@ -0,0 +1,25 @@
{.used.}
import json, strformat, hashes
include ../../../common/json_utils
type EnsUsernameDto* = ref object
chainId*: int
username*: string
proc `==`*(l, r: EnsUsernameDto): bool =
return l.chainId == r.chainid and l.username == r.username
proc `$`*(self: EnsUsernameDto): string =
result = fmt"""ContactDto(
chainId: {self.chainId},
username: {self.username}
)"""
proc hash*(dto: EnsUsernameDto): Hash =
return ($dto).hash
proc toEnsUsernameDto*(jsonObj: JsonNode): EnsUsernameDto =
result = EnsUsernameDto()
discard jsonObj.getProp("chainId", result.chainId)
discard jsonObj.getProp("username", result.username)

View File

@ -23,7 +23,9 @@ import ../network/service as network_service
import ../token/service as token_service
import ../eth/dto/coder
import ../eth/dto/transaction
import dto/ens_username_dto
export ens_username_dto
logScope:
topics = "ens-service"
@ -44,6 +46,7 @@ type
availabilityStatus*: string
EnsUsernameDetailsArgs* = ref object of Args
chainId*: int
ensUsername*: string
address*: string
pubkey*: string
@ -70,7 +73,7 @@ QtObject:
Service* = ref object of QObject
events: EventEmitter
threadpool: ThreadPool
pendingEnsUsernames*: HashSet[string]
pendingEnsUsernames*: HashSet[EnsUsernameDto]
settingsService: settings_service.Service
walletAccountService: wallet_account_service.Service
transactionService: transaction_service.Service
@ -99,17 +102,20 @@ QtObject:
result.networkService = networkService
result.tokenService = tokenService
proc getChainId(self: Service): int =
return self.networkService.getNetworkForEns().chainId
proc confirmTransaction(self: Service, trxType: string, ensUsername: string, transactionHash: string) =
self.pendingEnsUsernames.excl(ensUsername)
let dto = EnsUsernameDto(chainId: self.getChainId(), username: ensUsername)
let data = EnsTransactionArgs(transactionHash: transactionHash, ensUsername: ensUsername, transactionType: $trxType)
self.pendingEnsUsernames.excl(dto)
self.events.emit(SIGNAL_ENS_TRANSACTION_CONFIRMED, data)
proc revertTransaction(self: Service, trxType: string, ensUsername: string, transactionHash: string,
revertReason: string) =
self.pendingEnsUsernames.excl(ensUsername)
let data = EnsTransactionArgs(
transactionHash: transactionHash, ensUsername: ensUsername, transactionType: $trxType, revertReason: revertReason
)
let dto = EnsUsernameDto(chainId: self.getChainId(), username: ensUsername)
let data = EnsTransactionArgs(transactionHash: transactionHash, ensUsername: ensUsername, transactionType: $trxType, revertReason: revertReason)
self.pendingEnsUsernames.excl(dto)
self.events.emit(SIGNAL_ENS_TRANSACTION_REVERTED, data)
proc doConnect(self: Service) =
@ -134,16 +140,56 @@ QtObject:
for trx in self.transactionService.getPendingTransactions():
if trx.typeValue == $PendingTransactionTypeDto.RegisterENS or trx.typeValue == $PendingTransactionTypeDto.SetPubKey:
self.pendingEnsUsernames.incl trx.additionalData
let dto = EnsUsernameDto(chainId: trx.chainId, username: trx.additionalData)
self.pendingEnsUsernames.incl(dto)
proc getMyPendingEnsUsernames*(self: Service): seq[string] =
proc getMyPendingEnsUsernames*(self: Service): seq[EnsUsernameDto] =
for i in self.pendingEnsUsernames.items:
result.add(i)
proc getAllMyEnsUsernames*(self: Service, includePending: bool): seq[string] =
result = self.settingsService.getEnsUsernames()
if(includePending):
result.add(self.getMyPendingEnsUsernames())
proc getAllMyEnsUsernames*(self: Service, includePending: bool): seq[EnsUsernameDto] =
var response: JsonNode
try:
response = status_ens.getEnsUsernames().result
except Exception as e:
error "error occurred", procName="getAllMyEnsUsernames", msg = e.msg
return
if (response.kind != JArray):
warn "expected response is not a json object", procName="getAllMyEnsUsernames"
return
for jsonContact in response:
result.add(jsonContact.toEnsUsernameDto())
if (includePending):
for dto in self.getMyPendingEnsUsernames():
result.add(dto)
proc add*(self: Service, chainId: int, username: string): bool =
try:
let response = status_ens.add(chainId, username)
if (not response.error.isNil):
let msg = response.error.message
error "error adding ens username ", msg
return false
except Exception as e:
error "error occurred", procName="add", msg = e.msg
return false
return true
proc remove*(self: Service, chainId: int, username: string): bool =
try:
let response = status_ens.remove(chainId, username)
if (not response.error.isNil):
let msg = response.error.message
error "error removing ens username ", msg
return false
except Exception as e:
error "error occurred", procName="remove", msg = e.msg
return false
return true
proc onEnsUsernameAvailabilityChecked*(self: Service, response: string) {.slot.} =
let responseObj = response.parseJson
@ -165,9 +211,10 @@ QtObject:
proc checkEnsUsernameAvailability*(self: Service, ensUsername: string, isStatus: bool) =
let registeredEnsUsernames = self.getAllMyEnsUsernames(true)
var desiredEnsUsername = self.formatUsername(ensUsername, isStatus)
let dto = EnsUsernameDto(chainId: self.getChainId(),
username: self.formatUsername(ensUsername, isStatus))
var availability = ""
if registeredEnsUsernames.filter(proc(x: string):bool = x == desiredEnsUsername).len > 0:
if registeredEnsUsernames.find(dto) >= 0:
let data = EnsUsernameAvailabilityArgs(availabilityStatus: ENS_AVAILABILITY_STATUS_ALREADY_CONNECTED)
self.events.emit(SIGNAL_ENS_USERNAME_AVAILABILITY_CHECKED, data)
else:
@ -176,7 +223,7 @@ QtObject:
vptr: cast[ByteAddress](self.vptr),
slot: "onEnsUsernameAvailabilityChecked",
ensUsername: ensUsername,
chainId: self.networkService.getNetworkForEns().chainId,
chainId: self.getChainId(),
isStatus: isStatus,
myPublicKey: self.settingsService.getPublicKey(),
myWalletAddress: self.walletAccountService.getWalletAccount(0).address
@ -192,6 +239,7 @@ QtObject:
return
var data = EnsUsernameDetailsArgs()
discard responseObj.getProp("chainId", data.chainId)
discard responseObj.getProp("ensUsername", data.ensUsername)
discard responseObj.getProp("address", data.address)
discard responseObj.getProp("pubkey", data.pubkey)
@ -199,7 +247,7 @@ QtObject:
discard responseObj.getProp("expirationTime", data.expirationTime)
self.events.emit(SIGNAL_ENS_USERNAME_DETAILS_FETCHED, data)
proc fetchDetailsForEnsUsername*(self: Service, ensUsername: string) =
proc fetchDetailsForEnsUsername*(self: Service, chainId: int, ensUsername: string) =
var isStatus = false
var username = ensUsername
if ensUsername.endsWith(ens_utils.STATUS_DOMAIN):
@ -211,7 +259,7 @@ QtObject:
vptr: cast[ByteAddress](self.vptr),
slot: "onEnsUsernameDetailsFetched",
ensUsername: username,
chainId: self.networkService.getNetworkForEns().chainId,
chainId: chainId,
isStatus: isStatus
)
self.threadpool.start(arg)
@ -219,12 +267,9 @@ QtObject:
proc extractCoordinates(self: Service, pubkey: string):tuple[x: string, y:string] =
result = ("0x" & pubkey[4..67], "0x" & pubkey[68..131])
proc setPubKeyGasEstimate*(self: Service, ensUsername: string, address: string): int =
proc setPubKeyGasEstimate*(self: Service, chainId: int, ensUsername: string, address: string): int =
try:
let
chainId = self.networkService.getNetworkForEns().chainId
txData = ens_utils.buildTransaction(parseAddress(address), 0.u256)
let txData = ens_utils.buildTransaction(parseAddress(address), 0.u256)
let resp = status_ens.setPubKeyEstimate(chainId, %txData, ensUsername,
singletonInstance.userProfile.getPubKey())
result = resp.result.getInt
@ -234,6 +279,7 @@ QtObject:
proc setPubKey*(
self: Service,
chainId: int,
ensUsername: string,
address: string,
gas: string,
@ -244,11 +290,8 @@ QtObject:
eip1559Enabled: bool,
): string =
try:
let
chainId = self.networkService.getNetworkForEns().chainId
txData = ens_utils.buildTransaction(parseAddress(address), 0.u256, gas, gasPrice,
let txData = ens_utils.buildTransaction(parseAddress(address), 0.u256, gas, gasPrice,
eip1559Enabled, maxPriorityFeePerGas, maxFeePerGas)
let resp = status_ens.setPubKey(chainId, %txData, password, ensUsername.addDomain(),
singletonInstance.userProfile.getPubKey())
let hash = resp.result.getStr
@ -258,19 +301,17 @@ QtObject:
hash, $address, resolverAddress,
$PendingTransactionTypeDto.SetPubKey, ensUsername, chainId
)
self.pendingEnsUsernames.incl(ensUsername)
let dto = EnsUsernameDto(chainId: chainId, username: ensUsername)
self.pendingEnsUsernames.incl(dto)
result = $(%* { "result": hash, "success": true })
except Exception as e:
error "error occurred", procName="setPubKey", msg = e.msg
result = $(%* { "result": e.msg, "success": false })
proc releaseEnsEstimate*(self: Service, ensUsername: string, address: string): int =
proc releaseEnsEstimate*(self: Service, chainId: int, ensUsername: string, address: string): int =
try:
let
chainId = self.networkService.getNetworkForEns().chainId
txData = ens_utils.buildTransaction(parseAddress(address), 0.u256)
let txData = ens_utils.buildTransaction(parseAddress(address), 0.u256)
var userNameNoDomain = ensUsername
if ensUsername.endsWith(ens_utils.STATUS_DOMAIN):
userNameNoDomain = ensUsername.replace(ens_utils.STATUS_DOMAIN, "")
@ -282,12 +323,11 @@ QtObject:
result = 100000
proc getEnsRegisteredAddress*(self: Service): string =
let networkDto = self.networkService.getNetworkForEns()
return status_ens.getRegistrarAddress(networkDto.chainId).result.getStr
return status_ens.getRegistrarAddress(self.getChainId()).result.getStr
proc release*(
self: Service,
chainId: int,
ensUsername: string,
address: string,
gas: string,
@ -299,7 +339,6 @@ QtObject:
): string =
try:
let
chainId = self.networkService.getNetworkForEns().chainId
txData = ens_utils.buildTransaction(parseAddress(address), 0.u256, gas, gasPrice,
eip1559Enabled, maxPriorityFeePerGas, maxFeePerGas)
@ -315,19 +354,17 @@ QtObject:
hash, address, ensUsernamesAddress,
$PendingTransactionTypeDto.ReleaseENS, ensUsername, chainId
)
self.pendingEnsUsernames.excl(ensUsername)
let dto = EnsUsernameDto(chainId: chainId, username: ensUsername)
self.pendingEnsUsernames.excl(dto)
result = $(%* { "result": hash, "success": true })
except Exception as e:
error "error occurred", procName="release", msg = e.msg
result = $(%* { "result": e.msg, "success": false })
proc registerENSGasEstimate*(self: Service, ensUsername: string, address: string): int =
proc registerENSGasEstimate*(self: Service, chainId: int, ensUsername: string, address: string): int =
try:
let
chainId = self.networkService.getNetworkForEns().chainId
txData = ens_utils.buildTransaction(parseAddress(address), 0.u256)
let txData = ens_utils.buildTransaction(parseAddress(address), 0.u256)
let resp = status_ens.registerEstimate(chainId, %txData, ensUsername,
singletonInstance.userProfile.getPubKey())
result = resp.result.getInt
@ -337,11 +374,11 @@ QtObject:
proc getStatusToken*(self: Service): TokenDto =
let networkDto = self.networkService.getNetworkForEns()
return self.tokenService.findTokenBySymbol(networkDto, networkDto.sntSymbol())
proc registerEns*(
self: Service,
chainId: int,
username: string,
address: string,
gas: string,
@ -352,11 +389,8 @@ QtObject:
eip1559Enabled: bool,
): string =
try:
let
chainId = self.networkService.getNetworkForEns().chainId
txData = ens_utils.buildTransaction(parseAddress(address), 0.u256, gas, gasPrice,
let txData = ens_utils.buildTransaction(parseAddress(address), 0.u256, gas, gasPrice,
eip1559Enabled, maxPriorityFeePerGas, maxFeePerGas)
let resp = status_ens.register(chainId, %txData, password, username,
singletonInstance.userProfile.getPubKey())
let hash = resp.result.getStr
@ -368,7 +402,8 @@ QtObject:
chainId
)
self.pendingEnsUsernames.incl(ensUsername)
let dto = EnsUsernameDto(chainId: chainId, username: ensUsername)
self.pendingEnsUsernames.incl(dto)
result = $(%* { "result": hash, "success": true })
except Exception as e:
error "error occurred", procName="registerEns", msg = e.msg
@ -377,15 +412,12 @@ QtObject:
proc getSNTBalance*(self: Service): string =
let token = self.getStatusToken()
let account = self.walletAccountService.getWalletAccount(0).address
let networkDto = self.networkService.getNetworkForEns()
let balances = status_go_backend.getTokensBalancesForChainIDs(@[networkDto.chainId], @[account], @[token.addressAsString()]).result
let balances = status_go_backend.getTokensBalancesForChainIDs(@[self.getChainId()], @[account], @[token.addressAsString()]).result
return ens_utils.hex2Token(balances{account}{token.addressAsString()}.getStr, token.decimals)
proc resourceUrl*(self: Service, username: string): (string, string, string) =
try:
let chainId = self.networkService.getNetworkForEns().chainId
let response = status_ens.resourceURL(chainId, username)
let response = status_ens.resourceURL(self.getChainId(), username)
return (response.result{"Scheme"}.getStr, response.result{"Host"}.getStr, response.result{"Path"}.getStr)
except Exception as e:
error "Error getting ENS resourceUrl", username=username, exception=e.msg

View File

@ -96,11 +96,14 @@ proc toggleNetwork*(self: Service, chainId: int) =
network.enabled = not network.enabled
self.upsertNetwork(network)
proc getNetworkForEns*(self: Service): NetworkDto =
proc getChainIdForEns*(self: Service): int =
if self.settingsService.areTestNetworksEnabled():
return self.getNetwork(Goerli)
return Goerli
return Mainnet
return self.getNetwork(Mainnet)
proc getNetworkForEns*(self: Service): NetworkDto =
let chainId = self.getChainIdForEns()
return self.getNetwork(chainId)
proc getNetworkForStickers*(self: Service): NetworkDto =
if self.settingsService.areTestNetworksEnabled():

View File

@ -153,32 +153,6 @@ QtObject:
return true
return false
proc saveNewEnsUsername*(self: Service, username: string): bool =
var newEnsUsernames = self.settings.ensUsernames
newEnsUsernames.add(username)
let newEnsUsernamesAsJson = %* newEnsUsernames
if(self.saveSetting(KEY_ENS_USERNAMES, newEnsUsernamesAsJson)):
self.settings.ensUsernames = newEnsUsernames
return true
return false
proc removeEnsUsername*(self: Service, username: string): bool =
var newEnsUsernames = self.settings.ensUsernames
let index = newEnsUsernames.find(username)
if (index < 0):
return false
newEnsUsernames.delete(index)
let newEnsUsernamesAsJson = %* newEnsUsernames
if(self.saveSetting(KEY_ENS_USERNAMES, newEnsUsernamesAsJson)):
self.settings.ensUsernames = newEnsUsernames
return true
return false
proc getEnsUsernames*(self: Service): seq[string] =
return self.settings.ensUsernames
proc saveKeyUid*(self: Service, value: string): bool =
if(self.saveSetting(KEY_KEY_UID, value)):
self.settings.keyUid = value

View File

@ -3,6 +3,18 @@ import ./core, ./response_type
import ./utils
export response_type
proc getEnsUsernames*(): RpcResponse[JsonNode] {.raises: [Exception].} =
let payload = %* []
return core.callPrivateRPC("ens_getEnsUsernames", payload)
proc add*(chainId: int, username: string): RpcResponse[JsonNode] {.raises: [Exception].} =
let payload = %* [chainId, username]
return core.callPrivateRPC("ens_add", payload)
proc remove*(chainId: int, username: string): RpcResponse[JsonNode] {.raises: [Exception].} =
let payload = %* [chainId, username]
return core.callPrivateRPC("ens_remove", payload)
proc getRegistrarAddress*(chainId: int): RpcResponse[JsonNode] {.raises: [Exception].} =
let payload = %* [chainId]
@ -80,4 +92,4 @@ proc setPubKeyEstimate*(
chainId: int, txData: JsonNode, username: string, pubkey: string
): RpcResponse[JsonNode] {.raises: [Exception].} =
let payload = %* [chainId, txData, username, pubkey]
return core.callPrivateRPC("ens_setPubKeyEstimate", payload)
return core.callPrivateRPC("ens_setPubKeyEstimate", payload)

View File

@ -72,8 +72,7 @@ StatusDialog {
Layout.fillWidth: true
Layout.fillHeight: true
implicitHeight: contentHeight
model: root.ensUsernamesStore.ensUsernamesModel
model: root.ensUsernamesStore.currentChainEnsUsernamesModel
delegate: RadioDelegate {
id: radioDelegate

View File

@ -1,5 +1,6 @@
import QtQuick 2.13
import utils 1.0
import SortFilterProxyModel 0.2
QtObject {
id: root
@ -8,9 +9,18 @@ QtObject {
property var ensUsernamesModel: root.ensUsernamesModule ? ensUsernamesModule.model : []
readonly property QtObject currentChainEnsUsernamesModel: SortFilterProxyModel {
sourceModel: root.ensUsernamesModel
filters: ValueFilter {
roleName: "chainId"
value: root.chainId
}
}
property string pubkey: userProfile.pubKey
property string icon: userProfile.icon
property string preferredUsername: userProfile.preferredName
readonly property string chainId: ensUsernamesModule.chainId
property string username: userProfile.username
@ -34,22 +44,22 @@ QtObject {
return ensUsernamesModule.numOfPendingEnsUsernames()
}
function ensDetails(ensUsername) {
function ensDetails(chainId, ensUsername) {
if(!root.ensUsernamesModule)
return ""
ensUsernamesModule.fetchDetailsForEnsUsername(ensUsername)
ensUsernamesModule.fetchDetailsForEnsUsername(chainId, ensUsername)
}
function setPubKeyGasEstimate(ensUsername, address) {
function setPubKeyGasEstimate(chainId, ensUsername, address) {
if(!root.ensUsernamesModule)
return 0
return ensUsernamesModule.setPubKeyGasEstimate(ensUsername, address)
return ensUsernamesModule.setPubKeyGasEstimate(chainId, ensUsername, address)
}
function authenticateAndSetPubKey(ensUsername, address, gas, gasPrice, maxPriorityFeePerGas, maxFeePerGas, eip1559Enabled) {
function authenticateAndSetPubKey(chainId, ensUsername, address, gas, gasPrice, maxPriorityFeePerGas, maxFeePerGas, eip1559Enabled) {
if(!root.ensUsernamesModule)
return ""
return ensUsernamesModule.authenticateAndSetPubKey(ensUsername, address, gas, gasPrice, maxPriorityFeePerGas, maxFeePerGas, eip1559Enabled)
return ensUsernamesModule.authenticateAndSetPubKey(chainId, ensUsername, address, gas, gasPrice, maxPriorityFeePerGas, maxFeePerGas, eip1559Enabled)
}
function getEtherscanLink() {
@ -68,10 +78,10 @@ QtObject {
globalUtils.copyToClipboard(value)
}
function authenticateAndReleaseEns(ensUsername, address, gas, gasPrice, maxPriorityFeePerGas, maxFeePerGas, eip1559Enabled) {
function authenticateAndReleaseEns(chainId, ensUsername, address, gas, gasPrice, maxPriorityFeePerGas, maxFeePerGas, eip1559Enabled) {
if(!root.ensUsernamesModule)
return ""
return ensUsernamesModule.authenticateAndReleaseEns(ensUsername, address, gas, gasPrice, maxPriorityFeePerGas, maxFeePerGas, eip1559Enabled)
return ensUsernamesModule.authenticateAndReleaseEns(chainId, ensUsername, address, gas, gasPrice, maxPriorityFeePerGas, maxFeePerGas, eip1559Enabled)
}
function ensConnectOwnedUsername(name, isStatus) {
@ -86,10 +96,10 @@ QtObject {
return ensUsernamesModule.getEnsRegisteredAddress()
}
function authenticateAndRegisterEns(ensUsername, address, gasLimit, gasPrice, tipLimit, overallLimit, eip1559Enabled) {
function authenticateAndRegisterEns(chainId, ensUsername, address, gasLimit, gasPrice, tipLimit, overallLimit, eip1559Enabled) {
if(!root.ensUsernamesModule)
return
ensUsernamesModule.authenticateAndRegisterEns(ensUsername, address, gasLimit, gasPrice, tipLimit, overallLimit, eip1559Enabled)
ensUsernamesModule.authenticateAndRegisterEns(chainId, ensUsername, address, gasLimit, gasPrice, tipLimit, overallLimit, eip1559Enabled)
}
function getEnsRegistry() {
@ -148,16 +158,10 @@ QtObject {
return JSON.parse(walletSectionTransactions.suggestedFees(chainId))
}
function getChainIdForEns() {
function removeEnsUsername(chainId, ensUsername) {
if(!root.ensUsernamesModule)
return ""
return ensUsernamesModule.getChainIdForEns()
}
function removeEnsUsername(ensUsername) {
if(!root.ensUsernamesModule)
return ""
return ensUsernamesModule.removeEnsUsername(ensUsername)
return ensUsernamesModule.removeEnsUsername(chainId, ensUsername)
}
}

View File

@ -16,11 +16,12 @@ Item {
property var ensUsernamesStore
property var contactsStore
property string username: ""
property string chainId: ""
property string walletAddress: "-"
property string key: "-"
signal backBtnClicked();
signal usernameReleased(username: string);
signal usernameReleased()
QtObject {
id: d
@ -140,6 +141,7 @@ Item {
let eip1559Enabled = path.gasFees.eip1559Enabled
let maxFeePerGas = path.gasFees.maxFeePerGasM
root.ensUsernamesStore.authenticateAndReleaseEns(
root.chainId,
root.username,
selectedAccount.address,
path.gasAmount,
@ -163,7 +165,7 @@ Item {
return releaseEnsModal.sendingError.open()
}
for(var i=0; i<releaseEnsModal.bestRoutes.length; i++) {
usernameReleased(username);
usernameReleased()
let url = "%1/%2".arg(releaseEnsModal.store.getEtherscanLink(releaseEnsModal.bestRoutes[i].fromNetwork.chainId)).arg(response.result)
Global.displayToastMessage(qsTr("Transaction pending..."),
qsTr("View on etherscan"),
@ -195,7 +197,7 @@ Item {
type: StatusQControls.StatusBaseButton.Type.Danger
text: qsTr("Remove username")
onClicked: {
root.ensUsernamesStore.removeEnsUsername(root.username)
root.ensUsernamesStore.removeEnsUsername(root.chainId, root.username)
root.backBtnClicked()
}
}

View File

@ -23,7 +23,7 @@ Item {
property int profileContentWidth
signal addBtnClicked()
signal selectEns(string username)
signal selectEns(string username, string chainId)
Component.onCompleted: {
d.updateNumberOfPendingEnsUsernames()
@ -121,7 +121,8 @@ Item {
StatusListView {
id: lvEns
anchors.fill: parent
model: root.ensUsernamesStore.ensUsernamesModel
model: root.ensUsernamesStore.currentChainEnsUsernamesModel
spacing: 10
delegate: StatusListItem {
readonly property int indexOfDomainStart: model.ensUsername.indexOf(".")
@ -149,7 +150,7 @@ Item {
]
onClicked: {
root.selectEns(model.ensUsername)
root.selectEns(model.ensUsername, model.chainId)
}
}

View File

@ -86,6 +86,7 @@ Item {
let path = bestRoutes[0]
let eip1559Enabled = path.gasFees.eip1559Enabled
root.ensUsernamesStore.authenticateAndSetPubKey(
root.ensUsernamesStore.chainId,
ensUsername.text + (isStatus ? ".stateofus.eth" : "" ),
selectedAccount.address,
path.gasAmount,

View File

@ -73,6 +73,7 @@ Item {
let eip1559Enabled = path.gasFees.eip1559Enabled
let maxFeePerGas = path.gasFees.maxFeePerGasM
root.ensUsernamesStore.authenticateAndRegisterEns(
root.ensUsernamesStore.chainId,
username,
selectedAccount.address,
path.gasAmount,

View File

@ -20,6 +20,7 @@ Item {
property bool showSearchScreen: false
property string addedUsername: ""
property string selectedUsername: ""
property string selectedChainId: ""
signal next(output: string)
signal back()
@ -292,8 +293,9 @@ Item {
profileContentWidth: ensView.profileContentWidth
onAddBtnClicked: next("search")
onSelectEns: {
ensView.ensUsernamesStore.ensDetails(username)
selectedUsername = username;
ensView.ensUsernamesStore.ensDetails(chainId, username)
selectedUsername = username
selectedChainId = chainId
next("details")
}
}
@ -305,10 +307,12 @@ Item {
ensUsernamesStore: ensView.ensUsernamesStore
contactsStore: ensView.contactsStore
username: selectedUsername
onBackBtnClicked: back();
chainId: selectedChainId
onBackBtnClicked: back()
onUsernameReleased: {
selectedUsername = username;
done(username);
selectedUsername = username
selectedChainId = chainId
done(username)
}
}
}