feat: add modal to add an account with a private key
This commit is contained in:
parent
b8c5059de7
commit
2ade9e938d
|
@ -98,6 +98,9 @@ QtObject:
|
||||||
proc addAccountsFromSeed*(self: WalletView, seed: string, password: string, accountName: string, color: string) {.slot.} =
|
proc addAccountsFromSeed*(self: WalletView, seed: string, password: string, accountName: string, color: string) {.slot.} =
|
||||||
self.status.wallet.addAccountsFromSeed(seed, password, accountName, color)
|
self.status.wallet.addAccountsFromSeed(seed, password, accountName, color)
|
||||||
|
|
||||||
|
proc addAccountsFromPrivateKey*(self: WalletView, privateKey: string, password: string, accountName: string, color: string) {.slot.} =
|
||||||
|
self.status.wallet.addAccountsFromPrivateKey(privateKey, password, accountName, color)
|
||||||
|
|
||||||
proc getAccountList(self: WalletView): QVariant {.slot.} =
|
proc getAccountList(self: WalletView): QVariant {.slot.} =
|
||||||
return newQVariant(self.accounts)
|
return newQVariant(self.accounts)
|
||||||
|
|
||||||
|
|
|
@ -174,8 +174,18 @@ proc multiAccountImportMnemonic*(mnemonic: string): GeneratedAccount =
|
||||||
let importResult = $libstatus.multiAccountImportMnemonic($mnemonicJson)
|
let importResult = $libstatus.multiAccountImportMnemonic($mnemonicJson)
|
||||||
result = Json.decode(importResult, GeneratedAccount)
|
result = Json.decode(importResult, GeneratedAccount)
|
||||||
|
|
||||||
proc saveAccount*(account: GeneratedAccount, password: string, color: string, accountType: string): DerivedAccount =
|
proc MultiAccountImportPrivateKey*(privateKey: string): GeneratedAccount =
|
||||||
let storeDerivedResult = storeDerivedAccounts(account, password)
|
let privateKeyJson = %* {
|
||||||
|
"privateKey": privateKey
|
||||||
|
}
|
||||||
|
# libstatus.MultiAccountImportPrivateKey never results in an error given ANY input
|
||||||
|
let importResult = $libstatus.MultiAccountImportPrivateKey($privateKeyJson)
|
||||||
|
result = Json.decode(importResult, GeneratedAccount)
|
||||||
|
|
||||||
|
proc saveAccount*(account: GeneratedAccount, password: string, color: string, accountType: string, isADerivedAccount = true): DerivedAccount =
|
||||||
|
# Only store derived accounts. Private key accounts are not multiaccounts
|
||||||
|
if (isADerivedAccount):
|
||||||
|
discard storeDerivedAccounts(account, password)
|
||||||
|
|
||||||
var address = account.derived.defaultWallet.address
|
var address = account.derived.defaultWallet.address
|
||||||
var publicKey = account.derived.defaultWallet.publicKey
|
var publicKey = account.derived.defaultWallet.publicKey
|
||||||
|
|
|
@ -12,6 +12,8 @@ proc multiAccountStoreDerivedAccounts*(paramsJSON: cstring): cstring {.importc:
|
||||||
|
|
||||||
proc multiAccountImportMnemonic*(paramsJSON: cstring): cstring {.importc: "MultiAccountImportMnemonic".}
|
proc multiAccountImportMnemonic*(paramsJSON: cstring): cstring {.importc: "MultiAccountImportMnemonic".}
|
||||||
|
|
||||||
|
proc MultiAccountImportPrivateKey*(paramsJSON: cstring): cstring {.importc: "MultiAccountImportPrivateKey".}
|
||||||
|
|
||||||
proc multiAccountDeriveAddresses*(paramsJSON: cstring): cstring {.importc: "MultiAccountDeriveAddresses".}
|
proc multiAccountDeriveAddresses*(paramsJSON: cstring): cstring {.importc: "MultiAccountDeriveAddresses".}
|
||||||
|
|
||||||
proc saveAccountAndLogin*(accountData: cstring, password: cstring, settingsJSON: cstring, configJSON: cstring, subaccountData: cstring): cstring {.importc: "SaveAccountAndLogin".}
|
proc saveAccountAndLogin*(accountData: cstring, password: cstring, settingsJSON: cstring, configJSON: cstring, subaccountData: cstring): cstring {.importc: "SaveAccountAndLogin".}
|
||||||
|
|
|
@ -133,12 +133,12 @@ proc getTotalFiatBalance*(self: WalletModel): string =
|
||||||
var newBalance = 0.0
|
var newBalance = 0.0
|
||||||
fmt"{newBalance:.2f} {self.defaultCurrency}"
|
fmt"{newBalance:.2f} {self.defaultCurrency}"
|
||||||
|
|
||||||
proc addNewGeneratedAccount(self: WalletModel, generatedAccount: GeneratedAccount, password: string, accountName: string, color: string, accountType: string) =
|
proc addNewGeneratedAccount(self: WalletModel, generatedAccount: GeneratedAccount, password: string, accountName: string, color: string, accountType: string, isADerivedAccount = true) =
|
||||||
generatedAccount.name = accountName
|
generatedAccount.name = accountName
|
||||||
|
|
||||||
var derivedAccount: DerivedAccount
|
var derivedAccount: DerivedAccount
|
||||||
try:
|
try:
|
||||||
derivedAccount = status_accounts.saveAccount(generatedAccount, password, color, accountType)
|
derivedAccount = status_accounts.saveAccount(generatedAccount, password, color, accountType, isADerivedAccount)
|
||||||
except:
|
except:
|
||||||
error "Error storing the new account. Bad password?"
|
error "Error storing the new account. Bad password?"
|
||||||
return
|
return
|
||||||
|
@ -162,6 +162,10 @@ proc addAccountsFromSeed*(self: WalletModel, seed: string, password: string, acc
|
||||||
let generatedAccount = status_accounts.multiAccountImportMnemonic(mnemonic)
|
let generatedAccount = status_accounts.multiAccountImportMnemonic(mnemonic)
|
||||||
self.addNewGeneratedAccount(generatedAccount, password, accountName, color, constants.SEED)
|
self.addNewGeneratedAccount(generatedAccount, password, accountName, color, constants.SEED)
|
||||||
|
|
||||||
|
proc addAccountsFromPrivateKey*(self: WalletModel, privateKey: string, password: string, accountName: string, color: string) =
|
||||||
|
let generatedAccount = status_accounts.MultiAccountImportPrivateKey(privateKey)
|
||||||
|
self.addNewGeneratedAccount(generatedAccount, password, accountName, color, constants.SEED, false)
|
||||||
|
|
||||||
proc toggleAsset*(self: WalletModel, symbol: string, enable: bool, address: string, name: string, decimals: int, color: string) =
|
proc toggleAsset*(self: WalletModel, symbol: string, enable: bool, address: string, name: string, decimals: int, color: string) =
|
||||||
if enable:
|
if enable:
|
||||||
discard status_tokens.addCustomToken(address, name, symbol, decimals, color)
|
discard status_tokens.addCustomToken(address, name, symbol, decimals, color)
|
||||||
|
|
|
@ -83,6 +83,9 @@ Rectangle {
|
||||||
AddAccountWithSeed {
|
AddAccountWithSeed {
|
||||||
id: addAccountWithSeedModal
|
id: addAccountWithSeedModal
|
||||||
}
|
}
|
||||||
|
AddAccountWithPrivateKey {
|
||||||
|
id: addAccountWithPrivateKeydModal
|
||||||
|
}
|
||||||
|
|
||||||
PopupMenu {
|
PopupMenu {
|
||||||
id: newAccountMenu
|
id: newAccountMenu
|
||||||
|
@ -112,7 +115,7 @@ Rectangle {
|
||||||
text: qsTr("Enter a private key")
|
text: qsTr("Enter a private key")
|
||||||
icon.source: "../../../img/enter_private_key.svg"
|
icon.source: "../../../img/enter_private_key.svg"
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
console.log("TODO: Enter a private key")
|
addAccountWithPrivateKeydModal.open()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onAboutToHide: {
|
onAboutToHide: {
|
||||||
|
|
|
@ -0,0 +1,88 @@
|
||||||
|
import QtQuick 2.12
|
||||||
|
import QtQuick.Controls 2.3
|
||||||
|
import QtQuick.Layouts 1.3
|
||||||
|
import "../../../../imports"
|
||||||
|
import "../../../../shared"
|
||||||
|
|
||||||
|
ModalPopup {
|
||||||
|
id: popup
|
||||||
|
title: qsTr("Add account from private key")
|
||||||
|
height: 600
|
||||||
|
|
||||||
|
property int marginBetweenInputs: 38
|
||||||
|
property string selectedColor: Constants.accountColors[0]
|
||||||
|
|
||||||
|
onOpened: {
|
||||||
|
passwordInput.text = ""
|
||||||
|
passwordInput.forceActiveFocus(Qt.MouseFocusReason)
|
||||||
|
}
|
||||||
|
|
||||||
|
Input {
|
||||||
|
id: passwordInput
|
||||||
|
placeholderText: qsTr("Enter your password…")
|
||||||
|
label: qsTr("Password")
|
||||||
|
textField.echoMode: TextInput.Password
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Input {
|
||||||
|
id: accountPKeyInput
|
||||||
|
anchors.top: passwordInput.bottom
|
||||||
|
anchors.topMargin: marginBetweenInputs
|
||||||
|
placeholderText: qsTr("Paste the contents of your private key")
|
||||||
|
label: qsTr("Private key")
|
||||||
|
isTextArea: true
|
||||||
|
customHeight: 88
|
||||||
|
}
|
||||||
|
|
||||||
|
Input {
|
||||||
|
id: accountNameInput
|
||||||
|
anchors.top: accountPKeyInput.bottom
|
||||||
|
anchors.topMargin: marginBetweenInputs
|
||||||
|
placeholderText: qsTr("Enter an account name...")
|
||||||
|
label: qsTr("Account name")
|
||||||
|
}
|
||||||
|
|
||||||
|
Input {
|
||||||
|
id: accountColorInput
|
||||||
|
anchors.top: accountNameInput.bottom
|
||||||
|
anchors.topMargin: marginBetweenInputs
|
||||||
|
bgColor: selectedColor
|
||||||
|
label: qsTr("Account color")
|
||||||
|
selectOptions: Constants.accountColors.map(color => {
|
||||||
|
return {
|
||||||
|
text: "",
|
||||||
|
bgColor: color,
|
||||||
|
height: 52,
|
||||||
|
onClicked: function () {
|
||||||
|
selectedColor = color
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
footer: StyledButton {
|
||||||
|
anchors.top: parent.top
|
||||||
|
anchors.topMargin: Theme.padding
|
||||||
|
anchors.right: parent.right
|
||||||
|
anchors.rightMargin: Theme.padding
|
||||||
|
label: "Add account >"
|
||||||
|
|
||||||
|
disabled: passwordInput.text === "" || accountNameInput.text === "" || accountPKeyInput.textAreaText === ""
|
||||||
|
|
||||||
|
onClicked : {
|
||||||
|
// TODO add message to show validation errors
|
||||||
|
if (passwordInput.text === "" || accountNameInput.text === "" || accountPKeyInput.textAreaText === "") return;
|
||||||
|
|
||||||
|
walletModel.addAccountsFromPrivateKey(accountPKeyInput.textAreaText, passwordInput.text, accountNameInput.text, selectedColor)
|
||||||
|
// TODO manage errors adding account
|
||||||
|
popup.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*##^##
|
||||||
|
Designer {
|
||||||
|
D{i:0;formeditorColor:"#ffffff";height:500;width:400}
|
||||||
|
}
|
||||||
|
##^##*/
|
|
@ -4,3 +4,4 @@ TokenSettingsModalContent 1.0 TokenSettingsModalContent.qml
|
||||||
AddAccount 1.0 AddAccount.qml
|
AddAccount 1.0 AddAccount.qml
|
||||||
GenerateAccountModal 1.0 GenerateAccountModal.qml
|
GenerateAccountModal 1.0 GenerateAccountModal.qml
|
||||||
AddAccountWithSeed 1.0 AddAccountWithSeed.qml
|
AddAccountWithSeed 1.0 AddAccountWithSeed.qml
|
||||||
|
AddAccountWithPrivateKey 1.0 AddAccountWithPrivateKey.qml
|
||||||
|
|
|
@ -80,6 +80,7 @@ DISTFILES += \
|
||||||
app/AppLayouts/Wallet/AssetsTab.qml \
|
app/AppLayouts/Wallet/AssetsTab.qml \
|
||||||
app/AppLayouts/Wallet/CollectiblesTab.qml \
|
app/AppLayouts/Wallet/CollectiblesTab.qml \
|
||||||
app/AppLayouts/Wallet/Components/AddAccount.qml \
|
app/AppLayouts/Wallet/Components/AddAccount.qml \
|
||||||
|
app/AppLayouts/Wallet/Components/AddAccountWithPrivateKey.qml \
|
||||||
app/AppLayouts/Wallet/Components/AddAccountWithSeed.qml \
|
app/AppLayouts/Wallet/Components/AddAccountWithSeed.qml \
|
||||||
app/AppLayouts/Wallet/Components/GenerateAccountModal.qml \
|
app/AppLayouts/Wallet/Components/GenerateAccountModal.qml \
|
||||||
app/AppLayouts/Wallet/Components/SendModalContent.qml \
|
app/AppLayouts/Wallet/Components/SendModalContent.qml \
|
||||||
|
|
Loading…
Reference in New Issue