fix(@desktop/keycard): migrating new keypair updates the list of registered keycards
This commit is contained in:
parent
3af934bee6
commit
48d1ae5cd1
|
@ -47,6 +47,10 @@ proc init*(self: Controller) =
|
||||||
self.events.on(SIGNAL_LOGGEDIN_USER_IMAGE_CHANGED) do(e: Args):
|
self.events.on(SIGNAL_LOGGEDIN_USER_IMAGE_CHANGED) do(e: Args):
|
||||||
self.delegate.onLoggedInUserImageChanged()
|
self.delegate.onLoggedInUserImageChanged()
|
||||||
|
|
||||||
|
self.events.on(SIGNAL_NEW_KEYCARD_SET) do(e: Args):
|
||||||
|
let args = KeycardActivityArgs(e)
|
||||||
|
self.delegate.onNewKeycardSet(args.keyPair)
|
||||||
|
|
||||||
self.events.on(SIGNAL_KEYCARD_LOCKED) do(e: Args):
|
self.events.on(SIGNAL_KEYCARD_LOCKED) do(e: Args):
|
||||||
let args = KeycardActivityArgs(e)
|
let args = KeycardActivityArgs(e)
|
||||||
self.delegate.onKeycardLocked(args.keycardUid)
|
self.delegate.onKeycardLocked(args.keycardUid)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import NimQml
|
import NimQml
|
||||||
|
from ../../../../../app_service/service/wallet_account/service import KeyPairDto
|
||||||
|
|
||||||
type
|
type
|
||||||
AccessInterface* {.pure inheritable.} = ref object of RootObj
|
AccessInterface* {.pure inheritable.} = ref object of RootObj
|
||||||
|
@ -64,6 +65,9 @@ method runCreateNewPairingCodePopup*(self: AccessInterface) {.base.} =
|
||||||
method onLoggedInUserImageChanged*(self: AccessInterface) {.base.} =
|
method onLoggedInUserImageChanged*(self: AccessInterface) {.base.} =
|
||||||
raise newException(ValueError, "No implementation available")
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
|
method onNewKeycardSet*(self: AccessInterface, keyPair: KeyPairDto) {.base.} =
|
||||||
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
method onKeycardLocked*(self: AccessInterface, keycardUid: string) {.base.} =
|
method onKeycardLocked*(self: AccessInterface, keycardUid: string) {.base.} =
|
||||||
raise newException(ValueError, "No implementation available")
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
|
|
|
@ -157,45 +157,53 @@ method runCreatePukPopup*(self: Module) =
|
||||||
method runCreateNewPairingCodePopup*(self: Module) =
|
method runCreateNewPairingCodePopup*(self: Module) =
|
||||||
info "TODO: Create New Pairing Code for a Keycard..."
|
info "TODO: Create New Pairing Code for a Keycard..."
|
||||||
|
|
||||||
proc buildKeycardList(self: Module) =
|
proc buildKeycardItem(self: Module, walletAccounts: seq[WalletAccountDto], keyPair: KeyPairDto): KeycardItem =
|
||||||
let findAccountByAccountAddress = proc(accounts: seq[WalletAccountDto], address: string): WalletAccountDto =
|
let findAccountByAccountAddress = proc(accounts: seq[WalletAccountDto], address: string): WalletAccountDto =
|
||||||
for i in 0 ..< accounts.len:
|
for i in 0 ..< accounts.len:
|
||||||
if(accounts[i].address == address):
|
if(accounts[i].address == address):
|
||||||
return accounts[i]
|
return accounts[i]
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
let accounts = self.controller.getWalletAccounts()
|
|
||||||
var items: seq[KeycardItem]
|
|
||||||
let migratedKeyPairs = self.controller.getAllMigratedKeyPairs()
|
|
||||||
for kp in migratedKeyPairs:
|
|
||||||
var knownAccounts: seq[WalletAccountDto]
|
var knownAccounts: seq[WalletAccountDto]
|
||||||
for accAddr in kp.accountsAddresses:
|
for accAddr in keyPair.accountsAddresses:
|
||||||
let account = findAccountByAccountAddress(accounts, accAddr)
|
let account = findAccountByAccountAddress(walletAccounts, accAddr)
|
||||||
if account.isNil:
|
if account.isNil:
|
||||||
## we should never be here cause we need to remove deleted accounts from the `keypairs` table and sync
|
## we should never be here cause we need to remove deleted accounts from the `keypairs` table and sync
|
||||||
## that state accross different app instances
|
## that state accross different app instances
|
||||||
continue
|
continue
|
||||||
knownAccounts.add(account)
|
knownAccounts.add(account)
|
||||||
if knownAccounts.len == 0:
|
if knownAccounts.len == 0:
|
||||||
continue
|
return nil
|
||||||
var item = initKeycardItem(keycardUid = kp.keycardUid,
|
var item = initKeycardItem(keycardUid = keyPair.keycardUid,
|
||||||
pubKey = knownAccounts[0].publicKey,
|
pubKey = knownAccounts[0].publicKey,
|
||||||
keyUid = kp.keyUid,
|
keyUid = keyPair.keyUid,
|
||||||
locked = kp.keycardLocked,
|
locked = keyPair.keycardLocked,
|
||||||
name = kp.keycardName,
|
name = keyPair.keycardName,
|
||||||
derivedFrom = knownAccounts[0].derivedfrom)
|
derivedFrom = knownAccounts[0].derivedfrom)
|
||||||
for ka in knownAccounts:
|
for ka in knownAccounts:
|
||||||
|
var icon = ""
|
||||||
if ka.walletType == WalletTypeDefaultStatusAccount:
|
if ka.walletType == WalletTypeDefaultStatusAccount:
|
||||||
item.setPairType(KeyPairType.Profile)
|
item.setPairType(KeyPairType.Profile)
|
||||||
item.setPubKey(singletonInstance.userProfile.getPubKey())
|
item.setPubKey(singletonInstance.userProfile.getPubKey())
|
||||||
item.setImage(singletonInstance.userProfile.getIcon())
|
item.setImage(singletonInstance.userProfile.getIcon())
|
||||||
|
icon = "wallet"
|
||||||
if ka.walletType == WalletTypeSeed:
|
if ka.walletType == WalletTypeSeed:
|
||||||
item.setPairType(KeyPairType.SeedImport)
|
item.setPairType(KeyPairType.SeedImport)
|
||||||
item.setIcon("keycard")
|
item.setIcon("keycard")
|
||||||
if ka.walletType == WalletTypeKey:
|
if ka.walletType == WalletTypeKey:
|
||||||
item.setPairType(KeyPairType.PrivateKeyImport)
|
item.setPairType(KeyPairType.PrivateKeyImport)
|
||||||
item.setIcon("keycard")
|
item.setIcon("keycard")
|
||||||
item.addAccount(ka.name, ka.path, ka.address, ka.emoji, ka.color, icon = "", balance = 0.0)
|
item.addAccount(ka.name, ka.path, ka.address, ka.emoji, ka.color, icon = icon, balance = 0.0)
|
||||||
|
return item
|
||||||
|
|
||||||
|
proc buildKeycardList(self: Module) =
|
||||||
|
let walletAccounts = self.controller.getWalletAccounts()
|
||||||
|
var items: seq[KeycardItem]
|
||||||
|
let migratedKeyPairs = self.controller.getAllMigratedKeyPairs()
|
||||||
|
for kp in migratedKeyPairs:
|
||||||
|
let item = self.buildKeycardItem(walletAccounts, kp)
|
||||||
|
if item.isNil:
|
||||||
|
continue
|
||||||
items.add(item)
|
items.add(item)
|
||||||
self.view.setKeycardItems(items)
|
self.view.setKeycardItems(items)
|
||||||
|
|
||||||
|
@ -203,6 +211,14 @@ method onLoggedInUserImageChanged*(self: Module) =
|
||||||
self.view.keycardModel().setImage(singletonInstance.userProfile.getPubKey(), singletonInstance.userProfile.getIcon())
|
self.view.keycardModel().setImage(singletonInstance.userProfile.getPubKey(), singletonInstance.userProfile.getIcon())
|
||||||
self.view.emitKeycardProfileChangedSignal()
|
self.view.emitKeycardProfileChangedSignal()
|
||||||
|
|
||||||
|
method onNewKeycardSet*(self: Module, keyPair: KeyPairDto) =
|
||||||
|
let walletAccounts = self.controller.getWalletAccounts()
|
||||||
|
let item = self.buildKeycardItem(walletAccounts, keyPair)
|
||||||
|
if item.isNil:
|
||||||
|
error "cannot build keycard item for key pair", keyUid=keyPair.keyUid
|
||||||
|
return
|
||||||
|
self.view.keycardModel().addItem(item)
|
||||||
|
|
||||||
method onKeycardLocked*(self: Module, keycardUid: string) =
|
method onKeycardLocked*(self: Module, keycardUid: string) =
|
||||||
self.view.keycardModel().setLocked(keycardUid, true)
|
self.view.keycardModel().setLocked(keycardUid, true)
|
||||||
self.view.emitKeycardDetailsChangedSignal(keycardUid)
|
self.view.emitKeycardDetailsChangedSignal(keycardUid)
|
||||||
|
|
|
@ -33,6 +33,7 @@ const SIGNAL_WALLET_ACCOUNT_NETWORK_ENABLED_UPDATED* = "walletAccount/networkEna
|
||||||
const SIGNAL_WALLET_ACCOUNT_DERIVED_ADDRESS_READY* = "walletAccount/derivedAddressesReady"
|
const SIGNAL_WALLET_ACCOUNT_DERIVED_ADDRESS_READY* = "walletAccount/derivedAddressesReady"
|
||||||
const SIGNAL_WALLET_ACCOUNT_TOKENS_REBUILT* = "walletAccount/tokensRebuilt"
|
const SIGNAL_WALLET_ACCOUNT_TOKENS_REBUILT* = "walletAccount/tokensRebuilt"
|
||||||
|
|
||||||
|
const SIGNAL_NEW_KEYCARD_SET* = "newKeycardSet"
|
||||||
const SIGNAL_KEYCARD_LOCKED* = "keycardLocked"
|
const SIGNAL_KEYCARD_LOCKED* = "keycardLocked"
|
||||||
const SIGNAL_KEYCARD_UNLOCKED* = "keycardUnlocked"
|
const SIGNAL_KEYCARD_UNLOCKED* = "keycardUnlocked"
|
||||||
const SIGNAL_KEYCARD_UID_UPDATED* = "keycardUidUpdated"
|
const SIGNAL_KEYCARD_UID_UPDATED* = "keycardUidUpdated"
|
||||||
|
@ -90,6 +91,7 @@ type KeycardActivityArgs* = ref object of Args
|
||||||
keycardUid*: string
|
keycardUid*: string
|
||||||
keycardNewUid*: string
|
keycardNewUid*: string
|
||||||
keycardNewName*: string
|
keycardNewName*: string
|
||||||
|
keyPair*: KeyPairDto
|
||||||
|
|
||||||
const CheckBalanceSlotExecuteIntervalInSeconds = 15 * 60 # 15 mins
|
const CheckBalanceSlotExecuteIntervalInSeconds = 15 * 60 # 15 mins
|
||||||
const CheckBalanceTimerIntervalInMilliseconds = 5000 # 5 sec
|
const CheckBalanceTimerIntervalInMilliseconds = 5000 # 5 sec
|
||||||
|
@ -500,10 +502,11 @@ QtObject:
|
||||||
keyPair.keycardName,
|
keyPair.keycardName,
|
||||||
keyPair.keyUid,
|
keyPair.keyUid,
|
||||||
keyPair.accountsAddresses)
|
keyPair.accountsAddresses)
|
||||||
return self.responseHasNoErrors("addMigratedKeyPair", response)
|
result = self.responseHasNoErrors("addMigratedKeyPair", response)
|
||||||
|
if result:
|
||||||
|
self.events.emit(SIGNAL_NEW_KEYCARD_SET, KeycardActivityArgs(keyPair: keyPair))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error "error: ", procName="addMigratedKeyPair", errName = e.name, errDesription = e.msg
|
error "error: ", procName="addMigratedKeyPair", errName = e.name, errDesription = e.msg
|
||||||
return false
|
|
||||||
|
|
||||||
proc getAllMigratedKeyPairs*(self: Service): seq[KeyPairDto] =
|
proc getAllMigratedKeyPairs*(self: Service): seq[KeyPairDto] =
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in New Issue