def change_password(self, cb): if self.wallet.has_password(): self.protected( _("Changing PIN code.") + '\n' + _("Enter your current PIN:"), self._change_password, (cb, )) else: self._change_password(cb, None)
def update(self): format_amount = self.app.format_amount_and_units tx_hash, self.status_str, self.description, self.can_broadcast, amount, fee, height, conf, timestamp, exp_n = self.wallet.get_tx_info( self.tx) self.tx_hash = tx_hash or '' if timestamp: self.date_str = datetime.fromtimestamp(timestamp).isoformat( ' ')[:-3] elif exp_n: self.date_str = _('Within %d blocks') % exp_n if exp_n > 0 else _( 'unknown (low fee)') else: self.date_str = '' if amount is None: self.amount_str = _("Transaction unrelated to your wallet") elif amount > 0: self.is_mine = False self.amount_str = format_amount(amount) else: self.is_mine = True self.amount_str = format_amount(-amount) self.fee_str = format_amount(fee) if fee is not None else _('unknown') self.can_sign = self.wallet.can_sign(self.tx) self.ids.output_list.update(self.tx.outputs())
def do_new(self): addr = self.get_new_address() if not addr: self.app.show_info(_('Please use the existing requests first.')) else: self.save_request() self.app.show_info(_('New request added to your list.'))
def scan_qr(self, on_complete): if platform != 'android': return from jnius import autoclass from android import activity PythonActivity = autoclass('org.kivy.android.PythonActivity') Intent = autoclass('android.content.Intent') intent = Intent("com.google.zxing.client.android.SCAN") intent.putExtra("SCAN_MODE", "QR_CODE_MODE") def on_qr_result(requestCode, resultCode, intent): if requestCode == 0: if resultCode == -1: # RESULT_OK: contents = intent.getStringExtra("SCAN_RESULT") if intent.getStringExtra( "SCAN_RESULT_FORMAT") == 'QR_CODE': on_complete(contents) else: self.show_error( "wrong format " + intent.getStringExtra("SCAN_RESULT_FORMAT")) activity.bind(on_activity_result=on_qr_result) try: PythonActivity.mActivity.startActivityForResult(intent, 0) except: self.show_error( _('Could not start Barcode Scanner.') + ' ' + _('Please install the Barcode Scanner app from ZXing'))
def derivation_dialog_other(self, f, default_derivation): message = '\n'.join([ _('Enter your wallet derivation here.'), _('If you are not sure what this is, leave this field unchanged.') ]) self.line_dialog(run_next=f, title=_('Derivation'), message=message, default=default_derivation, test=bitcoin.is_bip32_derivation)
def import_addresses_or_keys(self): v = lambda x: keystore.is_address_list( x) or keystore.is_private_key_list(x) title = _("Import Bitcoin Nano Addresses") message = _( "Enter a list of Bitcoin Nano addresses (this will create a watching-only wallet), or a list of private keys." ) self.add_xpub_dialog(title=title, message=message, run_next=self.on_import, is_valid=v)
def _change_password(self, cb, old_password): if self.wallet.has_password(): if old_password is None: return try: self.wallet.check_password(old_password) except InvalidPassword: self.show_error(_("Invalid PIN")) return self.password_dialog(_('Enter new PIN'), self._change_password2, ( cb, old_password, ))
def _show_seed(self, label, password): if self.wallet.has_password() and password is None: return keystore = self.wallet.keystore try: seed = keystore.get_seed(password) passphrase = keystore.get_passphrase(password) except: self.show_error(_("Invalid PIN")) return label.text = _('Seed') + ':\n' + seed if passphrase: label.text += '\n\n' + _('Passphrase') + ': ' + passphrase
def new(self): name = os.path.basename(self.storage.path) title = _("Create") + ' ' + name message = '\n'.join([_("What kind of wallet do you want to create ?")]) wallet_kinds = [ ('standard', _("Standard wallet")), # ('multisig', _("Multi-signature wallet")), ('imported', _("Import Bitcoin Nano addresses or private keys")), ] choices = [pair for pair in wallet_kinds if pair[0] in wallet_types] self.choice_dialog(title=title, message=message, choices=choices, run_next=self.on_wallet_type)
def derivation_dialog(self, f): default = bip44_derivation(0) message = '\n'.join([ _('Enter your wallet derivation here.'), _('If you are not sure what this is, leave this field unchanged.'), _("If you want the wallet to use legacy Bitcoin Nano addresses use m/44'/0'/0'" ), _("If you want the wallet to use Bitcoin Cash addresses use m/44'/145'/0'" ) ]) self.line_dialog(run_next=f, title=_('Derivation'), message=message, default=default, test=bitcoin.is_bip32_derivation)
def _change_password3(self, cb, old_password, new_password, confirmed_password): if new_password == confirmed_password: self.wallet.update_password(old_password, new_password) cb() else: self.show_error(_("PIN numbers do not match"))
def update(self): self.menu_actions = [('Receive', self.do_show), ('Details', self.do_view)] wallet = self.app.wallet if not hasattr(wallet, 'change_addresses'): wallet.change_addresses = [] if not hasattr(wallet, 'receiving_addresses'): wallet.receiving_addresses = [] _list = wallet.change_addresses if self.screen.show_change else wallet.receiving_addresses search = self.screen.message container = self.screen.ids.search_container container.clear_widgets() n = 0 for address in _list: label = wallet.labels.get(address, '') balance = sum(wallet.get_addr_balance(address)) is_used = wallet.is_used(address) if self.screen.show_used == 1 and (balance or is_used): continue if self.screen.show_used == 2 and balance == 0: continue if self.screen.show_used == 3 and not is_used: continue card = self.get_card(address, balance, is_used, label) if search and not self.ext_search(card, search): continue container.add_widget(card) n += 1 if not n: msg = _('No address matching your search') container.add_widget(EmptyLabel(text=msg))
def _sign_tx(self, tx, password, on_success, on_failure): try: self.wallet.sign_transaction(tx, password) except InvalidPassword: Clock.schedule_once(lambda dt: on_failure(_("Invalid PIN"))) return Clock.schedule_once(lambda dt: on_success(tx))
def confirm_passphrase(self, seed, passphrase): f = lambda x: self.run('create_keystore', seed, x) if passphrase: title = _('Confirm Seed Extension') message = '\n'.join([ _('Your seed extension must be saved together with your seed.' ), _('Please type it here.'), ]) self.line_dialog(run_next=f, title=title, message=message, default='', test=lambda x: x == passphrase) else: f('')
class ShowSeedDialog(WizardDialog): seed_text = StringProperty('') ext = False message = _( "If you forget your PIN or lose your device, your seed phrase will be the only way to recover your funds." ) def __init__(self, wizard, **kwargs): super(ShowSeedDialog, self).__init__(wizard, **kwargs) self.seed_text = kwargs['seed_text'] def on_parent(self, instance, value): if value: app = App.get_running_app() self._back = _back = partial(self.ids.back.dispatch, 'on_release') def options_dialog(self): from .seed_options import SeedOptionsDialog def callback(status): self.ext = status d = SeedOptionsDialog(self.ext, callback) d.open() def get_params(self, b): return (self.ext, )
def passphrase_dialog(self, run_next): title = _('Seed extension') message = '\n'.join([ _('You may extend your seed with custom words.'), _('Your seed extension must be saved together with your seed.'), ]) warning = '\n'.join([ _('Note that this is NOT your encryption password.'), _('If you do not know what this is, leave this field empty.'), ]) self.line_dialog(title=title, message=message, warning=warning, default='', test=lambda x: True, run_next=run_next)
def request_password(self, run_next): def callback(pin): if pin: self.run('confirm_password', pin, run_next) else: run_next(None, None) self.password_dialog(_('Choose a PIN code'), callback)
def fx_status(self): fx = self.app.fx if fx.is_enabled(): source = fx.exchange.name() ccy = fx.get_currency() return '%s [%s]' % (ccy, source) else: return _('None')
def on_currency(self, ccy): b = (ccy != _('None')) self.fx.set_enabled(b) if b: if ccy != self.fx.get_currency(): self.fx.set_currency(ccy) self.app.fiat_unit = ccy Clock.schedule_once(lambda dt: self.add_exchanges())
def do_delete(self, obj): from .dialogs.question import Question def cb(result): if result: self.app.wallet.remove_payment_request(obj.address, self.app.electrum_config) self.update() d = Question(_('Delete request?'), cb) d.open()
def description_dialog(self, screen): from .uix.dialogs.label_dialog import LabelDialog text = screen.message def callback(text): screen.message = text d = LabelDialog(_('Enter description'), text, callback) d.open()
def create_addresses(self): def task(): self.wallet.synchronize() self.wallet.storage.write() self.terminate() msg = _( "Bitcoin Nano wallet is generating your addresses, please wait.") self.waiting_dialog(task, msg)
def on_keyboard(self, instance, key, keycode, codepoint, modifiers): if key == 27 and self.is_exit is False: self.is_exit = True self.show_info(_('Press again to exit')) return True # override settings button if key in (319, 282): # f1/settings button on android # self.gui.main_gui.toggle_settings(self) return True
def do_delete(self, obj): from .dialogs.question import Question def cb(result): if result: self.app.wallet.invoices.remove(obj.key) self.app.update_tab('invoices') d = Question(_('Delete invoice?'), cb) d.open()
def confirm_password(self, pin, run_next): def callback(conf): if conf == pin: run_next(pin, False) else: self.show_error(_('PIN mismatch')) self.run('request_password', run_next) self.password_dialog(_('Confirm your PIN code'), callback)
def __init__(self, wizard, **kwargs): super(RestoreSeedDialog, self).__init__(wizard, **kwargs) self._test = kwargs['test'] from bitcoinnano.mnemonic import Mnemonic from bitcoinnano.old_mnemonic import words as old_wordlist self.words = set(Mnemonic('en').wordlist).union(set(old_wordlist)) self.ids.text_input_seed.text = test_seed if is_test else '' self.message = _( 'Please type your seed phrase using the virtual keyboard.') self.title = _('Enter Seed') self.ext = False # Modifying the style of the input method for line in [self.ids.line1, self.ids.line2, self.ids.line3]: for c in line.children: if isinstance(c, Button): c.font_size = '20sp' c.font_name = 'gui/kivy/data/fonts/SourceHanSansK-Bold.ttf'
def restore_from_key(self): if self.wallet_type == 'standard': v = keystore.is_master_key title = _("Create keystore from a master key") message = ' '.join([ _("To create a watching-only wallet, please enter your master public key (xpub/ypub/zpub)." ), _("To create a spending wallet, please enter a master private key (xprv/yprv/zprv)." ) ]) self.add_xpub_dialog(title=title, message=message, run_next=self.on_restore_from_key, is_valid=v) else: i = len(self.keystores) + 1 self.add_cosigner_dialog(index=i, run_next=self.on_restore_from_key, is_valid=keystore.is_bip32_key)
def on_address(self, addr): req = self.app.wallet.get_payment_request(addr, self.app.electrum_config) self.screen.status = '' if req: self.screen.message = req.get('memo', '') amount = req.get('amount') self.screen.amount = self.app.format_amount_and_units(amount) if amount else '' status = req.get('status', PR_UNKNOWN) self.screen.status = _('Payment received') if status == PR_PAID else '' Clock.schedule_once(lambda dt: self.update_qr())
def export_private_keys(self, pk_label, addr): def show_private_key(addr, pk_label, password): if self.wallet.has_password() and password is None: return key = str(self.wallet.export_private_key(addr, password)[0]) pk_label.data = key self.protected( _("Enter your PIN code in order to decrypt your private key"), show_private_key, (addr, pk_label))
def on_ref_label(self, label, touch): if label.touched: label.touched = False self.qr_dialog(label.name, label.data, True) else: label.touched = True self._clipboard.copy(label.data) Clock.schedule_once(lambda dt: self.show_info( _('Text copied to clipboard.\nTap again to display it as QR code.' )))