feat(@desktop/wallet): Account view - Prefered network

fixes #11578
This commit is contained in:
Khushboo Mehta 2023-07-21 10:41:24 +02:00 committed by Khushboo-dev-cpp
parent f9e6e86c82
commit 6c5c36584a
72 changed files with 741 additions and 396 deletions

View File

@ -55,4 +55,7 @@ proc getCurrentCurrency*(self: Controller): string =
return self.walletAccountService.getCurrency()
proc getCurrencyFormat*(self: Controller, symbol: string): CurrencyFormatDto =
return self.currencyService.getCurrencyFormat(symbol)
return self.currencyService.getCurrencyFormat(symbol)
proc areTestNetworksEnabled*(self: Controller): bool =
return self.walletAccountService.areTestNetworksEnabled()

View File

@ -66,7 +66,7 @@ proc switchAccount*(self: Module, accountIndex: int) =
let keycardAccount = self.controller.isKeycardAccount(walletAccount)
let currency = self.controller.getCurrentCurrency()
let enabledChainIds = self.controller.getEnabledChainIds()
let areTestNetworksEnabled = self.controller.areTestNetworksEnabled()
let currencyFormat = self.controller.getCurrencyFormat(currency)
let accountItem = walletAccountToWalletAccountsItem(
@ -75,6 +75,7 @@ proc switchAccount*(self: Module, accountIndex: int) =
enabledChainIds,
currency,
currencyFormat,
areTestNetworksEnabled
)
self.view.setData(accountItem)

View File

@ -63,3 +63,12 @@ proc getCurrentCurrency*(self: Controller): string =
proc getCurrencyFormat*(self: Controller, symbol: string): CurrencyFormatDto =
return self.walletAccountService.getCurrencyFormat(symbol)
proc updateWalletAccountProdPreferredChains*(self: Controller, address, preferredChainIds: string) =
discard self.walletAccountService.updateWalletAccountProdPreferredChains(address, preferredChainIds)
proc updateWalletAccountTestPreferredChains*(self: Controller, address, preferredChainIds: string) =
discard self.walletAccountService.updateWalletAccountTestPreferredChains(address, preferredChainIds)
proc areTestNetworksEnabled*(self: Controller): bool =
return self.walletAccountService.areTestNetworksEnabled()

View File

@ -42,3 +42,9 @@ method getModuleAsVariant*(self: AccessInterface): QVariant {.base.} =
method toggleIncludeWatchOnlyAccount*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method updateWalletAccountProdPreferredChains*(self: AccessInterface, address, preferredChainIds: string) {.base.} =
raise newException(ValueError, "No implementation available")
method updateWalletAccountTestPreferredChains*(self: AccessInterface, address, preferredChainIds: string) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -1,45 +0,0 @@
import strformat
import ../../../../shared_models/wallet_account_item
import ./related_accounts_model as related_accounts_model
export wallet_account_item
type
Item* = ref object of WalletAccountItem
relatedAccounts: related_accounts_model.Model
proc initItem*(
name: string = "",
address: string = "",
path: string = "",
colorId: string = "",
walletType: string = "",
emoji: string = "",
relatedAccounts: related_accounts_model.Model = nil,
keyUid: string = "",
keycardAccount: bool = false,
position: int = 0,
operability: string = ""
): Item =
result = Item()
result.WalletAccountItem.setup(name,
address,
colorId,
emoji,
walletType,
path,
keyUid,
keycardAccount,
position,
operability)
result.relatedAccounts = relatedAccounts
proc `$`*(self: Item): string =
result = "ProfileSection-Accounts-Item("
result = result & $self.WalletAccountItem
result = result & "\nrelatedAccounts: " & $self.relatedAccounts
result = result & ")"
proc relatedAccounts*(self: Item): related_accounts_model.Model =
return self.relatedAccounts

View File

@ -1,7 +1,6 @@
import NimQml, Tables, strutils, sequtils, strformat
import ./item
export item
import ../../../../shared_models/wallet_account_item
type
ModelRole {.pure.} = enum
@ -11,7 +10,6 @@ type
ColorId,
WalletType,
Emoji,
RelatedAccounts,
KeyUid,
Position,
KeycardAccount,
@ -19,7 +17,7 @@ type
QtObject:
type
Model* = ref object of QAbstractListModel
items: seq[Item]
items: seq[WalletAccountItem]
proc delete(self: Model) =
self.items = @[]
@ -56,20 +54,19 @@ QtObject:
ModelRole.ColorId.int:"colorId",
ModelRole.WalletType.int:"walletType",
ModelRole.Emoji.int: "emoji",
ModelRole.RelatedAccounts.int: "relatedAccounts",
ModelRole.KeyUid.int: "keyUid",
ModelRole.Position.int: "position",
ModelRole.KeycardAccount.int: "keycardAccount",
}.toTable
proc setItems*(self: Model, items: seq[Item]) =
proc setItems*(self: Model, items: seq[WalletAccountItem]) =
self.beginResetModel()
self.items = items
self.endResetModel()
self.countChanged()
proc onUpdatedAccount*(self: Model, account: Item) =
proc onUpdatedAccount*(self: Model, account: WalletAccountItem) =
var i = 0
for item in self.items.mitems:
if account.address == item.address:
@ -106,8 +103,6 @@ QtObject:
result = newQVariant(item.walletType())
of ModelRole.Emoji:
result = newQVariant(item.emoji())
of ModelRole.RelatedAccounts:
result = newQVariant(item.relatedAccounts())
of ModelRole.KeyUid:
result = newQVariant(item.keyUid())
of ModelRole.Position:
@ -133,4 +128,4 @@ QtObject:
self.items.delete(fromRow)
self.items.insert(@[currentItem], toRow)
self.endMoveRows()
return true
return true

View File

@ -1,6 +1,6 @@
import NimQml, sequtils, sugar, chronicles, tables
import ./io_interface, ./view, ./item, ./controller
import ./io_interface, ./view, ./controller
import ../io_interface as delegate_interface
import app/modules/shared/wallet_utils
import app/modules/shared/keypairs
@ -62,7 +62,10 @@ method convertWalletAccountDtoToKeyPairAccountItem(self: Module, account: Wallet
balance = newCurrencyAmount(),
balanceFetched = false,
operability = account.operable,
isDefaultAccount = account.isWallet)
isDefaultAccount = account.isWallet,
self.controller.areTestNetworksEnabled(),
prodPreferredChainIds = account.prodPreferredChainIds,
testPreferredChainIds = account.testPreferredChainIds)
method createKeypairItems*(self: Module, walletAccounts: seq[WalletAccountDto], accountsTokens: OrderedTable[string, seq[WalletTokenDto]]): seq[KeyPairItem] =
let enabledChainIds = self.controller.getEnabledChainIds()
@ -70,7 +73,7 @@ method createKeypairItems*(self: Module, walletAccounts: seq[WalletAccountDto],
let currencyFormat = self.controller.getCurrencyFormat(currency)
var keyPairItems = keypairs.buildKeyPairsList(self.controller.getKeypairs(), excludeAlreadyMigratedPairs = false,
excludePrivateKeyKeypairs = false)
excludePrivateKeyKeypairs = false, self.controller.areTestNetworksEnabled())
var item = newKeyPairItem()
item.setIcon("show")
@ -90,7 +93,8 @@ method refreshWalletAccounts*(self: Module, accountsTokens: OrderedTable[string,
let items = walletAccounts.map(w => (block:
let keycardAccount = self.controller.isKeycardAccount(w)
walletAccountToWalletSettingsAccountsItem(w, keycardAccount)
let areTestNetworksEnabled = self.controller.areTestNetworksEnabled()
walletAccountToWalletAccountItem(w, keycardAccount, areTestNetworksEnabled)
))
self.view.setKeyPairModelItems(self.createKeypairItems(walletAccounts, accountsTokens))
@ -113,7 +117,8 @@ method load*(self: Module) =
self.events.on(SIGNAL_WALLET_ACCOUNT_UPDATED) do(e:Args):
let args = AccountArgs(e)
let keycardAccount = self.controller.isKeycardAccount(args.account)
self.view.onUpdatedAccount(walletAccountToWalletSettingsAccountsItem(args.account, keycardAccount))
let areTestNetworksEnabled = self.controller.areTestNetworksEnabled()
self.view.onUpdatedAccount(walletAccountToWalletAccountItem(args.account, keycardAccount, areTestNetworksEnabled), args.account.prodPreferredChainIds, args.account.testPreferredChainIds)
self.events.on(SIGNAL_NEW_KEYCARD_SET) do(e: Args):
let args = KeycardArgs(e)
@ -164,3 +169,9 @@ method renameKeypair*(self: Module, keyUid: string, name: string) =
proc onKeypairRenamed(self: Module, keyUid: string, name: string) =
self.view.keyPairModel.updateKeypairName(keyUid, name)
method updateWalletAccountProdPreferredChains*(self: Module, address, preferredChainIds: string) =
self.controller.updateWalletAccountProdPreferredChains(address, preferredChainIds)
method updateWalletAccountTestPreferredChains*(self: Module, address, preferredChainIds: string) =
self.controller.updateWalletAccountTestPreferredChains(address, preferredChainIds)

View File

@ -1,32 +0,0 @@
import strformat
type
Item* = object
name: string
colorId: string
emoji: string
proc initItem*(
name: string = "",
colorId: string = "",
emoji: string = "",
): Item =
result.name = name
result.colorId = colorId
result.emoji = emoji
proc `$`*(self: Item): string =
result = fmt"""WalletAccountItem(
name: {self.name},
colorId: {self.colorId},
emoji: {self.emoji},
]"""
proc getName*(self: Item): string =
return self.name
proc getEmoji*(self: Item): string =
return self.emoji
proc getColorId*(self: Item): string =
return self.colorId

View File

@ -1,73 +0,0 @@
import NimQml, Tables, strutils, strformat
import ./related_account_item
type
ModelRole {.pure.} = enum
Name = UserRole + 1,
ColorId,
Emoji,
QtObject:
type
Model* = ref object of QAbstractListModel
items: seq[Item]
proc delete(self: Model) =
self.items = @[]
self.QAbstractListModel.delete
proc setup(self: Model) =
self.QAbstractListModel.setup
proc newModel*(): Model =
new(result, delete)
result.setup
proc `$`*(self: Model): string =
for i in 0 ..< self.items.len:
result &= fmt"""[{i}]:({$self.items[i]})"""
proc countChanged(self: Model) {.signal.}
proc getCount*(self: Model): int {.slot.} =
self.items.len
QtProperty[int] count:
read = getCount
notify = countChanged
method rowCount(self: Model, index: QModelIndex = nil): int =
return self.items.len
method roleNames(self: Model): Table[int, string] =
{
ModelRole.Name.int:"name",
ModelRole.ColorId.int:"colorId",
ModelRole.Emoji.int: "emoji",
}.toTable
proc setItems*(self: Model, items: seq[Item]) =
self.beginResetModel()
self.items = items
self.endResetModel()
self.countChanged()
method data(self: Model, index: QModelIndex, role: int): QVariant =
if (not index.isValid):
return
if (index.row < 0 or index.row >= self.items.len):
return
let item = self.items[index.row]
let enumRole = role.ModelRole
case enumRole:
of ModelRole.Name:
result = newQVariant(item.getName())
of ModelRole.ColorId:
result = newQVariant(item.getColorId())
of ModelRole.Emoji:
result = newQVariant(item.getEmoji())

View File

@ -3,6 +3,7 @@ import NimQml, sequtils, strutils, sugar
import ./io_interface
import ./model
import app/modules/shared_models/keypair_model
import app/modules/shared_models/wallet_account_item
QtObject:
type
@ -39,15 +40,15 @@ QtObject:
read = getAccounts
notify = accountsChanged
proc setItems*(self: View, items: seq[Item]) =
proc setItems*(self: View, items: seq[WalletAccountItem]) =
self.accounts.setItems(items)
proc updateAccount(self: View, address: string, accountName: string, colorId: string, emoji: string) {.slot.} =
self.delegate.updateAccount(address, accountName, colorId, emoji)
proc onUpdatedAccount*(self: View, account: Item) =
proc onUpdatedAccount*(self: View, account: WalletAccountItem, prodPreferredChainIds: string, testPreferredChainIds: string) =
self.accounts.onUpdatedAccount(account)
self.keyPairModel.onUpdatedAccount(account.keyUid, account.address, account.name, account.colorId, account.emoji)
self.keyPairModel.onUpdatedAccount(account.keyUid, account.address, account.name, account.colorId, account.emoji, prodPreferredChainIds, testPreferredChainIds)
proc deleteAccount*(self: View, address: string) {.slot.} =
self.delegate.deleteAccount(address)
@ -90,4 +91,10 @@ QtObject:
discard self.accounts.moveItem(fromRow, toRow)
proc moveAccountFinally(self: View, fromRow: int, toRow: int) {.slot.} =
self.delegate.moveAccountFinally(fromRow, toRow)
self.delegate.moveAccountFinally(fromRow, toRow)
proc updateWalletAccountProdPreferredChains*(self: View, address: string, preferredChainIds: string) {.slot.} =
self.delegate.updateWalletAccountProdPreferredChains(address, preferredChainIds)
proc updateWalletAccountTestPreferredChains*(self: View, address: string, preferredChainIds: string) {.slot.} =
self.delegate.updateWalletAccountTestPreferredChains(address, preferredChainIds)

View File

@ -38,3 +38,9 @@ proc getShortName*(self: CombinedItem, areTestNetworksEnabled: bool): string =
return self.test.shortName()
else:
return self.prod.shortName()
proc getChainId*(self: CombinedItem, areTestNetworksEnabled: bool): int =
if areTestNetworksEnabled:
return self.test.chainId()
else:
return self.prod.chainId()

View File

@ -71,8 +71,19 @@ QtObject:
self.endResetModel()
self.countChanged()
proc getAllNetworksSupportedPrefix*(self: CombinedModel, areTestNetworksEnabled: bool): string =
var networkString = ""
proc getAllNetworksChainIds*(self: CombinedModel, areTestNetworksEnabled: bool): string =
var networks: seq[int] = @[]
for item in self.items:
networkString = networkString & item.getShortName(areTestNetworksEnabled) & ':'
networks.add(item.getChainId(areTestNetworksEnabled))
return networks.join(":")
proc getNetworkShortNames*(self: CombinedModel, preferredNetworks: string, areTestNetworksEnabled: bool): string =
var networkString = ""
let networks = preferredNetworks.split(":")
for nw in networks:
for item in self.items:
if $item.getChainId(areTestNetworksEnabled) == nw:
networkString = networkString & $item.getShortName(areTestNetworksEnabled) & ':'
break
return networkString

View File

@ -0,0 +1,96 @@
import NimQml, Tables, strutils, strformat
import ./item
type
ModelRole* {.pure.} = enum
ChainId = UserRole + 1,
Layer
ChainName
IconUrl
ShortName
ChainColor
QtObject:
type
Model* = ref object of QAbstractListModel
items: seq[Item]
proc delete(self: Model) =
self.items = @[]
self.QAbstractListModel.delete
proc setup(self: Model) =
self.QAbstractListModel.setup
proc newModel*(): Model =
new(result, delete)
result.setup
proc `$`*(self: Model): string =
for i in 0 ..< self.items.len:
result &= fmt"""[{i}]:({$self.items[i]})"""
proc countChanged(self: Model) {.signal.}
proc getCount(self: Model): int {.slot.} =
self.items.len
QtProperty[int] count:
read = getCount
notify = countChanged
method rowCount*(self: Model, index: QModelIndex = nil): int =
return self.items.len
method roleNames(self: Model): Table[int, string] =
{
ModelRole.ChainId.int:"chainId",
ModelRole.Layer.int:"layer",
ModelRole.ChainName.int:"chainName",
ModelRole.IconUrl.int:"iconUrl",
ModelRole.ShortName.int:"shortName",
ModelRole.ChainColor.int:"chainColor",
}.toTable
method data(self: Model, index: QModelIndex, role: int): QVariant =
if (not index.isValid):
return
if (index.row < 0 or index.row >= self.items.len):
return
let item = self.items[index.row]
let enumRole = role.ModelRole
case enumRole:
of ModelRole.ChainId:
result = newQVariant(item.chainId())
of ModelRole.Layer:
result = newQVariant(item.layer())
of ModelRole.ChainName:
result = newQVariant(item.chainName())
of ModelRole.IconUrl:
result = newQVariant(item.iconURL())
of ModelRole.ShortName:
result = newQVariant(item.shortName())
of ModelRole.ChainColor:
result = newQVariant(item.chainColor())
proc rowData*(self: Model, index: int, column: string): string {.slot.} =
if (index >= self.items.len):
return
let item = self.items[index]
case column:
of "chainId": result = $item.chainId()
of "layer": result = $item.layer()
of "chainName": result = $item.chainName()
of "iconUrl": result = $item.iconURL()
of "shortName": result = $item.shortName()
of "chainColor": result = $item.chainColor()
proc setItems*(self: Model, items: seq[Item]) =
self.beginResetModel()
self.items = items
self.endResetModel()
self.countChanged()

View File

@ -39,6 +39,7 @@ method getModuleAsVariant*(self: Module): QVariant =
return self.viewVariant
method refreshNetworks*(self: Module) =
var items: seq[Item] = @[]
var combinedItems: seq[CombinedItem] = @[]
for n in self.controller.getNetworks():
var prod = newItem(
@ -65,8 +66,12 @@ method refreshNetworks*(self: Module) =
n.test.blockExplorerURL,
n.test.nativeCurrencySymbol
)
if self.controller.areTestNetworksEnabled():
items.add(test)
else:
items.add(prod)
combinedItems.add(initCombinedItem(prod,test,n.prod.layer))
self.view.setItems(combinedItems)
self.view.setItems(items, combinedItems)
method load*(self: Module) =
self.controller.init()
@ -98,4 +103,4 @@ method fetchChainIdForUrl*(self: Module, url: string) =
self.controller.fetchChainIdForUrl(url)
method chainIdFetchedForUrl*(self: Module, url: string, chainId: int, success: bool) =
self.view.chainIdFetchedForUrl(url, chainId, success)
self.view.chainIdFetchedForUrl(url, chainId, success)

View File

@ -1,8 +1,8 @@
import Tables, NimQml, sequtils, sugar
#import ../../../../../../app_service/service/network/dto
import ./io_interface
#import ./item
import ./item
import ./model
import ./combined_item
import ./combined_model
@ -11,6 +11,7 @@ QtObject:
View* = ref object of QObject
delegate: io_interface.AccessInterface
combinedNetworks: CombinedModel
networks: Model
areTestNetworksEnabled: bool
proc setup(self: View) =
@ -24,6 +25,7 @@ QtObject:
new(result, delete)
result.delegate = delegate
result.combinedNetworks = newCombinedModel()
result.networks = newModel()
result.setup()
proc areTestNetworksEnabledChanged*(self: View) {.signal.}
@ -44,6 +46,13 @@ QtObject:
self.areTestNetworksEnabled = not self.areTestNetworksEnabled
self.areTestNetworksEnabledChanged()
proc networksChanged*(self: View) {.signal.}
proc getNetworks(self: View): QVariant {.slot.} =
return newQVariant(self.networks)
QtProperty[QVariant] networks:
read = getNetworks
notify = networksChanged
proc combinedNetworksChanged*(self: View) {.signal.}
proc getCombinedNetworks(self: View): QVariant {.slot.} =
return newQVariant(self.combinedNetworks)
@ -54,11 +63,15 @@ QtObject:
proc load*(self: View) =
self.delegate.viewDidLoad()
proc setItems*(self: View, combinedItems: seq[CombinedItem]) =
proc setItems*(self: View, items: seq[Item], combinedItems: seq[CombinedItem]) =
self.networks.setItems(items)
self.combinedNetworks.setItems(combinedItems)
proc getAllNetworksSupportedPrefix*(self: View): string {.slot.} =
return self.combinedNetworks.getAllNetworksSupportedPrefix(self.areTestNetworksEnabled)
proc getAllNetworksChainIds*(self: View): string {.slot.} =
return self.combinedNetworks.getAllNetworksChainIds(self.areTestNetworksEnabled)
proc getNetworkShortNames*(self: View, preferredNetworks: string): string {.slot.} =
return self.combinedNetworks.getNetworkShortNames(preferredNetworks, self.areTestNetworksEnabled)
proc updateNetworkEndPointValues*(self: View, chainId: int, newMainRpcInput, newFailoverRpcUrl: string) =
self.delegate.updateNetworkEndPointValues(chainId, newMainRpcInput, newFailoverRpcUrl)
@ -66,4 +79,4 @@ QtObject:
proc fetchChainIdForUrl*(self: View, url: string) {.slot.} =
self.delegate.fetchChainIdForUrl(url)
proc chainIdFetchedForUrl*(self: View, url: string, chainId: int, success: bool) {.signal.}
proc chainIdFetchedForUrl*(self: View, url: string, chainId: int, success: bool) {.signal.}

View File

@ -58,3 +58,12 @@ proc getWalletAccount*(self: Controller, address: string): WalletAccountDto =
proc updateAccount*(self: Controller, address: string, accountName: string, colorId: string, emoji: string) =
discard self.walletAccountService.updateWalletAccount(address, accountName, colorId, emoji)
proc updateWalletAccountProdPreferredChains*(self: Controller, address, preferredChainIds: string) =
discard self.walletAccountService.updateWalletAccountProdPreferredChains(address, preferredChainIds)
proc updateWalletAccountTestPreferredChains*(self: Controller, address, preferredChainIds: string) =
discard self.walletAccountService.updateWalletAccountTestPreferredChains(address, preferredChainIds)
proc areTestNetworksEnabled*(self: Controller): bool =
return self.walletAccountService.areTestNetworksEnabled()

View File

@ -30,3 +30,9 @@ method updateAccount*(self: AccessInterface, address: string, accountName: strin
# inheritance, which is not well supported in Nim.
method viewDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method updateWalletAccountProdPreferredChains*(self: AccessInterface, address, preferredChainIds: string) {.base.} =
raise newException(ValueError, "No implementation available")
method updateWalletAccountTestPreferredChains*(self: AccessInterface, address, preferredChainIds: string) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -25,6 +25,9 @@ proc initItem*(
keycardAccount: bool = false,
assetsLoading: bool = true,
isWallet: bool = false,
areTestNetworksEnabled: bool = false,
prodPreferredChainIds: string = "",
testPreferredChainIds: string = ""
): Item =
result = Item()
result.WalletAccountItem.setup(name,
@ -35,7 +38,11 @@ proc initItem*(
path,
keyUid,
keycardAccount,
position)
position,
operability = wa_dto.AccountFullyOperable,
areTestNetworksEnabled,
prodPreferredChainIds,
testPreferredChainIds)
result.createdAt = createdAt
result.assetsLoading = assetsLoading
result.currencyBalance = currencyBalance

View File

@ -19,6 +19,7 @@ type
KeycardAccount,
AssetsLoading,
IsWallet,
PreferredSharingChainIds
QtObject:
type
@ -68,6 +69,7 @@ QtObject:
ModelRole.KeycardAccount.int: "keycardAccount",
ModelRole.AssetsLoading.int: "assetsLoading",
ModelRole.IsWallet.int: "isWallet",
ModelRole.PreferredSharingChainIds.int: "preferredSharingChainIds"
}.toTable
@ -117,6 +119,8 @@ QtObject:
result = newQVariant(item.assetsLoading())
of ModelRole.IsWallet:
result = newQVariant(item.isWallet())
of ModelRole.PreferredSharingChainIds:
result = newQVariant(item.preferredSharingChainIds())
proc getNameByAddress*(self: Model, address: string): string =
for item in self.items:

View File

@ -46,6 +46,7 @@ method filterChanged*(self: Module, addresses: seq[string], chainIds: seq[int])
let walletAccounts = self.controller.getWalletAccounts()
let currency = self.controller.getCurrentCurrency()
let currencyFormat = self.controller.getCurrencyFormat(currency)
let areTestNetworksEnabled = self.controller.areTestNetworksEnabled()
let items = walletAccounts.map(w => (block:
let keycardAccount = self.controller.isKeycardAccount(w)
walletAccountToWalletAccountsItem(
@ -54,6 +55,7 @@ method filterChanged*(self: Module, addresses: seq[string], chainIds: seq[int])
chainIds,
currency,
currencyFormat,
areTestNetworksEnabled
)
))
self.view.setItems(items)
@ -75,3 +77,9 @@ method deleteAccount*(self: Module, address: string) =
method updateAccount*(self: Module, address: string, accountName: string, colorId: string, emoji: string) =
self.controller.updateAccount(address, accountName, colorId, emoji)
method updateWalletAccountProdPreferredChains*(self: Module, address, preferredChainIds: string) =
self.controller.updateWalletAccountProdPreferredChains(address, preferredChainIds)
method updateWalletAccountTestPreferredChains*(self: Module, address, preferredChainIds: string) =
self.controller.updateWalletAccountTestPreferredChains(address, preferredChainIds)

View File

@ -54,3 +54,10 @@ QtObject:
proc getColorByAddress(self: View, address: string): string {.slot.}=
return self.accounts.getColorByAddress(address)
proc updateWalletAccountProdPreferredChains*(self: View, address: string, preferredChainIds: string) {.slot.} =
self.delegate.updateWalletAccountProdPreferredChains(address, preferredChainIds)
proc updateWalletAccountTestPreferredChains*(self: View, address: string, preferredChainIds: string) {.slot.} =
self.delegate.updateWalletAccountTestPreferredChains(address, preferredChainIds)

View File

@ -17,7 +17,7 @@ proc initItem*(
result.hasMarketValuesCache = hasMarketValuesCache
proc `$`*(self: Item): string =
result = fmt"""WalletAccountItem(
result = fmt"""WalletAssetItem(
assetsLoading: {self.assetsLoading},
hasBalanceCache: {self.hasBalanceCache},
hasMarketValuesCache: {self.hasMarketValuesCache},
@ -30,4 +30,4 @@ proc getHasBalanceCache*(self: Item): bool =
return self.hasBalanceCache
proc getHasMarketValuesCache*(self: Item): bool =
return self.hasMarketValuesCache
return self.hasMarketValuesCache

View File

@ -1,4 +1,4 @@
import NimQml, Tables, strutils, strformat, sequtils
import NimQml, Tables, strutils, strformat, sequtils, sugar
import ./item
@ -241,8 +241,15 @@ QtObject:
return (chainIds, enable)
proc getAllNetworksSupportedPrefix*(self: Model): string =
proc getNetworkShortNames*(self: Model, preferredNetworks: string): string =
var networkString = ""
for item in self.items:
networkString = networkString & item.getShortName() & ':'
let networks = preferredNetworks.split(":")
for nw in networks:
for item in self.items:
if $item.getChainId() == nw:
networkString = networkString & item.getShortName() & ':'
break
return networkString
proc getAllNetworksChainIds*(self: Model): string =
return self.items.map(x => x.getChainId()).join(":")

View File

@ -126,8 +126,11 @@ QtObject:
proc getMainnetChainId*(self: View): int {.slot.} =
return self.layer1.getLayer1Network(self.areTestNetworksEnabled)
proc getAllNetworksSupportedPrefix*(self: View): string {.slot.} =
return self.all.getAllNetworksSupportedPrefix()
proc getNetworkShortNames*(self: View, preferredNetworks: string): string {.slot.} =
return self.all.getNetworkShortNames(preferredNetworks)
proc getAllNetworksChainIds*(self: View): string {.slot.} =
return self.all.getAllNetworksChainIds()
proc networkEnabledToUxEnabledState(enabled: bool, allEnabled: bool): UxEnabledState =
return if allEnabled:
@ -141,4 +144,4 @@ proc areAllEnabled(networks: seq[NetworkDto]): bool =
return networks.allIt(it.enabled)
proc getNetworkLayer*(self: View, chainId: int): string =
return self.all.getNetworkLayer(chainId)
return self.all.getNetworkLayer(chainId)

View File

@ -19,6 +19,9 @@ QtObject:
assets: token_model.Model,
currencyBalance: CurrencyAmount,
position: int,
areTestNetworksEnabled: bool,
prodPreferredChainIds: string,
testPreferredChainIds: string
) =
self.QObject.setup
self.WalletAccountItem.setup(name,
@ -29,7 +32,11 @@ QtObject:
path = "",
keyUid = "",
keycardAccount = false,
position)
position,
operability = wa_dto.AccountFullyOperable,
areTestNetworksEnabled,
prodPreferredChainIds,
testPreferredChainIds)
self.assets = assets
self.currencyBalance = currencyBalance
@ -44,10 +51,13 @@ QtObject:
walletType: string = "",
assets: token_model.Model = nil,
currencyBalance: CurrencyAmount = nil,
areTestNetworksEnabled: bool = false,
prodPreferredChainIds: string = "",
testPreferredChainIds: string = "",
position: int = 0,
): AccountItem =
new(result, delete)
result.setup(name, address, colorId, emoji, walletType, assets, currencyBalance, position)
result.setup(name, address, colorId, emoji, walletType, assets, currencyBalance, position, areTestNetworksEnabled, prodPreferredChainIds, testPreferredChainIds)
proc `$`*(self: AccountItem): string =
result = "WalletSection-Send-Item("
@ -72,4 +82,4 @@ QtObject:
return newQVariant(self.currencyBalance)
QtProperty[QVariant] currencyBalance:
read = getCurrencyBalanceAsQVariant
notify = currencyBalanceChanged
notify = currencyBalanceChanged

View File

@ -13,6 +13,7 @@ type
Assets,
CurrencyBalance,
Position,
PreferredSharingChainIds
QtObject:
type
@ -56,6 +57,7 @@ QtObject:
ModelRole.Assets.int: "assets",
ModelRole.CurrencyBalance.int: "currencyBalance",
ModelRole.Position.int: "position",
ModelRole.PreferredSharingChainIds.int: "preferredSharingChainIds"
}.toTable
proc setItems*(self: AccountsModel, items: seq[AccountItem]) =
@ -91,6 +93,8 @@ QtObject:
result = newQVariant(item.getAssetsAsQVariant())
of ModelRole.CurrencyBalance:
result = newQVariant(item.getCurrencyBalanceAsQVariant())
of ModelRole.PreferredSharingChainIds:
result = newQVariant(item.preferredSharingChainIds())
method getItemByIndex*(self: AccountsModel, index: int): AccountItem =
if index < 0 or index >= self.items.len:

View File

@ -101,3 +101,6 @@ proc transfer*(self: Controller, from_addr: string, to_addr: string, tokenSymbol
proc suggestedFees*(self: Controller, chainId: int): string =
let suggestedFees = self.transactionService.suggestedFees(chainId)
return suggestedFees.toJson()
proc areTestNetworksEnabled*(self: Controller): bool =
return self.walletAccountService.areTestNetworksEnabled()

View File

@ -62,6 +62,7 @@ method refreshWalletAccounts*(self: Module) =
let enabledChainIds = self.controller.getEnabledChainIds()
let currencyFormat = self.controller.getCurrencyFormat(currency)
let chainIds = self.controller.getChainIds()
let areTestNetworksEnabled = self.controller.areTestNetworksEnabled()
let items = walletAccounts.map(w => (block:
let tokenFormats = collect(initTable()):
@ -74,6 +75,7 @@ method refreshWalletAccounts*(self: Module) =
currency,
currencyFormat,
tokenFormats,
areTestNetworksEnabled,
)
))

View File

@ -11,7 +11,7 @@ logScope:
topics = "shared-keypairs"
proc buildKeyPairsList*(keypairs: seq[KeypairDto], excludeAlreadyMigratedPairs: bool,
excludePrivateKeyKeypairs: bool): seq[KeyPairItem] =
excludePrivateKeyKeypairs: bool, areTestNetworksEnabled: bool = false): seq[KeyPairItem] =
var items: seq[KeyPairItem]
for kp in keypairs:
if kp.accounts.len == 0:
@ -40,7 +40,7 @@ proc buildKeyPairsList*(keypairs: seq[KeypairDto], excludeAlreadyMigratedPairs:
if acc.emoji.len == 0:
icon = "wallet"
item.addAccount(newKeyPairAccountItem(acc.name, acc.path, acc.address, acc.publicKey, acc.emoji, acc.colorId,
icon, newCurrencyAmount(), balanceFetched = true, operability = acc.operable, acc.isWallet))
icon, newCurrencyAmount(), balanceFetched = true, operability = acc.operable, acc.isWallet, areTestNetworksEnabled, acc.prodPreferredChainIds, acc.testPreferredChainIds))
items.insert(item, 0) # Status Account must be at first place
continue
if kp.keypairType == KeypairTypeSeed:
@ -59,7 +59,7 @@ proc buildKeyPairsList*(keypairs: seq[KeypairDto], excludeAlreadyMigratedPairs:
if acc.emoji.len == 0:
icon = "wallet"
item.addAccount(newKeyPairAccountItem(acc.name, acc.path, acc.address, acc.publicKey, acc.emoji, acc.colorId,
icon, newCurrencyAmount(), balanceFetched = true, operability = acc.operable, acc.isWallet))
icon, newCurrencyAmount(), balanceFetched = true, operability = acc.operable, acc.isWallet, areTestNetworksEnabled, acc.prodPreferredChainIds, acc.testPreferredChainIds))
items.add(item)
continue
if kp.keypairType == KeypairTypeKey:
@ -80,7 +80,7 @@ proc buildKeyPairsList*(keypairs: seq[KeypairDto], excludeAlreadyMigratedPairs:
if acc.emoji.len == 0:
icon = "wallet"
item.addAccount(newKeyPairAccountItem(acc.name, acc.path, acc.address, acc.publicKey, acc.emoji, acc.colorId,
icon, newCurrencyAmount(), balanceFetched = true, operability = acc.operable, acc.isWallet))
icon, newCurrencyAmount(), balanceFetched = true, operability = acc.operable, acc.isWallet, areTestNetworksEnabled, acc.prodPreferredChainIds, acc.testPreferredChainIds))
items.add(item)
continue
if items.len == 0:

View File

@ -1,6 +1,6 @@
import tables, sequtils, sugar
import ../shared_models/[balance_item, currency_amount, token_item, token_model]
import ../shared_models/[balance_item, currency_amount, token_item, token_model, wallet_account_item]
import ../../../app_service/service/wallet_account/service as wallet_account_service
import ../../../app_service/service/currency/dto as currency_dto
@ -8,8 +8,6 @@ import ../../../app_service/service/currency/dto as currency_dto
import ../main/wallet_section/accounts/item as wallet_accounts_item
import ../main/wallet_section/assets/item as wallet_assets_item
import ../main/wallet_section/send/account_item as wallet_send_account_item
import ../main/profile_section/wallet/accounts/item as wallet_settings_accounts_item
import ../main/profile_section/wallet/accounts/[related_account_item, related_accounts_model]
proc currencyAmountToItem*(amount: float64, format: CurrencyFormatDto) : CurrencyAmount =
return newCurrencyAmount(
@ -26,36 +24,28 @@ proc balanceToItemBalanceItem*(b: BalanceDto, format: CurrencyFormatDto) : balan
b.chainId
)
proc walletAccountToRelatedAccountItem*(w: WalletAccountDto) : related_account_item.Item =
return related_account_item.initItem(
w.name,
w.colorId,
w.emoji,
)
proc walletAccountToWalletSettingsAccountsItem*(w: WalletAccountDto, keycardAccount: bool): wallet_settings_accounts_item.Item =
let relatedAccounts = related_accounts_model.newModel()
proc walletAccountToWalletAccountItem*(w: WalletAccountDto, keycardAccount: bool, areTestNetworksEnabled: bool): WalletAccountItem =
if w.isNil:
return wallet_settings_accounts_item.initItem()
return newWalletAccountItem()
relatedAccounts.setItems(w.relatedAccounts.map(x => walletAccountToRelatedAccountItem(x)))
return wallet_settings_accounts_item.initItem(
return newWalletAccountItem(
w.name,
w.address,
w.path,
w.colorId,
w.walletType,
w.emoji,
relatedAccounts,
w.walletType,
w.path,
w.keyUid,
keycardAccount,
w.position,
w.operable
w.operable,
areTestNetworksEnabled,
w.prodPreferredChainIds,
w.testPreferredChainIds
)
proc walletAccountToWalletAccountsItem*(w: WalletAccountDto, keycardAccount: bool, enabledChainIds: seq[int], currency: string,
currencyFormat: CurrencyFormatDto): wallet_accounts_item.Item =
currencyFormat: CurrencyFormatDto, areTestNetworksEnabled: bool): wallet_accounts_item.Item =
return wallet_accounts_item.initItem(
w.name,
w.address,
@ -69,7 +59,10 @@ proc walletAccountToWalletAccountsItem*(w: WalletAccountDto, keycardAccount: boo
w.position,
keycardAccount,
w.assetsLoading,
w.isWallet
w.isWallet,
areTestNetworksEnabled,
w.prodPreferredChainIds,
w.testPreferredChainIds
)
proc walletAccountToWalletAssetsItem*(w: WalletAccountDto): wallet_assets_item.Item =
@ -109,7 +102,7 @@ proc walletTokenToItem*(
)
proc walletAccountToWalletSendAccountItem*(w: WalletAccountDto, chainIds: seq[int], enabledChainIds: seq[int], currency: string,
currencyFormat: CurrencyFormatDto, tokenFormats: Table[string, CurrencyFormatDto]): wallet_send_account_item.AccountItem =
currencyFormat: CurrencyFormatDto, tokenFormats: Table[string, CurrencyFormatDto], areTestNetworksEnabled: bool): wallet_send_account_item.AccountItem =
let assets = token_model.newModel()
assets.setItems(
w.tokens.map(t => walletTokenToItem(t, chainIds, enabledChainIds, currency, currencyFormat, tokenFormats[t.symbol]))
@ -122,4 +115,7 @@ proc walletAccountToWalletSendAccountItem*(w: WalletAccountDto, chainIds: seq[in
w.walletType,
assets,
currencyAmountToItem(w.getCurrencyBalance(enabledChainIds, currency), currencyFormat),
areTestNetworksEnabled,
w.prodPreferredChainIds,
w.testPreferredChainIds
)

View File

@ -17,12 +17,16 @@ QtObject:
balance: CurrencyAmount
balanceFetched: bool
isDefaultAccount: bool
areTestNetworksEnabled: bool
prodPreferredChainIds: string
testPreferredChainIds: string
proc delete*(self: KeyPairAccountItem) =
self.QObject.delete
proc newKeyPairAccountItem*(name = "", path = "", address = "", pubKey = "", emoji = "", colorId = "", icon = "",
balance = newCurrencyAmount(), balanceFetched = true, operability = wa_dto.AccountFullyOperable, isDefaultAccount = false): KeyPairAccountItem =
balance = newCurrencyAmount(), balanceFetched = true, operability = wa_dto.AccountFullyOperable,
isDefaultAccount = false, areTestNetworksEnabled =false, prodPreferredChainIds = "", testPreferredChainIds = ""): KeyPairAccountItem =
new(result, delete)
result.QObject.setup
result.name = name
@ -36,6 +40,9 @@ QtObject:
result.balanceFetched = balanceFetched
result.operability = operability
result.isDefaultAccount = isDefaultAccount
result.areTestNetworksEnabled = areTestNetworksEnabled
result.prodPreferredChainIds = prodPreferredChainIds
result.testPreferredChainIds = testPreferredChainIds
proc `$`*(self: KeyPairAccountItem): string =
result = fmt"""KeyPairAccountItem[
@ -47,8 +54,11 @@ QtObject:
colorId: {self.colorId},
icon: {self.icon},
balance: {self.balance},
balanceFetched: {self.balanceFetched}
isDefaultAccount = {self.isDefaultAccount}
balanceFetched: {self.balanceFetched},
isDefaultAccount: {self.isDefaultAccount},
areTestNetworksEnabled: {self.areTestNetworksEnabled},
prodPreferredChainIds: {self.prodPreferredChainIds},
testPreferredChainIds: {self.testPreferredChainIds}
]"""
proc nameChanged*(self: KeyPairAccountItem) {.signal.}
@ -164,3 +174,19 @@ QtObject:
QtProperty[bool] isDefaultAccount:
read = getIsDefaultAccount
notify = isDefaultAccountChanged
proc preferredSharingChainIdsChanged*(self: KeyPairAccountItem) {.signal.}
proc preferredSharingChainIds*(self: KeyPairAccountItem): string {.slot.} =
if self.areTestNetworksEnabled:
return self.testPreferredChainIds
else :
return self.prodPreferredChainIds
proc setProdPreferredChainIds*(self: KeyPairAccountItem, value: string) =
self.prodPreferredChainIds = value
self.preferredSharingChainIdsChanged()
proc setTestPreferredChainIds*(self: KeyPairAccountItem, value: string) =
self.testPreferredChainIds = value
self.preferredSharingChainIdsChanged()
QtProperty[string] preferredSharingChainIds:
read = preferredSharingChainIds
notify = preferredSharingChainIdsChanged

View File

@ -114,7 +114,7 @@ QtObject:
self.removeItemAtIndex(i)
return
proc updateDetailsForAddressIfTheyAreSet*(self: KeyPairAccountModel, address, name, colorId, emoji: string) =
proc updateDetailsForAddressIfTheyAreSet*(self: KeyPairAccountModel, address, name, colorId, emoji, prodPreferredChainIds, testPreferredChainIds: string) =
for i in 0 ..< self.items.len:
if cmpIgnoreCase(self.items[i].getAddress(), address) == 0:
if name.len > 0:
@ -123,6 +123,10 @@ QtObject:
self.items[i].setColorId(colorId)
if emoji.len > 0:
self.items[i].setEmoji(emoji)
if prodPreferredChainIds.len > 0:
self.items[i].setProdPreferredChainIds(prodPreferredChainIds)
if testPreferredChainIds.len > 0:
self.items[i].setTestPreferredChainIds(testPreferredChainIds)
return
proc updateOperabilityForAddress*(self: KeyPairAccountModel, address: string, operability: string) =

View File

@ -248,8 +248,8 @@ QtObject:
return self.accounts.containsAccountPath(path)
proc containsPathOutOfTheDefaultStatusDerivationTree*(self: KeyPairItem): bool {.slot.} =
return self.accounts.containsPathOutOfTheDefaultStatusDerivationTree()
proc updateDetailsForAccountWithAddressIfTheyAreSet*(self: KeyPairItem, address, name, colorId, emoji: string) =
self.accounts.updateDetailsForAddressIfTheyAreSet(address, name, colorId, emoji)
proc updateDetailsForAccountWithAddressIfTheyAreSet*(self: KeyPairItem, address, name, colorId, emoji, prodPreferredChainIds, testPreferredChainIds: string) =
self.accounts.updateDetailsForAddressIfTheyAreSet(address, name, colorId, emoji, prodPreferredChainIds, testPreferredChainIds)
proc setBalanceForAddress*(self: KeyPairItem, address: string, balance: CurrencyAmount) =
self.accounts.setBalanceForAddress(address, balance)
proc updateOperabilityForAccountWithAddress*(self: KeyPairItem, address: string, operability: string) =

View File

@ -75,10 +75,10 @@ QtObject:
return self.items[i]
return nil
proc onUpdatedAccount*(self: KeyPairModel, keyUid, address, name, colorId, emoji: string) =
proc onUpdatedAccount*(self: KeyPairModel, keyUid, address, name, colorId, emoji, prodPreferredChainIds, testPreferredChainIds: string) =
for item in self.items:
if keyUid == item.getKeyUid():
item.getAccountsModel().updateDetailsForAddressIfTheyAreSet(address, name, colorId, emoji)
item.getAccountsModel().updateDetailsForAddressIfTheyAreSet(address, name, colorId, emoji, prodPreferredChainIds, testPreferredChainIds)
break
proc keypairNameExists*(self: KeyPairModel, name: string): bool =
@ -88,4 +88,4 @@ QtObject:
let item = self.findItemByKeyUid(keyUid)
if item.isNil:
return
item.setName(name)
item.setName(name)

View File

@ -15,6 +15,9 @@ QtObject:
keycardAccount: bool
position: int
operability: string
areTestNetworksEnabled: bool
prodPreferredChainIds: string
testPreferredChainIds: string
proc setup*(self: WalletAccountItem,
name: string = "",
@ -26,7 +29,10 @@ QtObject:
keyUid: string = "",
keycardAccount: bool = false,
position: int = 0,
operability: string = wa_dto.AccountFullyOperable
operability: string = wa_dto.AccountFullyOperable,
areTestNetworksEnabled: bool = false,
prodPreferredChainIds: string = "",
testPreferredChainIds: string = ""
) =
self.QObject.setup
self.name = name
@ -39,10 +45,43 @@ QtObject:
self.keycardAccount = keycardAccount
self.position = position
self.operability = operability
self.areTestNetworksEnabled = areTestNetworksEnabled
self.prodPreferredChainIds = prodPreferredChainIds
self.testPreferredChainIds = testPreferredChainIds
proc delete*(self: WalletAccountItem) =
self.QObject.delete
proc newWalletAccountItem*(
name: string = "",
address: string = "",
colorId: string = "",
emoji: string = "",
walletType: string = "",
path: string = "",
keyUid: string = "",
keycardAccount: bool = false,
position: int = 0,
operability: string = wa_dto.AccountFullyOperable,
areTestNetworksEnabled: bool = false,
prodPreferredChainIds: string = "",
testPreferredChainIds: string = ""): WalletAccountItem =
new(result, delete)
result.QObject.setup
result.name = name
result.address = address
result.colorId = colorId
result.emoji = emoji
result.walletType = walletType
result.path = path
result.keyUid = keyUid
result.keycardAccount = keycardAccount
result.position = position
result.operability = operability
result.areTestNetworksEnabled = areTestNetworksEnabled
result.prodPreferredChainIds = prodPreferredChainIds
result.testPreferredChainIds = testPreferredChainIds
proc `$`*(self: WalletAccountItem): string =
result = fmt"""WalletAccountItem(
name: {self.name},
@ -55,6 +94,9 @@ QtObject:
keycardAccount: {self.keycardAccount},
position: {self.position},
operability: {self.operability},
areTestNetworksEnabled: {self.areTestNetworksEnabled},
prodPreferredChainIds: {self.prodPreferredChainIds},
testPreferredChainIds: {self.testPreferredChainIds},
]"""
proc nameChanged*(self: WalletAccountItem) {.signal.}
@ -145,4 +187,14 @@ QtObject:
QtProperty[string] operability:
read = getOperability
write = setOperability
notify = operabilityChanged
notify = operabilityChanged
proc preferredSharingChainIdsChanged*(self: WalletAccountItem) {.signal.}
proc preferredSharingChainIds*(self: WalletAccountItem): string {.slot.} =
if self.areTestNetworksEnabled:
return self.testPreferredChainIds
else :
return self.prodPreferredChainIds
QtProperty[string] preferredSharingChainIds:
read = preferredSharingChainIds
notify = preferredSharingChainIdsChanged

View File

@ -167,9 +167,3 @@ QtObject:
self.items[i].removeAccountByAddress(acc)
if removeKeycardItemIfHasNoAccounts and self.items[i].getAccountsModel().getCount() == 0:
self.removeItem(i)
proc updateDetailsForAddressForKeyPairsWithKeyUid*(self: KeycardModel, keyUid: string, accAddress: string, accName: string,
accColor: string, accEmoji: string) =
for i in 0 ..< self.items.len:
if(self.items[i].getKeyUid() == keyUid):
self.items[i].updateDetailsForAccountWithAddressIfTheyAreSet(accAddress, accName, accColor, accEmoji)

View File

@ -99,7 +99,6 @@ type
isChat*: bool
tokens*: seq[WalletTokenDto]
emoji*: string
relatedAccounts*: seq[WalletAccountDto]
ens*: string
assetsLoading*: bool
hasBalanceCache*: bool
@ -108,6 +107,8 @@ type
operable*: string
createdAt*: int
position*: int
prodPreferredChainIDs*: string
testPreferredChainIDs*: string
proc toWalletAccountDto*(jsonObj: JsonNode): WalletAccountDto =
result = WalletAccountDto()
@ -127,6 +128,8 @@ proc toWalletAccountDto*(jsonObj: JsonNode): WalletAccountDto =
discard jsonObj.getProp("operable", result.operable)
discard jsonObj.getProp("createdAt", result.createdAt)
discard jsonObj.getProp("position", result.position)
discard jsonObj.getProp("prodPreferredChainIds", result.prodPreferredChainIds)
discard jsonObj.getProp("testPreferredChainIds", result.testPreferredChainIds)
result.assetsLoading = true
result.hasBalanceCache = false
result.hasMarketValuesCache = false
@ -147,6 +150,8 @@ proc `$`*(self: WalletAccountDto): string =
hasMarketValuesCache: {self.hasMarketValuesCache},
removed: {self.removed}
operable: {self.operable}
prodPreferredChainIds: {self.prodPreferredChainIds}
testPreferredChainIds: {self.testPreferredChainIds}
]"""
proc getCurrencyBalance*(self: BalanceDto, currencyPrice: float64): float64 =

View File

@ -227,21 +227,7 @@ QtObject:
error "error: ", errDesription
return
proc setRelatedAccountsToAccount(self: Service, account: WalletAccountDto) =
let keypair = self.getKeypairByKeyUid(account.keyUid)
if keypair.isNil:
return
account.relatedAccounts = keypair.accounts
proc setRelatedAccountsForAllAccounts(self: Service, keyUid: string) =
for wAcc in self.walletAccounts.mvalues:
if wAcc.keyUid == keyUid:
self.setRelatedAccountsToAccount(wAcc)
proc storeAccount(self: Service, account: WalletAccountDto, updateRelatedAccounts = true) =
if updateRelatedAccounts:
# updating related accounts for already added accounts
self.setRelatedAccountsForAllAccounts(account.keyUid)
proc storeAccount(self: Service, account: WalletAccountDto) =
# add new account to store
self.walletAccounts[account.address] = account
@ -342,7 +328,6 @@ QtObject:
for account in accounts:
let account = account # TODO https://github.com/nim-lang/Nim/issues/16740
self.setEnsName(account)
self.setRelatedAccountsToAccount(account)
self.storeAccount(account)
self.buildAllTokens(self.getAddresses(), store = true)
@ -426,7 +411,6 @@ QtObject:
return
self.setEnsName(newAccount)
self.setRelatedAccountsToAccount(newAccount)
self.storeAccount(newAccount)
self.buildAllTokens(@[newAccount.address], store = true)
@ -438,8 +422,6 @@ QtObject:
return
let removedAcc = self.walletAccounts[address]
self.walletAccounts.del(address)
# updating related accounts for other accounts
self.setRelatedAccountsForAllAccounts(removedAcc.keyUid)
if notify:
self.events.emit(SIGNAL_WALLET_ACCOUNT_DELETED, AccountArgs(account: removedAcc))
@ -450,24 +432,28 @@ QtObject:
if localAcc.isNil:
continue
localAcc.position = dbAcc.position
self.storeAccount(localAcc, updateRelatedAccounts = false)
self.storeAccount(localAcc)
proc updateAccountInLocalStoreAndNotify(self: Service, address, name, colorId, emoji: string,
positionUpdated: Option[bool] = none(bool), notify: bool = true) =
positionUpdated: Option[bool] = none(bool), prodPreferredChains: string = "", testPreferredChains: string = "", notify: bool = true) =
if address.len > 0:
if not self.walletAccountsContainsAddress(address):
return
var account = self.getAccountByAddress(address)
if account.isNil:
return
if name.len > 0 or colorId.len > 0 or emoji.len > 0:
if name.len > 0 or colorId.len > 0 or emoji.len > 0 or prodPreferredChains.len > 0 or testPreferredChains.len > 0:
if name.len > 0 and name != account.name:
account.name = name
if colorId.len > 0 and colorId != account.colorId:
account.colorId = colorId
if emoji.len > 0 and emoji != account.emoji:
account.emoji = emoji
self.storeAccount(account, updateRelatedAccounts = false)
if testPreferredChains.len > 0 and testPreferredChains != account.testPreferredChainIds:
account.testPreferredChainIds = testPreferredChains
if prodPreferredChains.len > 0 and prodPreferredChains != account.prodPreferredChainIds:
account.prodPreferredChainIds = prodPreferredChains
self.storeAccount(account)
if notify:
self.events.emit(SIGNAL_WALLET_ACCOUNT_UPDATED, AccountArgs(account: account))
else:
@ -594,7 +580,7 @@ QtObject:
try:
var account = self.getAccountByAddress(address)
let response = status_go_accounts.updateAccount(accountName, account.address, account.path, account.publicKey,
account.keyUid, account.walletType, colorId, emoji, account.isWallet, account.isChat)
account.keyUid, account.walletType, colorId, emoji, account.isWallet, account.isChat, account.prodPreferredChainIds, account.testPreferredChainIds)
if not response.error.isNil:
error "status-go error", procName="updateWalletAccount", errCode=response.error.code, errDesription=response.error.message
return false
@ -604,6 +590,40 @@ QtObject:
error "error: ", procName="updateWalletAccount", errName=e.name, errDesription=e.msg
return false
proc updateWalletAccountProdPreferredChains*(self: Service, address, preferredChainIds: string): bool =
if not self.walletAccountsContainsAddress(address):
error "account's address is not among known addresses: ", address=address
return false
try:
var account = self.getAccountByAddress(address)
let response = status_go_accounts.updateAccount(account.name, account.address, account.path, account.publicKey,
account.keyUid, account.walletType, account.colorId, account.emoji, account.isWallet, account.isChat, preferredChainIds, account.testPreferredChainIds)
if not response.error.isNil:
error "status-go error", procName="updateWalletAccount", errCode=response.error.code, errDesription=response.error.message
return false
self.updateAccountInLocalStoreAndNotify(address, name ="", colorId = "", emoji = "", positionUpdated = none(bool), prodPreferredChains = preferredChainIds, testPreferredChains = "")
return true
except Exception as e:
error "error: ", procName="updateWalletAccount", errName=e.name, errDesription=e.msg
return false
proc updateWalletAccountTestPreferredChains*(self: Service, address, preferredChainIds: string): bool =
if not self.walletAccountsContainsAddress(address):
error "account's address is not among known addresses: ", address=address
return false
try:
var account = self.getAccountByAddress(address)
let response = status_go_accounts.updateAccount(account.name, account.address, account.path, account.publicKey,
account.keyUid, account.walletType, account.colorId, account.emoji, account.isWallet, account.isChat, account.prodPreferredChainIds, preferredChainIds)
if not response.error.isNil:
error "status-go error", procName="updateWalletAccount", errCode=response.error.code, errDesription=response.error.message
return false
self.updateAccountInLocalStoreAndNotify(address, name ="", colorId = "", emoji = "", positionUpdated = none(bool), prodPreferredChains = "", testPreferredChains = preferredChainIds)
return true
except Exception as e:
error "error: ", procName="updateWalletAccount", errName=e.name, errDesription=e.msg
return false
proc moveAccountFinally*(self: Service, fromPosition: int, toPosition: int) =
var updated = false
try:
@ -1000,7 +1020,7 @@ QtObject:
else:
if self.walletAccountsContainsAddress(account.address):
self.updateAccountInLocalStoreAndNotify(account.address, account.name, account.colorId, account.emoji,
none(bool), notify)
none(bool), account.prodPreferredChainIDs, account.testPreferredChainIDs, notify)
else:
self.addNewAccountToLocalStoreAndNotify(notify)
@ -1061,3 +1081,6 @@ proc getEnabledChainIds*(self: Service): seq[int] =
proc getCurrencyFormat*(self: Service, symbol: string): CurrencyFormatDto =
return self.currencyService.getCurrencyFormat(symbol)
proc areTestNetworksEnabled*(self: Service): bool =
return self.settingsService.areTestNetworksEnabled()

View File

@ -102,7 +102,7 @@ proc addAccountWithoutKeystoreFileCreation*(name, address, path, publicKey, keyU
## Updates either regular or keycard account, without interaction to a Keystore file and notifies paired devices
proc updateAccount*(name, address, path: string, publicKey, keyUid, accountType, colorId, emoji: string,
walletDefaultAccount: bool, chatDefaultAccount: bool):
walletDefaultAccount: bool, chatDefaultAccount: bool, prodPreferredChainIds, testPreferredChainIds: string):
RpcResponse[JsonNode] {.raises: [Exception].} =
let payload = %* [
{
@ -116,6 +116,8 @@ proc updateAccount*(name, address, path: string, publicKey, keyUid, accountType,
"name": name,
"emoji": emoji,
"colorId": colorId,
"prodPreferredChainIds": prodPreferredChainIds,
"testPreferredChainIds": testPreferredChainIds
#"hidden" present on the status-go side, but we don't use it
#"clock" we leave this empty, set on the status-go side
#"removed" present on the status-go side, used for synchronization, no need to set it here

View File

@ -40,7 +40,8 @@ SplitView {
stripTrailingZeroes: false}),
isAllAccounts: false,
includeWatchOnly: false,
path: "m/44/60/0/0/34"
path: "m/44/60/0/0/34",
preferredSharingChainIds: walletStore.areTestNetworksEnabled ? "5:420:421613": "1:10:42161"
})
}
@ -49,22 +50,28 @@ SplitView {
}
readonly property QtObject walletStore: QtObject {
property var allNetworks: enabledNetworks
property var layer1Networks: NetworksModel.layer1Networks
property var layer2Networks: NetworksModel.layer2Networks
property var testNetworks: NetworksModel.testNetworks
property var enabledNetworks: NetworksModel.enabledNetworks
property var networks: NetworksModel.mainNetworks
property bool areTestNetworksEnabled: areTestNetworksEnabledCheckbox.checked
function toggleNetwork(chainId) {
}
function getAllNetworksSupportedPrefix(hovered) {
return hovered ? "<font color=\"" + "#627EEA" + "\">" + "eth:" + "</font>" +
"<font color=\"" + "#E90101" + "\">" + "opt:" + "</font>" +
"<font color=\"" + "#27A0EF" + "\">" + "arb:" + "</font>" : "eth:opt:arb:"
function getNetworkShortNames() {
return "eth:opt:arb:"
}
function getAllNetworksChainIds() {
return "1:10:42161"
}
function updateWalletAccountPreferredChains(address, preferredChainIds) {
console.warn("updateWalletAccountPreferredChains :: address ::", address, "preferredChainIds :: ", preferredChainIds)
}
function processPreferredSharingNetworkToggle(preferredSharingNetworksArray, network) {
console.warn("processPreferredSharingNetworkToggle :: preferredSharingNetworksArray ::", preferredSharingNetworksArray, "network :: ", network)
}
}
property var keyPairModel: WalletKeyPairModel {}
}
@ -82,4 +89,17 @@ SplitView {
keyPair: d.keyPairModel.data[0].keyPair
}
}
LogsAndControlsPanel {
id: logsAndControlsPanel
SplitView.minimumHeight: 100
SplitView.preferredHeight: 200
CheckBox {
id: areTestNetworksEnabledCheckbox
text: "areTestNetworksEnabled"
checked: false
}
}
}

View File

@ -30,7 +30,6 @@ SplitView {
isAssetView: isAssetBox.checked
layer1Networks: NetworksModel.layer1Networks
layer2Networks: NetworksModel.layer2Networks
testNetworks: NetworksModel.testNetworks
enabledNetworks: NetworksModel.enabledNetworks
allNetworks: enabledNetworks
accounts: WalletAccountsModel {}

View File

@ -47,7 +47,6 @@ SplitView {
layer1Networks: NetworksModel.layer1Networks
layer2Networks: NetworksModel.layer2Networks
testNetworks: NetworksModel.testNetworks
enabledNetworks: NetworksModel.enabledNetworks
allNetworks: enabledNetworks
accounts: WalletAccountsModel {}

View File

@ -83,7 +83,6 @@ SplitView {
privilegedModelChecked.checked ? privilegedTokensModel : mintedTokensModel
layer1Networks: NetworksModel.layer1Networks
layer2Networks: NetworksModel.layer2Networks
testNetworks: NetworksModel.testNetworks
enabledNetworks: NetworksModel.enabledNetworks
allNetworks: enabledNetworks
accounts: WalletAccountsModel {}

View File

@ -36,7 +36,6 @@ SplitView {
layer1Networks: NetworksModel.layer1Networks
layer2Networks: NetworksModel.layer2Networks
testNetworks: NetworksModel.testNetworks
enabledNetworks: NetworksModel.enabledNetworks
allNetworks: enabledNetworks

View File

@ -51,11 +51,6 @@ SplitView {
filters: [ValueFilter { roleName: "layer"; value: 2; },
ValueFilter { roleName: "isTest"; value: false; }]
}
testNetworks: SortFilterProxyModel {
sourceModel: simulatedNimModel
filters: [ValueFilter { roleName: "layer"; value: 2; },
ValueFilter { roleName: "isTest"; value: true; }]
}
enabledNetworks: SortFilterProxyModel {
sourceModel: simulatedNimModel
filters: ValueFilter { roleName: "isEnabled"; value: true; }
@ -84,7 +79,6 @@ SplitView {
layer1Networks: networkFilter.layer1Networks
layer2Networks: networkFilter.layer2Networks
testNetworks: networkFilter.testNetworks
useEnabledRole: false
@ -129,7 +123,6 @@ SplitView {
sourceComponent: NetworkSelectPopup {
layer1Networks: networkFilter.layer1Networks
layer2Networks: networkFilter.layer2Networks
testNetworks: networkFilter.testNetworks
singleSelection {
enabled: true

View File

@ -85,7 +85,6 @@ SplitView {
property var allNetworks: enabledNetworks
property var layer1Networks: NetworksModel.layer1Networks
property var layer2Networks: NetworksModel.layer2Networks
property var testNetworks: NetworksModel.testNetworks
property var enabledNetworks: NetworksModel.enabledNetworks
function toggleNetwork(chainId) {
}

View File

@ -9,7 +9,7 @@ QtObject {
readonly property int arbitrumNet: 3
readonly property int hermezNet: 4
readonly property int testnetNet: 5
readonly property int customNet: 6
readonly property int customNet: 6
readonly property var layer1Networks: ListModel {
function rowData(index, propName) {
@ -263,4 +263,42 @@ QtObject {
}]
)
}
readonly property var mainNetworks: ListModel {
Component.onCompleted: append([
{
chainId: 1,
chainName: "Ethereum Mainnet",
iconUrl: ModelsData.networks.ethereum,
isActive: true,
isEnabled: true,
shortName: "ETH",
chainColor: "blue",
layer: 1,
isTest: false
},
{
chainId: 10,
chainName: "Optimism",
iconUrl: ModelsData.networks.optimism,
isActive: false,
isEnabled: true,
shortName: "OPT",
chainColor: "red",
layer: 2,
isTest: false
},
{
chainId: 42161,
chainName: "Arbitrum",
iconUrl: ModelsData.networks.arbitrum,
isActive: false,
isEnabled: true,
shortName: "ARB",
chainColor: "purple",
layer: 2,
isTest: false
}
])
}
}

View File

@ -56,7 +56,6 @@ StackView {
// Network related properties:
property var layer1Networks
property var layer2Networks
property var testNetworks
property var enabledNetworks
property var allNetworks
@ -240,8 +239,7 @@ StackView {
layer1Networks: root.layer1Networks
layer2Networks: root.layer2Networks
testNetworks: root.testNetworks
enabledNetworks: root.testNetworks
enabledNetworks: root.enabledNetworks
allNetworks: root.allNetworks
accounts: root.accounts
@ -353,7 +351,6 @@ StackView {
viewWidth: root.viewWidth
layer1Networks: root.layer1Networks
layer2Networks: root.layer2Networks
testNetworks: root.testNetworks
enabledNetworks: root.enabledNetworks
allNetworks: root.allNetworks
accounts: root.accounts

View File

@ -342,7 +342,6 @@ StatusSectionLayout {
tokensModelWallet: root.rootStore.tokensModelWallet
layer1Networks: communityTokensStore.layer1Networks
layer2Networks: communityTokensStore.layer2Networks
testNetworks: communityTokensStore.testNetworks
enabledNetworks: communityTokensStore.enabledNetworks
allNetworks: communityTokensStore.allNetworks
accounts: root.rootStore.accounts

View File

@ -42,7 +42,6 @@ StatusScrollView {
// Network related properties:
property var layer1Networks
property var layer2Networks
property var testNetworks
property var enabledNetworks
property var allNetworks
@ -522,7 +521,6 @@ StatusScrollView {
allNetworks: root.allNetworks
layer1Networks: root.layer1Networks
layer2Networks: root.layer2Networks
testNetworks: root.testNetworks
enabledNetworks: root.enabledNetworks
multiSelection: false

View File

@ -30,7 +30,6 @@ StatusScrollView {
// Network related properties:
property var layer1Networks
property var layer2Networks
property var testNetworks
property var enabledNetworks
property var allNetworks
@ -318,7 +317,6 @@ StatusScrollView {
allNetworks: root.allNetworks
layer1Networks: root.layer1Networks
layer2Networks: root.layer2Networks
testNetworks: root.testNetworks
enabledNetworks: root.enabledNetworks
multiSelection: false

View File

@ -13,7 +13,7 @@ StatusListItem {
id: root
property var account
property string chainShortNames
property var getNetworkShortNames: function(chainIds){}
property int totalCount: 0
signal goToAccountView()
@ -22,6 +22,7 @@ StatusListItem {
title: account.name
subTitle: {
const elidedAddress = StatusQUtils.Utils.elideText(account.address,6,4)
let chainShortNames = root.getNetworkShortNames(model.account.preferredSharingChainIds)
return sensor.containsMouse ? WalletUtils.colorizedChainPrefix(chainShortNames) + Utils.richColorText(elidedAddress, Theme.palette.directColor1) : chainShortNames + elidedAddress
}
asset.color: !!account.colorId ? Utils.getColorForId(account.colorId): ""

View File

@ -13,7 +13,7 @@ Rectangle {
id: root
property var keyPair
property string chainShortNames
property var getNetworkShortNames: function(chainIds){}
property string userProfilePublicKey
property bool includeWatchOnlyAccount
@ -154,7 +154,7 @@ Rectangle {
width: ListView.view.width
account: model.account
totalCount: ListView.view.count
chainShortNames: root.chainShortNames
getNetworkShortNames: root.getNetworkShortNames
onGoToAccountView: root.goToAccountView(model.account)
}
}

View File

@ -11,6 +11,7 @@ QtObject {
property var accountSensitiveSettings: Global.appIsReady? localAccountSensitiveSettings : null
readonly property bool areTestNetworksEnabled: networksModule.areTestNetworksEnabled
readonly property var networks: networksModule.networks
readonly property var combinedNetworks: networksModule.combinedNetworks
property var selectedAccount
@ -48,8 +49,8 @@ QtObject {
root.accountsModule.moveAccountFinally(from, to)
}
function getAllNetworksSupportedPrefix() {
return networksModule.getAllNetworksSupportedPrefix()
function getAllNetworksChainIds() {
return networksModule.getAllNetworksChainIds()
}
function runAddAccountPopup() {
@ -63,4 +64,40 @@ QtObject {
function updateNetworkEndPointValues(chainId, newMainRpcInput, newFailoverRpcUrl) {
networksModule.updateNetworkEndPointValues(chainId, newMainRpcInput, newFailoverRpcUrl)
}
function updateWalletAccountPreferredChains(address, preferredChainIds) {
if(areTestNetworksEnabled) {
accountsModule.updateWalletAccountTestPreferredChains(address, preferredChainIds)
}
else {
accountsModule.updateWalletAccountProdPreferredChains(address, preferredChainIds)
}
}
function getNetworkShortNames(chainIds) {
return networksModule.getNetworkShortNames(chainIds)
}
function processPreferredSharingNetworkToggle(preferredSharingNetworks, toggledNetwork) {
let prefChains = preferredSharingNetworks
if(prefChains.length === networks.count) {
prefChains = [toggledNetwork.chainId.toString()]
}
else if(!prefChains.includes(toggledNetwork.chainId.toString())) {
prefChains.push(toggledNetwork.chainId.toString())
}
else {
if(prefChains.length === 1) {
prefChains = getAllNetworksChainIds().split(":")
}
else {
for(var i = 0; i < prefChains.length;i++) {
if(prefChains[i] === toggledNetwork.chainId.toString()) {
prefChains.splice(i, 1)
}
}
}
}
return prefChains
}
}

View File

@ -8,11 +8,14 @@ import StatusQ.Core.Theme 0.1
import StatusQ.Core.Utils 0.1 as StatusQUtils
import AppLayouts.Wallet 1.0
import AppLayouts.Wallet.controls 1.0
import shared.popups 1.0
import shared.panels 1.0
import utils 1.0
import SortFilterProxyModel 0.2
import "../../popups"
import "../../controls"
@ -29,8 +32,11 @@ ColumnLayout {
QtObject {
id: d
property bool watchOnlyAccount: keyPair && keyPair.pairType === Constants.keycard.keyPairType.watchOnly
property bool privateKeyAccount: keyPair && keyPair.pairType === Constants.keycard.keyPairType.privateKeyImport
readonly property bool watchOnlyAccount: keyPair && keyPair.pairType ? keyPair.pairType === Constants.keycard.keyPairType.watchOnly: false
readonly property bool privateKeyAccount: keyPair && keyPair.pairType ? keyPair.pairType === Constants.keycard.keyPairType.privateKeyImport: false
readonly property string preferredSharingNetworks: !!account ? account.preferredSharingChainIds: ""
property var preferredSharingNetworksArray: preferredSharingNetworks.split(":").filter(Boolean)
onPreferredSharingNetworksChanged: preferredSharingNetworksArray = preferredSharingNetworks.split(":").filter(Boolean)
}
spacing: 0
@ -100,7 +106,7 @@ ColumnLayout {
title: qsTr("Address")
subTitle: {
let address = root.account && root.account.address ? root.account.address: ""
d.watchOnlyAccount ? address : WalletUtils.colorizedChainPrefix(walletStore.getAllNetworksSupportedPrefix()) + address
return WalletUtils.colorizedChainPrefix(walletStore.getNetworkShortNames(d.preferredSharingNetworks)) + address
}
}
Separator {
@ -158,7 +164,7 @@ ColumnLayout {
Layout.fillWidth: true
title: qsTr("Derivation Path")
subTitle: root.account ? Utils.getPathForDisplay(root.account.path) : ""
visible: !!subTitle && !d.privateKeyAccount
visible: !!subTitle && !d.privateKeyAccount && !d.watchOnlyAccount
}
Separator {
Layout.fillWidth: true
@ -181,45 +187,67 @@ ColumnLayout {
color: Theme.palette.baseColor2
}
RowLayout {
StatusListItem {
Layout.fillWidth: true
title: qsTr("Preferred networks when sharing this address")
color: Theme.palette.transparent
components: [
NetworkFilter {
layer1Networks: SortFilterProxyModel {
sourceModel: root.walletStore.networks
filters: ValueFilter { roleName: "layer"; value: 1; }
}
layer2Networks: SortFilterProxyModel {
sourceModel: root.walletStore.networks
filters: ValueFilter { roleName: "layer"; value: 2; }
}
allNetworks: root.walletStore.networks
enabledNetworks: SortFilterProxyModel {
sourceModel: root.walletStore.networks
filters: ExpressionFilter {
expression: d.preferredSharingNetworksArray.includes(model.chainId.toString())
}
}
preferredNetworksMode: true
preferredSharingNetworks: d.preferredSharingNetworksArray
onToggleNetwork: (network) => {
d.preferredSharingNetworksArray = root.walletStore.processPreferredSharingNetworkToggle(d.preferredSharingNetworksArray, network)
}
control.popup.onClosed: root.walletStore.updateWalletAccountPreferredChains(root.account.address, d.preferredSharingNetworksArray.join(":"))
}
]
}
Separator {
Layout.fillWidth: true
Layout.preferredHeight: 1
color: Theme.palette.baseColor2
}
StatusButton {
Layout.topMargin: 20
Layout.fillWidth: true
spacing: 8
StatusButton {
Layout.fillWidth: true
visible: !d.watchOnlyAccount && !d.privateKeyAccount
text: keyPair && keyPair.migratedToKeycard? qsTr("Stop using Keycard") : qsTr("Migrate to Keycard")
icon.name: "keycard"
onClicked: {
if (keyPair && keyPair.migratedToKeycard)
console.warn("TODO: stop using Keycard")
else
console.warn("TODO: move keys to a Keycard")
}
}
StatusButton {
Layout.fillWidth: true
objectName: "deleteAccountButton"
visible: !!root.account && !root.account.isDefaultAccount
text: qsTr("Remove account")
icon.name: "delete"
type: StatusBaseButton.Type.Danger
onClicked: confirmationPopup.open()
objectName: "deleteAccountButton"
visible: !!root.account && !root.account.isDefaultAccount
text: qsTr("Remove account")
icon.name: "delete"
type: StatusBaseButton.Type.Danger
onClicked: confirmationPopup.open()
ConfirmationDialog {
id: confirmationPopup
confirmButtonObjectName: "confirmDeleteAccountButton"
headerSettings.title: qsTr("Confirm %1 Removal").arg(root.account ? root.account.name : "")
confirmationText: qsTr("You will not be able to restore viewing access to this account in the future unless you enter this accounts address again.")
confirmButtonLabel: qsTr("Remove Account")
onConfirmButtonClicked: {
root.walletStore.deleteAccount(root.account.address);
confirmationPopup.close()
root.goBack()
}
ConfirmationDialog {
id: confirmationPopup
confirmButtonObjectName: "confirmDeleteAccountButton"
headerSettings.title: qsTr("Confirm %1 Removal").arg(root.account ? root.account.name : "")
confirmationText: qsTr("You will not be able to restore viewing access to this account in the future unless you enter this accounts address again.")
confirmButtonLabel: qsTr("Remove Account")
onConfirmButtonClicked: {
root.walletStore.deleteAccount(root.account.address);
confirmationPopup.close()
root.goBack()
}
}
}
Component {
id: renameAccountModalComponent
RenameAccontModal {

View File

@ -101,7 +101,7 @@ Column {
delegate: WalletKeyPairDelegate {
width: parent.width
keyPair: model.keyPair
chainShortNames: walletStore.getAllNetworksSupportedPrefix()
getNetworkShortNames: walletStore.getNetworkShortNames
userProfilePublicKey: walletStore.userProfilePublicKey
includeWatchOnlyAccount: walletStore.includeWatchOnlyAccount
onGoToAccountView: root.goToAccountView(account, keyPair)

View File

@ -17,9 +17,10 @@ StatusComboBox {
required property var allNetworks
required property var layer1Networks
required property var layer2Networks
required property var testNetworks
required property var enabledNetworks
property bool multiSelection: true
property bool preferredNetworksMode: false
property var preferredSharingNetworks: []
/// \c network is a network.model.nim entry
/// It is called for every toggled network if \c multiSelection is \c true
@ -37,9 +38,6 @@ StatusComboBox {
} else if(!!root.layer2Networks && ModelUtils.contains(root.layer2Networks, "chainId", chainId)) {
d.currentModel = root.layer2Networks
chainIdExists = true
} else if(!!root.testNetworks && ModelUtils.contains(root.testNetworks, "chainId", chainId)) {
d.currentModel = root.testNetworks
chainIdExists = true
}
}
@ -65,6 +63,7 @@ StatusComboBox {
readonly property string selectedIconUrl: ModelUtils.get(d.currentModel, d.currentIndex, "iconUrl") ?? ""
readonly property bool allSelected: (!!root.enabledNetworks && !!root.allNetworks) ? root.enabledNetworks.count === root.allNetworks.count :
false
readonly property bool noneSelected: (!!root.enabledNetworks) ? root.enabledNetworks.count === 0 : false
// Persist selection between selectPopupLoader reloads
property var currentModel: layer1Networks
@ -108,7 +107,7 @@ StatusComboBox {
lineHeight: 24
lineHeightMode: Text.FixedHeight
verticalAlignment: Text.AlignVCenter
text: root.multiSelection ? (d.allSelected ? qsTr("All networks") : "") : d.selectedChainName
text: root.multiSelection ? (d.noneSelected ? qsTr("Select networks"): d.allSelected ? qsTr("All networks") : "") : d.selectedChainName
color: Theme.palette.baseColor1
visible: !!text
}
@ -132,7 +131,8 @@ StatusComboBox {
control.popup.contentItem: NetworkSelectionView {
layer1Networks: root.layer1Networks
layer2Networks: root.layer2Networks
testNetworks: root.testNetworks
preferredSharingNetworks: root.preferredSharingNetworks
preferredNetworksMode: root.preferredNetworksMode
implicitWidth: contentWidth
implicitHeight: contentHeight

View File

@ -16,6 +16,11 @@ StatusListItem {
property var radioButtonGroup
property bool useEnabledRole: true
// Needed for preferred sharing networks
property bool preferredNetworksMode: false
property var preferredSharingNetworks: []
property bool allChecked: true
signal toggleNetwork(var network, var model, int index)
/// Mirrors Nim's UxEnabledState enum from networks/item.nim
@ -47,7 +52,10 @@ StatusListItem {
visible: !root.singleSelection.enabled
checkState: {
if(root.useEnabledRole) {
if(root.preferredNetworksMode) {
return root.allChecked ? Qt.PartiallyChecked : preferredSharingNetworks.includes(model.chainId.toString()) ? Qt.Checked : Qt.Unchecked
}
else if(root.useEnabledRole) {
return model.isEnabled ? Qt.Checked : Qt.Unchecked
} else if(model.enabledState === NetworkSelectItemDelegate.Enabled) {
return Qt.Checked

View File

@ -116,7 +116,6 @@ Item {
allNetworks: walletStore.allNetworks
layer1Networks: walletStore.layer1Networks
layer2Networks: walletStore.layer2Networks
testNetworks: walletStore.testNetworks
enabledNetworks: walletStore.enabledNetworks
onToggleNetwork: (network) => {

View File

@ -14,20 +14,10 @@ import "../views"
StatusDialog {
id: root
modal: false
standardButtons: Dialog.NoButton
anchors.centerIn: undefined
padding: 4
width: 360
implicitHeight: Math.min(432, scrollView.contentHeight + root.padding * 2)
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
required property var layer1Networks
required property var layer2Networks
property var testNetworks: null
property var preferredSharingNetworks: []
property bool preferredNetworksMode: false
/// Grouped properties for single selection state. \c singleSelection.enabled is \c false by default
/// \see SingleSelectionInfo
@ -47,6 +37,17 @@ StatusDialog {
property SingleSelectionInfo singleSelection: SingleSelectionInfo {}
}
modal: false
standardButtons: Dialog.NoButton
anchors.centerIn: undefined
padding: 4
width: 360
implicitHeight: Math.min(432, scrollView.contentHeight + root.padding * 2)
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
background: Rectangle {
radius: Style.current.radius
color: Style.current.background
@ -67,7 +68,8 @@ StatusDialog {
anchors.fill: parent
layer1Networks: root.layer1Networks
layer2Networks: root.layer2Networks
testNetworks: root.testNetworks
preferredNetworksMode: root.preferredNetworksMode
preferredSharingNetworks: root.preferredSharingNetworks
useEnabledRole: root.useEnabledRole
singleSelection: d.singleSelection
onToggleNetwork: {

View File

@ -32,6 +32,7 @@ StatusModal {
QtObject {
id: d
property string completeAddressWithNetworkPrefix
property var preferredSharingNetworksArray: !!RootStore.selectedReceiveAccount ? RootStore.selectedReceiveAccount.preferredSharingChainIds.split(":").filter(Boolean): []
}
headerSettings.title: qsTr("Receive")
@ -48,8 +49,8 @@ StatusModal {
sorters: RoleSorter { roleName: "position"; sortOrder: Qt.AscendingOrder }
}
selectedAccount: RootStore.selectedReceiveAccount
getNetworkShortNames: RootStore.getNetworkShortNames
onSelectedIndexChanged: RootStore.switchReceiveAccount(selectedIndex)
}
@ -99,7 +100,7 @@ StatusModal {
tagPrimaryLabel.text: model.shortName
tagPrimaryLabel.color: model.chainColor
image.source: Style.svg("tiny/" + model.iconUrl)
visible: model.isEnabled
visible: d.preferredSharingNetworksArray.includes(model.chainId.toString())
MouseArea {
anchors.fill: parent
cursorShape: root.readOnly ? Qt.ArrowCursor : Qt.PointingHandCursor
@ -209,7 +210,7 @@ StatusModal {
font.pixelSize: 15
color: chainColor
text: shortName + ":"
visible: model.isEnabled
visible: d.preferredSharingNetworksArray.includes(model.chainId.toString())
onVisibleChanged: {
if (root.readOnly)
return
@ -258,12 +259,18 @@ StatusModal {
layer1Networks: layer1NetworksClone
layer2Networks: layer2NetworksClone
preferredNetworksMode: true
preferredSharingNetworks: d.preferredSharingNetworksArray
useEnabledRole: false
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
onToggleNetwork: (network, networkModel, index) => {
network.isEnabled = !network.isEnabled
}
d.preferredSharingNetworksArray = RootStore.processPreferredSharingNetworkToggle( d.preferredSharingNetworksArray, network)
}
onClosed: RootStore.updateWalletAccountPreferredChains(root.address, d.preferredSharingNetworksArray.join(":"))
CloneModel {
id: layer1NetworksClone

View File

@ -88,7 +88,6 @@ QtObject {
property var layer1Networks: networksModule.layer1
property var layer2Networks: networksModule.layer2
property var testNetworks: networksModule.test
property var enabledNetworks: networksModule.enabled
property var allNetworks: networksModule.all
onAllNetworksChanged: {
@ -234,4 +233,44 @@ QtObject {
function toggleWatchOnlyAccounts() {
walletSection.toggleWatchOnlyAccounts()
}
function getAllNetworksChainIds() {
return networksModule.getAllNetworksChainIds()
}
function getNetworkShortNames(chainIds) {
return networksModule.getNetworkShortNames(chainIds)
}
function updateWalletAccountPreferredChains(address, preferredChainIds) {
if(areTestNetworksEnabled) {
walletSectionAccounts.updateWalletAccountTestPreferredChains(address, preferredChainIds)
}
else {
walletSectionAccounts.updateWalletAccountProdPreferredChains(address, preferredChainIds)
}
}
function processPreferredSharingNetworkToggle(preferredSharingNetworks, toggledNetwork) {
let prefChains = preferredSharingNetworks
if(prefChains.length === allNetworks.count) {
prefChains = [toggledNetwork.chainId.toString()]
}
else if(!prefChains.includes(toggledNetwork.chainId.toString())) {
prefChains.push(toggledNetwork.chainId.toString())
}
else {
if(prefChains.length === 1) {
prefChains = getAllNetworksChainIds().split(":")
}
else {
for(var i = 0; i < prefChains.length;i++) {
if(prefChains[i] === toggledNetwork.chainId.toString()) {
prefChains.splice(i, 1)
}
}
}
}
return prefChains
}
}

View File

@ -4,6 +4,8 @@ import QtQuick.Controls 2.15
import StatusQ.Core 0.1
import StatusQ.Core.Theme 0.1
import SortFilterProxyModel 0.2
import utils 1.0
import "../stores/NetworkSelectPopup"
@ -12,11 +14,12 @@ import "../controls"
StatusScrollView {
id: root
property var testNetworks: null
required property var layer1Networks
required property var layer2Networks
property bool useEnabledRole: true
property SingleSelectionInfo singleSelection: SingleSelectionInfo {}
property var preferredSharingNetworks: []
property bool preferredNetworksMode: false
signal toggleNetwork(var network, var model, int index)
@ -48,6 +51,9 @@ StatusScrollView {
useEnabledRole: root.useEnabledRole
singleSelection: root.singleSelection
onToggleNetwork: root.toggleNetwork(network, model, index)
preferredNetworksMode: root.preferredNetworksMode
preferredSharingNetworks: root.preferredSharingNetworks
allChecked: root.preferredSharingNetworks.length === layer1Networks.count + layer2Networks.count
}
}
@ -75,20 +81,9 @@ StatusScrollView {
useEnabledRole: root.useEnabledRole
singleSelection: root.singleSelection
onToggleNetwork: root.toggleNetwork(network, model, index)
}
}
Repeater {
id: chainRepeater3
model: root.testNetworks
delegate: NetworkSelectItemDelegate {
implicitHeight: 48
width: parent.width
radioButtonGroup: radioBtnGroup
networkModel: chainRepeater3.model
useEnabledRole: root.useEnabledRole
singleSelection: root.singleSelection
onToggleNetwork: root.toggleNetwork(network, model, index)
preferredNetworksMode: root.preferredNetworksMode
preferredSharingNetworks: root.preferredSharingNetworks
allChecked: root.preferredSharingNetworks.length === layer1Networks.count + layer2Networks.count
}
}
}

View File

@ -14,7 +14,7 @@ StatusListItem {
id: root
property var modelData
property string chainShortNames
property var getNetworkShortNames: function(chainIds){}
property bool clearVisible: false
signal cleared()
@ -25,6 +25,7 @@ StatusListItem {
subTitle:{
if(!!modelData) {
let elidedAddress = StatusQUtils.Utils.elideText(modelData.address,6,4)
let chainShortNames = root.getNetworkShortNames(modelData.preferredSharingChainIds)
return sensor.containsMouse ? WalletUtils.colorizedChainPrefix(chainShortNames) || Utils.richColorText(elidedAddress, Theme.palette.directColor1) : elidedAddress
}
return ""

View File

@ -14,7 +14,7 @@ StatusComboBox {
id: root
property var selectedAccount
property string chainShortNames
property var getNetworkShortNames: function(chainIds){}
property int selectedIndex: -1
control.padding: 0
@ -67,7 +67,7 @@ StatusComboBox {
delegate: WalletAccountListItem {
width: ListView.view.width
modelData: model
chainShortNames: root.chainShortNames
getNetworkShortNames: root.getNetworkShortNames
color: sensor.containsMouse || highlighted ?
Theme.palette.baseColor2 :
selectedAccount.name === model.name ? Theme.palette.statusListItem.highlightColor : "transparent"

View File

@ -157,7 +157,7 @@ StatusDialog {
sorters: RoleSorter { roleName: "position"; sortOrder: Qt.AscendingOrder }
}
selectedAccount: !!popup.selectedAccount ? popup.selectedAccount: {}
chainShortNames: store.getAllNetworksSupportedPrefix()
getNetworkShortNames: function(chainIds) {return store.getNetworkShortNames(chainIds)}
onSelectedIndexChanged: store.switchSenderAccount(selectedIndex)
}

View File

@ -9,7 +9,6 @@ QtObject {
// Network selection properties:
property var layer1Networks: networksModule.layer1
property var layer2Networks: networksModule.layer2
property var testNetworks: networksModule.test
property var enabledNetworks: networksModule.enabled
property var allNetworks: networksModule.all

View File

@ -26,12 +26,13 @@ QtObject {
property var senderAccounts: walletSectionSendInst.senderAccounts
property var selectedSenderAccount: walletSectionSendInst.selectedSenderAccount
property string signingPhrase: walletSectionInst.signingPhrase
property bool areTestNetworksEnabled: networksModule.areTestNetworksEnabled
property var savedAddressesModel: SortFilterProxyModel {
sourceModel: walletSectionSavedAddresses.model
filters: [
ValueFilter {
roleName: "isTest"
value: networksModule.areTestNetworksEnabled
value: areTestNetworksEnabled
}
]
}
@ -289,4 +290,8 @@ QtObject {
function switchSenderAccount(index) {
walletSectionSendInst.switchSenderAccount(index)
}
function getNetworkShortNames(chainIds) {
return networksModule.getNetworkShortNames(chainIds)
}
}

View File

@ -140,7 +140,6 @@ Loader {
id: myAccountRecipient
WalletAccountListItem {
implicitWidth: parent.width
chainShortNames: store.getAllNetworksSupportedPrefix()
modelData: root.selectedRecipient
radius: 8
clearVisible: true
@ -149,6 +148,7 @@ Loader {
subTitle: {
if(!!modelData) {
let elidedAddress = StatusQUtils.Utils.elideText(modelData.address,6,4)
let chainShortNames = store.getNetworkShortNames(modelData.preferredSharingChainIds)
return WalletUtils.colorizedChainPrefix(chainShortNames) + StatusQUtils.Utils.elideText(elidedAddress,6,4)
}
return ""

View File

@ -135,13 +135,15 @@ Item {
delegate: WalletAccountListItem {
implicitWidth: ListView.view.width
modelData: model
chainShortNames: root.store.getAllNetworksSupportedPrefix()
getNetworkShortNames: root.store.getNetworkShortNames
onClicked: recipientSelected({name: modelData.name,
address: modelData.address,
color: modelData.color,
emoji: modelData.emoji,
walletType: modelData.walletType,
currencyBalance: modelData.currencyBalance}, TabAddressSelectorView.Type.Account )
currencyBalance: modelData.currencyBalance,
preferredSharingChainIds: modelData.preferredSharingChainIds},
TabAddressSelectorView.Type.Account)
}
model: root.store.accounts

View File

@ -819,8 +819,7 @@ QtObject {
}
function getPathForDisplay(path) {
let letters = path.split("/").join(" / ")
return letters
return path.split("/").join(" / ")
}
// Leave this function at the bottom of the file as QT Creator messes up the code color after this

2
vendor/status-go vendored

@ -1 +1 @@
Subproject commit eb8d74e1aed94930241c9fb466805b09bd45810d
Subproject commit 1df8c1c5110e7b3600ea8defecaf0447009c1b18