Skip to content
This repository has been archived by the owner on Sep 1, 2021. It is now read-only.

Commit

Permalink
Merge branch 'feature/ticket21_switch_network' into develop
Browse files Browse the repository at this point in the history
Also fixes refactoring #11
  • Loading branch information
AndreMiras committed Apr 5, 2018
2 parents 6555c7f + 501b7ef commit b729bcf
Show file tree
Hide file tree
Showing 4 changed files with 301 additions and 166 deletions.
40 changes: 40 additions & 0 deletions src/etheroll.kv
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#:import MDBottomNavigation kivymd.tabs.MDBottomNavigation
#:import MDBottomNavigationItem kivymd.tabs.MDBottomNavigationItem
#:import MDTextField kivymd.textfields.MDTextField
#:import MDCheckbox kivymd.selectioncontrols.MDCheckbox
#:import MDSlider kivymd.slider.MDSlider
#:import Toolbar kivymd.toolbar.Toolbar
#:import ROUND_DIGITS etheroll.ROUND_DIGITS
Expand Down Expand Up @@ -70,6 +71,36 @@
ImportKeystore:


<SettingsScreen>:
name: 'settings_screen'
BoxLayout:
orientation: 'vertical'
BoxLayout:
orientation: 'horizontal'
MDCheckbox:
id: mainnet_checkbox_id
group: 'network'
size_hint: None, None
size: dp(48), dp(48)
pos_hint: {'center_x': 0.5, 'center_y': 0.5}
active: True
on_release:
print(root.network)
MDLabel:
text: 'Mainnet'
BoxLayout:
orientation: 'horizontal'
MDCheckbox:
id: testnet_checkbox_id
group: 'network'
size_hint: None, None
size: dp(48), dp(48)
pos_hint: {'center_x': 0.5, 'center_y': 0.5}
MDLabel:
text: 'Testnet'
PushUp:


<AboutScreen>:
BoxLayout:
orientation: "vertical"
Expand Down Expand Up @@ -183,6 +214,12 @@
on_release:
app.root.ids.screen_manager_id.transition.direction = "right"
app.root.ids.screen_manager_id.current = "switch_account_screen"
NavigationDrawerIconButton:
icon: "settings"
text: "Settings"
on_release:
app.root.ids.screen_manager_id.transition.direction = "right"
app.root.ids.screen_manager_id.current = "settings_screen"
NavigationDrawerIconButton:
icon: "help"
text: "About"
Expand All @@ -208,6 +245,9 @@ Controller:
SwitchAccountScreen:
id: switch_account_screen_id
name: "switch_account_screen"
SettingsScreen:
id: settings_screen_id
name: "settings_screen"
AboutScreen:
id: about_screen_id
name: "about_screen"
51 changes: 45 additions & 6 deletions src/etheroll.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#!/usr/bin/env python
from __future__ import print_function, unicode_literals

import os
from os.path import expanduser

Expand Down Expand Up @@ -169,6 +167,31 @@ def on_account_selected(self, account):
self.on_back()


class SettingsScreen(SubScreen):
"""
Screen for configuring network, gas price...
"""

def __init__(self, **kwargs):
super(SettingsScreen, self).__init__(**kwargs)
# Clock.schedule_once(self._after_init)

@property
def network(self):
"""
Returns selected network.
"""
if self.is_mainnet():
return pyetheroll.ChainID.MAINNET
return pyetheroll.ChainID.ROPSTEN

def is_mainnet(self):
return self.ids.mainnet_checkbox_id.active

def is_testnet(self):
return self.ids.testnet_checkbox_id.active


class AboutScreen(SubScreen):
project_page_property = StringProperty(
"https://github.com/AndreMiras/EtherollApp")
Expand Down Expand Up @@ -293,7 +316,8 @@ def __init__(self, **kwargs):
super(Controller, self).__init__(**kwargs)
Clock.schedule_once(self._after_init)
self._init_pyethapp()
self.account_passwords = {}
self._account_passwords = {}
self._pyetheroll = None

def _after_init(self, dt):
"""
Expand All @@ -314,6 +338,17 @@ def _init_pyethapp(self, keystore_dir=None):
config=dict(accounts=dict(keystore_dir=keystore_dir)))
AccountsService.register_with_app(self.pyethapp)

@property
def pyetheroll(self):
"""
Gets or creates the Etheroll object.
Also recreates the object if the chain_id changed.
"""
chain_id = self.settings_screen.network
if self._pyetheroll is None or self._pyetheroll.chain_id != chain_id:
self._pyetheroll = pyetheroll.Etheroll(chain_id)
return self._pyetheroll

@classmethod
def get_keystore_path(cls):
"""
Expand Down Expand Up @@ -410,11 +445,15 @@ def roll_screen(self):
def switch_account_screen(self):
return self.ids.switch_account_screen_id

@property
def settings_screen(self):
return self.ids.settings_screen_id

def on_unlock_clicked(self, dialog, account, password):
"""
Caches the password and call roll method again.
"""
self.account_passwords[account.address.hex()] = password
self._account_passwords[account.address.hex()] = password
dialog.dismiss()
# calling roll again since the password is now cached
self.roll()
Expand Down Expand Up @@ -444,7 +483,7 @@ def get_account_password(self, account):
"""
address = account.address.hex()
try:
return self.account_passwords[address]
return self._account_passwords[address]
except KeyError:
self.prompt_password_dialog(account)

Expand Down Expand Up @@ -484,7 +523,7 @@ def roll(self):
password = self.get_account_password(account)
if password is not None:
try:
tx_hash = pyetheroll.player_roll_dice(
tx_hash = self.pyetheroll.player_roll_dice(
bet_size, chances, wallet_path, password)
except ValueError as exception:
self.dialog_roll_error(exception)
Expand Down
Loading

0 comments on commit b729bcf

Please sign in to comment.