chore: move logic for resolving suggested derivation path to status-go
Closes #14188
This commit is contained in:
parent
5473e3b14e
commit
7047ecf2b6
|
@ -245,3 +245,9 @@ proc fetchAddressesFromKeycard*(self: Controller, bip44Paths: seq[string]) =
|
||||||
self.connectKeycardReponseSignal()
|
self.connectKeycardReponseSignal()
|
||||||
self.tmpPaths = bip44Paths
|
self.tmpPaths = bip44Paths
|
||||||
self.keycardService.startExportPublicFlow(bip44Paths, exportMasterAddr=true, exportPrivateAddr=false, pin=self.getPin())
|
self.keycardService.startExportPublicFlow(bip44Paths, exportMasterAddr=true, exportPrivateAddr=false, pin=self.getPin())
|
||||||
|
|
||||||
|
proc getNumOfAddressesToGenerateForKeypair*(self: Controller, keyUid: string): int =
|
||||||
|
return self.walletAccountService.getNumOfAddressesToGenerateForKeypair(keyUid)
|
||||||
|
|
||||||
|
proc resolveSuggestedPathForKeypair*(self: Controller, keyUid: string): string =
|
||||||
|
return self.walletAccountService.resolveSuggestedPathForKeypair(keyUid)
|
|
@ -1,4 +1,4 @@
|
||||||
import NimQml, Tables, strutils, sequtils, sugar, chronicles
|
import NimQml, Tables, strutils, sequtils, chronicles
|
||||||
|
|
||||||
import io_interface
|
import io_interface
|
||||||
import view, controller
|
import view, controller
|
||||||
|
@ -29,10 +29,6 @@ const Label_ImportNew = "LABEL-IMPORT-NEW"
|
||||||
const Label_OptionAddNewMasterKey = "LABEL-OPTION-ADD-NEW-MASTER-KEY"
|
const Label_OptionAddNewMasterKey = "LABEL-OPTION-ADD-NEW-MASTER-KEY"
|
||||||
const Label_OptionAddWatchOnlyAcc = "LABEL-OPTION-ADD-WATCH-ONLY-ACC"
|
const Label_OptionAddWatchOnlyAcc = "LABEL-OPTION-ADD-WATCH-ONLY-ACC"
|
||||||
|
|
||||||
const MaxNumOfGeneratedAddresses = 100
|
|
||||||
const NumOfGeneratedAddressesRegular = MaxNumOfGeneratedAddresses
|
|
||||||
const NumOfGeneratedAddressesKeycard = 10
|
|
||||||
|
|
||||||
|
|
||||||
logScope:
|
logScope:
|
||||||
topics = "wallet-add-account-module"
|
topics = "wallet-add-account-module"
|
||||||
|
@ -266,16 +262,7 @@ proc isKeyPairAlreadyAdded[T](self: Module[T], keyUid: string): bool =
|
||||||
|
|
||||||
proc getNumOfAddressesToGenerate[T](self: Module[T]): int =
|
proc getNumOfAddressesToGenerate[T](self: Module[T]): int =
|
||||||
let selectedOrigin = self.view.getSelectedOrigin()
|
let selectedOrigin = self.view.getSelectedOrigin()
|
||||||
if selectedOrigin.getMigratedToKeycard():
|
return self.controller.getNumOfAddressesToGenerateForKeypair(selectedOrigin.getKeyUid())
|
||||||
var indexOfLastDefaultCreatedAcc = 0
|
|
||||||
let keypair = self.controller.getKeypairByKeyUid(selectedOrigin.getKeyUid())
|
|
||||||
if not keypair.isNil:
|
|
||||||
indexOfLastDefaultCreatedAcc = keypair.lastUsedDerivationIndex
|
|
||||||
let final = NumOfGeneratedAddressesKeycard + indexOfLastDefaultCreatedAcc # In case of a Keycard keypair always offer 10 addresses more then the last used derivation index
|
|
||||||
if final < MaxNumOfGeneratedAddresses:
|
|
||||||
return final
|
|
||||||
return MaxNumOfGeneratedAddresses
|
|
||||||
return NumOfGeneratedAddressesRegular
|
|
||||||
|
|
||||||
proc fetchAddressForDerivationPath[T](self: Module[T]) =
|
proc fetchAddressForDerivationPath[T](self: Module[T]) =
|
||||||
let derivationPath = self.view.getDerivationPath()
|
let derivationPath = self.view.getDerivationPath()
|
||||||
|
@ -360,23 +347,12 @@ method changeDerivationPath*[T](self: Module[T], derivationPath: string) =
|
||||||
return
|
return
|
||||||
self.fetchAddressForDerivationPath()
|
self.fetchAddressForDerivationPath()
|
||||||
|
|
||||||
proc resolveSuggestedPathForSelectedOrigin[T](self: Module[T]): tuple[suggestedPath: string, usedIndex: int] =
|
proc resolveSuggestedPathForSelectedOrigin[T](self: Module[T]): string =
|
||||||
var nextIndex = 0
|
|
||||||
let selectedOrigin = self.view.getSelectedOrigin()
|
let selectedOrigin = self.view.getSelectedOrigin()
|
||||||
let keypair = self.controller.getKeypairByKeyUid(selectedOrigin.getKeyUid())
|
return self.controller.resolveSuggestedPathForKeypair(selectedOrigin.getKeyUid())
|
||||||
if keypair.isNil:
|
|
||||||
let suggestedPath = account_constants.PATH_WALLET_ROOT & "/" & $nextIndex
|
|
||||||
return (suggestedPath, nextIndex)
|
|
||||||
nextIndex = selectedOrigin.getLastUsedDerivationIndex() + 1
|
|
||||||
for i in nextIndex ..< self.getNumOfAddressesToGenerate():
|
|
||||||
let suggestedPath = account_constants.PATH_WALLET_ROOT & "/" & $i
|
|
||||||
if keypair.accounts.filter(x => x.path == suggestedPath).len == 0:
|
|
||||||
return (suggestedPath, i)
|
|
||||||
error "we couldn't find available path for new account"
|
|
||||||
|
|
||||||
method resetDerivationPath*[T](self: Module[T]) =
|
method resetDerivationPath*[T](self: Module[T]) =
|
||||||
let selectedOrigin = self.view.getSelectedOrigin()
|
let suggestedPath = self.resolveSuggestedPathForSelectedOrigin()
|
||||||
let (suggestedPath, _) = self.resolveSuggestedPathForSelectedOrigin()
|
|
||||||
self.changeDerivationPath(suggestedPath)
|
self.changeDerivationPath(suggestedPath)
|
||||||
|
|
||||||
proc setItemForSelectedOrigin[T](self: Module[T], item: KeyPairItem) =
|
proc setItemForSelectedOrigin[T](self: Module[T], item: KeyPairItem) =
|
||||||
|
@ -390,7 +366,7 @@ proc setItemForSelectedOrigin[T](self: Module[T], item: KeyPairItem) =
|
||||||
self.view.setWatchOnlyAccAddress(newDerivedAddressItem())
|
self.view.setWatchOnlyAccAddress(newDerivedAddressItem())
|
||||||
return
|
return
|
||||||
|
|
||||||
let (suggestedPath, _) = self.resolveSuggestedPathForSelectedOrigin()
|
let suggestedPath = self.resolveSuggestedPathForSelectedOrigin()
|
||||||
self.view.setSuggestedDerivationPath(suggestedPath)
|
self.view.setSuggestedDerivationPath(suggestedPath)
|
||||||
self.view.setDerivationPath(suggestedPath)
|
self.view.setDerivationPath(suggestedPath)
|
||||||
|
|
||||||
|
|
|
@ -788,3 +788,21 @@ proc addressWasShown*(self: Service, address: string) =
|
||||||
raise newException(CatchableError, response.error.message)
|
raise newException(CatchableError, response.error.message)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error "error: ", procName="addressWasShown", errName=e.name, errDesription=e.msg
|
error "error: ", procName="addressWasShown", errName=e.name, errDesription=e.msg
|
||||||
|
|
||||||
|
proc getNumOfAddressesToGenerateForKeypair*(self: Service, keyUid: string): int =
|
||||||
|
try:
|
||||||
|
let response = status_go_accounts.getNumOfAddressesToGenerateForKeypair(keyUid)
|
||||||
|
if not response.error.isNil:
|
||||||
|
raise newException(CatchableError, response.error.message)
|
||||||
|
return response.result.getInt
|
||||||
|
except Exception as e:
|
||||||
|
error "error: ", procName="getNumOfAddressesToGenerateForKeypair", errName=e.name, errDesription=e.msg
|
||||||
|
|
||||||
|
proc resolveSuggestedPathForKeypair*(self: Service, keyUid: string): string =
|
||||||
|
try:
|
||||||
|
let response = status_go_accounts.resolveSuggestedPathForKeypair(keyUid)
|
||||||
|
if not response.error.isNil:
|
||||||
|
raise newException(CatchableError, response.error.message)
|
||||||
|
return response.result.getStr
|
||||||
|
except Exception as e:
|
||||||
|
error "error: ", procName="resolveSuggestedPathForKeypair", errName=e.name, errDesription=e.msg
|
||||||
|
|
|
@ -499,3 +499,11 @@ proc getProfileShowcaseEntriesLimit*(): RpcResponse[JsonNode] =
|
||||||
proc addressWasShown*(address: string): RpcResponse[JsonNode] =
|
proc addressWasShown*(address: string): RpcResponse[JsonNode] =
|
||||||
let payload = %* [address]
|
let payload = %* [address]
|
||||||
return core.callPrivateRPC("accounts_addressWasShown", payload)
|
return core.callPrivateRPC("accounts_addressWasShown", payload)
|
||||||
|
|
||||||
|
proc getNumOfAddressesToGenerateForKeypair*(keyUID: string): RpcResponse[JsonNode] =
|
||||||
|
let payload = %* [keyUID]
|
||||||
|
result = core.callPrivateRPC("accounts_getNumOfAddressesToGenerateForKeypair", payload)
|
||||||
|
|
||||||
|
proc resolveSuggestedPathForKeypair*(keyUID: string): RpcResponse[JsonNode] =
|
||||||
|
let payload = %* [keyUID]
|
||||||
|
result = core.callPrivateRPC("accounts_resolveSuggestedPathForKeypair", payload)
|
|
@ -1 +1 @@
|
||||||
Subproject commit 98c3be55b937582374e60adb651543c5f1348c29
|
Subproject commit caf3de119055a4169c1efa83d0a42c11221aa014
|
Loading…
Reference in New Issue