feat: enable deleting a wallet account
This commit is contained in:
parent
7476cf3d16
commit
4d7eee1ebf
|
@ -111,6 +111,16 @@ QtObject:
|
|||
self.accountListChanged()
|
||||
self.accounts.forceUpdate()
|
||||
|
||||
proc deleteAccount*(self: WalletView, address: string): string {.slot.} =
|
||||
result = self.status.wallet.deleteAccount(address)
|
||||
if (result == ""):
|
||||
let index = self.accounts.getAccountindexByAddress(address)
|
||||
if (index == -1):
|
||||
return fmt"Unable to find the account with the address {address}"
|
||||
self.accounts.deleteAccountAtIndex(index)
|
||||
self.accountListChanged()
|
||||
self.accounts.forceUpdate()
|
||||
|
||||
proc getAccountList(self: WalletView): QVariant {.slot.} =
|
||||
return newQVariant(self.accounts)
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import NimQml
|
||||
import Tables
|
||||
import sequtils as sequtils
|
||||
import random
|
||||
import ./account_item
|
||||
import ../../../status/wallet
|
||||
|
@ -30,6 +31,17 @@ QtObject:
|
|||
|
||||
proc getAccount*(self: AccountList, index: int): WalletAccount = self.accounts[index]
|
||||
|
||||
proc getAccountindexByAddress*(self: AccountList, address: string): int =
|
||||
var i = 0
|
||||
for account in self.accounts:
|
||||
if (account.address == address):
|
||||
return i
|
||||
i = i + 1
|
||||
return -1
|
||||
|
||||
proc deleteAccountAtIndex*(self: AccountList, index: int) =
|
||||
sequtils.delete(self.accounts, index, index)
|
||||
|
||||
method rowCount*(self: AccountList, index: QModelIndex = nil): int =
|
||||
return self.accounts.len
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import libstatus
|
||||
import core
|
||||
import json
|
||||
import utils
|
||||
import utils as utils
|
||||
import accounts/constants
|
||||
import nimcrypto
|
||||
import os
|
||||
|
@ -214,7 +214,7 @@ proc saveAccount*(account: GeneratedAccount, password: string, color: string, ac
|
|||
|
||||
proc changeAccount*(account: WalletAccount): string =
|
||||
try:
|
||||
let res= callPrivateRPC("accounts_saveAccounts", %* [
|
||||
let response = callPrivateRPC("accounts_saveAccounts", %* [
|
||||
[{
|
||||
"color": account.iconColor,
|
||||
"name": account.name,
|
||||
|
@ -224,11 +224,23 @@ proc changeAccount*(account: WalletAccount): string =
|
|||
"path": "m/44'/60'/0'/0/1"
|
||||
}]
|
||||
])
|
||||
|
||||
utils.handleRPCErrors(response)
|
||||
return ""
|
||||
except Exception as e:
|
||||
error "Error saving the account", msg=e.msg
|
||||
result = e.msg
|
||||
|
||||
proc deleteAccount*(address: string): string =
|
||||
try:
|
||||
let response = callPrivateRPC("accounts_deleteAccount", %* [address])
|
||||
|
||||
utils.handleRPCErrors(response)
|
||||
return ""
|
||||
except Exception as e:
|
||||
error "Error removing the account", msg=e.msg
|
||||
result = e.msg
|
||||
|
||||
proc deriveAccounts*(accountId: string): MultiAccounts =
|
||||
let deriveJson = %* {
|
||||
"accountID": accountId,
|
||||
|
|
|
@ -33,3 +33,8 @@ proc generateSigningPhrase*(count: int): string =
|
|||
phrases.add(rng.sample(signing_phrases.phrases))
|
||||
|
||||
result = phrases.join(" ")
|
||||
|
||||
proc handleRPCErrors*(response: string) =
|
||||
let parsedReponse = parseJson(response)
|
||||
if (parsedReponse.hasKey("error")):
|
||||
raise newException(ValueError, parsedReponse["error"]["message"].str)
|
||||
|
|
|
@ -133,6 +133,9 @@ proc changeAccountSettings*(self: WalletModel, address: string, accountName: str
|
|||
selectedAccount.iconColor = color
|
||||
result = status_accounts.changeAccount(selectedAccount)
|
||||
|
||||
proc deleteAccount*(self: WalletModel, address: string): string =
|
||||
result = status_accounts.deleteAccount(address)
|
||||
|
||||
proc toggleAsset*(self: WalletModel, symbol: string, enable: bool, address: string, name: string, decimals: int, color: string) =
|
||||
self.tokens = addOrRemoveToken(enable, address, name, symbol, decimals, color)
|
||||
for account in self.accounts:
|
||||
|
|
|
@ -7,6 +7,7 @@ import "../../../shared"
|
|||
|
||||
ModalPopup {
|
||||
property var currentAccount: walletModel.currentAccount
|
||||
property var changeSelectedAccount
|
||||
id: popup
|
||||
// TODO add icon when we have that feature
|
||||
title: qsTr("Status account settings")
|
||||
|
@ -97,9 +98,24 @@ ModalPopup {
|
|||
btnColor: Theme.white
|
||||
textColor: Theme.red
|
||||
|
||||
MessageDialog {
|
||||
id: deleteError
|
||||
title: "Deleting account failed"
|
||||
icon: StandardIcon.Critical
|
||||
standardButtons: StandardButton.Ok
|
||||
}
|
||||
|
||||
onClicked : {
|
||||
// TODO add a confirmation message
|
||||
console.log('DELETE')
|
||||
const error = walletModel.deleteAccount(currentAccount.address);
|
||||
if (error) {
|
||||
deleteError.text = error
|
||||
deleteError.open()
|
||||
return
|
||||
}
|
||||
|
||||
// Change active account to the first
|
||||
changeSelectedAccount(0)
|
||||
popup.close();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,13 @@ import "./Components"
|
|||
|
||||
Item {
|
||||
property int selectedAccount: 0
|
||||
property var changeSelectedAccount: function(newIndex) {
|
||||
if (newIndex > walletModel.accounts) {
|
||||
return
|
||||
}
|
||||
selectedAccount = newIndex
|
||||
walletModel.setCurrentAccountByIndex(newIndex)
|
||||
}
|
||||
id: walletInfoContainer
|
||||
width: 340
|
||||
|
||||
|
@ -145,8 +152,7 @@ Item {
|
|||
MouseArea {
|
||||
anchors.fill: parent
|
||||
onClicked: {
|
||||
selectedAccount = index
|
||||
walletModel.setCurrentAccountByIndex(index)
|
||||
changeSelectedAccount(index)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import "../../../shared"
|
|||
|
||||
Item {
|
||||
property var currentAccount: walletModel.currentAccount
|
||||
property var changeSelectedAccount
|
||||
|
||||
id: walletHeader
|
||||
height: walletAddress.y + walletAddress.height
|
||||
|
@ -79,6 +80,7 @@ Item {
|
|||
|
||||
AccountSettingsModal {
|
||||
id: accountSettingsModal
|
||||
changeSelectedAccount: walletHeader.changeSelectedAccount
|
||||
}
|
||||
|
||||
Item {
|
||||
|
|
|
@ -31,6 +31,7 @@ SplitView {
|
|||
|
||||
WalletHeader {
|
||||
id: walletHeader
|
||||
changeSelectedAccount: leftTab.changeSelectedAccount
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
|
|
Loading…
Reference in New Issue