Skip to content

Commit

Permalink
feat(@desktop/wallet): Updated UI for bridge and multi routing support
Browse files Browse the repository at this point in the history
fixes #7334
  • Loading branch information
Khushboo-dev-cpp committed Oct 26, 2022
1 parent afaf771 commit e661cd0
Show file tree
Hide file tree
Showing 74 changed files with 2,245 additions and 2,182 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@ proc getWalletAccount*(self: Controller, accountIndex: int): wallet_account_serv
return self.walletAccountService.getWalletAccount(accountIndex)

proc getIndex*(self: Controller, address: string): int =
return self.walletAccountService.getIndex(address)
return self.walletAccountService.getIndex(address)

method findTokenSymbolByAddress*(self: Controller, address: string): string =
return self.walletAccountService.findTokenSymbolByAddress(address)
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ method isLoaded*(self: AccessInterface): bool {.base.} =
method switchAccountByAddress*(self: AccessInterface, address: string) {.base.} =
raise newException(ValueError, "No implementation available")

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

# View Delegate Interface
# Delegate for the view must be declared here due to use of QtObject and multi
# inheritance, which is not well supported in Nim.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ proc setAssets(self: Module, tokens: seq[WalletTokenDto]) =
t.changePct24hour,
t.change24hour,
t.currencyPrice,
t.decimals,
)
items.add(item)

Expand Down Expand Up @@ -104,3 +105,6 @@ proc onTokensRebuilt(self: Module, accountsTokens: OrderedTable[string, seq[Wall
if not accountsTokens.contains(walletAccount.address):
return
self.setAssets(accountsTokens[walletAccount.address])

method findTokenSymbolByAddress*(self: Module, address: string): string =
return self.controller.findTokenSymbolByAddress(address)
9 changes: 9 additions & 0 deletions src/app/modules/main/browser_section/current_account/view.nim
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,15 @@ QtObject:

proc connectedAccountDeleted*(self: View) {.signal.}

proc findTokenSymbolByAddress*(self: View, address: string): string {.slot.} =
return self.delegate.findTokenSymbolByAddress(address)

proc hasGas*(self: View, chainId: int, nativeGasSymbol: string, requiredGas: float): bool {.slot.} =
return self.assets.hasGas(chainId, nativeGasSymbol, requiredGas)

proc getTokenBalanceOnChain*(self: View, chainId: int, tokenSymbol: string): string {.slot.} =
return self.assets.getTokenBalanceOnChain(chainId, tokenSymbol)

proc setData*(self: View, dto: wallet_account_service.WalletAccountDto) =
self.name = dto.name
self.nameChanged()
Expand Down
16 changes: 16 additions & 0 deletions src/app/modules/main/browser_section/provider/controller.nim
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import ../../../../../app_service/service/network/service as network_service
import ../../../../../app_service/service/settings/service as settings_service
import ../../../../../app_service/service/provider/service as provider_service
import ../../../../../app_service/service/wallet_account/service
import ../../../shared_modules/keycard_popup/io_interface as keycard_shared_module

const UNIQUE_BROWSER_SECTION_TRANSACTION_MODULE_IDENTIFIER* = "BrowserSection-TransactionModule"

type
Controller* = ref object of RootObj
Expand Down Expand Up @@ -43,6 +46,12 @@ proc init*(self: Controller) =
self.events.on(SIGNAL_WALLET_ACCOUNT_NETWORK_ENABLED_UPDATED) do(e: Args):
self.delegate.updateNetwork(self.getNetwork())

self.events.on(SIGNAL_SHARED_KEYCARD_MODULE_USER_AUTHENTICATED) do(e: Args):
let args = SharedKeycarModuleArgs(e)
if args.uniqueIdentifier != UNIQUE_BROWSER_SECTION_TRANSACTION_MODULE_IDENTIFIER:
return
self.delegate.onUserAuthenticated(args.password)

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

Expand All @@ -55,3 +64,10 @@ proc postMessage*(self: Controller, payloadMethod: string, requestType: string,

proc ensResourceURL*(self: Controller, ens: string, url: string): (string, string, string, string, bool) =
return self.providerService.ensResourceURL(ens, url)

proc authenticateUser*(self: Controller, keyUid = "", bip44Path = "", txHash = "") =
let data = SharedKeycarModuleAuthenticationArgs(uniqueIdentifier: UNIQUE_BROWSER_SECTION_TRANSACTION_MODULE_IDENTIFIER,
keyUid: keyUid,
bip44Path: bip44Path,
txHash: txHash)
self.events.emit(SIGNAL_SHARED_KEYCARD_MODULE_AUTHENTICATE_USER, data)
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,10 @@ method viewDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

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

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

method onUserAuthenticated*(self: AccessInterface, password: string) {.base.} =
raise newException(ValueError, "No implementation available")
29 changes: 29 additions & 0 deletions src/app/modules/main/browser_section/provider/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import NimQml
import io_interface
import view
import controller
import std/json
import ../../../../core/eventemitter

import ../io_interface as delegate_interface
Expand All @@ -11,13 +12,20 @@ import ../../../../../app_service/service/provider/service as provider_service
import ../../../../global/global_singleton
export io_interface

# Shouldn't be public ever, user only within this module.
type TmpSendTransactionDetails = object
payloadMethod: string
requestType: string
message: string

type
Module* = ref object of io_interface.AccessInterface
delegate: delegate_interface.AccessInterface
view: View
viewVariant: QVariant
moduleLoaded: bool
controller: Controller
tmpSendTransactionDetails: TmpSendTransactionDetails

proc newModule*(
delegate: delegate_interface.AccessInterface,
Expand Down Expand Up @@ -72,3 +80,24 @@ method ensResourceURL*(self: Module, ens: string, url: string): (string, string,
method updateNetwork*(self: Module, network: NetworkDto) =
self.view.chainId = network.chainId
self.view.chainName = network.chainName

method authenticateToPostMessage*(self: Module, payloadMethod: string, requestType: string, message: string) {.slot.} =
self.tmpSendTransactionDetails.payloadMethod = payloadMethod
self.tmpSendTransactionDetails.requestType = requestType
self.tmpSendTransactionDetails.message = message

if singletonInstance.userProfile.getIsKeycardUser():
let keyUid = singletonInstance.userProfile.getKeyUid()
self.controller.authenticateUser(keyUid)
else:
self.controller.authenticateUser()

method onUserAuthenticated*(self: Module, password: string) =
let jsonNode = parseJson(self.tmpSendTransactionDetails.message)

if jsonNode.kind == JObject and jsonNode.contains("payload"):
jsonNode["payload"]["password"] = %* password
self.tmpSendTransactionDetails.message = $jsonNode
self.postMessage(self.tmpSendTransactionDetails.payloadMethod,
self.tmpSendTransactionDetails.requestType,
self.tmpSendTransactionDetails.message)
4 changes: 4 additions & 0 deletions src/app/modules/main/browser_section/provider/view.nim
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,7 @@ QtObject:
newHost = base

result = url_replaceHostAndAddPath(url, newHost, http_scheme, "")

proc authenticateToPostMessage*(self: View, payloadMethod: string, requestType: string, message: string) {.slot.} =
self.delegate.authenticateToPostMessage(payloadMethod, requestType, message)

32 changes: 32 additions & 0 deletions src/app/modules/main/networks/model.nim
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,26 @@ QtObject:
of ModelRole.Balance:
result = newQVariant(item.getBalance())

proc rowData(self: Model, index: int, column: string): string {.slot.} =
if (index >= self.items.len):
return
let item = self.items[index]
case column:
of "chainId": result = $item.getChainId()
of "nativeCurrencyDecimals": result = $item.getNativeCurrencyDecimals()
of "layer": result = $item.getLayer()
of "chainName": result = $item.getChainName()
of "rpcURL": result = $item.getRpcURL()
of "blockExplorerURL": result = $item.getBlockExplorerURL()
of "nativeCurrencyName": result = $item.getNativeCurrencyName()
of "nativeCurrencySymbol": result = $item.getNativeCurrencySymbol()
of "isTest": result = $item.getIsTest()
of "isEnabled": result = $item.getIsEnabled()
of "iconUrl": result = $item.getIconURL()
of "chainColor": result = $item.getChainColor()
of "shortName": result = $item.getShortName()
of "balance": result = $item.getBalance()

proc setItems*(self: Model, items: seq[Item]) =
self.beginResetModel()
self.items = items
Expand Down Expand Up @@ -143,4 +163,16 @@ QtObject:
for item in self.items:
if(item.getShortName() == toLowerAscii(shortName)):
return item.getChainName()
return ""

proc getNetworkColor*(self: Model, shortName: string): string {.slot.} =
for item in self.items:
if(item.getShortName() == toLowerAscii(shortName)):
return item.getChainColor()
return ""

proc getNetworkChainId*(self: Model, shortName: string): int {.slot.} =
for item in self.items:
if(item.getShortName() == toLowerAscii(shortName)):
return item.getChainId()
return 0
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ 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/dto
import ../../../shared_modules/keycard_popup/io_interface as keycard_shared_module

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 Down Expand Up @@ -54,6 +57,12 @@ proc init*(self: Controller) =
let args = EnsTransactionArgs(e)
self.delegate.ensTransactionReverted(args.transactionType, args.ensUsername, args.transactionHash, args.revertReason)

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.onUserAuthenticated(args.password)

proc checkEnsUsernameAvailability*(self: Controller, desiredEnsUsername: string, statusDomain: bool) =
self.ensService.checkEnsUsernameAvailability(desiredEnsUsername, statusDomain)

Expand Down Expand Up @@ -129,4 +138,11 @@ proc getStatusToken*(self: Controller): string =
return $jsonObj

proc getNetwork*(self: Controller): NetworkDto =
return self.networkService.getNetworkForEns()
return self.networkService.getNetworkForEns()

proc authenticateUser*(self: Controller, keyUid = "", bip44Path = "", txHash = "") =
let data = SharedKeycarModuleAuthenticationArgs(uniqueIdentifier: UNIQUE_ENS_SECTION_TRANSACTION_MODULE_IDENTIFIER,
keyUid: keyUid,
bip44Path: bip44Path,
txHash: txHash)
self.events.emit(SIGNAL_SHARED_KEYCARD_MODULE_AUTHENTICATE_USER, data)
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ method fetchDetailsForEnsUsername*(self: AccessInterface, ensUsername: string) {
method setPubKeyGasEstimate*(self: AccessInterface, ensUsername: string, address: string): int {.base.} =
raise newException(ValueError, "No implementation available")

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

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

method release*(self: AccessInterface, ensUsername: string, address: string, gas: string, gasPrice: string,
maxPriorityFeePerGas: string, maxFeePerGas: string, password: string, eip1559Enabled: bool): string {.base.} =
method authenticateAndReleaseEns*(self: AccessInterface, 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.} =
Expand All @@ -65,8 +65,8 @@ method getEnsRegisteredAddress*(self: AccessInterface): string {.base.} =
method registerEnsGasEstimate*(self: AccessInterface, ensUsername: string, address: string): int {.base.} =
raise newException(ValueError, "No implementation available")

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

method getSNTBalance*(self: AccessInterface): string {.base.} =
Expand All @@ -93,3 +93,6 @@ method getChainIdForEns*(self: AccessInterface): int {.base.} =

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

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

0 comments on commit e661cd0

Please sign in to comment.