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.tmpPaths = bip44Paths
|
||||
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 view, controller
|
||||
|
@ -29,10 +29,6 @@ const Label_ImportNew = "LABEL-IMPORT-NEW"
|
|||
const Label_OptionAddNewMasterKey = "LABEL-OPTION-ADD-NEW-MASTER-KEY"
|
||||
const Label_OptionAddWatchOnlyAcc = "LABEL-OPTION-ADD-WATCH-ONLY-ACC"
|
||||
|
||||
const MaxNumOfGeneratedAddresses = 100
|
||||
const NumOfGeneratedAddressesRegular = MaxNumOfGeneratedAddresses
|
||||
const NumOfGeneratedAddressesKeycard = 10
|
||||
|
||||
|
||||
logScope:
|
||||
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 =
|
||||
let selectedOrigin = self.view.getSelectedOrigin()
|
||||
if selectedOrigin.getMigratedToKeycard():
|
||||
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
|
||||
return self.controller.getNumOfAddressesToGenerateForKeypair(selectedOrigin.getKeyUid())
|
||||
|
||||
proc fetchAddressForDerivationPath[T](self: Module[T]) =
|
||||
let derivationPath = self.view.getDerivationPath()
|
||||
|
@ -360,23 +347,12 @@ method changeDerivationPath*[T](self: Module[T], derivationPath: string) =
|
|||
return
|
||||
self.fetchAddressForDerivationPath()
|
||||
|
||||
proc resolveSuggestedPathForSelectedOrigin[T](self: Module[T]): tuple[suggestedPath: string, usedIndex: int] =
|
||||
var nextIndex = 0
|
||||
proc resolveSuggestedPathForSelectedOrigin[T](self: Module[T]): string =
|
||||
let selectedOrigin = self.view.getSelectedOrigin()
|
||||
let keypair = self.controller.getKeypairByKeyUid(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"
|
||||
return self.controller.resolveSuggestedPathForKeypair(selectedOrigin.getKeyUid())
|
||||
|
||||
method resetDerivationPath*[T](self: Module[T]) =
|
||||
let selectedOrigin = self.view.getSelectedOrigin()
|
||||
let (suggestedPath, _) = self.resolveSuggestedPathForSelectedOrigin()
|
||||
let suggestedPath = self.resolveSuggestedPathForSelectedOrigin()
|
||||
self.changeDerivationPath(suggestedPath)
|
||||
|
||||
proc setItemForSelectedOrigin[T](self: Module[T], item: KeyPairItem) =
|
||||
|
@ -390,7 +366,7 @@ proc setItemForSelectedOrigin[T](self: Module[T], item: KeyPairItem) =
|
|||
self.view.setWatchOnlyAccAddress(newDerivedAddressItem())
|
||||
return
|
||||
|
||||
let (suggestedPath, _) = self.resolveSuggestedPathForSelectedOrigin()
|
||||
let suggestedPath = self.resolveSuggestedPathForSelectedOrigin()
|
||||
self.view.setSuggestedDerivationPath(suggestedPath)
|
||||
self.view.setDerivationPath(suggestedPath)
|
||||
|
||||
|
|
|
@ -788,3 +788,21 @@ proc addressWasShown*(self: Service, address: string) =
|
|||
raise newException(CatchableError, response.error.message)
|
||||
except Exception as e:
|
||||
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
|
||||
|
|
|
@ -498,4 +498,12 @@ proc getProfileShowcaseEntriesLimit*(): RpcResponse[JsonNode] =
|
|||
|
||||
proc addressWasShown*(address: string): RpcResponse[JsonNode] =
|
||||
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