-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(@desktop/keycard): migrate an exsiting account from Keycard t…
…o Status Desktop Fixes: #7030
- Loading branch information
1 parent
6db0583
commit 32fcda4
Showing
39 changed files
with
651 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
...pp/modules/shared_modules/keycard_popup/internal/importing_from_keycard_failure_state.nim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
type | ||
ImportingFromKeycardFailureState* = ref object of State | ||
|
||
proc newImportingFromKeycardFailureState*(flowType: FlowType, backState: State): ImportingFromKeycardFailureState = | ||
result = ImportingFromKeycardFailureState() | ||
result.setup(flowType, StateType.ImportingFromKeycardFailure, backState) | ||
|
||
proc delete*(self: ImportingFromKeycardFailureState) = | ||
self.State.delete | ||
|
||
method executePrePrimaryStateCommand*(self: ImportingFromKeycardFailureState, controller: Controller) = | ||
if self.flowType == FlowType.ImportFromKeycard: | ||
controller.terminateCurrentFlow(lastStepInTheCurrentFlow = true) | ||
|
||
method executeCancelCommand*(self: ImportingFromKeycardFailureState, controller: Controller) = | ||
if self.flowType == FlowType.ImportFromKeycard: | ||
controller.terminateCurrentFlow(lastStepInTheCurrentFlow = true) |
50 changes: 50 additions & 0 deletions
50
src/app/modules/shared_modules/keycard_popup/internal/importing_from_keycard_state.nim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
type | ||
ImportingFromKeycardState* = ref object of State | ||
paths: seq[string] | ||
addresses: seq[string] | ||
|
||
proc newImportingFromKeycardState*(flowType: FlowType, backState: State): ImportingFromKeycardState = | ||
result = ImportingFromKeycardState() | ||
result.setup(flowType, StateType.ImportingFromKeycard, backState) | ||
|
||
proc delete*(self: ImportingFromKeycardState) = | ||
self.State.delete | ||
|
||
proc addAccountsToWallet(self: ImportingFromKeycardState, controller: Controller): bool = | ||
let kpForProcessing = controller.getKeyPairForProcessing() | ||
let kpHelper = controller.getKeyPairHelper() | ||
for account in kpForProcessing.getAccountsModel().getItems(): | ||
self.addresses.add(account.getAddress()) | ||
if not controller.addWalletAccount(name = account.getName(), | ||
address = account.getAddress(), | ||
path = account.getPath(), | ||
addressAccountIsDerivedFrom = kpForProcessing.getDerivedFrom(), | ||
publicKey = account.getPubKey(), | ||
keyUid = kpForProcessing.getKeyUid(), | ||
accountType = if account.getPath() == PATH_DEFAULT_WALLET: SEED else: GENERATED, | ||
color = account.getColor(), | ||
emoji = account.getEmoji()): | ||
return false | ||
return true | ||
|
||
proc doMigration(self: ImportingFromKeycardState, controller: Controller) = | ||
let kpForProcessing = controller.getKeyPairForProcessing() | ||
var kpDto = KeyPairDto(keycardUid: controller.getKeycardUid(), | ||
keycardName: kpForProcessing.getName(), | ||
keycardLocked: false, | ||
accountsAddresses: self.addresses, | ||
keyUid: kpForProcessing.getKeyUid()) | ||
controller.addMigratedKeyPair(kpDto) | ||
|
||
method getNextPrimaryState*(self: ImportingFromKeycardState, controller: Controller): State = | ||
if self.flowType == FlowType.ImportFromKeycard: | ||
if not self.addAccountsToWallet(controller): | ||
return createState(StateType.ImportingFromKeycardFailure, self.flowType, nil) | ||
self.doMigration(controller) | ||
return nil | ||
|
||
method getNextSecondaryState*(self: ImportingFromKeycardState, controller: Controller): State = | ||
if self.flowType == FlowType.ImportFromKeycard: | ||
if controller.getAddingMigratedKeypairSuccess(): | ||
return createState(StateType.ImportingFromKeycardSuccess, self.flowType, nil) | ||
return createState(StateType.ImportingFromKeycardFailure, self.flowType, nil) |
22 changes: 22 additions & 0 deletions
22
...pp/modules/shared_modules/keycard_popup/internal/importing_from_keycard_success_state.nim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
type | ||
ImportingFromKeycardSuccessState* = ref object of State | ||
|
||
proc newImportingFromKeycardSuccessState*(flowType: FlowType, backState: State): ImportingFromKeycardSuccessState = | ||
result = ImportingFromKeycardSuccessState() | ||
result.setup(flowType, StateType.ImportingFromKeycardSuccess, backState) | ||
|
||
proc delete*(self: ImportingFromKeycardSuccessState) = | ||
self.State.delete | ||
|
||
method executePrePrimaryStateCommand*(self: ImportingFromKeycardSuccessState, controller: Controller) = | ||
if self.flowType == FlowType.ImportFromKeycard: | ||
controller.terminateCurrentFlow(lastStepInTheCurrentFlow = true) | ||
|
||
method executePreSecondaryStateCommand*(self: ImportingFromKeycardSuccessState, controller: Controller) = | ||
if self.flowType == FlowType.ImportFromKeycard: | ||
controller.switchToWalletSection() | ||
controller.terminateCurrentFlow(lastStepInTheCurrentFlow = true) | ||
|
||
method executeCancelCommand*(self: ImportingFromKeycardSuccessState, controller: Controller) = | ||
if self.flowType == FlowType.ImportFromKeycard: | ||
controller.terminateCurrentFlow(lastStepInTheCurrentFlow = true) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.