diff --git a/src/cutecoin/core/app.py b/src/cutecoin/core/app.py index 3893d1438b44325b500998d6da20f8c5a4caeffe..0fbfd924dca9272c249ebfed5cae989b5e7bb381 100644 --- a/src/cutecoin/core/app.py +++ b/src/cutecoin/core/app.py @@ -239,6 +239,24 @@ class Application(QObject): data['version'] = __version__ json.dump(data, outfile, indent=4, sort_keys=True) + def save_wallet(self, account, wallet): + """ + Save wallet of account in cache + + :param cutecoin.core.account.Account account: Account instance + :param cutecoin.core.wallet.Wallet wallet: Wallet instance + """ + if not os.path.exists(os.path.join(config.parameters['home'], + account.name, '__cache__')): + os.makedirs(os.path.join(config.parameters['home'], + account.name, '__cache__')) + wallet_path = os.path.join(config.parameters['home'], + account.name, '__cache__', wallet.pubkey) + with open(wallet_path, 'w') as outfile: + data = wallet.jsonify_caches() + data['version'] = __version__ + json.dump(data, outfile, indent=4, sort_keys=True) + def save_cache(self, account): ''' Save the cache of an account @@ -250,12 +268,7 @@ class Application(QObject): os.makedirs(os.path.join(config.parameters['home'], account.name, '__cache__')) for wallet in account.wallets: - wallet_path = os.path.join(config.parameters['home'], - account.name, '__cache__', wallet.pubkey) - with open(wallet_path, 'w') as outfile: - data = wallet.jsonify_caches() - data['version'] = __version__ - json.dump(data, outfile, indent=4, sort_keys=True) + self.save_wallet(account, wallet) for community in account.communities: community_path = os.path.join(config.parameters['home'], @@ -267,6 +280,7 @@ class Application(QObject): community.currency + '_network') with open(network_path, 'w') as outfile: + data = dict() data['network'] = community.jsonify_network() data['version'] = __version__ json.dump(data, outfile, indent=4, sort_keys=True) diff --git a/src/cutecoin/gui/mainwindow.py b/src/cutecoin/gui/mainwindow.py index caa26f3b4159117c6f17de76f5db69a082ee1b65..faa70e907d855b9cfdfdc7f0b65a19f70c9d84ca 100644 --- a/src/cutecoin/gui/mainwindow.py +++ b/src/cutecoin/gui/mainwindow.py @@ -57,7 +57,7 @@ class MainWindow(QMainWindow, Ui_MainWindow): def __init__(self, app): """ Init - :param ..core.app.Application app: + :param cutecoin.core.app.Application app: application """ # Set up the user interface from Designer. super().__init__() diff --git a/src/cutecoin/gui/wallets_tab.py b/src/cutecoin/gui/wallets_tab.py index 565d94ada25a13ba0bd14bfae0f1dbd5d51d5fd8..48cff5fe6066c95562d251fc8396cac705c80ff2 100644 --- a/src/cutecoin/gui/wallets_tab.py +++ b/src/cutecoin/gui/wallets_tab.py @@ -10,6 +10,7 @@ from PyQt5.QtCore import QDateTime, QModelIndex, Qt, QLocale from PyQt5.QtGui import QCursor from ..core.person import Person from ..core.wallet import Wallet +from ..gui.password_asker import PasswordAskerDialog from ..models.wallets import WalletsTableModel, WalletsFilterProxyModel from .transfer import TransferMoneyDialog from ..tools.exceptions import MembershipNotFoundError @@ -22,9 +23,13 @@ class WalletsTabWidget(QWidget, Ui_WalletsTab): ''' def __init__(self, app, account, community, password_asker): - ''' - Constructor - ''' + """ + Init + :param cutecoin.core.app.Application app: Application instance + :param cutecoin.core.account.Account account: Account instance + :param cutecoin.core.community.Community community: Community instance + :param cutecoin.gui.password_asker.PasswordAskerDialog password_asker: PasswordAskerDialog instance + """ super().__init__() self.setupUi(self) self.app = app @@ -156,6 +161,9 @@ class WalletsTabWidget(QWidget, Ui_WalletsTab): pubkey = model.sourceModel().data(pubkey_index, Qt.DisplayRole) menu = QMenu(model.data(index, Qt.DisplayRole), self) + new_wallet = QAction(self.tr("New Wallet"), self) + new_wallet.triggered.connect(self.new_wallet) + rename = QAction(self.tr("Rename"), self) rename.triggered.connect(self.rename_wallet) rename.setData(name_index) @@ -175,12 +183,34 @@ class WalletsTabWidget(QWidget, Ui_WalletsTab): transfer_action.setData(wallets) transfer_to.addAction(transfer_action) + menu.addAction(new_wallet) menu.addAction(rename) menu.addAction(copy_pubkey) menu.addMenu(transfer_to) # Show the context menu. menu.exec_(QCursor.pos()) + def new_wallet(self): + """ + Create a new wallet + """ + password_asker = PasswordAskerDialog(self.app.current_account) + password = password_asker.exec_() + if password_asker.result() == QDialog.Rejected: + return None + # create new wallet by increasing wallet pool size + self.account.set_walletpool_size(len(self.account.wallets) + 1, password) + # capture new wallet + wallet = self.account.wallets[len(self.account.wallets)-1] + # feed cache data of the wallet + wallet.refresh_cache(self.community, list()) + # save wallet cache on disk + self.app.save_wallet(self.account, self.account.wallets[len(self.account.wallets)-1]) + # save account cache on disk (update number of wallets) + self.app.save(self.account) + # refresh wallet list in gui + self.refresh() + def rename_wallet(self): index = self.sender().data() self.table_wallets.edit(index)