fix(desktop/wallet): new account with error

This commit is contained in:
Anthony Laibe 2021-11-12 11:01:13 +01:00
parent da4d895131
commit df670bfcbb
10 changed files with 92 additions and 83 deletions

View File

@ -25,17 +25,17 @@ method init*[T](self: Controller[T]) =
method getWalletAccounts*[T](self: Controller[T]): seq[wallet_account_service.WalletAccountDto] =
return self.walletAccountService.getWalletAccounts()
method generateNewAccount*[T](self: Controller[T], password: string, accountName: string, color: string) =
self.walletAccountService.generateNewAccount(password, accountName, color)
method generateNewAccount*[T](self: Controller[T], password: string, accountName: string, color: string): string =
return self.walletAccountService.generateNewAccount(password, accountName, color)
method addAccountsFromPrivateKey*[T](self: Controller[T], privateKey: string, password: string, accountName: string, color: string) =
self.walletAccountService.addAccountsFromPrivateKey(privateKey, password, accountName, color)
method addAccountsFromPrivateKey*[T](self: Controller[T], privateKey: string, password: string, accountName: string, color: string): string =
return self.walletAccountService.addAccountsFromPrivateKey(privateKey, password, accountName, color)
method addAccountsFromSeed*[T](self: Controller[T], seedPhrase: string, password: string, accountName: string, color: string) =
self.walletAccountService.addAccountsFromSeed(seedPhrase, password, accountName, color)
method addAccountsFromSeed*[T](self: Controller[T], seedPhrase: string, password: string, accountName: string, color: string): string =
return self.walletAccountService.addAccountsFromSeed(seedPhrase, password, accountName, color)
method addWatchOnlyAccount*[T](self: Controller[T], address: string, accountName: string, color: string) =
self.walletAccountService.addWatchOnlyAccount(address, accountName, color)
method addWatchOnlyAccount*[T](self: Controller[T], address: string, accountName: string, color: string): string =
return self.walletAccountService.addWatchOnlyAccount(address, accountName, color)
method deleteAccount*[T](self: Controller[T], address: string) =
self.walletAccountService.deleteAccount(address)

View File

@ -13,16 +13,16 @@ method init*(self: AccessInterface) {.base.} =
method getWalletAccounts*(self: AccessInterface): seq[wallet_account_service.WalletAccountDto] {.base.} =
raise newException(ValueError, "No implementation available")
method generateNewAccount*(self: AccessInterface, password: string, accountName: string, color: string) {.base.} =
method generateNewAccount*(self: AccessInterface, password: string, accountName: string, color: string): string {.base.} =
raise newException(ValueError, "No implementation available")
method addAccountsFromPrivateKey*(self: AccessInterface, privateKey: string, password: string, accountName: string, color: string) {.base.} =
method addAccountsFromPrivateKey*(self: AccessInterface, privateKey: string, password: string, accountName: string, color: string): string {.base.} =
raise newException(ValueError, "No implementation available")
method addAccountsFromSeed*(self: AccessInterface, seedPhrase: string, password: string, accountName: string, color: string) {.base.} =
method addAccountsFromSeed*(self: AccessInterface, seedPhrase: string, password: string, accountName: string, color: string): string {.base.} =
raise newException(ValueError, "No implementation available")
method addWatchOnlyAccount*(self: AccessInterface, address: string, accountName: string, color: string) {.base.} =
method addWatchOnlyAccount*(self: AccessInterface, address: string, accountName: string, color: string): string {.base.} =
raise newException(ValueError, "No implementation available")
method deleteAccount*(self: AccessInterface, address: string) {.base.} =

View File

@ -11,16 +11,16 @@ method load*(self: AccessInterface) {.base.} =
method isLoaded*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available")
method generateNewAccount*(self: AccessInterface, password: string, accountName: string, color: string) {.base.} =
method generateNewAccount*(self: AccessInterface, password: string, accountName: string, color: string): string {.base.} =
raise newException(ValueError, "No implementation available")
method addAccountsFromPrivateKey*(self: AccessInterface, privateKey: string, password: string, accountName: string, color: string) {.base.} =
method addAccountsFromPrivateKey*(self: AccessInterface, privateKey: string, password: string, accountName: string, color: string): string {.base.} =
raise newException(ValueError, "No implementation available")
method addAccountsFromSeed*(self: AccessInterface, seedPhrase: string, password: string, accountName: string, color: string) {.base.} =
method addAccountsFromSeed*(self: AccessInterface, seedPhrase: string, password: string, accountName: string, color: string): string {.base.} =
raise newException(ValueError, "No implementation available")
method addWatchOnlyAccount*(self: AccessInterface, address: string, accountName: string, color: string) {.base.} =
method addWatchOnlyAccount*(self: AccessInterface, address: string, accountName: string, color: string): string {.base.} =
raise newException(ValueError, "No implementation available")
method deleteAccount*(self: AccessInterface, address: string) {.base.} =

View File

@ -89,17 +89,17 @@ method load*[T](self: Module[T]) =
method isLoaded*[T](self: Module[T]): bool =
return self.moduleLoaded
method generateNewAccount*[T](self: Module[T], password: string, accountName: string, color: string) =
self.controller.generateNewAccount(password, accountName, color)
method generateNewAccount*[T](self: Module[T], password: string, accountName: string, color: string): string =
return self.controller.generateNewAccount(password, accountName, color)
method addAccountsFromPrivateKey*[T](self: Module[T], privateKey: string, password: string, accountName: string, color: string) =
self.controller.addAccountsFromPrivateKey(privateKey, password, accountName, color)
method addAccountsFromPrivateKey*[T](self: Module[T], privateKey: string, password: string, accountName: string, color: string): string =
return self.controller.addAccountsFromPrivateKey(privateKey, password, accountName, color)
method addAccountsFromSeed*[T](self: Module[T], seedPhrase: string, password: string, accountName: string, color: string) =
self.controller.addAccountsFromSeed(seedPhrase, password, accountName, color)
method addAccountsFromSeed*[T](self: Module[T], seedPhrase: string, password: string, accountName: string, color: string): string =
return self.controller.addAccountsFromSeed(seedPhrase, password, accountName, color)
method addWatchOnlyAccount*[T](self: Module[T], address: string, accountName: string, color: string) =
self.controller.addWatchOnlyAccount(address, accountName, color)
method addWatchOnlyAccount*[T](self: Module[T], address: string, accountName: string, color: string): string =
return self.controller.addWatchOnlyAccount(address, accountName, color)
method deleteAccount*[T](self: Module[T], address: string) =
self.controller.deleteAccount(address)

View File

@ -35,17 +35,17 @@ QtObject:
proc setItems*(self: View, items: seq[Item]) =
self.model.setItems(items)
proc generateNewAccount*(self: View, password: string, accountName: string, color: string) {.slot.} =
self.delegate.generateNewAccount(password, accountName, color)
proc generateNewAccount*(self: View, password: string, accountName: string, color: string): string {.slot.} =
return self.delegate.generateNewAccount(password, accountName, color)
proc addAccountsFromPrivateKey*(self: View, privateKey: string, password: string, accountName: string, color: string) {.slot.} =
self.delegate.addAccountsFromPrivateKey(privateKey, password, accountName, color)
proc addAccountsFromPrivateKey*(self: View, privateKey: string, password: string, accountName: string, color: string): string {.slot.} =
return self.delegate.addAccountsFromPrivateKey(privateKey, password, accountName, color)
proc addAccountsFromSeed*(self: View, seedPhrase: string, password: string, accountName: string, color: string) {.slot.} =
self.delegate.addAccountsFromSeed(seedPhrase, password, accountName, color)
proc addAccountsFromSeed*(self: View, seedPhrase: string, password: string, accountName: string, color: string): string {.slot.} =
return self.delegate.addAccountsFromSeed(seedPhrase, password, accountName, color)
proc addWatchOnlyAccount*(self: View, address: string, accountName: string, color: string) {.slot.} =
self.delegate.addWatchOnlyAccount(address, accountName, color)
proc addWatchOnlyAccount*(self: View, address: string, accountName: string, color: string): string {.slot.} =
return self.delegate.addWatchOnlyAccount(address, accountName, color)
proc deleteAccount*(self: View, address: string) {.slot.} =
self.delegate.deleteAccount(address)

View File

@ -207,42 +207,50 @@ method saveAccount(
walletIndex: int = 0,
id: string = "",
publicKey: string = "",
) =
status_go_accounts.saveAccount(
address,
name,
password,
color,
accountType,
isADerivedAccount = true,
walletIndex,
id,
publicKey,
)
let accounts = fetchAccounts()
let prices = self.fetchPrices()
): string =
try:
status_go_accounts.saveAccount(
address,
name,
password,
color,
accountType,
isADerivedAccount = true,
walletIndex,
id,
publicKey,
)
let accounts = fetchAccounts()
let prices = self.fetchPrices()
var newAccount = accounts[0]
for account in accounts:
if not self.accounts.haskey(account.address):
newAccount = account
break
var newAccount = accounts[0]
for account in accounts:
if not self.accounts.haskey(account.address):
newAccount = account
break
newAccount.tokens = self.buildTokens(newAccount, prices)
self.accounts[newAccount.address] = newAccount
self.events.emit("walletAccount/accountSaved", AccountSaved(account: newAccount))
newAccount.tokens = self.buildTokens(newAccount, prices)
self.accounts[newAccount.address] = newAccount
self.events.emit("walletAccount/accountSaved", AccountSaved(account: newAccount))
except Exception as e:
return fmt"Error adding new account: {e.msg}"
method generateNewAccount*(self: Service, password: string, accountName: string, color: string) =
method generateNewAccount*(self: Service, password: string, accountName: string, color: string): string =
let
setting = self.settingService.getSetting()
walletRootAddress = setting.walletRootAddress
walletIndex = setting.latestDerivedPath + 1
defaultAccount = self.getDefaultAccount()
isPasswordOk = status_go_accounts.verifyAccountPassword(defaultAccount, password, KEYSTOREDIR)
if not isPasswordOk:
return "Error generating new account: invalid password"
let accountResponse = status_go_accounts.loadAccount(walletRootAddress, password)
let accountId = accountResponse.result{"id"}.getStr
let path = "m/" & $walletIndex
let deriveResponse = status_go_accounts.deriveAccounts(accountId, @[path])
self.saveAccount(
let errMsg = self.saveAccount(
deriveResponse.result[path]{"address"}.getStr,
accountName,
password,
@ -253,19 +261,22 @@ method generateNewAccount*(self: Service, password: string, accountName: string,
accountId,
deriveResponse.result[path]{"publicKey"}.getStr
)
if errMsg != "":
return errMsg
discard self.settingService.saveSetting("latest-derived-path", walletIndex)
return ""
method addAccountsFromPrivateKey*(self: Service, privateKey: string, password: string, accountName: string, color: string) =
method addAccountsFromPrivateKey*(self: Service, privateKey: string, password: string, accountName: string, color: string): string =
let
accountResponse = status_go_accounts.multiAccountImportPrivateKey(privateKey)
defaultAccount = self.getDefaultAccount()
isPasswordOk = status_go_accounts.verifyAccountPassword(defaultAccount, password, KEYSTOREDIR)
if not isPasswordOk:
return
return "Error generating new account: invalid password"
self.saveAccount(
return self.saveAccount(
accountResponse.result{"address"}.getStr,
accountName,
password,
@ -277,7 +288,7 @@ method addAccountsFromPrivateKey*(self: Service, privateKey: string, password: s
accountResponse.result{"publicKey"}.getStr,
)
method addAccountsFromSeed*(self: Service, seedPhrase: string, password: string, accountName: string, color: string) =
method addAccountsFromSeed*(self: Service, seedPhrase: string, password: string, accountName: string, color: string): string =
let mnemonic = replace(seedPhrase, ',', ' ')
let paths = @[PATH_WALLET_ROOT, PATH_EIP_1581, PATH_WHISPER, PATH_DEFAULT_WALLET]
let accountResponse = status_go_accounts.multiAccountImportMnemonic(mnemonic)
@ -289,9 +300,9 @@ method addAccountsFromSeed*(self: Service, seedPhrase: string, password: string,
isPasswordOk = status_go_accounts.verifyAccountPassword(defaultAccount, password, KEYSTOREDIR)
if not isPasswordOk:
return
return "Error generating new account: invalid password"
self.saveAccount(
return self.saveAccount(
deriveResponse.result[PATH_DEFAULT_WALLET]{"address"}.getStr,
accountName,
password,
@ -303,8 +314,8 @@ method addAccountsFromSeed*(self: Service, seedPhrase: string, password: string,
deriveResponse.result[PATH_DEFAULT_WALLET]{"publicKey"}.getStr
)
method addWatchOnlyAccount*(self: Service, address: string, accountName: string, color: string) =
self.saveAccount(address, accountName, "", color, status_go_accounts.WATCH, false)
method addWatchOnlyAccount*(self: Service, address: string, accountName: string, color: string): string =
return self.saveAccount(address, accountName, "", color, status_go_accounts.WATCH, false)
method deleteAccount*(self: Service, address: string) =
discard status_go_accounts.deleteAccount(address)

View File

@ -24,16 +24,16 @@ method getWalletAccount*(self: ServiceInterface, accountIndex: int): WalletAccou
method getCurrencyBalance*(self: ServiceInterface): float64 {.base.} =
raise newException(ValueError, "No implementation available")
method generateNewAccount*(self: ServiceInterface, password: string, accountName: string, color: string) {.base.} =
method generateNewAccount*(self: ServiceInterface, password: string, accountName: string, color: string): string {.base.} =
raise newException(ValueError, "No implementation available")
method addAccountsFromPrivateKey*(self: ServiceInterface, privateKey: string, password: string, accountName: string, color: string) {.base.} =
method addAccountsFromPrivateKey*(self: ServiceInterface, privateKey: string, password: string, accountName: string, color: string): string {.base.} =
raise newException(ValueError, "No implementation available")
method addAccountsFromSeed*(self: ServiceInterface, seedPhrase: string, password: string, accountName: string, color: string) {.base.} =
method addAccountsFromSeed*(self: ServiceInterface, seedPhrase: string, password: string, accountName: string, color: string): string {.base.} =
raise newException(ValueError, "No implementation available")
method addWatchOnlyAccount*(self: ServiceInterface, address: string, accountName: string, color: string) {.base.} =
method addWatchOnlyAccount*(self: ServiceInterface, address: string, accountName: string, color: string): string {.base.} =
raise newException(ValueError, "No implementation available")
method deleteAccount*(self: ServiceInterface, address: string) {.base.} =

View File

@ -139,17 +139,16 @@ ModalPopup {
return loading = false
}
const result = RootStore.addAccountsFromPrivateKey(accountPKeyInput.text, passwordInput.text, accountNameInput.text, accountColorInput.selectedColor)
const errMessage = RootStore.addAccountsFromPrivateKey(accountPKeyInput.text, passwordInput.text, accountNameInput.text, accountColorInput.selectedColor)
loading = false
if (result) {
let resultJson = JSON.parse(result);
if (errMessage) {
errorSound.play();
if (Utils.isInvalidPasswordMessage(resultJson.error)) {
if (Utils.isInvalidPasswordMessage(errMessage)) {
//% "Wrong password"
popup.passwordValidationError = qsTrId("wrong-password")
} else {
accountError.text = resultJson.error
accountError.text = errMessage
accountError.open()
}
return

View File

@ -140,16 +140,15 @@ ModalPopup {
return loading = false
}
const result = RootStore.addAccountsFromSeed(seedPhraseTextArea.textArea.text, passwordInput.text, accountNameInput.text, accountColorInput.selectedColor)
const errMessage = RootStore.addAccountsFromSeed(seedPhraseTextArea.textArea.text, passwordInput.text, accountNameInput.text, accountColorInput.selectedColor)
loading = false
if (result) {
let resultJson = JSON.parse(result);
if (errMessage) {
errorSound.play();
if (Utils.isInvalidPasswordMessage(resultJson.error)) {
if (Utils.isInvalidPasswordMessage(errMessage)) {
//% "Wrong password"
popup.passwordValidationError = qsTrId("wrong-password")
} else {
accountError.text = resultJson.error
accountError.text = errMessage
accountError.open()
}
return

View File

@ -112,16 +112,16 @@ ModalPopup {
return loading = false
}
const result = RootStore.generateNewAccount(passwordInput.text, accountNameInput.text, accountColorInput.selectedColor)
const errMessage = RootStore.generateNewAccount(passwordInput.text, accountNameInput.text, accountColorInput.selectedColor)
console.log(errMessage)
loading = false
if (result) {
let resultJson = JSON.parse(result);
if (errMessage) {
errorSound.play();
if (Utils.isInvalidPasswordMessage(resultJson.error)) {
if (Utils.isInvalidPasswordMessage(errMessage)) {
//% "Wrong password"
popup.passwordValidationError = qsTrId("wrong-password")
} else {
accountError.text = resultJson.error;
accountError.text = errMessage;
accountError.open();
}
return