feat(wallet): Networks model improvements (#15305)

* refactor getters for chainIds and enabledChainIds
* simplify community chainIds getter
* simplify usage of network dto objects
* remove duplicated roles from send area
* rename network model in send module to network route model
This commit is contained in:
Cuteivist 2024-07-03 10:51:15 +02:00 committed by GitHub
parent 4bcda69d4a
commit c934ba74ef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
32 changed files with 393 additions and 463 deletions

View File

@ -1,4 +1,3 @@
import sugar, sequtils
import io_interface
import app_service/service/wallet_account/service as wallet_account_service
import app_service/service/network/service as network_service
@ -43,10 +42,10 @@ proc getIndex*(self: Controller, address: string): int =
return self.walletAccountService.getIndex(address)
proc getChainIds*(self: Controller): seq[int] =
return self.networkService.getCurrentNetworks().map(n => n.chainId)
return self.networkService.getCurrentNetworksChainIds()
proc getEnabledChainIds*(self: Controller): seq[int] =
return self.networkService.getCurrentNetworks().filter(n => n.isEnabled).map(n => n.chainId)
return self.networkService.getEnabledChainIds()
proc getCurrentCurrency*(self: Controller): string =
return self.walletAccountService.getCurrency()

View File

@ -478,8 +478,8 @@ proc runSigningOnKeycard*(self: Controller, keyUid: string, path: string, dataTo
proc removeCommunityChat*(self: Controller, communityId: string, channelId: string) =
self.communityService.deleteCommunityChat(communityId, channelId)
proc getCurrentNetworks*(self: Controller): seq[NetworkItem] =
return self.networksService.getCurrentNetworks()
proc getCurrentNetworksChainIds*(self: Controller): seq[int] =
return self.networksService.getCurrentNetworksChainIds()
proc promoteSelfToControlNode*(self: Controller, communityId: string) =
self.communityService.promoteSelfToControlNode(communityId)

View File

@ -607,7 +607,7 @@ proc buildTokensAndCollectiblesFromWallet(self: Module) =
var tokenListItems: seq[TokenListItem]
# Common ERC20 tokens
let allNetworks = self.controller.getCurrentNetworks().map(n => n.chainId)
let allNetworks = self.controller.getCurrentNetworksChainIds()
let erc20Tokens = self.controller.getTokenBySymbolList().filter(t => (block:
let filteredChains = t.addressPerChainId.filter(apC => allNetworks.contains(apc.chainId))
return filteredChains.len != 0

View File

@ -1,4 +1,3 @@
import sugar, sequtils
import io_interface
import ../../../../core/eventemitter
@ -222,4 +221,4 @@ proc fetchProfileShowcaseAccountsByAddress*(self: Controller, address: string) =
self.contactsService.fetchProfileShowcaseAccountsByAddress(address)
proc getEnabledChainIds*(self: Controller): seq[int] =
return self.networkService.getCurrentNetworks().filter(n => n.isEnabled).map(n => n.chainId)
return self.networkService.getEnabledChainIds()

View File

@ -1,4 +1,3 @@
import sugar, sequtils
import io_interface
import ../../../../../app_service/service/wallet_account/service as wallet_account_service
import ../../../../../app_service/service/network/service as network_service
@ -40,7 +39,7 @@ proc deleteAccount*(self: Controller, address: string) =
self.walletAccountService.deleteAccount(address)
proc getEnabledChainIds*(self: Controller): seq[int] =
return self.networkService.getCurrentNetworks().filter(n => n.isEnabled).map(n => n.chainId)
return self.networkService.getEnabledChainIds()
proc getCurrentCurrency*(self: Controller): string =
return self.walletAccountService.getCurrency()
@ -76,4 +75,4 @@ proc getTokensMarketValuesLoading*(self: Controller): bool =
return self.walletAccountService.getTokensMarketValuesLoading()
proc getChainIds*(self: Controller): seq[int] =
return self.networkService.getCurrentNetworks().map(n => n.chainId)
return self.networkService.getCurrentNetworksChainIds()

View File

@ -50,7 +50,7 @@ proc getWalletAddresses*(self: Controller): seq[string] =
return self.walletAccountService.getWalletAccounts().map(a => a.address)
proc getChainIds*(self: Controller): seq[int] =
return self.networkService.getCurrentNetworks().map(n => n.chainId)
return self.networkService.getCurrentNetworksChainIds()
proc updateCollectiblePreferences*(self: Controller, tokenPreferencesJson: string) =
self.collectibleService.updateCollectiblePreferences(tokenPreferencesJson)

View File

@ -1,4 +1,3 @@
import sugar, sequtils
import io_interface
import app_service/service/wallet_account/service as wallet_account_service
import app_service/service/network/service as network_service
@ -39,7 +38,7 @@ proc init*(self: Controller) =
discard
proc getChainIds*(self: Controller): seq[int] =
return self.networkService.getCurrentNetworks().map(n => n.chainId)
return self.networkService.getCurrentNetworksChainIds()
proc getCurrentCurrency*(self: Controller): string =
return self.walletAccountService.getCurrency()

View File

@ -1,4 +1,3 @@
import sequtils, sugar
import io_interface
import app_service/service/settings/service as settings_service
import app_service/service/wallet_account/service as wallet_account_service
@ -62,7 +61,7 @@ proc getWalletAccounts*(self: Controller): seq[wallet_account_service.WalletAcco
return self.walletAccountService.getWalletAccounts()
proc getEnabledChainIds*(self: Controller): seq[int] =
return self.networkService.getCurrentNetworks().filter(n => n.isEnabled).map(n => n.chainId)
return self.networkService.getEnabledChainIds()
proc getKeypairByAccountAddress*(self: Controller, address: string): KeypairDto =
return self.walletAccountService.getKeypairByAccountAddress(address)

View File

@ -93,7 +93,7 @@ QtObject:
proc getNetworkShortNames*(self: View, preferredNetworks: string): string {.slot.} =
return self.flatNetworks.getNetworkShortNames(preferredNetworks, self.areTestNetworksEnabled)
proc getNetworkIds*(self: View, shortNames: string): string {.slot.} =
return self.flatNetworks.getNetworkIds(shortNames, self.areTestNetworksEnabled)

View File

@ -1,4 +1,4 @@
import Tables, sugar, sequtils
import Tables
import uuids, chronicles, options
import io_interface
import app_service/service/wallet_account/service as wallet_account_service
@ -84,10 +84,7 @@ proc getWalletAccounts*(self: Controller): seq[wallet_account_service.WalletAcco
return self.walletAccountService.getWalletAccounts()
proc getChainIds*(self: Controller): seq[int] =
return self.networkService.getCurrentNetworks().map(n => n.chainId)
proc getEnabledChainIds*(self: Controller): seq[int] =
return self.networkService.getCurrentNetworks().filter(n => n.isEnabled).map(n => n.chainId)
return self.networkService.getCurrentNetworksChainIds()
proc getCurrentCurrency*(self: Controller): string =
return self.walletAccountService.getCurrency()

View File

@ -1,6 +1,7 @@
import Tables, options
import app/modules/shared_models/currency_amount
import app_service/service/transaction/dto
import app_service/service/network/network_item
import app/modules/shared_models/collectibles_model as collectibles
import app/modules/shared_models/collectibles_nested_model as nested_collectibles
from app_service/service/keycard/service import KeycardEvent
@ -92,3 +93,9 @@ method hasGas*(self: AccessInterface, accountAddress: string, chainId: int, nati
method transactionSendingComplete*(self: AccessInterface, txHash: string, success: bool) {.base.} =
raise newException(ValueError, "No implementation available")
method getNetworkItem*(self: AccessInterface, chainId: int): NetworkItem {.base.} =
raise newException(ValueError, "No implementation available")
method getNetworkChainId*(self: AccessInterface, shortName: string): int {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -1,6 +1,6 @@
import tables, NimQml, sequtils, sugar, stint, strutils, chronicles, options
import ./io_interface, ./view, ./controller, ./network_item, ./transaction_routes, ./suggested_route_item, ./suggested_route_model, ./gas_estimate_item, ./gas_fees_item, ./network_model
import ./io_interface, ./view, ./controller, ./network_route_item, ./transaction_routes, ./suggested_route_item, ./suggested_route_model, ./gas_estimate_item, ./gas_fees_item, ./network_route_model
import ../io_interface as delegate_interface
import app/global/global_singleton
import app/core/eventemitter
@ -91,17 +91,10 @@ method delete*(self: Module) =
self.nestedCollectiblesModel.delete
self.collectiblesController.delete
proc convertSendToNetworkToNetworkItem(self: Module, network: SendToNetwork): network_item.NetworkItem =
result = initNetworkItem(
proc convertSendToNetworkToNetworkItem(self: Module, network: SendToNetwork): NetworkRouteItem =
result = initNetworkRouteItem(
network.chainId,
network.chainName,
network.iconUrl,
chainColor = "",
shortName = "",
layer = 0,
nativeCurrencyDecimals = 0,
nativeCurrencyName = "",
nativeCurrencySymbol = "",
true,
true,
true,
@ -111,17 +104,10 @@ proc convertSendToNetworkToNetworkItem(self: Module, network: SendToNetwork): ne
amountIn = "",
$network.amountOut)
proc convertNetworkDtoToNetworkItem(self: Module, network: network_service_item.NetworkItem): network_item.NetworkItem =
result = initNetworkItem(
network.chainId,
network.chainName,
network.iconUrl,
network.chainColor,
network.shortName,
proc convertNetworkDtoToNetworkRouteItem(self: Module, network: network_service_item.NetworkItem): NetworkRouteItem =
result = initNetworkRouteItem(
network.chainId,
network.layer,
network.nativeCurrencyDecimals,
network.nativeCurrencyName,
network.nativeCurrencySymbol,
true,
false,
true,
@ -171,8 +157,8 @@ proc convertTransactionPathDtoToSuggestedRouteItem(self: Module, path: Transacti
proc refreshNetworks*(self: Module) =
let networks = self.controller.getCurrentNetworks()
let fromNetworks = networks.map(x => self.convertNetworkDtoToNetworkItem(x))
let toNetworks = networks.map(x => self.convertNetworkDtoToNetworkItem(x))
let fromNetworks = networks.map(x => self.convertNetworkDtoToNetworkRouteItem(x))
let toNetworks = networks.map(x => self.convertNetworkDtoToNetworkRouteItem(x))
self.view.setNetworkItems(fromNetworks, toNetworks)
method load*(self: Module) =
@ -196,6 +182,12 @@ method viewDidLoad*(self: Module) =
method getTokenBalance*(self: Module, address: string, chainId: int, tokensKey: string): CurrencyAmount =
return self.controller.getTokenBalance(address, chainId, tokensKey)
method getNetworkItem*(self: Module, chainId: int): network_service_item.NetworkItem =
let networks = self.controller.getCurrentNetworks().filter(x => x.chainId == chainId)
if networks.len == 0:
return nil
return networks[0]
method authenticateAndTransfer*(self: Module, fromAddr: string, toAddr: string, assetKey: string, toAssetKey: string, uuid: string,
sendType: SendType, selectedTokenName: string, selectedTokenIsOwnerToken: bool) =
self.tmpSendTransactionDetails.fromAddr = fromAddr
@ -289,15 +281,15 @@ method suggestedRoutesReady*(self: Module, uuid: string, suggestedRoutes: Sugges
suggestedRouteModel.setItems(paths)
let gasTimeEstimate = self.convertFeesDtoToGasEstimateItem(suggestedRoutes.gasTimeEstimate)
let networks = suggestedRoutes.toNetworks.map(x => self.convertSendToNetworkToNetworkItem(x))
let toNetworksModel = newNetworkModel()
toNetworksModel.setItems(networks)
let toNetworksRouteModel = newNetworkRouteModel()
toNetworksRouteModel.setItems(networks)
self.view.updatedNetworksWithRoutes(paths, gasTimeEstimate.getTotalFeesInEth())
let transactionRoutes = newTransactionRoutes(
uuid = uuid,
suggestedRoutes = suggestedRouteModel,
gasTimeEstimate = gasTimeEstimate,
amountToReceive = suggestedRoutes.amountToReceive,
toNetworksModel = toNetworksModel,
toNetworksRouteModel = toNetworksRouteModel,
rawPaths = suggestedRoutes.rawBest)
self.view.setTransactionRoute(transactionRoutes)
@ -351,6 +343,27 @@ method getCollectiblesModel*(self: Module): collectibles.Model =
method getNestedCollectiblesModel*(self: Module): nested_collectibles.Model =
return self.nestedCollectiblesModel
proc getNetworkColor(self: Module, shortName: string): string =
let networks = self.controller.getCurrentNetworks()
for network in networks:
if cmpIgnoreCase(network.chainName, shortName) == 0:
return network.chainColor
return ""
proc getLayer1NetworkChainId*(self: Module): int =
let networks = self.controller.getCurrentNetworks()
for network in networks:
if network.layer == NETWORK_LAYER_1:
return network.chainId
return 0
method getNetworkChainId*(self: Module, shortName: string): int =
let networks = self.controller.getCurrentNetworks()
for network in networks:
if cmpIgnoreCase(network.chainName, shortName) == 0:
return network.chainId
return 0
method splitAndFormatAddressPrefix*(self: Module, text : string, updateInStore: bool): string {.slot.} =
var tempPreferredChains: seq[int]
var chainFound = false
@ -360,15 +373,15 @@ method splitAndFormatAddressPrefix*(self: Module, text : string, updateInStore:
if word.startsWith("0x"):
editedText = editedText & word
else:
let chainColor = self.view.getNetworkColor(word)
let chainColor = self.getNetworkColor(word)
if not chainColor.isEmptyOrWhitespace():
chainFound = true
tempPreferredChains.add(self.view.getNetworkChainId(word))
tempPreferredChains.add(self.getNetworkChainId(word))
editedText = editedText & "<span style='color: " & chainColor & "'>" & word & "</span>" & ":"
if updateInStore:
if not chainFound:
self.view.updateRoutePreferredChains(self.view.getLayer1NetworkChainId())
self.view.updateRoutePreferredChains($self.getLayer1NetworkChainId())
else:
self.view.updateRoutePreferredChains(tempPreferredChains.join(":"))

View File

@ -1,161 +0,0 @@
import stew/shims/strformat, strutils
import app/modules/shared_models/currency_amount
type
NetworkItem* = ref object
chainId: int
chainName: string
iconUrl: string
chainColor: string
shortName: string
layer: int
nativeCurrencyDecimals: int
nativeCurrencyName: string
nativeCurrencySymbol: string
isEnabled: bool
isPreferred: bool
hasGas: bool
tokenBalance: CurrencyAmount
locked: bool
lockedAmount: string
amountIn: string
amountOut: string
toNetworks: seq[int]
proc initNetworkItem*(
chainId: int,
chainName: string,
iconUrl: string,
chainColor: string,
shortName: string,
layer: int,
nativeCurrencyDecimals: int,
nativeCurrencyName: string,
nativeCurrencySymbol: string,
isEnabled: bool,
isPreferred: bool,
hasGas: bool,
tokenBalance: CurrencyAmount,
locked: bool = false,
lockedAmount: string = "",
amountIn: string = "",
amountOut: string = "",
toNetworks: seq[int] = @[]
): NetworkItem =
result = NetworkItem()
result.chainId = chainId
result.chainName = chainName
result.iconUrl = iconUrl
result.chainColor = chainColor
result.shortName = shortName
result.layer = layer
result.nativeCurrencyDecimals = nativeCurrencyDecimals
result.nativeCurrencyName = nativeCurrencyName
result.nativeCurrencySymbol = nativeCurrencySymbol
result.isEnabled = isEnabled
result.isPreferred = isPreferred
result.hasGas = hasGas
result.tokenBalance = tokenBalance
result.locked = locked
result.lockedAmount = lockedAmount
result.amountIn = amountIn
result.amountOut = amountOut
result.toNetworks = toNetworks
proc `$`*(self: NetworkItem): string =
result = fmt"""NetworkItem(
chainId: {self.chainId},
chainName: {self.chainName},
iconUrl:{self.iconUrl},
chainColor: {self.chainColor},
shortName: {self.shortName},
layer: {self.layer},
nativeCurrencyDecimals: {self.nativeCurrencyDecimals},
nativeCurrencyName:{self.nativeCurrencyName},
nativeCurrencySymbol:{self.nativeCurrencySymbol},
isEnabled:{self.isEnabled},
isPreferred:{self.isPreferred},
hasGas:{self.hasGas},
tokenBalance:{self.tokenBalance},
locked:{self.locked},
lockedAmount:{self.lockedAmount},
amountIn:{self.amountIn},
amountOut:{self.amountOut},
toNetworks:{self.toNetworks},
]"""
proc getChainId*(self: NetworkItem): int =
return self.chainId
proc getChainName*(self: NetworkItem): string =
return self.chainName
proc getIconURL*(self: NetworkItem): string =
return self.iconUrl
proc getShortName*(self: NetworkItem): string =
return self.shortName
proc getChainColor*(self: NetworkItem): string =
return self.chainColor
proc getLayer*(self: NetworkItem): int =
return self.layer
proc getNativeCurrencyDecimals*(self: NetworkItem): int =
return self.nativeCurrencyDecimals
proc getNativeCurrencyName*(self: NetworkItem): string =
return self.nativeCurrencyName
proc getNativeCurrencySymbol*(self: NetworkItem): string =
return self.nativeCurrencySymbol
proc getIsEnabled*(self: NetworkItem): bool =
return self.isEnabled
proc `isEnabled=`*(self: NetworkItem, value: bool) {.inline.} =
self.isEnabled = value
proc getIsPreferred*(self: NetworkItem): bool =
return self.isPreferred
proc `isPreferred=`*(self: NetworkItem, value: bool) {.inline.} =
self.isPreferred = value
proc getHasGas*(self: NetworkItem): bool =
return self.hasGas
proc `hasGas=`*(self: NetworkItem, value: bool) {.inline.} =
self.hasGas = value
proc getTokenBalance*(self: NetworkItem): CurrencyAmount =
return self.tokenBalance
proc `tokenBalance=`*(self: NetworkItem, value: CurrencyAmount) {.inline.} =
self.tokenBalance = value
proc getLocked*(self: NetworkItem): bool =
return self.locked
proc `locked=`*(self: NetworkItem, value: bool) {.inline.} =
self.locked = value
proc getLockedAmount*(self: NetworkItem): string =
return self.lockedAmount
proc `lockedAmount=`*(self: NetworkItem, value: string) {.inline.} =
self.lockedAmount = value
proc getAmountIn*(self: NetworkItem): string =
return self.amountIn
proc `amountIn=`*(self: NetworkItem, value: string) {.inline.} =
self.amountIn = value
proc getAmountOut*(self: NetworkItem): string =
return self.amountOut
proc `amountOut=`*(self: NetworkItem, value: string) {.inline.} =
self.amountOut = value
proc getToNetworks*(self: NetworkItem): string =
return self.toNetworks.join(":")
proc `toNetworks=`*(self: NetworkItem, value: int) {.inline.} =
self.toNetworks.add(value)
proc resetToNetworks*(self: NetworkItem) =
self.toNetworks = @[]

View File

@ -0,0 +1,112 @@
import stew/shims/strformat, strutils
import app/modules/shared_models/currency_amount
type
NetworkRouteItem* = ref object
chainId: int
layer: int
isRouteEnabled: bool
isRoutePreferred: bool
hasGas: bool
tokenBalance: CurrencyAmount
locked: bool
lockedAmount: string
amountIn: string
amountOut: string
toNetworks: seq[int]
proc initNetworkRouteItem*(
chainId: int,
layer: int,
isRouteEnabled: bool,
isRoutePreferred: bool,
hasGas: bool,
tokenBalance: CurrencyAmount,
locked: bool = false,
lockedAmount: string = "",
amountIn: string = "",
amountOut: string = "",
toNetworks: seq[int] = @[]
): NetworkRouteItem =
result = NetworkRouteItem()
result.chainId = chainId
result.layer = layer
result.isRouteEnabled = isRouteEnabled
result.isRoutePreferred = isRoutePreferred
result.hasGas = hasGas
result.tokenBalance = tokenBalance
result.locked = locked
result.lockedAmount = lockedAmount
result.amountIn = amountIn
result.amountOut = amountOut
result.toNetworks = toNetworks
proc `$`*(self: NetworkRouteItem): string =
result = fmt"""NetworkRouteItem(
chainId: {self.chainId},
layer: {self.layer},
isRouteEnabled:{self.isRouteEnabled},
isRoutePreferred:{self.isRoutePreferred},
hasGas:{self.hasGas},
tokenBalance:{self.tokenBalance},
locked:{self.locked},
lockedAmount:{self.lockedAmount},
amountIn:{self.amountIn},
amountOut:{self.amountOut},
toNetworks:{self.toNetworks},
]"""
proc getChainId*(self: NetworkRouteItem): int =
return self.chainId
proc getLayer*(self: NetworkRouteItem): int =
return self.layer
proc getIsRouteEnabled*(self: NetworkRouteItem): bool =
return self.isRouteEnabled
proc `isRouteEnabled=`*(self: NetworkRouteItem, value: bool) {.inline.} =
self.isRouteEnabled = value
proc getIsRoutePreferred*(self: NetworkRouteItem): bool =
return self.isRoutePreferred
proc `isRoutePreferred=`*(self: NetworkRouteItem, value: bool) {.inline.} =
self.isRoutePreferred = value
proc getHasGas*(self: NetworkRouteItem): bool =
return self.hasGas
proc `hasGas=`*(self: NetworkRouteItem, value: bool) {.inline.} =
self.hasGas = value
proc getTokenBalance*(self: NetworkRouteItem): CurrencyAmount =
return self.tokenBalance
proc `tokenBalance=`*(self: NetworkRouteItem, value: CurrencyAmount) {.inline.} =
self.tokenBalance = value
proc getLocked*(self: NetworkRouteItem): bool =
return self.locked
proc `locked=`*(self: NetworkRouteItem, value: bool) {.inline.} =
self.locked = value
proc getLockedAmount*(self: NetworkRouteItem): string =
return self.lockedAmount
proc `lockedAmount=`*(self: NetworkRouteItem, value: string) {.inline.} =
self.lockedAmount = value
proc getAmountIn*(self: NetworkRouteItem): string =
return self.amountIn
proc `amountIn=`*(self: NetworkRouteItem, value: string) {.inline.} =
self.amountIn = value
proc getAmountOut*(self: NetworkRouteItem): string =
return self.amountOut
proc `amountOut=`*(self: NetworkRouteItem, value: string) {.inline.} =
self.amountOut = value
proc getToNetworks*(self: NetworkRouteItem): string =
return self.toNetworks.join(":")
proc `toNetworks=`*(self: NetworkRouteItem, value: int) {.inline.} =
self.toNetworks.add(value)
proc resetToNetworks*(self: NetworkRouteItem) =
self.toNetworks = @[]

View File

@ -2,21 +2,13 @@ import NimQml, Tables, strutils, stew/shims/strformat, sequtils, sugar, json, st
import app_service/service/network/types
import app/modules/shared_models/currency_amount
import ./network_item, ./suggested_route_item
import ./network_route_item, ./suggested_route_item
type
ModelRole* {.pure.} = enum
ChainId = UserRole + 1,
ChainName
IconUrl
ChainColor
ShortName
Layer
NativeCurrencyDecimals
NativeCurrencyName
NativeCurrencySymbol
IsEnabled
IsPreferred
IsRouteEnabled
IsRoutePreferred
HasGas
TokenBalance
Locked
@ -26,49 +18,41 @@ type
ToNetworks
QtObject:
type NetworkModel* = ref object of QAbstractListModel
items*: seq[NetworkItem]
type NetworkRouteModel* = ref object of QAbstractListModel
items*: seq[NetworkRouteItem]
proc delete(self: NetworkModel) =
proc delete(self: NetworkRouteModel) =
self.items = @[]
self.QAbstractListModel.delete
proc setup(self: NetworkModel) =
proc setup(self: NetworkRouteModel) =
self.QAbstractListModel.setup
proc newNetworkModel*(): NetworkModel =
proc newNetworkRouteModel*(): NetworkRouteModel =
new(result, delete)
result.setup
proc `$`*(self: NetworkModel): string =
proc `$`*(self: NetworkRouteModel): string =
for i in 0 ..< self.items.len:
result &= fmt"""[{i}]:({$self.items[i]})"""
proc countChanged(self: NetworkModel) {.signal.}
proc countChanged(self: NetworkRouteModel) {.signal.}
proc getCount(self: NetworkModel): int {.slot.} =
proc getCount(self: NetworkRouteModel): int {.slot.} =
self.items.len
QtProperty[int] count:
read = getCount
notify = countChanged
method rowCount*(self: NetworkModel, index: QModelIndex = nil): int =
method rowCount*(self: NetworkRouteModel, index: QModelIndex = nil): int =
return self.items.len
method roleNames(self: NetworkModel): Table[int, string] =
method roleNames(self: NetworkRouteModel): Table[int, string] =
{
ModelRole.ChainId.int:"chainId",
ModelRole.ChainName.int:"chainName",
ModelRole.IconUrl.int:"iconUrl",
ModelRole.ShortName.int: "shortName",
ModelRole.Layer.int: "layer",
ModelRole.ChainColor.int: "chainColor",
ModelRole.NativeCurrencyDecimals.int:"nativeCurrencyDecimals",
ModelRole.NativeCurrencyName.int:"nativeCurrencyName",
ModelRole.NativeCurrencySymbol.int:"nativeCurrencySymbol",
ModelRole.IsEnabled.int:"isEnabled",
ModelRole.IsPreferred.int:"isPreferred",
ModelRole.IsRouteEnabled.int:"isRouteEnabled",
ModelRole.IsRoutePreferred.int:"isRoutePreferred",
ModelRole.HasGas.int:"hasGas",
ModelRole.TokenBalance.int:"tokenBalance",
ModelRole.Locked.int:"locked",
@ -78,7 +62,7 @@ QtObject:
ModelRole.ToNetworks.int:"toNetworks"
}.toTable
method data(self: NetworkModel, index: QModelIndex, role: int): QVariant =
method data(self: NetworkRouteModel, index: QModelIndex, role: int): QVariant =
if (not index.isValid):
return
@ -91,26 +75,10 @@ QtObject:
case enumRole:
of ModelRole.ChainId:
result = newQVariant(item.getChainId())
of ModelRole.ChainName:
result = newQVariant(item.getChainName())
of ModelRole.IconUrl:
result = newQVariant(item.getIconURL())
of ModelRole.ShortName:
result = newQVariant(item.getShortName())
of ModelRole.Layer:
result = newQVariant(item.getLayer())
of ModelRole.ChainColor:
result = newQVariant(item.getChainColor())
of ModelRole.NativeCurrencyDecimals:
result = newQVariant(item.getNativeCurrencyDecimals())
of ModelRole.NativeCurrencyName:
result = newQVariant(item.getNativeCurrencyName())
of ModelRole.NativeCurrencySymbol:
result = newQVariant(item.getNativeCurrencySymbol())
of ModelRole.IsEnabled:
result = newQVariant(item.getIsEnabled())
of ModelRole.IsPreferred:
result = newQVariant(item.getIsPreferred())
of ModelRole.IsRouteEnabled:
result = newQVariant(item.getIsRouteEnabled())
of ModelRole.IsRoutePreferred:
result = newQVariant(item.getIsRoutePreferred())
of ModelRole.HasGas:
result = newQVariant(item.getHasGas())
of ModelRole.TokenBalance:
@ -126,22 +94,16 @@ QtObject:
of ModelRole.ToNetworks:
result = newQVariant(item.getToNetworks())
proc setItems*(self: NetworkModel, items: seq[NetworkItem]) =
proc setItems*(self: NetworkRouteModel, items: seq[NetworkRouteItem]) =
self.beginResetModel()
self.items = items
self.endResetModel()
self.countChanged()
proc getAllNetworksChainIds*(self: NetworkModel): seq[int] =
proc getAllNetworksChainIds*(self: NetworkRouteModel): seq[int] =
return self.items.map(x => x.getChainId())
proc getNetworkNativeGasSymbol*(self: NetworkModel, chainId: int): string =
for item in self.items:
if item.getChainId() == chainId:
return item.getNativeCurrencySymbol()
return ""
proc reset*(self: NetworkModel) =
proc reset*(self: NetworkRouteModel) =
for i in 0 ..< self.items.len:
let index = self.createIndex(i, 0, nil)
defer: index.delete
@ -149,15 +111,15 @@ QtObject:
self.items[i].amountOut = ""
self.items[i].resetToNetworks()
self.items[i].hasGas = true
self.items[i].isEnabled = true
self.items[i].isPreferred = true
self.items[i].isRouteEnabled = true
self.items[i].isRoutePreferred = true
self.items[i].locked = false
self.items[i].lockedAmount = ""
self.dataChanged(index, index, @[ModelRole.AmountIn.int, ModelRole.ToNetworks.int, ModelRole.HasGas.int,
ModelRole.AmountOut.int, ModelRole.IsEnabled.int, ModelRole.IsPreferred.int, ModelRole.Locked.int,
ModelRole.AmountOut.int, ModelRole.IsRouteEnabled.int, ModelRole.IsRoutePreferred.int, ModelRole.Locked.int,
ModelRole.LockedAmount.int])
proc updateTokenBalanceForSymbol*(self: NetworkModel, chainId: int, tokenBalance: CurrencyAmount) =
proc updateTokenBalanceForSymbol*(self: NetworkRouteModel, chainId: int, tokenBalance: CurrencyAmount) =
for i in 0 ..< self.items.len:
if(self.items[i].getChainId() == chainId):
let index = self.createIndex(i, 0, nil)
@ -165,7 +127,7 @@ QtObject:
self.items[i].tokenBalance = tokenBalance
self.dataChanged(index, index, @[ModelRole.TokenBalance.int])
proc updateFromNetworks*(self: NetworkModel, path: SuggestedRouteItem, hasGas: bool) =
proc updateFromNetworks*(self: NetworkRouteModel, path: SuggestedRouteItem, hasGas: bool) =
for i in 0 ..< self.items.len:
if path.getfromNetwork() == self.items[i].getChainId():
let index = self.createIndex(i, 0, nil)
@ -176,7 +138,7 @@ QtObject:
self.items[i].locked = path.getAmountInLocked()
self.dataChanged(index, index, @[ModelRole.AmountIn.int, ModelRole.ToNetworks.int, ModelRole.HasGas.int, ModelRole.Locked.int])
proc updateToNetworks*(self: NetworkModel, path: SuggestedRouteItem) =
proc updateToNetworks*(self: NetworkRouteModel, path: SuggestedRouteItem) =
for i in 0 ..< self.items.len:
if path.getToNetwork() == self.items[i].getChainId():
let index = self.createIndex(i, 0, nil)
@ -187,7 +149,7 @@ QtObject:
self.items[i].amountOut = path.getAmountOut()
self.dataChanged(index, index, @[ModelRole.AmountOut.int])
proc resetPathData*(self: NetworkModel) =
proc resetPathData*(self: NetworkRouteModel) =
for i in 0 ..< self.items.len:
let index = self.createIndex(i, 0, nil)
defer: index.delete
@ -198,113 +160,88 @@ QtObject:
self.items[i].amountOut = ""
self.dataChanged(index, index, @[ModelRole.AmountIn.int, ModelRole.ToNetworks.int, ModelRole.HasGas.int, ModelRole.Locked.int, ModelRole.AmountOut.int])
proc getRouteDisabledNetworkChainIds*(self: NetworkModel): seq[int] =
proc getRouteDisabledNetworkChainIds*(self: NetworkRouteModel): seq[int] =
var disbaledChains: seq[int] = @[]
for item in self.items:
if not item.getIsEnabled():
if not item.getIsRouteEnabled():
disbaledChains.add(item.getChainId())
return disbaledChains
proc getRouteLockedChainIds*(self: NetworkModel): Table[string, string] =
proc getRouteLockedChainIds*(self: NetworkRouteModel): Table[string, string] =
var lockedChains: Table[string, string]
for item in self.items:
if item.getLocked():
lockedChains[$item.getChainId()] = "0x" & item.getLockedAmount()
return lockedChains
proc updateRoutePreferredChains*(self: NetworkModel, chainIds: string) =
proc updateRoutePreferredChains*(self: NetworkRouteModel, chainIds: string) =
try:
for i in 0 ..< self.items.len:
let index = self.createIndex(i, 0, nil)
defer: index.delete
self.items[i].isPreferred = false
self.items[i].isEnabled = false
self.items[i].isRoutePreferred = false
self.items[i].isRouteEnabled = false
if chainIds.len == 0:
if self.items[i].getLayer() == 1:
self.items[i].isPreferred = true
self.items[i].isEnabled = true
if self.items[i].getLayer() == NETWORK_LAYER_1:
self.items[i].isRoutePreferred = true
self.items[i].isRouteEnabled = true
else:
for chainID in chainIds.split(':'):
if $self.items[i].getChainId() == chainID:
self.items[i].isPreferred = true
self.items[i].isEnabled = true
self.dataChanged(index, index, @[ModelRole.IsPreferred.int, ModelRole.IsEnabled.int])
self.items[i].isRoutePreferred = true
self.items[i].isRouteEnabled = true
self.dataChanged(index, index, @[ModelRole.IsRoutePreferred.int, ModelRole.IsRouteEnabled.int])
except:
discard
proc disableRouteUnpreferredChains*(self: NetworkModel) =
proc disableRouteUnpreferredChains*(self: NetworkRouteModel) =
for i in 0 ..< self.items.len:
if not self.items[i].getIsPreferred():
if not self.items[i].getIsRoutePreferred():
let index = self.createIndex(i, 0, nil)
defer: index.delete
self.items[i].isEnabled = false
self.dataChanged(index, index, @[ModelRole.IsEnabled.int])
self.items[i].isRouteEnabled = false
self.dataChanged(index, index, @[ModelRole.IsRouteEnabled.int])
proc enableRouteUnpreferredChains*(self: NetworkModel) =
proc enableRouteUnpreferredChains*(self: NetworkRouteModel) =
for i in 0 ..< self.items.len:
if not self.items[i].getIsPreferred():
if not self.items[i].getIsRoutePreferred():
let index = self.createIndex(i, 0, nil)
defer: index.delete
self.items[i].isEnabled = true
self.dataChanged(index, index, @[ModelRole.IsEnabled.int])
self.items[i].isRouteEnabled = true
self.dataChanged(index, index, @[ModelRole.IsRouteEnabled.int])
proc setAllNetworksAsRoutePreferredChains*(self: NetworkModel) {.slot.} =
proc setAllNetworksAsRoutePreferredChains*(self: NetworkRouteModel) {.slot.} =
for i in 0 ..< self.items.len:
let index = self.createIndex(i, 0, nil)
defer: index.delete
self.items[i].isPreferred = true
self.dataChanged(index, index, @[ModelRole.IsPreferred.int])
self.items[i].isRoutePreferred = true
self.dataChanged(index, index, @[ModelRole.IsRoutePreferred.int])
proc getNetworkColor*(self: NetworkModel, shortName: string): string =
for item in self.items:
if cmpIgnoreCase(item.getShortName(), shortName) == 0:
return item.getChainColor()
return ""
proc getNetworkChainId*(self: NetworkModel, shortName: string): int {.slot.} =
for item in self.items:
if cmpIgnoreCase(item.getShortName(), shortName) == 0:
return item.getChainId()
return 0
proc getNetworkName*(self: NetworkModel, chainId: int): string {.slot.} =
for item in self.items:
if item.getChainId() == chainId:
return item.getChainName()
return ""
proc getIconUrl*(self: NetworkModel, chainId: int): string =
for item in self.items:
if item.getChainId() == chainId:
return item.getIconURL()
return ""
proc toggleRouteDisabledChains*(self: NetworkModel, chainId: int) {.slot.} =
proc toggleRouteDisabledChains*(self: NetworkRouteModel, chainId: int) {.slot.} =
for i in 0 ..< self.items.len:
if(self.items[i].getChainId() == chainId):
let index = self.createIndex(i, 0, nil)
defer: index.delete
self.items[i].isEnabled = not self.items[i].getIsEnabled()
self.dataChanged(index, index, @[ModelRole.IsEnabled.int])
self.items[i].isRouteEnabled = not self.items[i].getIsRouteEnabled()
self.dataChanged(index, index, @[ModelRole.IsRouteEnabled.int])
proc setRouteDisabledChains*(self: NetworkModel, chainId: int, disabled: bool) {.slot.} =
proc setRouteDisabledChains*(self: NetworkRouteModel, chainId: int, disabled: bool) {.slot.} =
for i in 0 ..< self.items.len:
if(self.items[i].getChainId() == chainId):
let index = self.createIndex(i, 0, nil)
defer: index.delete
self.items[i].isEnabled = not disabled
self.dataChanged(index, index, @[ModelRole.IsEnabled.int])
self.items[i].isRouteEnabled = not disabled
self.dataChanged(index, index, @[ModelRole.IsRouteEnabled.int])
proc setRouteEnabledFromChains*(self: NetworkModel, chainId: int) {.slot.} =
proc setRouteEnabledFromChains*(self: NetworkRouteModel, chainId: int) {.slot.} =
for i in 0 ..< self.items.len:
let index = self.createIndex(i, 0, nil)
self.items[i].isEnabled = false
self.items[i].isRouteEnabled = false
if(self.items[i].getChainId() == chainId):
self.items[i].isEnabled = true
self.dataChanged(index, index, @[ModelRole.IsEnabled.int])
self.items[i].isRouteEnabled = true
self.dataChanged(index, index, @[ModelRole.IsRouteEnabled.int])
proc lockCard*(self: NetworkModel, chainId: int, amount: string, lock: bool) {.slot.} =
proc lockCard*(self: NetworkRouteModel, chainId: int, amount: string, lock: bool) {.slot.} =
for i in 0 ..< self.items.len:
if(self.items[i].getChainId() == chainId):
let index = self.createIndex(i, 0, nil)
@ -314,9 +251,3 @@ QtObject:
if self.items[i].getLocked():
self.items[i].lockedAmount = amount
self.dataChanged(index, index, @[ModelRole.LockedAmount.int])
proc getLayer1Network*(self: NetworkModel): int =
for item in self.items:
if item.getLayer() == NETWORK_LAYER_1:
return item.getChainId()
return 0

View File

@ -1,6 +1,6 @@
import NimQml, stew/shims/strformat, stint
import ./gas_estimate_item, ./suggested_route_model, ./network_model
import ./gas_estimate_item, ./suggested_route_model, ./network_route_model, ./io_interface
QtObject:
type TransactionRoutes* = ref object of QObject
@ -8,7 +8,7 @@ QtObject:
suggestedRoutes: SuggestedRouteModel
gasTimeEstimate: GasEstimateItem
amountToReceive: UInt256
toNetworksModel: NetworkModel
toNetworksRouteModel: NetworkRouteModel
rawPaths: string
proc setup*(self: TransactionRoutes,
@ -16,7 +16,7 @@ QtObject:
suggestedRoutes: SuggestedRouteModel,
gasTimeEstimate: GasEstimateItem,
amountToReceive: UInt256,
toNetworksModel: NetworkModel,
toNetworksRouteModel: NetworkRouteModel,
rawPaths: string
) =
self.QObject.setup
@ -24,7 +24,7 @@ QtObject:
self.suggestedRoutes = suggestedRoutes
self.gasTimeEstimate = gasTimeEstimate
self.amountToReceive = amountToReceive
self.toNetworksModel = toNetworksModel
self.toNetworksRouteModel = toNetworksRouteModel
self.rawPaths = rawPaths
proc delete*(self: TransactionRoutes) =
@ -35,11 +35,11 @@ QtObject:
suggestedRoutes: SuggestedRouteModel = newSuggestedRouteModel(),
gasTimeEstimate: GasEstimateItem = newGasEstimateItem(),
amountToReceive: UInt256 = stint.u256(0),
toNetworksModel: NetworkModel = newNetworkModel(),
toNetworksRouteModel: NetworkRouteModel = newNetworkRouteModel(),
rawPaths: string = ""
): TransactionRoutes =
new(result, delete)
result.setup(uuid, suggestedRoutes, gasTimeEstimate, amountToReceive, toNetworksModel, rawPaths)
result.setup(uuid, suggestedRoutes, gasTimeEstimate, amountToReceive, toNetworksRouteModel, rawPaths)
proc `$`*(self: TransactionRoutes): string =
result = fmt"""TransactionRoutes(
@ -47,7 +47,7 @@ QtObject:
suggestedRoutes: {self.suggestedRoutes},
gasTimeEstimate: {self.gasTimeEstimate},
amountToReceive: {self.amountToReceive},
toNetworksModel: {self.toNetworksModel},
toNetworksRouteModel: {self.toNetworksRouteModel},
rawPaths: {self.rawPaths},
]"""
@ -81,8 +81,8 @@ QtObject:
proc toNetworksChanged*(self: TransactionRoutes) {.signal.}
proc getToNetworks*(self: TransactionRoutes): QVariant {.slot.} =
return newQVariant(self.toNetworksModel)
QtProperty[QVariant] toNetworksModel:
return newQVariant(self.toNetworksRouteModel)
QtProperty[QVariant] toNetworksRouteModel:
read = getToNetworks
notify = toNetworksChanged

View File

@ -1,9 +1,10 @@
import NimQml, Tables, json, sequtils, strutils, stint, options, chronicles
import uuids
import ./io_interface, ./network_model, ./network_item, ./suggested_route_item, ./transaction_routes
import ./io_interface, ./network_route_model, ./network_route_item, ./suggested_route_item, ./transaction_routes
import app/modules/shared_models/collectibles_model as collectibles
import app/modules/shared_models/collectibles_nested_model as nested_collectibles
import app_service/service/network/service as network_service
import app_service/service/transaction/dto as transaction_dto
QtObject:
@ -14,8 +15,8 @@ QtObject:
collectiblesModel: collectibles.Model
nestedCollectiblesModel: nested_collectibles.Model
# for send modal
fromNetworksModel: NetworkModel
toNetworksModel: NetworkModel
fromNetworksRouteModel: NetworkRouteModel
toNetworksRouteModel: NetworkRouteModel
transactionRoutes: TransactionRoutes
selectedAssetKey: string
selectedToAssetKey: string
@ -33,8 +34,8 @@ QtObject:
proc updateNetworksTokenBalance(self: View)
proc delete*(self: View) =
self.fromNetworksModel.delete
self.toNetworksModel.delete
self.fromNetworksRouteModel.delete
self.toNetworksRouteModel.delete
self.transactionRoutes.delete
self.QObject.delete
@ -42,8 +43,8 @@ QtObject:
new(result, delete)
result.QObject.setup
result.delegate = delegate
result.fromNetworksModel = newNetworkModel()
result.toNetworksModel = newNetworkModel()
result.fromNetworksRouteModel = newNetworkRouteModel()
result.toNetworksRouteModel = newNetworkRouteModel()
result.transactionRoutes = newTransactionRoutes()
result.collectiblesModel = delegate.getCollectiblesModel()
result.nestedCollectiblesModel = delegate.getNestedCollectiblesModel()
@ -86,19 +87,19 @@ QtObject:
read = getSelectedReceiveAccountAddress
notify = selectedReceiveAccountAddressChanged
proc fromNetworksModelChanged*(self: View) {.signal.}
proc getFromNetworksModel(self: View): QVariant {.slot.} =
return newQVariant(self.fromNetworksModel)
QtProperty[QVariant] fromNetworksModel:
read = getFromNetworksModel
notify = fromNetworksModelChanged
proc fromNetworksRouteModelChanged*(self: View) {.signal.}
proc getfromNetworksRouteModel(self: View): QVariant {.slot.} =
return newQVariant(self.fromNetworksRouteModel)
QtProperty[QVariant] fromNetworksRouteModel:
read = getfromNetworksRouteModel
notify = fromNetworksRouteModelChanged
proc toNetworksModelChanged*(self: View) {.signal.}
proc getToNetworksModel(self: View): QVariant {.slot.} =
return newQVariant(self.toNetworksModel)
QtProperty[QVariant] toNetworksModel:
read = getToNetworksModel
notify = toNetworksModelChanged
proc toNetworksRouteModelChanged*(self: View) {.signal.}
proc gettoNetworksRouteModel(self: View): QVariant {.slot.} =
return newQVariant(self.toNetworksRouteModel)
QtProperty[QVariant] toNetworksRouteModel:
read = gettoNetworksRouteModel
notify = toNetworksRouteModelChanged
proc selectedAssetKeyChanged*(self: View) {.signal.}
proc getSelectedAssetKey*(self: View): string {.slot.} =
@ -166,18 +167,18 @@ QtObject:
proc updateNetworksDisabledChains(self: View) =
# if the setting to show unpreferred chains is toggled, add all unpreferred chains to disabled chains list
if not self.showUnPreferredChains:
self.toNetworksModel.disableRouteUnpreferredChains()
self.toNetworksRouteModel.disableRouteUnpreferredChains()
else:
self.toNetworksModel.enableRouteUnpreferredChains()
self.toNetworksRouteModel.enableRouteUnpreferredChains()
proc updateNetworksTokenBalance(self: View) =
for chainId in self.toNetworksModel.getAllNetworksChainIds():
self.fromNetworksModel.updateTokenBalanceForSymbol(chainId, self.delegate.getTokenBalance(self.selectedSenderAccountAddress, chainId, self.selectedAssetKey))
self.toNetworksModel.updateTokenBalanceForSymbol(chainId, self.delegate.getTokenBalance(self.selectedSenderAccountAddress, chainId, self.selectedAssetKey))
for chainId in self.toNetworksRouteModel.getAllNetworksChainIds():
self.fromNetworksRouteModel.updateTokenBalanceForSymbol(chainId, self.delegate.getTokenBalance(self.selectedSenderAccountAddress, chainId, self.selectedAssetKey))
self.toNetworksRouteModel.updateTokenBalanceForSymbol(chainId, self.delegate.getTokenBalance(self.selectedSenderAccountAddress, chainId, self.selectedAssetKey))
proc setNetworkItems*(self: View, fromNetworks: seq[NetworkItem], toNetworks: seq[NetworkItem]) =
self.fromNetworksModel.setItems(fromNetworks)
self.toNetworksModel.setItems(toNetworks)
proc setNetworkItems*(self: View, fromNetworks: seq[NetworkRouteItem], toNetworks: seq[NetworkRouteItem]) =
self.fromNetworksRouteModel.setItems(fromNetworks)
self.toNetworksRouteModel.setItems(toNetworks)
proc transactionSent*(self: View, chainId: int, txHash: string, uuid: string, error: string) {.signal.}
proc sendTransactionSentSignal*(self: View, chainId: int, txHash: string, uuid: string, error: string) =
@ -216,42 +217,34 @@ QtObject:
amountIn,
self.selectedToAssetKey,
amountOut,
self.fromNetworksModel.getRouteDisabledNetworkChainIds(),
self.toNetworksModel.getRouteDisabledNetworkChainIds(),
self.fromNetworksModel.getRouteLockedChainIds(),
self.fromNetworksRouteModel.getRouteDisabledNetworkChainIds(),
self.toNetworksRouteModel.getRouteDisabledNetworkChainIds(),
self.fromNetworksRouteModel.getRouteLockedChainIds(),
extraParamsTable
)
proc updateRoutePreferredChains*(self: View, chainIds: string) {.slot.} =
self.toNetworksModel.updateRoutePreferredChains(chainIds)
self.toNetworksRouteModel.updateRoutePreferredChains(chainIds)
proc updatedNetworksWithRoutes*(self: View, paths: seq[SuggestedRouteItem], totalFeesInEth: float) =
self.fromNetworksModel.resetPathData()
self.toNetworksModel.resetPathData()
self.fromNetworksRouteModel.resetPathData()
self.toNetworksRouteModel.resetPathData()
for path in paths:
let fromChainId = path.getfromNetwork()
let hasGas = self.delegate.hasGas(self.selectedSenderAccountAddress, fromChainId, self.fromNetworksModel.getNetworkNativeGasSymbol(fromChainId), totalFeesInEth)
self.fromNetworksModel.updateFromNetworks(path, hasGas)
self.toNetworksModel.updateToNetworks(path)
let networkItem = self.delegate.getNetworkItem(fromChainId)
let hasGas = self.delegate.hasGas(self.selectedSenderAccountAddress, fromChainId, networkItem.nativeCurrencySymbol, totalFeesInEth)
self.fromNetworksRouteModel.updateFromNetworks(path, hasGas)
self.toNetworksRouteModel.updateToNetworks(path)
proc resetStoredProperties*(self: View) {.slot.} =
self.sendType = transaction_dto.SendType.Transfer
self.selectedRecipient = ""
self.fromNetworksModel.reset()
self.toNetworksModel.reset()
self.fromNetworksRouteModel.reset()
self.toNetworksRouteModel.reset()
self.transactionRoutes = newTransactionRoutes()
self.selectedAssetKey = ""
self.showUnPreferredChains = false
proc getLayer1NetworkChainId*(self: View): string =
return $self.fromNetworksModel.getLayer1Network()
proc getNetworkColor*(self: View, shortName : string): string =
return self.fromNetworksModel.getNetworkColor(shortName)
proc getNetworkChainId*(self: View, shortName : string): int =
return self.fromNetworksModel.getNetworkChainId(shortName)
proc splitAndFormatAddressPrefix(self: View, text : string, updateInStore: bool): string {.slot.} =
return self.delegate.splitAndFormatAddressPrefix(text, updateInStore)
@ -267,12 +260,9 @@ QtObject:
return ""
var preferredChains: seq[int]
for shortName in chainShortNames.split(':'):
preferredChains.add(self.fromNetworksModel.getNetworkChainId(shortName))
preferredChains.add(self.delegate.getNetworkChainId(shortName))
return preferredChains.join(":")
proc getIconUrl*(self: View, chainId: int): string {.slot.} =
return self.fromNetworksModel.getIconUrl(chainId)
# "Stateless" methods
proc fetchSuggestedRoutesWithParameters*(self: View,
uuid: string,

View File

@ -470,12 +470,12 @@ QtObject:
self.resetMessageCursor(chatArg.chatId)
proc getTransactionDetails*(self: Service, message: MessageDto): (string, string) =
let networksDto = self.networkService.getCurrentNetworks()
var token = self.tokenService.findTokenByAddress(networksDto[0].chainId, ZERO_ADDRESS)
let chainIds = self.networkService.getCurrentNetworksChainIds()
var token = self.tokenService.findTokenByAddress(chainIds[0], ZERO_ADDRESS)
if message.transactionParameters.contract != "":
for networkDto in networksDto:
let tokenFound = self.tokenService.findTokenByAddress(networkDto.chainId, message.transactionParameters.contract)
for chainId in chainIds:
let tokenFound = self.tokenService.findTokenByAddress(chainId, message.transactionParameters.contract)
if tokenFound == nil:
continue

View File

@ -68,6 +68,12 @@ proc getFlatNetworks*(self: Service): var seq[NetworkItem] =
proc getCurrentNetworks*(self: Service): seq[NetworkItem] =
self.flatNetworks.filter(n => n.isTest == self.settingsService.areTestNetworksEnabled())
proc getCurrentNetworksChainIds*(self: Service): seq[int] =
return self.getCurrentNetworks().map(n => n.chainId)
proc getEnabledChainIds*(self: Service): seq[int] =
return self.getCurrentNetworks().filter(n => n.isEnabled).map(n => n.chainId)
proc upsertNetwork*(self: Service, network: NetworkItem): bool =
let response = backend.addEthereumChain(backend.Network(
chainId: network.chainId,

View File

@ -1,4 +1,4 @@
import NimQml, chronicles, Tables, strutils, sequtils, sugar, json
import NimQml, chronicles, Tables, strutils, sequtils, json
import ../../../app/global/global_singleton
import ../../../app/core/eventemitter
@ -143,7 +143,7 @@ QtObject:
var chaindIdsDown: seq[int] = @[]
var lastSuccessAt: int = connection_status_backend.INVALID_TIMESTAMP # latest succesful connectinon between the down chains
let allChainIds = self.networkService.getCurrentNetworks().map(a => a.chainId)
let allChainIds = self.networkService.getCurrentNetworksChainIds()
for id in allChainIds:
if chainStatusTable.hasKey($id) and chainStatusTable[$id].value != connection_status_backend.StateValue.Unknown:
if chainStatusTable[$id].value == connection_status_backend.StateValue.Connected:

View File

@ -761,7 +761,7 @@ proc fetchChainIdForUrl*(self: Service, url: string, isMainUrl: bool) =
self.threadpool.start(arg)
proc getEnabledChainIds*(self: Service): seq[int] =
return self.networkService.getCurrentNetworks().filter(n => n.isEnabled).map(n => n.chainId)
return self.networkService.getEnabledChainIds()
proc getCurrencyFormat*(self: Service, symbol: string): CurrencyFormatDto =
return self.currencyService.getCurrencyFormat(symbol)

View File

@ -132,7 +132,7 @@ proc getOrFetchBalanceForAddressInPreferredCurrency*(self: Service, address: str
result.balance = 0.0
result.fetched = false
return
let chainIds = self.networkService.getCurrentNetworks().map(n => n.chainId)
let chainIds = self.networkService.getCurrentNetworksChainIds()
result.balance = self.getTotalCurrencyBalance(@[acc.address], chainIds)
result.fetched = true
@ -159,7 +159,7 @@ proc checkRecentHistory*(self: Service, addresses: seq[string]) =
if(not main_constants.WALLET_ENABLED):
return
try:
let chainIds = self.networkService.getCurrentNetworks().map(a => a.chainId)
let chainIds = self.networkService.getCurrentNetworksChainIds()
status_go_transactions.checkRecentHistory(chainIds, addresses)
except Exception as e:
let errDescription = e.msg

View File

@ -187,10 +187,10 @@ SplitView {
totalTime:2
},
amountToReceive: txStore.amountToSend - (txStore.amountToSend*5/100),
toNetworksModel: dummyEventData.toModel
toNetworksRouteModel: dummyEventData.toModel
}
txStore.fromNetworksModel.updateFromNetworks(dummyEventData.suggestesRoutes)
txStore.toNetworksModel.updateToNetworks(dummyEventData.suggestesRoutes)
txStore.fromNetworksRouteModel.updateFromNetworks(dummyEventData.suggestesRoutes)
txStore.toNetworksRouteModel.updateToNetworks(dummyEventData.suggestesRoutes)
txStore.walletSectionSendInst.suggestedRoutesReady(txRoutes)
txStore.suggestedRoutesCalled = false
}

View File

@ -66,7 +66,7 @@ QtObject {
nativeCurrencyDecimals: 18,
isTest: false,
layer: 1,
isEnabled: true,
isRouteEnabled: true,
},
{
chainId: 11155111,
@ -80,7 +80,7 @@ QtObject {
nativeCurrencyDecimals: 18,
isTest: true,
layer: 1,
isEnabled: true,
isRouteEnabled: true,
},
{
chainId: 10,
@ -94,7 +94,7 @@ QtObject {
nativeCurrencyDecimals: 18,
isTest: false,
layer: 2,
isEnabled: true,
isRouteEnabled: true,
},
{
chainId: 420,
@ -108,7 +108,7 @@ QtObject {
nativeCurrencyDecimals: 18,
isTest: true,
layer: 2,
isEnabled: true,
isRouteEnabled: true,
},
{
chainId: 42161,
@ -122,7 +122,7 @@ QtObject {
nativeCurrencyDecimals: 18,
isTest: false,
layer: 2,
isEnabled: true,
isRouteEnabled: true,
},
{
chainId: 421613,
@ -136,7 +136,7 @@ QtObject {
nativeCurrencyDecimals: 18,
isTest: true,
layer: 2,
isEnabled: true,
isRouteEnabled: true,
}]
)
}
@ -174,8 +174,8 @@ QtObject {
nativeCurrencyDecimals: 18,
nativeCurrencyName: "Ether",
nativeCurrencySymbol: "ETH",
isEnabled: true,
isPreferred: true,
isRouteEnabled: true,
isRoutePreferred: true,
hasGas: true,
tokenBalance: ({
displayDecimals: true,
@ -198,8 +198,8 @@ QtObject {
nativeCurrencyDecimals: 18,
nativeCurrencyName: "Ether",
nativeCurrencySymbol: "ETH",
isEnabled: true,
isPreferred: true,
isRouteEnabled: true,
isRoutePreferred: true,
hasGas: true,
tokenBalance: ({
displayDecimals: true,
@ -223,8 +223,8 @@ QtObject {
nativeCurrencyDecimals: 18,
nativeCurrencyName: "Ether",
nativeCurrencySymbol: "ETH",
isEnabled: true,
isPreferred: true,
isRouteEnabled: true,
isRoutePreferred: true,
hasGas: true,
tokenBalance: ({
displayDecimals: true,
@ -243,19 +243,19 @@ QtObject {
readonly property var sendToNetworks: ListModel {
function updateRoutePreferredChains(chainIds) {
for( let i=0; i<count; i++) {
get(i).isPreferred = false
get(i).isEnabled = false
get(i).isRoutePreferred = false
get(i).isRouteEnabled = false
if(chainIds.length === 0) {
if(get(i).layer() === 1) {
get(i).isPreferred = true
get(i).isEnabled = true
get(i).isRoutePreferred = true
get(i).isRouteEnabled = true
}
}
else {
for (let k =0;k<chainIds.split(":").length;k++) {
if(get(i).chainId.toString() === chainIds[k].toString()) {
get(i).isPreferred = true
get(i).isEnabled = true
get(i).isRoutePreferred = true
get(i).isRouteEnabled = true
}
}
}
@ -293,8 +293,8 @@ QtObject {
nativeCurrencyDecimals: 18,
nativeCurrencyName: "Ether",
nativeCurrencySymbol: "ETH",
isEnabled: true,
isPreferred: true,
isRouteEnabled: true,
isRoutePreferred: true,
hasGas: true,
tokenBalance: ({
displayDecimals: true,
@ -317,8 +317,8 @@ QtObject {
nativeCurrencyDecimals: 18,
nativeCurrencyName: "Ether",
nativeCurrencySymbol: "ETH",
isEnabled: true,
isPreferred: true,
isRouteEnabled: true,
isRoutePreferred: true,
hasGas: true,
tokenBalance: ({
displayDecimals: true,
@ -336,14 +336,15 @@ QtObject {
chainName: "Arbitrum",
iconUrl: ModelsData.networks.arbitrum,
isActive: false,
isEnabled: true,
shortName: "ARB",
chainColor: "purple",
layer: 2,
nativeCurrencyDecimals: 18,
nativeCurrencyName: "Ether",
nativeCurrencySymbol: "ETH",
isEnabled: true,
isPreferred: true,
isRouteEnabled: true,
isRoutePreferred: true,
hasGas: true,
tokenBalance: ({
displayDecimals: true,

View File

@ -25,8 +25,8 @@ QtObject {
}
property var flatNetworksModel: NetworksModel.flatNetworks
property var fromNetworksModel: NetworksModel.sendFromNetworks
property var toNetworksModel: NetworksModel.sendToNetworks
property var fromNetworksRouteModel: NetworksModel.sendFromNetworks
property var toNetworksRouteModel: NetworksModel.sendToNetworks
property var selectedSenderAccount: accounts.get(0)
readonly property QtObject collectiblesModel: ManageCollectiblesModel {}
readonly property QtObject nestedCollectiblesModel: WalletNestedCollectiblesModel {}
@ -190,7 +190,7 @@ QtObject {
}
function updateRoutePreferredChains(chainIds) {
root.toNetworksModel.updateRoutePreferredChains(chainIds)
root.toNetworksRouteModel.updateRoutePreferredChains(chainIds)
}
function toggleShowUnPreferredChains() {
@ -219,8 +219,8 @@ QtObject {
root.selectedRecipient = ""
root.selectedAssetKey = ""
root.showUnPreferredChains = false
root.fromNetworksModel.reset()
root.toNetworksModel.reset()
root.fromNetworksRouteModel.reset()
root.toNetworksRouteModel.reset()
}
function getNetworkName(chainId) {

View File

@ -174,6 +174,19 @@ StatusDialog {
: 0
}
LeftJoinModel {
id: fromNetworksRouteModel
leftModel: popup.store.fromNetworksRouteModel
rightModel: popup.store.flatNetworksModel
joinRole: "chainId"
}
LeftJoinModel {
id: toNetworksRouteModel
leftModel: popup.store.toNetworksRouteModel
rightModel: popup.store.flatNetworksModel
joinRole: "chainId"
}
ModelEntry {
id: selectedSenderAccountEntry
key: "address"
@ -513,6 +526,8 @@ StatusDialog {
isCollectiblesTransfer: d.isCollectiblesTransfer
bestRoutes: popup.bestRoutes
totalFeesInFiat: d.totalFeesInFiat
fromNetworksList: fromNetworksRouteModel
toNetworksList: toNetworksRouteModel
}
}
}
@ -545,7 +560,7 @@ StatusDialog {
// If collectible
d.totalAmountToReceive = txRoutes.amountToReceive
}
networkSelector.toNetworksList = txRoutes.toNetworksModel
networkSelector.suggestedToNetworksList = txRoutes.toNetworksRouteModel
popup.isLoading = false
}
}

View File

@ -27,6 +27,8 @@ Item {
property bool interactive: true
property var weiToEth: function(wei) {}
property var reCalculateSuggestedRoute: function() {}
property var fromNetworksList
property var toNetworksList
property int errorType: Constants.NoError
property bool isLoading
@ -39,6 +41,8 @@ Item {
function resetAllSetValues() {
for(var i = 0; i<fromNetworksRepeater.count; i++) {
fromNetworksRepeater.itemAt(i).routeOnNetwork = 0
}
for(var i = 0; i<toNetworksRepeater.count; i++) {
toNetworksRepeater.itemAt(i).routeOnNetwork = 0
toNetworksRepeater.itemAt(i).bentLine = 0
}
@ -81,7 +85,7 @@ Item {
}
Repeater {
id: fromNetworksRepeater
model: store.fromNetworksModel
model: root.fromNetworksList
StatusCard {
id: fromNetwork
locale: LocaleUtils.userInputLocale
@ -113,7 +117,7 @@ Item {
disableText: qsTr("Disable")
enableText: qsTr("Enable")
advancedMode: root.customMode
disabled: !model.isEnabled
disabled: !model.isRouteEnabled
clickable: root.interactive
onClicked: {
store.toggleFromDisabledChains(model.chainId)
@ -163,12 +167,12 @@ Item {
Repeater {
id: toNetworksRepeater
model: store.toNetworksModel
model: root.toNetworksList
StatusCard {
id: toCard
locale: LocaleUtils.userInputLocale
objectName: model.chainId
property bool preferred: model.isPreferred
property bool preferred: model.isRoutePreferred
property int bentLine: 0
property int routeOnNetwork: 0
primaryText: model.chainName
@ -180,7 +184,7 @@ Item {
disabledText: qsTr("Disabled")
disableText: qsTr("Disable")
enableText: qsTr("Enable")
disabled: !model.isEnabled
disabled: !model.isRouteEnabled
clickable: root.interactive
loading: root.isLoading
onClicked: {

View File

@ -29,7 +29,9 @@ Item {
property bool interactive: true
property bool isBridgeTx: false
property bool isCollectiblesTransfer: false
property var fromNetworksList
property var toNetworksList
property var suggestedToNetworksList
property int errorType: Constants.NoError
property var bestRoutes
property double totalFeesInFiat
@ -86,7 +88,8 @@ Item {
store: root.store
errorMode: root.errorMode
errorType: root.errorType
toNetworksList: root.toNetworksList
fromNetworksList: root.fromNetworksList
toNetworksList: root.suggestedToNetworksList
// Collectibles don't have a symbol
selectedSymbol: !!root.selectedAsset && !!root.selectedAsset.symbol ? root.selectedAsset.symbol: ""
weiToEth: function(wei) {
@ -119,6 +122,8 @@ Item {
minReceiveCryptoDecimals: root.minReceiveCryptoDecimals
selectedAsset: root.selectedAsset
onReCalculateSuggestedRoute: root.reCalculateSuggestedRoute()
fromNetworksList: root.fromNetworksList
toNetworksList: root.toNetworksList
isLoading: root.isLoading
interactive: root.interactive
isBridgeTx: root.isBridgeTx

View File

@ -28,6 +28,8 @@ ColumnLayout {
property var weiToEth: function(wei) {}
property bool interactive: true
property bool isBridgeTx: false
property var toNetworksList
property var fromNetworksList
property int errorType: Constants.NoError
signal reCalculateSuggestedRoute()
@ -99,6 +101,8 @@ ColumnLayout {
reCalculateSuggestedRoute: function() {
root.reCalculateSuggestedRoute()
}
toNetworksList: root.toNetworksList
fromNetworksList: root.fromNetworksList
weiToEth: root.weiToEth
interactive: root.interactive
errorType: root.errorType

View File

@ -9,6 +9,7 @@ import StatusQ.Popups 0.1
import StatusQ.Components 0.1
import StatusQ.Core 0.1
import StatusQ.Core.Theme 0.1
import StatusQ 0.1
import "../controls"
@ -20,6 +21,7 @@ RowLayout {
property bool isLoading: false
property bool isBridgeTx: false
property bool isCollectiblesTransfer: false
property var fromNetworksList
property var toNetworksList
property var weiToEth: function(wei) {}
property var formatCurrencyAmount: function () {}
@ -71,7 +73,15 @@ RowLayout {
Repeater {
id: repeater
objectName: "networksList"
model: isBridgeTx ? store.fromNetworksModel : root.toNetworksList
model: LeftJoinModel {
leftModel: {
const m = isBridgeTx ? root.fromNetworksList : root.toNetworksList
return !!m ? m : null
}
rightModel: root.store.flatNetworksModel
joinRole: "chainId"
}
delegate: isBridgeTx ? networkItem : routeItem
}
}

View File

@ -23,9 +23,9 @@ QtObject {
readonly property var accounts: walletSectionAccounts.accounts
property var fromNetworksModel: walletSectionSendInst.fromNetworksModel
property var toNetworksModel: walletSectionSendInst.toNetworksModel
property var flatNetworksModel: networksModule.flatNetworks
readonly property var fromNetworksRouteModel: walletSectionSendInst.fromNetworksRouteModel
readonly property var toNetworksRouteModel: walletSectionSendInst.toNetworksRouteModel
readonly property string selectedReceiverAccountAddress: walletSectionSendInst.selectedReceiveAccountAddress
readonly property string selectedSenderAccountAddress: walletSectionSendInst.selectedSenderAccountAddress
property var collectiblesModel: walletSectionSendInst.collectiblesModel
@ -160,15 +160,15 @@ QtObject {
}
function toggleFromDisabledChains(chainId) {
fromNetworksModel.toggleRouteDisabledChains(chainId)
walletSectionSendInst.fromNetworksRouteModel.toggleRouteDisabledChains(chainId)
}
function toggleToDisabledChains(chainId) {
toNetworksModel.toggleRouteDisabledChains(chainId)
walletSectionSendInst.toNetworksRouteModel.toggleRouteDisabledChains(chainId)
}
function setRouteDisabledChains(chainId, disabled) {
toNetworksModel.setRouteDisabledChains(chainId, disabled)
walletSectionSendInst.toNetworksRouteModel.setRouteDisabledChains(chainId, disabled)
}
function setSelectedTokenName(tokenName) {
@ -180,7 +180,7 @@ QtObject {
}
function setRouteEnabledFromChains(chainId) {
fromNetworksModel.setRouteEnabledFromChains(chainId)
walletSectionSendInst.fromNetworksRouteModel.setRouteEnabledFromChains(chainId)
}
function setSelectedAssetKey(assetsKey) {
@ -188,7 +188,7 @@ QtObject {
}
function getNetworkName(chainId) {
return fromNetworksModel.getNetworkName(chainId)
return ModelUtils.getByKey(root.flatNetworksModel, "chainId", chainId, "chainName")
}
function updateRoutePreferredChains(chainIds) {
@ -200,11 +200,11 @@ QtObject {
}
function setAllNetworksAsRoutePreferredChains() {
toNetworksModel.setAllNetworksAsRoutePreferredChains()
walletSectionSendInst.toNetworksRouteModel.setAllNetworksAsRoutePreferredChains()
}
function lockCard(chainId, amount, lock) {
fromNetworksModel.lockCard(chainId, amount, lock)
walletSectionSendInst.fromNetworksRouteModel.lockCard(chainId, amount, lock)
}
function resetStoredProperties() {

View File

@ -55,7 +55,8 @@ StatusWindow {
geometry.x > Screen.desktopAvailableWidth ||
geometry.y > Screen.desktopAvailableHeight ||
geometry.width > Screen.desktopAvailableWidth ||
geometry.height > Screen.desktopAvailableHeight)
geometry.height > Screen.desktopAvailableHeight ||
geometry.x < 0 || geometry.y < 0)
{
let screen = Qt.application.screens[0];