qt: warn user if in testnet mode

closes #5295
This commit is contained in:
SomberNight 2019-04-28 06:31:01 +02:00
parent 162d81c156
commit 99f9a1b484
No known key found for this signature in database
GPG key ID: B33B5F232C6271E9
3 changed files with 31 additions and 2 deletions

View file

@ -198,6 +198,7 @@ class ElectrumGui(PrintError):
self.build_tray_menu() self.build_tray_menu()
# FIXME: Remove in favour of the load_wallet hook # FIXME: Remove in favour of the load_wallet hook
run_hook('on_new_window', w) run_hook('on_new_window', w)
w.warn_if_testnet()
w.warn_if_watching_only() w.warn_if_watching_only()
return w return w

View file

@ -468,7 +468,32 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
_("This means you will not be able to spend Bitcoins with it."), _("This means you will not be able to spend Bitcoins with it."),
_("Make sure you own the seed phrase or the private keys, before you request Bitcoins to be sent to this wallet.") _("Make sure you own the seed phrase or the private keys, before you request Bitcoins to be sent to this wallet.")
]) ])
self.show_warning(msg, title=_('Information')) self.show_warning(msg, title=_('Watch-only wallet'))
def warn_if_testnet(self):
if not constants.net.TESTNET:
return
# user might have opted out already
if self.config.get('dont_show_testnet_warning', False):
return
# only show once per process lifecycle
if getattr(self.gui_object, '_warned_testnet', False):
return
self.gui_object._warned_testnet = True
msg = ''.join([
_("You are in testnet mode."), ' ',
_("Testnet coins are worthless."), '\n',
_("Testnet is separate from the main Bitcoin network. It is used for testing.")
])
cb = QCheckBox(_("Don't show this again."))
cb_checked = False
def on_cb(x):
nonlocal cb_checked
cb_checked = x == Qt.Checked
cb.stateChanged.connect(on_cb)
self.show_warning(msg, title=_('Testnet'), checkbox=cb)
if cb_checked:
self.config.set_key('dont_show_testnet_warning', True)
def open_wallet(self): def open_wallet(self):
try: try:

View file

@ -218,7 +218,8 @@ class MessageBoxMixin(object):
title or _('Information'), msg, **kwargs) title or _('Information'), msg, **kwargs)
def msg_box(self, icon, parent, title, text, buttons=QMessageBox.Ok, def msg_box(self, icon, parent, title, text, buttons=QMessageBox.Ok,
defaultButton=QMessageBox.NoButton, rich_text=False): defaultButton=QMessageBox.NoButton, *, rich_text=False,
checkbox=None):
parent = parent or self.top_level_window() parent = parent or self.top_level_window()
if type(icon) is QPixmap: if type(icon) is QPixmap:
d = QMessageBox(QMessageBox.Information, title, str(text), buttons, parent) d = QMessageBox(QMessageBox.Information, title, str(text), buttons, parent)
@ -233,6 +234,8 @@ class MessageBoxMixin(object):
else: else:
d.setTextInteractionFlags(Qt.TextSelectableByMouse) d.setTextInteractionFlags(Qt.TextSelectableByMouse)
d.setTextFormat(Qt.PlainText) d.setTextFormat(Qt.PlainText)
if checkbox is not None:
d.setCheckBox(checkbox)
return d.exec_() return d.exec_()
class WindowModalDialog(QDialog, MessageBoxMixin): class WindowModalDialog(QDialog, MessageBoxMixin):