diff --git a/src/app/modules/main/browser_section/current_account/controller.nim b/src/app/modules/main/browser_section/current_account/controller.nim
index a2cea997a..42aade139 100644
--- a/src/app/modules/main/browser_section/current_account/controller.nim
+++ b/src/app/modules/main/browser_section/current_account/controller.nim
@@ -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()
diff --git a/src/app/modules/main/communities/controller.nim b/src/app/modules/main/communities/controller.nim
index dda6ffe94..bb6731923 100644
--- a/src/app/modules/main/communities/controller.nim
+++ b/src/app/modules/main/communities/controller.nim
@@ -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)
diff --git a/src/app/modules/main/communities/module.nim b/src/app/modules/main/communities/module.nim
index a7b71704c..c8907184a 100644
--- a/src/app/modules/main/communities/module.nim
+++ b/src/app/modules/main/communities/module.nim
@@ -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
diff --git a/src/app/modules/main/profile_section/contacts/controller.nim b/src/app/modules/main/profile_section/contacts/controller.nim
index 471f37a70..5c1cdb79f 100644
--- a/src/app/modules/main/profile_section/contacts/controller.nim
+++ b/src/app/modules/main/profile_section/contacts/controller.nim
@@ -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)
\ No newline at end of file
+ return self.networkService.getEnabledChainIds()
\ No newline at end of file
diff --git a/src/app/modules/main/wallet_section/accounts/controller.nim b/src/app/modules/main/wallet_section/accounts/controller.nim
index f561483ca..fc304c890 100644
--- a/src/app/modules/main/wallet_section/accounts/controller.nim
+++ b/src/app/modules/main/wallet_section/accounts/controller.nim
@@ -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()
diff --git a/src/app/modules/main/wallet_section/all_collectibles/controller.nim b/src/app/modules/main/wallet_section/all_collectibles/controller.nim
index b4168d290..f1f9d5346 100644
--- a/src/app/modules/main/wallet_section/all_collectibles/controller.nim
+++ b/src/app/modules/main/wallet_section/all_collectibles/controller.nim
@@ -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)
diff --git a/src/app/modules/main/wallet_section/assets/controller.nim b/src/app/modules/main/wallet_section/assets/controller.nim
index 13257d1b9..03396694c 100644
--- a/src/app/modules/main/wallet_section/assets/controller.nim
+++ b/src/app/modules/main/wallet_section/assets/controller.nim
@@ -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()
diff --git a/src/app/modules/main/wallet_section/controller.nim b/src/app/modules/main/wallet_section/controller.nim
index 2f1fcac6e..dc38d6eff 100644
--- a/src/app/modules/main/wallet_section/controller.nim
+++ b/src/app/modules/main/wallet_section/controller.nim
@@ -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)
diff --git a/src/app/modules/main/wallet_section/send/controller.nim b/src/app/modules/main/wallet_section/send/controller.nim
index b8d8db9ca..6bddaddd3 100644
--- a/src/app/modules/main/wallet_section/send/controller.nim
+++ b/src/app/modules/main/wallet_section/send/controller.nim
@@ -1,5 +1,4 @@
-import sugar, sequtils, stint
-import uuids, chronicles, options
+import stint, uuids, chronicles, options
import io_interface
import app_service/service/wallet_account/service as wallet_account_service
import app_service/service/network/service as network_service
@@ -81,10 +80,10 @@ 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)
+ 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()
diff --git a/src/app/modules/main/wallet_section/send/io_interface.nim b/src/app/modules/main/wallet_section/send/io_interface.nim
index 76d79db9e..4eaea3109 100644
--- a/src/app/modules/main/wallet_section/send/io_interface.nim
+++ b/src/app/modules/main/wallet_section/send/io_interface.nim
@@ -1,6 +1,7 @@
import stint, 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
@@ -78,3 +79,9 @@ method onTransactionSigned*(self: AccessInterface, keycardFlowType: string, keyc
method hasGas*(self: AccessInterface, accountAddress: string, chainId: int, nativeGasSymbol: string, requiredGas: float): 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")
\ No newline at end of file
diff --git a/src/app/modules/main/wallet_section/send/module.nim b/src/app/modules/main/wallet_section/send/module.nim
index 226a8cf1c..26ad86648 100644
--- a/src/app/modules/main/wallet_section/send/module.nim
+++ b/src/app/modules/main/wallet_section/send/module.nim
@@ -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
@@ -89,17 +89,9 @@ 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,
@@ -109,17 +101,9 @@ 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,
- network.layer,
- network.nativeCurrencyDecimals,
- network.nativeCurrencyName,
- network.nativeCurrencySymbol,
+proc convertNetworkDtoToNetworkRouteItem(self: Module, network: network_service_item.NetworkItem): NetworkRouteItem =
+ result = initNetworkRouteItem(
+ network.chainId,
true,
false,
true,
@@ -167,8 +151,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) =
@@ -192,6 +176,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
@@ -286,14 +276,15 @@ method suggestedRoutesReady*(self: Module, suggestedRoutes: SuggestedRoutesDto)
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(self)
+ toNetworksRouteModel.setItems(networks)
self.view.updatedNetworksWithRoutes(paths, gasTimeEstimate.getTotalFeesInEth())
let transactionRoutes = newTransactionRoutes(
+ self,
suggestedRoutes = suggestedRouteModel,
gasTimeEstimate = gasTimeEstimate,
amountToReceive = suggestedRoutes.amountToReceive,
- toNetworksModel = toNetworksModel,
+ toNetworksRouteModel = toNetworksRouteModel,
rawPaths = suggestedRoutes.rawBest)
self.view.setTransactionRoute(transactionRoutes)
@@ -319,6 +310,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
@@ -328,15 +340,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 & "" & word & "" & ":"
if updateInStore:
if not chainFound:
- self.view.updateRoutePreferredChains(self.view.getLayer1NetworkChainId())
+ self.view.updateRoutePreferredChains($self.getLayer1NetworkChainId())
else:
self.view.updateRoutePreferredChains(tempPreferredChains.join(":"))
diff --git a/src/app/modules/main/wallet_section/send/network_item.nim b/src/app/modules/main/wallet_section/send/network_item.nim
deleted file mode 100644
index 10cf70f10..000000000
--- a/src/app/modules/main/wallet_section/send/network_item.nim
+++ /dev/null
@@ -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 = @[]
-
diff --git a/src/app/modules/main/wallet_section/send/network_route_item.nim b/src/app/modules/main/wallet_section/send/network_route_item.nim
new file mode 100644
index 000000000..0a3e752f6
--- /dev/null
+++ b/src/app/modules/main/wallet_section/send/network_route_item.nim
@@ -0,0 +1,105 @@
+import stew/shims/strformat, strutils
+
+import app/modules/shared_models/currency_amount
+
+type
+ NetworkRouteItem* = ref object
+ chainId: int
+ isRouteEnabled: bool
+ isRoutePreferred: bool
+ hasGas: bool
+ tokenBalance: CurrencyAmount
+ locked: bool
+ lockedAmount: string
+ amountIn: string
+ amountOut: string
+ toNetworks: seq[int]
+
+proc initNetworkRouteItem*(
+ chainId: 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.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},
+ 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 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 = @[]
+
diff --git a/src/app/modules/main/wallet_section/send/network_model.nim b/src/app/modules/main/wallet_section/send/network_route_model.nim
similarity index 50%
rename from src/app/modules/main/wallet_section/send/network_model.nim
rename to src/app/modules/main/wallet_section/send/network_route_model.nim
index 3fbc3e1f0..73cf18418 100644
--- a/src/app/modules/main/wallet_section/send/network_model.nim
+++ b/src/app/modules/main/wallet_section/send/network_route_model.nim
@@ -1,22 +1,15 @@
import NimQml, Tables, strutils, stew/shims/strformat, sequtils, sugar, json, stint
+import ./io_interface
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 +19,43 @@ type
ToNetworks
QtObject:
- type NetworkModel* = ref object of QAbstractListModel
- items*: seq[NetworkItem]
+ type NetworkRouteModel* = ref object of QAbstractListModel
+ delegate: io_interface.AccessInterface
+ 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*(delegate: io_interface.AccessInterface): NetworkRouteModel =
new(result, delete)
result.setup
+ result.delegate = delegate
- 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 +65,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 +78,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 +97,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 +114,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 +130,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 +141,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 +152,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,119 +163,96 @@ 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): string =
+ proc getRouteLockedChainIds*(self: NetworkRouteModel): string =
var jsonObject = newJObject()
for item in self.items:
if item.getLocked():
jsonObject[$item.getChainId()] = %* ("0x" & item.getLockedAmount())
return $jsonObject
- 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
+ let networkItem = self.delegate.getNetworkItem(self.items[i].getChainId())
+ if networkItem != nil and networkItem.layer == 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 getRoutePreferredNetworkChainIds*(self: NetworkModel): seq[int] =
+ proc getRoutePreferredNetworkChainIds*(self: NetworkRouteModel): seq[int] =
var preferredChains: seq[int] = @[]
for item in self.items:
- if item.getIsPreferred():
+ if item.getIsRoutePreferred():
preferredChains.add(item.getChainId())
return preferredChains
- 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)
@@ -320,9 +262,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
diff --git a/src/app/modules/main/wallet_section/send/transaction_routes.nim b/src/app/modules/main/wallet_section/send/transaction_routes.nim
index a50ed5d7b..967f53732 100644
--- a/src/app/modules/main/wallet_section/send/transaction_routes.nim
+++ b/src/app/modules/main/wallet_section/send/transaction_routes.nim
@@ -1,48 +1,49 @@
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
suggestedRoutes: SuggestedRouteModel
gasTimeEstimate: GasEstimateItem
amountToReceive: UInt256
- toNetworksModel: NetworkModel
+ toNetworksRouteModel: NetworkRouteModel
rawPaths: string
proc setup*(self: TransactionRoutes,
suggestedRoutes: SuggestedRouteModel,
gasTimeEstimate: GasEstimateItem,
amountToReceive: UInt256,
- toNetworksModel: NetworkModel,
+ toNetworksRouteModel: NetworkRouteModel,
rawPaths: string
) =
self.QObject.setup
self.suggestedRoutes = suggestedRoutes
self.gasTimeEstimate = gasTimeEstimate
self.amountToReceive = amountToReceive
- self.toNetworksModel = toNetworksModel
+ self.toNetworksRouteModel = toNetworksRouteModel
self.rawPaths = rawPaths
proc delete*(self: TransactionRoutes) =
self.QObject.delete
proc newTransactionRoutes*(
+ delegate: io_interface.AccessInterface,
suggestedRoutes: SuggestedRouteModel = newSuggestedRouteModel(),
gasTimeEstimate: GasEstimateItem = newGasEstimateItem(),
amountToReceive: UInt256 = stint.u256(0),
- toNetworksModel: NetworkModel = newNetworkModel(),
+ toNetworksRouteModel: NetworkRouteModel = newNetworkRouteModel(delegate),
rawPaths: string = ""
): TransactionRoutes =
new(result, delete)
- result.setup(suggestedRoutes, gasTimeEstimate, amountToReceive, toNetworksModel, rawPaths)
+ result.setup(suggestedRoutes, gasTimeEstimate, amountToReceive, toNetworksRouteModel, rawPaths)
proc `$`*(self: TransactionRoutes): string =
result = fmt"""TransactionRoutes(
suggestedRoutes: {self.suggestedRoutes},
gasTimeEstimate: {self.gasTimeEstimate},
amountToReceive: {self.amountToReceive},
- toNetworksModel: {self.toNetworksModel},
+ toNetworksRouteModel: {self.toNetworksRouteModel},
rawPaths: {self.rawPaths},
]"""
@@ -69,8 +70,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
diff --git a/src/app/modules/main/wallet_section/send/view.nim b/src/app/modules/main/wallet_section/send/view.nim
index 03fc17a6e..70af134de 100644
--- a/src/app/modules/main/wallet_section/send/view.nim
+++ b/src/app/modules/main/wallet_section/send/view.nim
@@ -1,8 +1,9 @@
import NimQml, sequtils, strutils, stint, options
-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:
@@ -13,8 +14,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
@@ -32,8 +33,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
@@ -41,9 +42,9 @@ QtObject:
new(result, delete)
result.QObject.setup
result.delegate = delegate
- result.fromNetworksModel = newNetworkModel()
- result.toNetworksModel = newNetworkModel()
- result.transactionRoutes = newTransactionRoutes()
+ result.fromNetworksRouteModel = newNetworkRouteModel(delegate)
+ result.toNetworksRouteModel = newNetworkRouteModel(delegate)
+ result.transactionRoutes = newTransactionRoutes(delegate)
result.collectiblesModel = delegate.getCollectiblesModel()
result.nestedCollectiblesModel = delegate.getNestedCollectiblesModel()
@@ -85,19 +86,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.} =
@@ -165,18 +166,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) =
@@ -213,40 +214,32 @@ QtObject:
discard
self.delegate.suggestedRoutes(self.selectedSenderAccountAddress, self.selectedRecipient,
- parsedAmount, self.selectedAssetKey, self.selectedToAssetKey, self.fromNetworksModel.getRouteDisabledNetworkChainIds(),
- self.toNetworksModel.getRouteDisabledNetworkChainIds(), self.toNetworksModel.getRoutePreferredNetworkChainIds(),
- self.sendType, self.fromNetworksModel.getRouteLockedChainIds())
+ parsedAmount, self.selectedAssetKey, self.selectedToAssetKey, self.fromNetworksRouteModel.getRouteDisabledNetworkChainIds(),
+ self.toNetworksRouteModel.getRouteDisabledNetworkChainIds(), self.toNetworksRouteModel.getRoutePreferredNetworkChainIds(),
+ self.sendType, self.fromNetworksRouteModel.getRouteLockedChainIds())
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.transactionRoutes = newTransactionRoutes()
+ self.fromNetworksRouteModel.reset()
+ self.toNetworksRouteModel.reset()
+ self.transactionRoutes = newTransactionRoutes(self.delegate)
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)
@@ -262,12 +255,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, accountFrom: string, accountTo: string, amount: string, token: string, toToken: string,
disabledFromChainIDs: string, disabledToChainIDs: string, preferredChainIDs: string, sendType: int, lockedInAmounts: string) {.slot.} =
diff --git a/src/app_service/service/message/service.nim b/src/app_service/service/message/service.nim
index a76b23b14..1cda572ba 100644
--- a/src/app_service/service/message/service.nim
+++ b/src/app_service/service/message/service.nim
@@ -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
diff --git a/src/app_service/service/network/service.nim b/src/app_service/service/network/service.nim
index 15bc9cc0f..b52c8327f 100644
--- a/src/app_service/service/network/service.nim
+++ b/src/app_service/service/network/service.nim
@@ -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,
diff --git a/src/app_service/service/network_connection/service.nim b/src/app_service/service/network_connection/service.nim
index b8235397f..6e34a206c 100644
--- a/src/app_service/service/network_connection/service.nim
+++ b/src/app_service/service/network_connection/service.nim
@@ -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:
diff --git a/src/app_service/service/wallet_account/service_account.nim b/src/app_service/service/wallet_account/service_account.nim
index 42b2140b6..e4440fa02 100644
--- a/src/app_service/service/wallet_account/service_account.nim
+++ b/src/app_service/service/wallet_account/service_account.nim
@@ -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)
diff --git a/src/app_service/service/wallet_account/service_token.nim b/src/app_service/service/wallet_account/service_token.nim
index b8293e651..4edfebc3f 100644
--- a/src/app_service/service/wallet_account/service_token.nim
+++ b/src/app_service/service/wallet_account/service_token.nim
@@ -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
diff --git a/storybook/pages/SendModalPage.qml b/storybook/pages/SendModalPage.qml
index 142f0be57..1c146ac9c 100644
--- a/storybook/pages/SendModalPage.qml
+++ b/storybook/pages/SendModalPage.qml
@@ -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
}
diff --git a/storybook/src/Models/NetworksModel.qml b/storybook/src/Models/NetworksModel.qml
index 65a7c85e4..e168f2730 100644
--- a/storybook/src/Models/NetworksModel.qml
+++ b/storybook/src/Models/NetworksModel.qml
@@ -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 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];