feat: add watch only accounts to wallet

This commit is contained in:
Jonathan Rainville 2020-06-09 15:29:57 -04:00 committed by Iuri Matias
parent c3f9d57e5d
commit 7295fde809
8 changed files with 96 additions and 4 deletions

View File

@ -101,6 +101,9 @@ QtObject:
proc addAccountsFromPrivateKey*(self: WalletView, privateKey: string, password: string, accountName: string, color: string) {.slot.} =
self.status.wallet.addAccountsFromPrivateKey(privateKey, password, accountName, color)
proc addWatchOnlyAccount*(self: WalletView, address: string, accountName: string, color: string) {.slot.} =
self.status.wallet.addWatchOnlyAccount(address, accountName, color)
proc getAccountList(self: WalletView): QVariant {.slot.} =
return newQVariant(self.accounts)

View File

@ -3,6 +3,7 @@ import json
const GENERATED* = "generated"
const SEED* = "seed"
const KEY* = "key"
const WATCH* = "watch"
const PATH_WALLET_ROOT* = "m/44'/60'/0'/0"
# EIP1581 Root Key, the extended key from which any whisper key/encryption key can be derived

View File

@ -22,7 +22,8 @@ proc getWalletAccounts*(): seq[WalletAccount] =
walletAccounts.add(WalletAccount(
address: $account["address"].getStr,
path: $account["path"].getStr,
publicKey: $account["public-key"].getStr,
# Watch accoutns don't have a public key
publicKey: if (account.hasKey("public-key")): $account["public-key"].getStr else: "",
name: $account["name"].getStr,
color: $account["color"].getStr,
wallet: $account["wallet"].getStr == "true",
@ -30,7 +31,8 @@ proc getWalletAccounts*(): seq[WalletAccount] =
))
result = walletAccounts
except:
error "Failed getting wallet accounts"
let msg = getCurrentExceptionMsg()
error "Failed getting wallet accounts", msg
proc sendTransaction*(from_address: string, to: string, value: string, password: string): string =

View File

@ -143,6 +143,7 @@ proc addNewGeneratedAccount(self: WalletModel, generatedAccount: GeneratedAccoun
error "Error storing the new account. Bad password?"
return
# TODO actually fetch the balance for accounts that are not generated
var symbol = "SNT"
var asset = Asset(name:"Status", symbol: symbol, value: fmt"0.0", fiatValue: "$" & fmt"0.0", image: fmt"../../img/token-icons/{toLowerAscii(symbol)}.svg")
@ -164,7 +165,11 @@ proc addAccountsFromSeed*(self: WalletModel, seed: string, password: string, acc
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)
self.addNewGeneratedAccount(generatedAccount, password, accountName, color, constants.KEY, false)
proc addWatchOnlyAccount*(self: WalletModel, address: string, accountName: string, color: string) =
let account = GeneratedAccount(address: address)
self.addNewGeneratedAccount(account, "", accountName, color, constants.WATCH, false)
proc toggleAsset*(self: WalletModel, symbol: string, enable: bool, address: string, name: string, decimals: int, color: string) =
if enable:

View File

@ -86,6 +86,9 @@ Rectangle {
AddAccountWithPrivateKey {
id: addAccountWithPrivateKeydModal
}
AddWatchOnlyAccount {
id: addWatchOnlyAccountModal
}
PopupMenu {
id: newAccountMenu
@ -101,7 +104,7 @@ Rectangle {
text: qsTr("Add a watch-only address")
icon.source: "../../../img/add_watch_only.svg"
onTriggered: {
console.log("TODO: Add a watch-only address")
addWatchOnlyAccountModal.open()
}
}
QQC2.Action {

View File

@ -0,0 +1,75 @@
import QtQuick 2.12
import QtQuick.Controls 2.3
import QtQuick.Layouts 1.3
import "../../../../imports"
import "../../../../shared"
ModalPopup {
id: popup
title: qsTr("Add a watch-only account")
property int marginBetweenInputs: 38
property string selectedColor: Constants.accountColors[0]
onOpened: {
addressInput.text = "";
addressInput.forceActiveFocus(Qt.MouseFocusReason)
}
Input {
id: addressInput
// TODO add QR code reader for the address
placeholderText: qsTr("Enter address...")
label: qsTr("Account address")
}
Input {
id: accountNameInput
anchors.top: addressInput.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: addressInput.text === "" || accountNameInput.text === ""
onClicked : {
// TODO add message to show validation errors
if (addressInput.text === "" || accountNameInput.text === "") return;
walletModel.addWatchOnlyAccount(addressInput.text, accountNameInput.text, selectedColor);
// TODO manage errors adding account
popup.close();
}
}
}
/*##^##
Designer {
D{i:0;formeditorColor:"#ffffff";height:500;width:400}
}
##^##*/

View File

@ -5,3 +5,4 @@ AddAccount 1.0 AddAccount.qml
GenerateAccountModal 1.0 GenerateAccountModal.qml
AddAccountWithSeed 1.0 AddAccountWithSeed.qml
AddAccountWithPrivateKey 1.0 AddAccountWithPrivateKey.qml
AddWatchOnlyAccount 1.0 AddWatchOnlyAccount.qml

View File

@ -82,6 +82,8 @@ DISTFILES += \
app/AppLayouts/Wallet/Components/AddAccount.qml \
app/AppLayouts/Wallet/Components/AddAccountWithPrivateKey.qml \
app/AppLayouts/Wallet/Components/AddAccountWithSeed.qml \
app/AppLayouts/Wallet/Components/AddWatchOnlyAccount \
app/AppLayouts/Wallet/Components/AddWatchOnlyAccount.qml \
app/AppLayouts/Wallet/Components/GenerateAccountModal.qml \
app/AppLayouts/Wallet/Components/SendModalContent.qml \
app/AppLayouts/Wallet/Components/SetCurrencyModalContent.qml \