def DoDelete() -> None: nonlocal tf, placeholder, prefill if not parent.wallet: return if isCurrent: utils.show_alert(vc = vc, title = _('Cannot Delete Active Wallet'), message = _("You are requesting the deletion of the currently active wallet. In order to delete this wallet, please switch to another wallet, then select this option again on this wallet."), actions = [ [_("OK") ] ]) return # TRANSLATORS: This is the text that the user needs to enter to confirm wallet deletion delete_confirm_text = pgettext("iOS wallet delete confirmation", "delete").lower().strip() def DeleteChk() -> None: nonlocal tf, placeholder, prefill prefill = '' if tf: txt = str(tf.text).lower().strip() if txt == 'delete' or txt == delete_confirm_text: # support i18n try: os.remove(info.full_path) parent.set_wallet_use_touchid(info.name, None, clear_asked = True) # clear cached password if any parent.refresh_components('wallets') utils.show_notification(message = _("Wallet deleted successfully")) except: parent.show_error(vc = vc, message = str(sys.exc_info()[1])) else: parent.show_error(vc = vc, title = _("Not Deleted"), message = _("You didn't enter the text '{delete_confirm_text}' in the previous dialog. For your own safety, the wallet file was not deleted.").format(delete_confirm_text=delete_confirm_text)) Release() placeholder = _("Type '{delete_confirm_text}' to proceed").format(delete_confirm_text=delete_confirm_text) utils.show_alert(vc = vc, title = _('Delete Wallet'), message = _("You are about to delete the wallet '{wallet_name}'. Unless you have other copies of this wallet or you wrote its seed down, you may lose funds!\n\nIn order to proceed, please type the word '{delete_confirm_text}' in the box below:").format(wallet_name=info.name, delete_confirm_text=delete_confirm_text), actions = [ [ _("Cancel"), Release ], [ _("Delete"), DeleteChk ]], cancel = _("Cancel"), destructive = _('Delete'), uiTextFieldHandlers = [ TfHandler ])
def update(self): host, port, protocol, proxy_config, auto_connect = self.network.get_parameters() preferred_only = self.network.is_whitelist_only() if not self.server_host.hasFocus() and not self.server_port.hasFocus(): self.server_host.setText(host) self.server_port.setText(port) self.ssl_cb.setChecked(protocol=='s') ssl_disable = self.ssl_cb.isChecked() and not self.tor_cb.isChecked() and not host.lower().endswith('.onion') for w in [self.ssl_cb]:#, self.ssl_help]: w.setDisabled(ssl_disable) self.autoconnect_cb.setChecked(auto_connect) self.preferred_only_cb.setChecked(preferred_only) self.servers = self.network.get_servers() host = self.network.interface.host if self.network.interface else pgettext('Referencing server', 'None') is_onion = host.lower().endswith('.onion') if is_onion and host in self.servers and 'display' in self.servers[host]: host = self.servers[host]['display'] + ' (.onion)' self.server_label.setText(host) self.set_protocol(protocol) def protocol_suffix(): if protocol == 't': return ' (non-SSL)' elif protocol == 's': return ' [SSL]' return '' server_list_txt = (_('Server peers') if self.network.is_connected() else _('Servers')) + " ({})".format(len(self.servers)) server_list_txt += protocol_suffix() self.server_list_label.setText(server_list_txt) if self.network.blacklisted_servers: bl_srv_ct_str = ' ({}) <a href="ViewBanList">{}</a>'.format(len(self.network.blacklisted_servers), _("View ban list...")) else: bl_srv_ct_str = " (0)<i> </i>" # ensure rich text servers_whitelisted = set(get_eligible_servers(self.servers, protocol)).intersection(self.network.whitelisted_servers) - self.network.blacklisted_servers self.legend_label.setText(ServerFlag.Symbol[ServerFlag.Preferred] + "=" + _("Preferred") + " ({})".format(len(servers_whitelisted)) + " " + ServerFlag.Symbol[ServerFlag.Banned] + "=" + _("Banned") + bl_srv_ct_str) self.servers_list.update(self.network, self.servers, self.protocol, self.tor_cb.isChecked()) self.enable_set_server() height_str = "%d "%(self.network.get_local_height()) + _('blocks') self.height_label.setText(height_str) n = len(self.network.get_interfaces()) status = _("Connected to %d nodes.")%n if n else _("Not connected") if n: status += protocol_suffix() self.status_label.setText(status) chains = self.network.get_blockchains() if len(chains)>1: chain = self.network.blockchain() checkpoint = chain.get_base_height() name = chain.get_name() msg = _('Chain split detected at block %d')%checkpoint + '\n' msg += (_('You are following branch') if auto_connect else _('Your server is on branch'))+ ' ' + name msg += ' (%d %s)' % (chain.get_branch_size(), _('blocks')) else: msg = '' self.split_label.setText(msg) self.nodes_list_widget.update(self.network, self.servers)
def setFiatExchangeButtonText_(self, b : ObjCInstance) -> None: b = self.tableView.viewWithTag_(TAG_FIAT_EXCHANGE) if b is None else b if b is None: return fx = gui.ElectrumGui.gui.daemon.fx if gui.ElectrumGui.gui.daemon else None ex = fx.config_exchange() if fx else None ex = ex if ex in self.exchanges else None if ex is None: ex = pgettext('Referencing Fiat rate source', 'None') if self.normalButtonColor is None: self.normalButtonColor = b.titleColorForState_(UIControlStateNormal) b.setTitleColor_forState_(self.warnButtonColor,UIControlStateNormal) elif self.normalButtonColor is not None: b.setTitleColor_forState_(self.normalButtonColor,UIControlStateNormal) b.setTitle_forState_(str(ex), UIControlStateNormal)
def updateCurrencies(self): parent = gui.ElectrumGui.gui self.currencies = [pgettext('Referencing Fiat currency', 'None')] if not parent.daemon or not parent.daemon.fx: return currencies = [self.currencies[0],*sorted(parent.daemon.fx.get_currencies(parent.daemon.fx.get_history_config()))] special = [ 'USD', 'EUR', 'GBP', 'CAD', 'AUD' ] i = 1 for s in special: try: ix = currencies.index(s) currencies.pop(ix) currencies.insert(i, s) i += 1 except: pass self.currencies = currencies
def setupCell_section_row_(self, cell : ObjCInstance, secName_oc : ObjCInstance, row : int) -> None: secName = py_from_ns(secName_oc) parent = gui.ElectrumGui.gui fx = parent.daemon.fx if parent.daemon else None cell.tag = 0 cell.contentView.tag = TAG_CONTENTVIEW if secName == 'Tools': if row == 0: cell.imageView.image = parent.cashaddr_icon() cell.textLabel.text = _("Address Converter") cell.detailTextLabel.text = _("Convert between Legacy and Cashaddr formats") cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator elif row == 1: statusText = self.networkStatusText if self.networkStatusText else _("Offline") cell.imageView.image = UIImage.imageNamed_("network_icon_new") cell.textLabel.text = _("Network Settings") cell.detailTextLabel.text = _("Status:") + " " + statusText cell.accessoryType = UITableViewCellAccessoryNone elif row == 2: cell.imageView.image = UIImage.imageNamed_("password_icon_new") cell.textLabel.text = _("Change or Set Password") cell.detailTextLabel.text = _("Modify wallet password & encryption settings") cell.accessoryType = UITableViewCellAccessoryNone elif row == 3: cell.imageView.image = UIImage.imageNamed_("seed_icon_new") cell.textLabel.text = _("Wallet Recovery Seed") cell.detailTextLabel.text = _("View the wallet seed phrase used for wallet recovery") cell.accessoryType = UITableViewCellAccessoryNone # ensure all of the above icons are the same size: 24x24, centered, unscaled cell.imageView.contentMode = UIViewContentModeCenter f = cell.imageView.frame f.size = CGSizeMake(24,24) cell.imageView.frame = f cell.textLabel.textColor = utils.uicolor_custom('dark') cell.detailTextLabel.textColor = utils.uicolor_custom('dark') cell.textLabel.font = UIFont.systemFontOfSize_weight_(16.0, UIFontWeightRegular) cell.detailTextLabel.font = UIFont.systemFontOfSize_weight_(12.0, UIFontWeightThin) elif secName == 'Fees': if row == 0: l = cell.viewWithTag_(1) tf = cell.viewWithTag_(2) l.text = _('Max static fee') tf.placeholder = parent.base_unit() tf.delegate = self tf.text = get_max_static_fee_str(parent) if tf.allTargets.count <= 0: tf.addTarget_action_forControlEvents_(self, SEL(b'onMaxStaticFee:'), UIControlEventEditingChanged) if isinstance(tf, amountedit.BTCkBEdit): tf.setUseUnitLabel_(True) tf.fixedUnitLabelWidth = 75.0 utils.uitf_redo_attrs(tf) elif row == 1: # 'edit fees manually', a bool cell l = cell.viewWithTag_(1) s = cell.viewWithTag_(2) if s.allTargets.count <= 0: s.addTarget_action_forControlEvents_(self, SEL(b'onShowFee:'), UIControlEventValueChanged) l.text = _('Edit fees manually') s.on = parent.prefs_get_show_fee() elif secName == 'Transactions': l = cell.viewWithTag_(1) s = cell.viewWithTag_(2) if row == 0: l.text = _("Enable Schnorr signatures") b, enabled = parent.prefs_use_schnorr, parent.prefs_is_schnorr_possible s.on = b utils.uiview_set_enabled(cell, enabled) if s.allTargets.count <= 0: s.addTarget_action_forControlEvents_(self, SEL(b'onEnableSchnorr:'), UIControlEventValueChanged) elif row == 1: l.text = _("Use change addresses") b, enabled = parent.prefs_get_use_change() s.on = b utils.uiview_set_enabled(cell, enabled) if s.allTargets.count <= 0: s.addTarget_action_forControlEvents_(self, SEL(b'onUseChange:'), UIControlEventValueChanged) elif row == 2: l.text = _("Use multiple change addresses") cell.contentView.tag = TAG_MULTIPLE_CHANGE_CELL b1, enabled = parent.prefs_get_multiple_change() s.on = b1 utils.uiview_set_enabled(cell.contentView, enabled) if s.allTargets.count <= 0: s.addTarget_action_forControlEvents_(self, SEL(b'onUseMultiple:'), UIControlEventValueChanged) elif row == 3: l.text = _("Spend only confirmed coins") s.on = parent.prefs_get_confirmed_only() if s.allTargets.count <= 0: s.addTarget_action_forControlEvents_(self, SEL(b'onConfirmedOnly:'), UIControlEventValueChanged) elif secName == 'Appearance': if row == 0: l = cell.viewWithTag_(1) s = cell.viewWithTag_(2) l.text = _('Hide download banner') s.on = parent.prefs_get_downloading_notif_hidden() if s.allTargets.count <= 0: s.addTarget_action_forControlEvents_(self, SEL(b'onHideDLBanner:'), UIControlEventValueChanged) elif row == 1: l = cell.viewWithTag_(1) s = cell.viewWithTag_(2) l.text = _('CashAddr address format') s.on = parent.prefs_get_use_cashaddr() if s.allTargets.count <= 0: s.addTarget_action_forControlEvents_(self, SEL(b'onUseCashAddr:'), UIControlEventValueChanged) elif row == 2: l = cell.viewWithTag_(1) b = cell.viewWithTag_(2) b = b if b is not None else cell.viewWithTag_(TAG_NZ) l.text = _('Zeros after decimal point') if b is not None: b.tag = TAG_NZ if b.allTargets.count <= 0: b.addTarget_action_forControlEvents_(self, SEL(b'onNZBut:'), UIControlEventPrimaryActionTriggered) nr = len(self.getNumZerosList()) nz_prefs = parent.prefs_get_num_zeros() if nz_prefs >= nr: nz_prefs = nr-1 b.setTitle_forState_(str(nz_prefs),UIControlStateNormal) elif row == 3: l = cell.viewWithTag_(1) b = cell.viewWithTag_(2) b = b if b is not None else cell.viewWithTag_(TAG_BASE_UNIT) l.text = _('Base unit') if b is not None: b.tag = TAG_BASE_UNIT b.setTitle_forState_(parent.base_unit(),UIControlStateNormal) if b.allTargets.count <= 0: b.addTarget_action_forControlEvents_(self, SEL(b'onBaseUnitBut:'), UIControlEventPrimaryActionTriggered) elif row == 4: l = cell.viewWithTag_(1) b = cell.viewWithTag_(2) b = b if b is not None else cell.viewWithTag_(TAG_BLOCK_EXPLORER) l.text = _('Online Block Explorer') if b is not None: b.tag = TAG_BLOCK_EXPLORER be = web.BE_sorted_list() be = be if be is not None and len(be) > 0 else ["None"] beprefs = web.BE_from_config(parent.config) if beprefs not in be: beprefs = be[0] b.setTitle_forState_(beprefs,UIControlStateNormal) if b.allTargets.count <= 0: b.addTarget_action_forControlEvents_(self, SEL(b'onBlockExplorerBut:'), UIControlEventPrimaryActionTriggered) elif secName == 'Fiat': if row == 0: l = cell.viewWithTag_(1) b = cell.viewWithTag_(2) b = b if b is not None else cell.viewWithTag_(TAG_FIAT_CURRENCY) l.text = _('Fiat currency') if b is not None: b.tag = TAG_FIAT_CURRENCY b.enabled = True curr = fx.get_currency() if fx and fx.is_enabled() else pgettext('Referencing Fiat currency', 'None') b.setTitle_forState_(curr, UIControlStateNormal) if b.allTargets.count <= 0: b.addTarget_action_forControlEvents_(self, SEL(b'onFiatCurrencyBut:'), UIControlEventPrimaryActionTriggered) elif row == 1: l = cell.viewWithTag_(1) s = cell.viewWithTag_(2) l.text = _('Show history rates') s.on = bool(fx and fx.get_history_config()) if s.allTargets.count <= 0: s.addTarget_action_forControlEvents_(self, SEL(b'onFiatHistory:'), UIControlEventValueChanged) enabled = bool(bool(fx) and fx.is_enabled()) utils.uiview_set_enabled(cell.contentView, enabled) elif row == 2: l = cell.viewWithTag_(1) s = cell.viewWithTag_(2) l.text = _('Show Fiat balance for addresses') s.on = bool(fx and fx.get_fiat_address_config()) if s.allTargets.count <= 0: s.addTarget_action_forControlEvents_(self, SEL(b'onFiatBal:'), UIControlEventValueChanged) enabled = bool(bool(fx) and fx.is_enabled()) utils.uiview_set_enabled(cell.contentView, enabled) elif row == 3: l = cell.viewWithTag_(1) b = cell.viewWithTag_(2) b = b if b is not None else cell.viewWithTag_(TAG_FIAT_EXCHANGE) l.text = _('Source') if b is not None: b.tag = TAG_FIAT_EXCHANGE b.setTitle_forState_(pgettext('Referencing Fiat rate source', 'None'), UIControlStateNormal) self.setFiatExchangeButtonText_(b) if b.allTargets.count <= 0: b.addTarget_action_forControlEvents_(self, SEL(b'onFiatExchangeBut:'), UIControlEventPrimaryActionTriggered)
def refresh(self) -> None: utils.NSLog("NETOWRK VC UPDATE, isMainThread = %s",str(NSThread.currentThread.isMainThread)) if not parent() or not parent().daemon or not parent().daemon.network: utils.NSLog("NetworkDialogVC: No network defined, returning early from refresh") return if not parent().networkVC or not self.viewIfLoaded: utils.NSLog("NetworkDialogVC: Returning early, view has been deallocated") return network = parent().daemon.network chains = network.get_blockchains() n_chains = len(chains) host, port, protocol, proxy_config, auto_connect = network.get_parameters() self.hostTF.text = str(host) self.portTF.text = str(port) self.lastPort = at(int(port)) self.autoServerSW.on = bool(auto_connect) host = network.interface.host if network.interface else pgettext('Referencing server', 'None') self.serverLbl.text = str(host) #self.set_protocol(protocol) self.protocol = protocol servers_orig = network.get_servers() servers = [] if servers_orig: servers_orig = sorted(servers_orig.items()) use_tor = False for s in servers_orig: # filter out tor and servers with no port on our protocol host, d = s if host.endswith('.onion') and not use_tor: continue if d.get(protocol,None): ser_server = serialize_server(host, d.get(protocol), protocol) servers.append((host, d, ser_server)) utils.nspy_put_byname(self, servers, 'servers') self.peersTV.reloadData() self.updateAutoServerSWStuff() height_str = "%d "%(network.get_local_height()) + _('blocks') self.heightLbl.text = str(height_str) n = len(network.get_interfaces()) status = _("Connected to %d nodes.")%n if n else _("Not connected") self.statusLbl.text = str(status) if len(chains)>1: chain = network.blockchain() checkpoint = chain.get_base_height() name = chain.get_name() msg = _('Chain split detected at block %d')%checkpoint + '\n' msg += (_('You are following branch') if auto_connect else _('Your server is on branch'))+ ' ' + name msg += ' (%d %s)' % (chain.get_branch_size(), _('blocks')) else: msg = '' utils.uilabel_replace_attributed_text(self.splitLbl, msg, self.splitAttrTxtOrig) # setup 'connected' data -- list of ConnData items connected = [] for k, items in chains.items(): b = network.blockchains[k] name = b.get_name() secHeader = _("Connected node") + ", " + _("Height") secItems = list() extraData = None if n_chains > 1: secHeader = "(" + (name + '@%d'%b.get_base_height()) + ") " + _("Host") + ", " + _("Height") extraData = [ False, b.base_height, name ] for i in items: star = ' *' if i == network.interface else '' extraData = [True, i.server, ''] #if n_chains <= 1 else extraData item = [i.host + star, '%d'%i.tip, extraData] secItems.append(item) section = ConnData(secHeader,secItems) connected.append(section) utils.nspy_put_byname(self, connected, 'connected') self.connectedTV.reloadData()