Browse Source

create wallet at end of new wallet wizard

patch-4
Sander van Grieken 3 years ago
parent
commit
4cae116ad8
  1. 13
      electrum/gui/qml/components/NewWalletWizard.qml
  2. 3
      electrum/gui/qml/components/Wallets.qml
  3. 20
      electrum/gui/qml/qebitcoin.py
  4. 1
      electrum/gui/qml/qedaemon.py
  5. 43
      electrum/gui/qml/qewalletdb.py

13
electrum/gui/qml/components/NewWalletWizard.qml

@ -2,11 +2,15 @@ import QtQuick 2.6
import QtQuick.Layouts 1.0
import QtQuick.Controls 2.1
import org.electrum 1.0
Wizard {
id: walletwizard
title: qsTr('New Wallet')
signal walletCreated
enter: null // disable transition
// State transition functions. These functions are called when the 'Next'
@ -77,5 +81,14 @@ Wizard {
start.next.connect(function() {walletnameDone()})
}
onAccepted: {
console.log('Finished new wallet wizard')
walletdb.create_storage(wizard_data)
}
WalletDB {
id: walletdb
onCreateSuccess: walletwizard.walletCreated()
}
}

3
electrum/gui/qml/components/Wallets.qml

@ -100,6 +100,9 @@ Pane {
onClicked: {
var dialog = app.newWalletWizard.createObject(rootItem)
dialog.open()
dialog.walletCreated.connect(function() {
Daemon.availableWallets.reload()
})
}
}
}

20
electrum/gui/qml/qebitcoin.py

@ -13,6 +13,9 @@ class QEBitcoin(QObject):
generatedSeedChanged = pyqtSignal()
generatedSeed = ''
seedValidChanged = pyqtSignal()
seedValid = False
@pyqtProperty('QString', notify=generatedSeedChanged)
def generated_seed(self):
return self.generatedSeed
@ -20,8 +23,23 @@ class QEBitcoin(QObject):
@pyqtSlot()
@pyqtSlot(str)
@pyqtSlot(str,str)
def generate_seed(self, seed_type='standard', language='en'):
def generate_seed(self, seed_type='segwit', language='en'):
self._logger.debug('generating seed of type ' + str(seed_type))
self.generatedSeed = mnemonic.Mnemonic(language).make_seed(seed_type=seed_type)
self._logger.debug('seed generated')
self.generatedSeedChanged.emit()
@pyqtProperty(bool, notify=seedValidChanged)
def seed_valid(self):
return self.seedValid
@pyqtSlot(str)
@pyqtSlot(str,str)
@pyqtSlot(str,str,str)
@pyqtSlot(str,str,str,str)
def verify_seed(self, seed, bip39=False, seed_type='segwit', language='en'):
self._logger.debug('verify seed of type ' + str(seed_type))
#TODO
#self._logger.debug('seed verified')
#self.seedValidChanged.emit()

1
electrum/gui/qml/qedaemon.py

@ -57,6 +57,7 @@ class QEAvailableWalletListModel(QEWalletListModel):
self.daemon = daemon
self.reload()
@pyqtSlot()
def reload(self):
if len(self.wallets) > 0:
self.beginRemoveRows(QModelIndex(), 0, len(self.wallets) - 1)

43
electrum/gui/qml/qewalletdb.py

@ -1,9 +1,12 @@
import os
from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject
from electrum.logging import Logger, get_logger
from electrum.storage import WalletStorage
from electrum.storage import WalletStorage, StorageEncryptionVersion
from electrum.wallet_db import WalletDB
from electrum.util import InvalidPassword
from electrum import keystore
from .qedaemon import QEDaemon
@ -29,6 +32,8 @@ class QEWalletDB(QObject):
upgradingChanged = pyqtSignal()
splitFinished = pyqtSignal()
readyChanged = pyqtSignal()
createError = pyqtSignal([str], arguments=["error"])
createSuccess = pyqtSignal()
def reset(self):
self._path = None
@ -201,3 +206,39 @@ class QEWalletDB(QObject):
#wallet.start_network(self.network)
#self._wallets[path] = wallet
#return wallet
@pyqtSlot('QJSValue')
def create_storage(self, js_data):
self._logger.info('Creating wallet from wizard data')
data = js_data.toVariant()
self._logger.debug(str(data))
try:
path = os.path.join(os.path.dirname(self.daemon.config.get_wallet_path()), data['wallet_name'])
if os.path.exists(path):
raise Exception('file already exists at path')
storage = WalletStorage(path)
k = keystore.from_seed(data['seed'], data['seed_extra_words'], data['wallet_type'] == 'multisig')
if data['encrypt']:
storage.set_password(data['password'], enc_version=StorageEncryptionVersion.USER_PASSWORD)
db = WalletDB('', manual_upgrades=False)
db.set_keystore_encryption(bool(data['password']) and data['encrypt'])
db.put('wallet_type', data['wallet_type'])
db.put('seed_type', data['seed_type'])
db.put('keystore', k.dump())
if k.can_have_deterministic_lightning_xprv():
db.put('lightning_xprv', k.get_lightning_xprv(None))
db.load_plugins()
db.write(storage)
self.createSuccess.emit()
except Exception as e:
self._logger.error(str(e))
self.createError.emit(str(e))

Loading…
Cancel
Save