def on_empty_account_list(): controller = App.get_running_app().root keystore_dir = controller.account_utils.keystore_dir title = "No account found" body = "No account found in:\n%s" % keystore_dir dialog = Dialog.create_dialog(title, body) dialog.open()
def show_redirect_dialog(self): title = "Account created, redirecting..." body = "" body += "Your account was created, " body += "you will be redirected to the overview." dialog = Dialog.create_dialog(title, body) dialog.open()
def on_keyboard(self, window, key, *args): """ Handles the back button (Android) and ESC key. Goes back to the previous screen, dicards dialogs or exits the application if none left. """ if key == 27: if Dialog.dialogs: Dialog.dismiss_all_dialogs() return True from etheroll.utils import SubScreen current_screen = self.screen_manager.current_screen # if is sub-screen loads previous and stops the propagation # otherwise propagates the key to exit if isinstance(current_screen, SubScreen): current_screen.on_back() return True return False
def on_account_none(): """ Error dialog on no account selected. """ title = "No account selected" body = "Please select an account before rolling" dialog = Dialog.create_dialog(title, body) dialog.open()
def player_roll_dice(self, bet_size, chances, wallet_path, password, gas_price): """ Sending the bet to the smart contract requires signing a transaction which requires CPU computation to unlock the account, hence this is ran in a thread. """ roll_screen = self.roll_screen try: Dialog.snackbar_message("Sending bet...") roll_screen.toggle_widgets(False) tx_hash = self.pyetheroll.player_roll_dice(bet_size, chances, wallet_path, password, gas_price) except ValueError as exception: roll_screen.toggle_widgets(True) self.dialog_roll_error(exception) return roll_screen.toggle_widgets(True) self.dialog_roll_success(tx_hash)
def dialog_roll_error(self, exception): """ Shows different error message depending on the exception. On "MAC mismatch" (wrong password), void the cached password so the user can try again refs: https://github.com/AndreMiras/EtherollApp/issues/9 """ title = "Error rolling" body = str(exception) if exception.args[0] == 'MAC mismatch': title = "Wrong password" body = "Can't unlock wallet, wrong password." account = self.current_account self._account_passwords.pop(account.address.hex()) dialog = Dialog.create_dialog(title, body) dialog.open()
def try_unlock(account, password): """ Just as a security measure, verifies we can unlock the newly created account with provided password. """ # making sure it's locked first account.lock() try: account.unlock(password) except ValueError: title = "Unlock error" body = "" body += "Couldn't unlock your account.\n" body += "The issue should be reported." dialog = Dialog.create_dialog(title, body) dialog.open() return
def dialog(cls, account): """ Prompt the password dialog. """ title = "Enter your password" password_form = cls() password_form.ids.account_id.text = "0x" + account.address.hex() dialog = Dialog.create_dialog_content_helper(title=title, content=password_form) # workaround for MDDialog container size (too small by default) dialog.ids.container.size_hint_y = 1 dialog.add_action_button( "Unlock", action=lambda *x: password_form.dispatch( 'on_unlock', dialog, account, password_form.password)) # hitting enter on the text should also submit password_form.ids.password_id.bind( on_text_validate=lambda *x: password_form.dispatch( 'on_unlock', dialog, account, password_form.password)) return dialog
def show_qr_code(self): """ Shows address QR Code in a dialog. """ # lazy loading from kivy.garden.qrcode import QRCodeWidget from kivy.metrics import dp account = self.current_account if not account: return address = "0x" + account.address.hex() title = address qr_code = QRCodeWidget() qr_code.data = address dialog = Dialog.create_dialog_content_helper(title=title, content=qr_code) # workaround for MDDialog container size (too small by default) dialog.ids.container.size_hint_y = 1 dialog.height = dp(500) dialog.add_action_button("OK", action=lambda *x: dialog.dismiss()) dialog.open() return dialog
def create_account(self): """ Creates an account from provided form. Verify we can unlock it. Disables widgets during the process, so the user doesn't try to create another account during the process. """ self.toggle_widgets(False) if not self.verify_fields(): Dialog.show_invalid_form_dialog() self.toggle_widgets(True) return password = self.new_password1 Dialog.snackbar_message("Creating account...") controller = App.get_running_app().root account = controller.account_utils.new_account(password=password) Dialog.snackbar_message("Created!") self.toggle_widgets(True) self.on_account_created(account) # CreateNewAccount.try_unlock(account, password) self.show_redirect_dialog() self.load_landing_page() return account
def on_connection_refused(): title = 'No network' body = 'No network, could not retrieve roll history.' dialog = Dialog.create_dialog(title, body) dialog.open()
def dialog_roll_success(tx_hash): title = "Rolled successfully" body = "Transaction hash:\n" + tx_hash.hex() dialog = Dialog.create_dialog(title, body) dialog.open()
def on_connection_refused(): title = 'No network' body = 'No network, could not retrieve account balance.' dialog = Dialog.create_dialog(title, body) dialog.open()