diff --git a/src/app/modules/shared_modules/keycard_popup/models/key_pair_account_item.nim b/src/app/modules/shared_models/keypair_account_item.nim similarity index 98% rename from src/app/modules/shared_modules/keycard_popup/models/key_pair_account_item.nim rename to src/app/modules/shared_models/keypair_account_item.nim index 84b7ada5d3..6bd6ba90e4 100644 --- a/src/app/modules/shared_modules/keycard_popup/models/key_pair_account_item.nim +++ b/src/app/modules/shared_models/keypair_account_item.nim @@ -38,7 +38,6 @@ QtObject: emoji: {self.emoji}, color: {self.color}, icon: {self.icon}, - icon: {$self.icon}, balance: {self.balance}, balanceFetched: {self.balanceFetched} ]""" diff --git a/src/app/modules/shared_modules/keycard_popup/models/key_pair_account_model.nim b/src/app/modules/shared_models/keypair_account_model.nim similarity index 93% rename from src/app/modules/shared_modules/keycard_popup/models/key_pair_account_model.nim rename to src/app/modules/shared_models/keypair_account_model.nim index fed808b4e7..1a1d9f87cd 100644 --- a/src/app/modules/shared_modules/keycard_popup/models/key_pair_account_model.nim +++ b/src/app/modules/shared_models/keypair_account_model.nim @@ -1,9 +1,9 @@ import NimQml, Tables, strformat, strutils -import key_pair_account_item +import keypair_account_item -import ../../../../../app_service/common/utils +import ../../../app_service/common/utils -export key_pair_account_item +export keypair_account_item type ModelRole {.pure.} = enum @@ -80,6 +80,12 @@ QtObject: return true return false + proc containsAccountPath*(self: KeyPairAccountModel, path: string): bool = + for it in self.items: + if it.getPath() == path: + return true + return false + proc containsPathOutOfTheDefaultStatusDerivationTree*(self: KeyPairAccountModel): bool = for it in self.items: if utils.isPathOutOfTheDefaultStatusDerivationTree(it.getPath()): diff --git a/src/app/modules/shared_modules/keycard_popup/models/key_pair_item.nim b/src/app/modules/shared_models/keypair_item.nim similarity index 78% rename from src/app/modules/shared_modules/keycard_popup/models/key_pair_item.nim rename to src/app/modules/shared_models/keypair_item.nim index 4cf09a3575..cda2382665 100644 --- a/src/app/modules/shared_modules/keycard_popup/models/key_pair_item.nim +++ b/src/app/modules/shared_models/keypair_item.nim @@ -1,7 +1,7 @@ import NimQml, strformat -import key_pair_account_model +import keypair_account_model -export key_pair_account_model +export keypair_account_model type KeyPairType* {.pure.} = enum @@ -20,6 +20,8 @@ QtObject: icon: string pairType: KeyPairType derivedFrom: string + lastUsedDerivationIndex: int + migratedToKeycard: bool accounts: KeyPairAccountModel observedAccount: KeyPairAccountItem @@ -31,7 +33,9 @@ QtObject: image: string, icon: string, pairType: KeyPairType, - derivedFrom: string + derivedFrom: string, + lastUsedDerivationIndex: int, + migratedToKeycard: bool ) = self.QObject.setup self.keyUid = keyUid @@ -42,6 +46,8 @@ QtObject: self.icon = icon self.pairType = pairType self.derivedFrom = derivedFrom + self.lastUsedDerivationIndex = lastUsedDerivationIndex + self.migratedToKeycard = migratedToKeycard self.accounts = newKeyPairAccountModel() proc delete*(self: KeyPairItem) = @@ -54,9 +60,11 @@ QtObject: image = "", icon = "", pairType = KeyPairType.Unknown, - derivedFrom = ""): KeyPairItem = + derivedFrom = "", + lastUsedDerivationIndex = 0, + migratedToKeycard = false): KeyPairItem = new(result, delete) - result.setup(keyUid, pubKey, locked, name, image, icon, pairType, derivedFrom) + result.setup(keyUid, pubKey, locked, name, image, icon, pairType, derivedFrom, lastUsedDerivationIndex, migratedToKeycard) proc `$`*(self: KeyPairItem): string = result = fmt"""KeyPairItem[ @@ -68,6 +76,8 @@ QtObject: icon: {self.icon}, pairType: {$self.pairType}, derivedFrom: {self.derivedFrom}, + lastUsedDerivationIndex: {self.lastUsedDerivationIndex}, + migratedToKeycard: {self.migratedToKeycard}, accounts: {$self.accounts} ]""" @@ -159,6 +169,28 @@ QtObject: write = setDerivedFrom notify = derivedFromChanged + proc lastUsedDerivationIndexChanged*(self: KeyPairItem) {.signal.} + proc getLastUsedDerivationIndex*(self: KeyPairItem): int {.slot.} = + return self.lastUsedDerivationIndex + proc setLastUsedDerivationIndex*(self: KeyPairItem, value: int) {.slot.} = + self.lastUsedDerivationIndex = value + self.lastUsedDerivationIndexChanged() + QtProperty[int] lastUsedDerivationIndex: + read = getLastUsedDerivationIndex + write = setLastUsedDerivationIndex + notify = lastUsedDerivationIndexChanged + + proc migratedToKeycardChanged*(self: KeyPairItem) {.signal.} + proc getMigratedToKeycard*(self: KeyPairItem): bool {.slot.} = + return self.migratedToKeycard + proc setMigratedToKeycard*(self: KeyPairItem, value: bool) {.slot.} = + self.migratedToKeycard = value + self.migratedToKeycardChanged() + QtProperty[bool] migratedToKeycard: + read = getMigratedToKeycard + write = setMigratedToKeycard + notify = migratedToKeycardChanged + proc observedAccountChanged*(self: KeyPairItem) {.signal.} proc getObservedAccountAsVariant*(self: KeyPairItem): QVariant {.slot.} = return newQVariant(self.observedAccount) @@ -192,6 +224,8 @@ QtObject: self.setLastAccountAsObservedAccount() proc containsAccountAddress*(self: KeyPairItem, address: string): bool = return self.accounts.containsAccountAddress(address) + proc containsAccountPath*(self: KeyPairItem, path: string): bool = + return self.accounts.containsAccountPath(path) proc containsPathOutOfTheDefaultStatusDerivationTree*(self: KeyPairItem): bool {.slot.} = return self.accounts.containsPathOutOfTheDefaultStatusDerivationTree() proc updateDetailsForAccountWithAddressIfTheyAreSet*(self: KeyPairItem, address, name, color, emoji: string) = @@ -208,5 +242,7 @@ QtObject: self.setIcon(item.getIcon()) self.setPairType(item.getPairType()) self.setDerivedFrom(item.getDerivedFrom()) + self.setMigratedToKeycard(item.getMigratedToKeycard()) + self.setLastUsedDerivationIndex(item.getLastUsedDerivationIndex()) self.setAccounts(item.getAccountsModel().getItems()) self.setLastAccountAsObservedAccount() \ No newline at end of file diff --git a/src/app/modules/shared_modules/keycard_popup/models/key_pair_model.nim b/src/app/modules/shared_models/keypair_model.nim similarity index 75% rename from src/app/modules/shared_modules/keycard_popup/models/key_pair_model.nim rename to src/app/modules/shared_models/keypair_model.nim index 5bc83d1853..94adf70043 100644 --- a/src/app/modules/shared_modules/keycard_popup/models/key_pair_model.nim +++ b/src/app/modules/shared_models/keypair_model.nim @@ -1,7 +1,7 @@ import NimQml, Tables, strformat -import key_pair_item +import keypair_item -export key_pair_item +export keypair_item type ModelRole {.pure.} = enum @@ -30,12 +30,6 @@ QtObject: read = getCount notify = countChanged - proc setItems*(self: KeyPairModel, items: seq[KeyPairItem]) = - self.beginResetModel() - self.items = items - self.endResetModel() - self.countChanged() - proc `$`*(self: KeyPairModel): string = for i in 0 ..< self.items.len: result &= fmt"""KeyPairModel: @@ -61,8 +55,28 @@ QtObject: of ModelRole.KeyPair: result = newQVariant(item) + proc setItems*(self: KeyPairModel, items: seq[KeyPairItem]) = + self.beginResetModel() + self.items = items + self.endResetModel() + self.countChanged() + + proc addItem*(self: KeyPairModel, item: KeyPairItem) = + let parentModelIndex = newQModelIndex() + defer: parentModelIndex.delete + self.beginInsertRows(parentModelIndex, self.items.len, self.items.len) + self.items.add(item) + self.endInsertRows() + self.countChanged() + proc findItemByPublicKey*(self: KeyPairModel, publicKey: string): KeyPairItem = for i in 0 ..< self.items.len: if(self.items[i].getPubKey() == publicKey): return self.items[i] + return nil + + proc findItemByKeyUid*(self: KeyPairModel, keyUid: string): KeyPairItem = + for i in 0 ..< self.items.len: + if(self.items[i].getKeyUid() == keyUid): + return self.items[i] return nil \ No newline at end of file diff --git a/src/app/modules/shared_modules/keycard_popup/controller.nim b/src/app/modules/shared_modules/keycard_popup/controller.nim index 3939e22a7b..00db7995f1 100644 --- a/src/app/modules/shared_modules/keycard_popup/controller.nim +++ b/src/app/modules/shared_modules/keycard_popup/controller.nim @@ -18,7 +18,7 @@ import ../../../../app_service/service/accounts/service as accounts_service import ../../../../app_service/service/wallet_account/service as wallet_account_service import ../../../../app_service/service/keychain/service as keychain_service -import models/[key_pair_item] +import ../../shared_models/[keypair_item] logScope: topics = "keycard-popup-controller" diff --git a/src/app/modules/shared_modules/keycard_popup/internal/state_factory.nim b/src/app/modules/shared_modules/keycard_popup/internal/state_factory.nim index 55517b79ee..32078d83db 100644 --- a/src/app/modules/shared_modules/keycard_popup/internal/state_factory.nim +++ b/src/app/modules/shared_modules/keycard_popup/internal/state_factory.nim @@ -7,7 +7,7 @@ from ../../../../../app_service/service/keycard/service import PUKLengthForStatu import ../../../../../app_service/common/account_constants import ../../../../../app_service/service/wallet_account/key_pair_dto import ../controller -import ../models/[key_pair_model] +import ../../../shared_models/[keypair_model] import state logScope: diff --git a/src/app/modules/shared_modules/keycard_popup/io_interface.nim b/src/app/modules/shared_modules/keycard_popup/io_interface.nim index dd1c0dbc74..1deb274b1f 100644 --- a/src/app/modules/shared_modules/keycard_popup/io_interface.nim +++ b/src/app/modules/shared_modules/keycard_popup/io_interface.nim @@ -2,7 +2,7 @@ import NimQml, tables import ../../../../app/core/eventemitter from ../../../../app_service/service/keycard/service import KeycardEvent, CardMetadata, KeyDetails from ../../../../app_service/service/wallet_account/service as wallet_account_service import WalletTokenDto -import models/key_pair_item +import ../../shared_models/keypair_item const SIGNAL_SHARED_KEYCARD_MODULE_USER_AUTHENTICATED_AND_WALLET_ADDRESS_GENERATED* = "sharedKeycarModuleUserAuthenticatedAndWalletAddressGenerated" diff --git a/src/app/modules/shared_modules/keycard_popup/models/keycard_item.nim b/src/app/modules/shared_modules/keycard_popup/models/keycard_item.nim index 90353f920b..ed92c9b1cf 100644 --- a/src/app/modules/shared_modules/keycard_popup/models/keycard_item.nim +++ b/src/app/modules/shared_modules/keycard_popup/models/keycard_item.nim @@ -1,7 +1,7 @@ import NimQml, strformat -import key_pair_item +import ../../../shared_models/keypair_item -export key_pair_item +export keypair_item QtObject: type KeycardItem* = ref object of KeyPairItem @@ -19,10 +19,13 @@ QtObject: image = "", icon = "", pairType = KeyPairType.Unknown, - derivedFrom = "" + derivedFrom = "", + lastUsedDerivationIndex = 0, + migratedToKeycard = true ): KeycardItem = new(result, delete) - result.KeyPairItem.setup(keyUid, pubKey, locked, name, image, icon, pairType, derivedFrom) + result.KeyPairItem.setup(keyUid, pubKey, locked, name, image, icon, pairType, derivedFrom,lastUsedDerivationIndex, + migratedToKeycard) result.keycardUid = keycardUid proc `$`*(self: KeycardItem): string = diff --git a/src/app/modules/shared_modules/keycard_popup/module.nim b/src/app/modules/shared_modules/keycard_popup/module.nim index eec1135024..13cd5306c7 100644 --- a/src/app/modules/shared_modules/keycard_popup/module.nim +++ b/src/app/modules/shared_modules/keycard_popup/module.nim @@ -3,7 +3,7 @@ import NimQml, tables, random, strutils, sequtils, sugar, chronicles import io_interface import view, controller import internal/[state, state_factory] -import models/[key_pair_model, key_pair_item] +import ../../shared_models/[keypair_model, keypair_item] import ../../../global/global_singleton import ../../../core/eventemitter diff --git a/src/app/modules/shared_modules/keycard_popup/view.nim b/src/app/modules/shared_modules/keycard_popup/view.nim index 5a015282f2..34d171c517 100644 --- a/src/app/modules/shared_modules/keycard_popup/view.nim +++ b/src/app/modules/shared_modules/keycard_popup/view.nim @@ -1,7 +1,7 @@ import NimQml import io_interface import internal/[state, state_wrapper] -import models/[key_pair_model, key_pair_item] +import ../../shared_models/[keypair_model, keypair_item] QtObject: type