Skip to content

Commit

Permalink
feat: Added chainId to ens usernames
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-sirotin committed Feb 1, 2023
1 parent 0bd957e commit 1523c9f
Show file tree
Hide file tree
Showing 19 changed files with 329 additions and 216 deletions.
2 changes: 0 additions & 2 deletions src/app/boot/app_controller.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
61 changes: 35 additions & 26 deletions src/app/modules/main/profile_section/ens_usernames/controller.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)):
Expand All @@ -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()
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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")

Expand All @@ -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")

Expand Down
27 changes: 17 additions & 10 deletions src/app/modules/main/profile_section/ens_usernames/model.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 =
Expand All @@ -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()
Expand All @@ -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

Expand All @@ -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

Expand Down
Loading

0 comments on commit 1523c9f

Please sign in to comment.