def remove_local_tx(self): txid = self.tx.txid() to_delete = {txid} to_delete |= self.wallet.get_depending_transactions(txid) question = _("Are you sure you want to remove this transaction?") if len(to_delete) > 1: question = (_( "Are you sure you want to remove this transaction and {} child transactions?" ).format(len(to_delete) - 1)) def on_prompt(b): if b: for tx in to_delete: self.wallet.remove_transaction(tx) self.wallet.storage.write() self.app._trigger_update_wallet() # FIXME private... self.dismiss() d = Question(question, on_prompt) d.open()
def do_delete(self, obj): from .question import Question def cb(result): if result: self.app.wallet.invoices.remove(obj.key) self.hide_menu() self.update() d = Question(_('Delete invoice?'), cb) d.open()
def update_action_button(self): action_button = self.ids.action_button options = ( ActionButtonOption(text=_('Sign'), func=lambda btn: self.do_sign(), enabled=self.can_sign), ActionButtonOption(text=_('Broadcast'), func=lambda btn: self.do_broadcast(), enabled=self.can_broadcast), ActionButtonOption(text=_('Bump fee'), func=lambda btn: self.do_rbf(), enabled=self.can_rbf), ActionButtonOption(text=_('Remove'), func=lambda btn: self.remove_local_tx(), enabled=self.is_local_tx), ) num_options = sum(map(lambda o: bool(o.enabled), options)) # if no options available, hide button if num_options == 0: action_button.disabled = True action_button.opacity = 0 return action_button.disabled = False action_button.opacity = 1 if num_options == 1: # only one option, button will correspond to that for option in options: if option.enabled: action_button.text = option.text self._action_button_fn = option.func else: # multiple options. button opens dropdown which has one sub-button for each dropdown = DropDown() action_button.text = _('Options') self._action_button_fn = dropdown.open for option in options: if option.enabled: btn = Button(text=option.text, size_hint_y=None, height=48) btn.bind(on_release=option.func) dropdown.add_widget(btn)
def do_delete(self, req): from .question import Question def cb(result): if result: self.app.wallet.remove_payment_request( req.address, self.app.electrum_config) self.hide_menu() self.update() d = Question(_('Delete request'), cb) d.open()
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 __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: f(obj), 0.15) l.on_release = func self.ids.buttons.add_widget(l)
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_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 MonetaryUnit address or a payment request')) return if not bitcoin.is_address(address): self.app.show_error( _('Invalid MonetaryUnit 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 = [TxOutput(bitcoin.TYPE_ADDRESS, address, amount)] message = 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 = 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 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 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_list, self.app.base_unit, cb, keep_choice_order=True) self._unit_dialog.open()
def on_password(self, pw): if len(pw) == 6: if self.check_password(pw): if self.is_change == 0: self.success = True self.pw = pw self.message = _('Please wait...') self.dismiss() elif self.is_change == 1: self.pw = pw self.message = _('Enter new PIN') self.ids.kb.password = '' self.is_change = 2 elif self.is_change == 2: self.new_password = pw self.message = _('Confirm new PIN') self.ids.kb.password = '' self.is_change = 3 elif self.is_change == 3: self.success = pw == self.new_password self.dismiss() else: self.app.show_error(_('Wrong PIN')) self.ids.kb.password = ''
def update(self): format_amount = self.app.format_amount_and_units tx_details = self.wallet.get_tx_info(self.tx) tx_mined_status = tx_details.tx_mined_status exp_n = tx_details.mempool_depth_bytes amount, fee = tx_details.amount, tx_details.fee self.status_str = tx_details.status self.description = tx_details.label self.can_broadcast = tx_details.can_broadcast self.can_rbf = tx_details.can_bump self.tx_hash = tx_details.txid or '' if tx_mined_status.timestamp: self.date_label = _('Date') self.date_str = datetime.fromtimestamp( tx_mined_status.timestamp).isoformat(' ')[:-3] elif exp_n: self.date_label = _('Mempool depth') self.date_str = _('{} from tip').format('%.2f MB' % (exp_n / 1000000)) else: self.date_label = '' 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.get_outputs_for_UI()) self.is_local_tx = tx_mined_status.height == TX_HEIGHT_LOCAL self.update_action_button()
def set_URI(self, text): if not self.app.wallet: self.payment_request_queued = text return import electrum_mue as electrum try: uri = electrum.util.parse_URI(text, self.app.on_pr) except: self.app.show_info(_("Not a MonetaryUnit 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 save_request(self): addr = self.screen.address if not addr: return False amount = self.screen.amount message = self.screen.message amount = self.app.get_amount(amount) if amount else 0 req = self.app.wallet.make_payment_request(addr, amount, message, None) try: self.app.wallet.add_payment_request(req, self.app.electrum_config) added_request = True except Exception as e: self.app.show_error( _('Error adding payment request') + ':\n' + str(e)) added_request = False finally: self.app.update_tab('requests') return added_request
def do_save(self): if not self.screen.address: return if self.screen.is_pr: # it should be already saved return # save address as invoice from electrum_mue.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.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 do_share(self): uri = self.get_URI() self.app.do_share(uri, _("Share MonetaryUnit Request"))
cols: 1 id: invoices_container size_hint: 1, None height: self.minimum_height spacing: '2dp' padding: '12dp' ''') from kivy.properties import BooleanProperty from electrum_mue.gui.kivy.i18n import _ from electrum_mue.util import format_time from electrum_mue.paymentrequest import PR_UNPAID, PR_PAID, PR_UNKNOWN, PR_EXPIRED from electrum_mue.gui.kivy.uix.context_menu import ContextMenu invoice_text = { PR_UNPAID: _('Pending'), PR_UNKNOWN: _('Unknown'), PR_PAID: _('Paid'), PR_EXPIRED: _('Expired') } pr_icon = { PR_UNPAID: 'atlas://electrum_mue/gui/kivy/theming/light/important', PR_UNKNOWN: 'atlas://electrum_mue/gui/kivy/theming/light/important', PR_PAID: 'atlas://electrum_mue/gui/kivy/theming/light/confirmed', PR_EXPIRED: 'atlas://electrum_mue/gui/kivy/theming/light/close' } class InvoicesDialog(Factory.Popup): def __init__(self, app, screen, callback): Factory.Popup.__init__(self)
def do_save(self): if self.save_request(): self.app.show_info(_('Request was saved.'))
def do_new(self): is_unused = self.get_new_address() if not is_unused: self.app.show_info(_('Please use the existing requests first.'))
def _do_sign(self, password): self.status_str = _('Signing') + '...' Clock.schedule_once(lambda dt: self.__do_sign(password), 0.1)
def __init__(self, msg, callback): Factory.Popup.__init__(self) self.title = _('Question') self.message = msg self.callback = callback
def proxy_status(self): net_params = self.app.network.get_parameters() proxy = net_params.proxy return proxy.get('host') + ':' + proxy.get('port') if proxy else _( 'None')
def __do_sign(self, password): try: self.app.wallet.sign_transaction(self.tx, password) except InvalidPassword: self.app.show_error(_("Invalid PIN")) self.update()
def add_currencies(self): currencies = [_('None')] + self.fx.get_currencies( self.has_history_rates) my_ccy = self.fx.get_currency() if self.fx.is_enabled() else _('None') self.ids.ccy.values = currencies self.ids.ccy.text = my_ccy
class InfoBubble(Factory.Bubble): '''Bubble to be used to display short Help Information''' message = StringProperty(_('Nothing set !')) '''Message to be displayed; defaults to "nothing set"''' icon = StringProperty('') ''' Icon to be displayed along with the message defaults to '' :attr:`icon` is a `StringProperty` defaults to `''` ''' fs = BooleanProperty(False) ''' Show Bubble in half screen mode :attr:`fs` is a `BooleanProperty` defaults to `False` ''' modal = BooleanProperty(False) ''' Allow bubble to be hidden on touch. :attr:`modal` is a `BooleanProperty` defauult to `False`. ''' exit = BooleanProperty(False) '''Indicates whether to exit app after bubble is closed. :attr:`exit` is a `BooleanProperty` defaults to False. ''' dim_background = BooleanProperty(False) ''' Indicates Whether to draw a background on the windows behind the bubble. :attr:`dim` is a `BooleanProperty` defaults to `False`. ''' def on_touch_down(self, touch): if self.modal: return True self.hide() if self.collide_point(*touch.pos): return True def show(self, pos, duration, width=None, modal=False, exit=False): '''Animate the bubble into position''' self.modal, self.exit = modal, exit if width: self.width = width if self.modal: from kivy.uix.modalview import ModalView self._modal_view = m = ModalView(background_color=[.5, .5, .5, .2]) Window.add_widget(m) m.add_widget(self) else: Window.add_widget(self) # wait for the bubble to adjust its size according to text then animate Clock.schedule_once(lambda dt: self._show(pos, duration)) def _show(self, pos, duration): def on_stop(*l): if duration: Clock.schedule_once(self.hide, duration + .5) self.opacity = 0 arrow_pos = self.arrow_pos if arrow_pos[0] in ('l', 'r'): pos = pos[0], pos[1] - (self.height/2) else: pos = pos[0] - (self.width/2), pos[1] self.limit_to = Window anim = Factory.Animation(opacity=1, pos=pos, d=.32) anim.bind(on_complete=on_stop) anim.cancel_all(self) anim.start(self) def hide(self, now=False): ''' Auto fade out the Bubble ''' def on_stop(*l): if self.modal: m = self._modal_view m.remove_widget(self) Window.remove_widget(m) Window.remove_widget(self) if self.exit: App.get_running_app().stop() import sys sys.exit() else: App.get_running_app().is_exit = False if now: return on_stop() anim = Factory.Animation(opacity=0, d=.25) anim.bind(on_complete=on_stop) anim.cancel_all(self) anim.start(self)
def do_copy(self): uri = self.get_URI() self.app._clipboard.copy(uri) self.app.show_info(_('Request copied to clipboard'))
def do_paste(self): contents = self.app._clipboard.paste() if not contents: self.app.show_info(_("Clipboard is empty")) return self.set_URI(contents)
def do_sign(self): self.app.protected( _("Enter your PIN code in order to sign this transaction"), self._do_sign, ())