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 __init__(self, wizard, **kwargs): super(RestoreSeedDialog, self).__init__(wizard, **kwargs) self._test = kwargs['test'] from electrum_mrng.mnemonic import Mnemonic from electrum_mrng.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
def get_card(self, tx_hash, height, conf, timestamp, value, balance): status, status_str = self.app.wallet.get_tx_status( tx_hash, height, conf, timestamp) icon = "atlas://gui/kivy/theming/light/" + TX_ICONS[status] label = self.app.wallet.get_label(tx_hash) if tx_hash else _( 'Pruned transaction outputs') date = timestamp_to_datetime(timestamp) ri = self.cards.get(tx_hash) if ri is None: ri = Factory.HistoryItem() ri.screen = self ri.tx_hash = tx_hash self.cards[tx_hash] = ri ri.icon = icon ri.date = status_str ri.message = label ri.value = value or 0 ri.amount = self.app.format_amount(value, True) if value is not None else '--' ri.confirmations = conf if self.app.fiat_unit and date: rate = self.app.fx.history_rate(date) if rate: s = self.app.fx.value_str(value, rate) ri.quote_text = '' if s is None else s + ' ' + self.app.fiat_unit return ri
def update(self): if not self.screen.address: self.get_new_address() else: status = self.app.wallet.get_request_status(self.screen.address) self.screen.status = _( 'Payment received') if status == PR_PAID else ''
def unit_dialog(self, item, dt): if self._unit_dialog is None: def cb(text): self.app._set_bu(text) item.bu = self.app.base_unit self._unit_dialog = ChoiceDialog(_('Denomination'), base_units.keys(), self.app.base_unit, cb) self._unit_dialog.open()
def get_card(self, req): address = req['address'] timestamp = req.get('time', 0) amount = req.get('amount') expiration = req.get('exp', None) status = req.get('status') signature = req.get('sig') ci = self.cards.get(address) if ci is None: ci = Factory.RequestItem() ci.screen = self ci.address = address self.cards[address] = ci ci.memo = self.app.wallet.get_label(address) if amount: status = req.get('status') ci.status = request_text[status] else: received = self.app.wallet.get_addr_received(address) ci.status = self.app.format_amount_and_units(amount) ci.icon = pr_icon[status] ci.amount = self.app.format_amount_and_units(amount) if amount else _( 'No Amount') ci.date = format_time(timestamp) return ci
def new_wallet(self, app, dirname): def cb(text): if text: app.load_wallet_by_name(os.path.join(dirname, text)) d = LabelDialog(_('Enter wallet name'), '', cb) d.open()
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 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 coinselect_dialog(self, item, dt): if self._coinselect_dialog is None: choosers = sorted(coinchooser.COIN_CHOOSERS.keys()) chooser_name = coinchooser.get_name(self.config) def cb(text): self.config.set_key('coin_chooser', text) item.status = text self._coinselect_dialog = ChoiceDialog(_('Coin selection'), choosers, chooser_name, cb) self._coinselect_dialog.open()
def language_dialog(self, item, dt): if self._language_dialog is None: l = self.config.get('language', 'en_UK') def cb(key): self.config.set_key("language", key, True) item.lang = self.get_language_name() self.app.language = key self._language_dialog = ChoiceDialog(_('Language'), languages, l, cb) self._language_dialog.open()
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 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 label_dialog(self, obj): from dialogs.label_dialog import LabelDialog key = obj.tx_hash text = self.app.wallet.get_label(key) def callback(text): self.app.wallet.set_label(key, text) self.update() d = LabelDialog(_('Enter Transaction Label'), text, callback) d.open()
def _do_send(self, amount, message, outputs, rbf): # make unsigned transaction config = self.app.electrum_config coins = self.app.wallet.get_spendable_coins(None, config) try: tx = self.app.wallet.make_unsigned_transaction( coins, outputs, config, None) except NotEnoughFunds: self.app.show_error(_("Not enough funds")) return except Exception as e: traceback.print_exc(file=sys.stdout) self.app.show_error(str(e)) return if rbf: tx.set_rbf(True) fee = tx.get_fee() msg = [ _("Amount to be sent") + ": " + self.app.format_amount_and_units(amount), _("Network fee") + ": " + self.app.format_amount_and_units(fee), ] if fee >= config.get('confirm_fee', 1000000): msg.append( _('Warning') + ': ' + _("The fee for this transaction seems unusually high.")) msg.append(_("Enter your PIN code to proceed")) self.app.protected('\n'.join(msg), self.send_tx, (tx, message))
def do_send(self): if self.screen.is_pr: if self.payment_request.has_expired(): self.app.show_error(_('Payment request has expired')) return outputs = self.payment_request.get_outputs() else: address = str(self.screen.address) if not address: self.app.show_error( _('Recipient not specified.') + ' ' + _('Please scan a MorningStar address or a payment request') ) return if not bitcoin.is_address(address): self.app.show_error( _('Invalid MorningStar Address') + ':\n' + address) return try: amount = self.app.get_amount(self.screen.amount) except: self.app.show_error( _('Invalid amount') + ':\n' + self.screen.amount) return outputs = [(bitcoin.TYPE_ADDRESS, address, amount)] message = unicode(self.screen.message) amount = sum(map(lambda x: x[2], outputs)) if self.app.electrum_config.get('use_rbf'): from dialogs.question import Question d = Question(_('Should this transaction be replaceable?'), lambda b: self._do_send(amount, message, outputs, b)) d.open() else: self._do_send(amount, message, outputs, False)
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 = unicode(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 update(self): format_amount = self.app.format_amount_and_units tx_hash, self.status_str, self.description, self.can_broadcast, self.can_rbf, 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 get_fee_text(self, value): if self.ids.dynfees.active: tooltip = fee_levels[value] if self.config.has_fee_estimates(): dynfee = self.config.dynfee(value) tooltip += '\n' + (self.app.format_amount_and_units(dynfee)) + '/kB' else: fee_rate = value * self.fee_step tooltip = self.app.format_amount_and_units(fee_rate) + '/kB' if self.config.has_fee_estimates(): i = self.config.reverse_dynfee(fee_rate) tooltip += '\n' + (_('low fee') if i < 0 else 'Within %d blocks'%i) return tooltip
def __init__(self, obj, action_list): Bubble.__init__(self) self.obj = obj for k, v in action_list: l = MenuItem() l.text = _(k) def func(f=v): Clock.schedule_once(lambda dt: self.hide(), 0.1) Clock.schedule_once(lambda dt: f(obj), 0.15) l.on_release = func self.ids.buttons.add_widget(l)
def update(self): self.menu_actions = [('Show', self.do_show), ('Details', self.do_view), ('Delete', self.do_delete)] requests_list = self.screen.ids.requests_container requests_list.clear_widgets() _list = self.app.wallet.get_sorted_requests( self.app.electrum_config) if self.app.wallet else [] for req in _list: ci = self.get_card(req) requests_list.add_widget(ci) if not _list: msg = _('This screen shows the list of payment requests you made.') requests_list.add_widget(EmptyLabel(text=msg))
def set_URI(self, text): import electrum_mrng as electrum try: uri = electrum.util.parse_URI(text, self.app.on_pr) except: self.app.show_info(_("Not a MorningStar URI")) return amount = uri.get('amount') self.screen.address = uri.get('address', '') self.screen.message = uri.get('message', '') self.screen.amount = self.app.format_amount_and_units( amount) if amount else '' self.payment_request = None self.screen.is_pr = False
def get_card(self, pr): key = pr.get_id() ci = self.cards.get(key) if ci is None: ci = Factory.InvoiceItem() ci.key = key ci.screen = self self.cards[key] = ci ci.requestor = pr.get_requestor() ci.memo = pr.get_memo() amount = pr.get_amount() if amount: ci.amount = self.app.format_amount_and_units(amount) status = self.app.wallet.invoices.get_status(ci.key) ci.status = invoice_text[status] ci.icon = pr_icon[status] else: ci.amount = _('No Amount') ci.status = '' exp = pr.get_expiration_date() ci.date = format_time(exp) if exp else _('Never') return ci
def update(self): self.menu_actions = [('Pay', self.do_pay), ('Details', self.do_view), ('Delete', self.do_delete)] invoices_list = self.screen.ids.invoices_container invoices_list.clear_widgets() _list = self.app.wallet.invoices.sorted_list() for pr in _list: ci = self.get_card(pr) invoices_list.add_widget(ci) if not _list: msg = _( 'This screen shows the list of payment requests that have been sent to you. You may also use it to store contact addresses.' ) invoices_list.add_widget(EmptyLabel(text=msg))
def update(self, see_all=False): if self.app.wallet is None: return history = reversed(self.app.wallet.get_history()) history_card = self.screen.ids.history_container history_card.clear_widgets() count = 0 for item in history: ri = self.get_card(*item) count += 1 history_card.add_widget(ri) if count == 0: msg = _( 'This screen shows your list of transactions. It is currently empty.' ) history_card.add_widget(EmptyLabel(text=msg))
class ShowSeedDialog(WizardDialog): seed_text = StringProperty('') message = _( "If you forget your PIN or lose your device, your seed phrase will be the only way to recover your funds." ) ext = False 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 do_save(self): if not self.screen.address: return if self.screen.is_pr: # it sould be already saved return # save address as invoice from electrum_mrng.paymentrequest import make_unsigned_request, PaymentRequest req = {'address': self.screen.address, 'memo': self.screen.message} amount = self.app.get_amount( self.screen.amount) if self.screen.amount else 0 req['amount'] = amount pr = make_unsigned_request(req).SerializeToString() pr = PaymentRequest(pr) self.app.wallet.invoices.add(pr) self.app.update_tab('invoices') self.app.show_info(_("Invoice saved")) if pr.is_pr(): self.screen.is_pr = True self.payment_request = pr else: self.screen.is_pr = False self.payment_request = None
def add_currencies(self): currencies = [_('None')] + self.fx.get_currencies(True) my_ccy = self.fx.get_currency() if self.fx.is_enabled() else _('None') self.ids.ccy.values = currencies self.ids.ccy.text = my_ccy
def __init__(self, msg, callback): Factory.Popup.__init__(self) self.title = _('Question') self.message = msg self.callback = callback
def do_copy(self): uri = self.get_URI() self.app._clipboard.copy(uri) self.app.show_info(_('Request copied to clipboard'))