Skip to content

Commit

Permalink
Merge #3bb17ec into OSX
Browse files Browse the repository at this point in the history
  • Loading branch information
freQniK committed Oct 4, 2024
1 parent 4c345af commit 30fba28
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/bin/routes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ else
route delete -net 128.0.0.0/1 198.18.0.1
route delete -net 198.18.0.0/15 198.18.0.1
ifconfig utun123 198.18.0.1 198.18.0.1 down
pkill -9 v2ray
pkill -9 tun2socks
pkill -9 v2ray
fi
4 changes: 3 additions & 1 deletion src/cli/sentinel.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from urllib.parse import urlparse
import copy
import random
from copy import deepcopy

from treelib import Tree
from treelib.exceptions import DuplicatedNodeIdError
Expand All @@ -32,6 +33,7 @@
class NodeTreeData():
BackupNodeTree = None
NodeTree = None
SubResult = None
NodeScores = {}
NodeLocations = {}
NodeTypes = {}
Expand Down Expand Up @@ -493,7 +495,7 @@ def get_subscriptions(self, ADDRESS):
})
k += 1

return SubsFinalResult
self.SubResult = deepcopy(SubsFinalResult)


def GetQuota(self, id):
Expand Down
34 changes: 24 additions & 10 deletions src/cli/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,9 @@ def send_2plan_wallet(self, KEYNAME, plan_id, DENOM, amount_required):
if tx.get("log", None) is None:
try:
tx_response = sdk.nodes.wait_for_tx(tx["hash"], timeout=25)
except mospy.exceptions.clients.TransactionTimeout as e:
except (mospy.exceptions.clients.TransactionTimeout,
mospy.exceptions.clients.NodeException,
mospy.exceptions.clients.NodeTimeoutException) as e:
return (False, {'hash' : None, 'success' : False, 'message' : "GRPC Error"})

tx_height = tx_response.get("txResponse", {}).get("height", 0) if isinstance(tx_response, dict) else tx_response.tx_response.height
Expand Down Expand Up @@ -429,7 +431,8 @@ def subscribe(self, KEYNAME, NODE, DEPOSIT, GB, hourly):
status_code = e.code()

if status_code == StatusCode.NOT_FOUND:
return(False, "Wallet not found on blockchain. Please verify you have sent coins to your wallet to activate it. Then try your subscription again")
self.returncode = (False, "Wallet not found on blockchain. Please verify you have sent coins to your wallet to activate it. Then try your subscription again")
return
balance = self.get_balance(sdk._account.address)

amount_required = float(DEPOSIT.replace(DENOM, ""))
Expand All @@ -438,7 +441,8 @@ def subscribe(self, KEYNAME, NODE, DEPOSIT, GB, hourly):
ubalance = balance.get(token_ibc[DENOM][1:], 0) * IBCTokens.SATOSHI

if ubalance < amount_required:
return(False, f"Balance is too low, required: {round(amount_required / IBCTokens.SATOSHI, 4)}{token_ibc[DENOM][1:]}")
self.returncode = (False, f"Balance is too low, required: {round(amount_required / IBCTokens.SATOSHI, 4)}{token_ibc[DENOM][1:]}")
return

gas = random.randint(ConfParams.GAS, 314159)

Expand All @@ -459,23 +463,29 @@ def subscribe(self, KEYNAME, NODE, DEPOSIT, GB, hourly):

if tx.get("log", None) is not None:
print(tx["log"])
return(False, tx["log"])
self.returncode = (False, tx["log"])
return

if tx.get("hash", None) is not None:
try:
tx_response = sdk.nodes.wait_for_tx(tx["hash"], timeout=25)
except mospy.exceptions.clients.TransactionTimeout as e:
except (mospy.exceptions.clients.TransactionTimeout,
mospy.exceptions.clients.NodeException,
mospy.exceptions.clients.NodeTimeoutException) as e:
print(str(e))
return(False, "GRPC Error")
self.returncode = (False, "GRPC Error")
return

print(tx_response)
subscription_id = search_attribute(
tx_response, "sentinel.node.v2.EventCreateSubscription", "id"
)
if subscription_id:
return (True, subscription_id)
self.returncode = (True, subscription_id)
return

return(False, "Tx error")
self.returncode = (False, "Tx error")
return

def DetermineDenom(self, deposit):
for key,value in IBCTokens.IBCUNITTOKEN.items():
Expand Down Expand Up @@ -534,7 +544,9 @@ def unsubscribe(self, subId):
if tx.get("log", None) is None:
try:
tx_response = sdk.plans.wait_for_tx(tx["hash"], timeout=25)
except mospy.exceptions.clients.TransactionTimeout as e:
except (mospy.exceptions.clients.TransactionTimeout,
mospy.exceptions.clients.NodeException,
mospy.exceptions.clients.NodeTimeoutException) as e:
print(str(e))
return {'hash' : "0x0", 'success' : False, 'message' : "GRPC Error"}
tx_height = tx_response.get("txResponse", {}).get("height", 0) if isinstance(tx_response, dict) else tx_response.tx_response.height
Expand Down Expand Up @@ -610,7 +622,9 @@ def connect(self, ID, address, type):

try:
tx_response = sdk.sessions.wait_for_tx(tx["hash"], timeout=25)
except mospy.exceptions.clients.TransactionTimeout as e:
except (mospy.exceptions.clients.TransactionTimeout,
mospy.exceptions.clients.NodeException,
mospy.exceptions.clients.NodeTimeoutException) as e:
print(str(e))
conndesc.write("GRPC Error... Exiting")
conndesc.flush()
Expand Down
73 changes: 51 additions & 22 deletions src/ui/screens.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,6 @@ class MainWindow(Screen):
dnscrypt = False
warpd_disconnected = True
NodeTree = None
SubResult = None
MeileConfig = None
ConnectedNode = None
menu = None
Expand Down Expand Up @@ -1257,7 +1256,7 @@ def Refresh(self):
pass

# Clear out Subscriptions
self.SubResult = None
self.NodeTree.SubResult = None
# Redraw Map Pins
self.AddCountryNodePins(False)
self.refresh_country_recycler()
Expand Down Expand Up @@ -1676,49 +1675,74 @@ def set_previous_screen(self):


class SubscriptionScreen(MDBoxLayout):
SubResult = None

def __init__(self, node_tree, **kwargs):
super(SubscriptionScreen, self).__init__()
self.NodeTree = node_tree

self.get_config(None)
self.add_loading_popup("Loading...")
self.cd = ConnectionDialog()
self.set_conn_dialog(self.cd, "Loading Subscriptions...")

if self.address:
Clock.schedule_once(self.subs_callback, 0.25)
self.subs_callback(None)
return
else:
self.remove_loading_widget(None)
self.sub_address_error()
return

'''
def GetSubscriptions(self):
mw = Meile.app.root.get_screen(WindowNames.MAIN_WINDOW)
'''
Make this a background thread and not on main loop
Remove ThreadWtithResult dep.
Add loading bar or spinning wheel
'''
try:
thread = ThreadWithResult(target=self.NodeTree.get_subscriptions, args=(self.address,))
thread.start()
thread.join()
mw.SubResult = thread.result
print("Staring thread...")
#self.NodeTree.get_subscriptions(self.address)
t = Thread(target=lambda: self.NodeTree.get_subscriptions(self.address))
t.start()
l = 13
pool = l*100
inc = float(1/pool)
while t.is_alive():
yield 0.0165
self.cd.ids.pb.value += inc
print("Thread completed.")
self.cd.ids.pb.value = 1
#thread = ThreadWithResult(target=self.NodeTree.get_subscriptions, args=(self.address,))
#thread.start()
#thread.join()
mw.NodeTree.SubResult = deepcopy(self.NodeTree.SubResult)
print(mw.NodeTree.SubResult)
except Exception as e:
print(str(e))
return None

'''

@delayable
def subs_callback(self, dt):
yield 0.314
mw = Meile.app.root.get_screen(WindowNames.MAIN_WINDOW)

if not mw.SubResult:
self.GetSubscriptions()
if mw.NodeTree.SubResult is None:
try:
t = Thread(target=lambda: self.NodeTree.get_subscriptions(self.address))
t.start()
l = 13
pool = l*100
inc = float(1/pool)
while t.is_alive():
yield 0.0165
self.cd.ids.pb.value += inc
self.cd.ids.pb.value = 1
mw.NodeTree.SubResult = deepcopy(self.NodeTree.SubResult)
print(mw.NodeTree.SubResult)
except Exception as e:
print(str(e))
return None
try:
for sub in mw.SubResult:
for sub in mw.NodeTree.SubResult:
self.add_sub_rv_data(sub)
except TypeError:
print("Connection Error")
Expand All @@ -1729,7 +1753,7 @@ def subs_callback(self, dt):

# Auto-connect from NodeCarousel if sub found
if mw.SubCaller:
for sub in mw.SubResult:
for sub in mw.NodeTree.SubResult:
print(sub)
if mw.NodeCarouselData['address'] == sub[NodeKeys.FinalSubsKeys[2]]:
mw.SelectedSubscription['id'] = sub[NodeKeys.FinalSubsKeys[0]]
Expand Down Expand Up @@ -1812,9 +1836,14 @@ def get_config(self, dt):
self.address = CONFIG['wallet'].get("address")

@mainthread
def add_loading_popup(self, title_text):
def set_conn_dialog(self, cd, title):
self.dialog = None
self.dialog = MDDialog(title=title_text,md_bg_color=get_color_from_hex(MeileColors.BLACK))
self.dialog = MDDialog(
title=title,
type="custom",
content_cls=cd,
md_bg_color=get_color_from_hex(MeileColors.BLACK),
)
self.dialog.open()

@mainthread
Expand Down
20 changes: 13 additions & 7 deletions src/ui/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from kivymd.uix.menu import MDDropdownMenu
from kivymd.uix.list import OneLineIconListItem
from kivymd.uix.behaviors import HoverBehavior
from kivymd.theming import ThemableBehavior
from kivymd.uix.behaviors.elevation import RectangularElevationBehavior
from kivyoav.delayed import delayable

Expand All @@ -38,6 +37,7 @@
from requests.auth import HTTPBasicAuth
import json
import webbrowser
import sys

from typedef.konstants import IBCTokens, HTTParams, MeileColors, NodeKeys
from typedef.win import CoinsList, WindowNames
Expand Down Expand Up @@ -1474,9 +1474,15 @@ def subscribe(self, subscribe_dialog, *kwargs):
KEYNAME = CONFIG['wallet'].get('keyname', '')

hwf = HandleWalletFunctions()
returncode = hwf.subscribe(KEYNAME, sub_node[1], deposit, sub_node[3], sub_node[4])
t = Thread(target=lambda: hwf.subscribe(KEYNAME, sub_node[1], deposit, sub_node[3], sub_node[4]))
t.start()

if returncode[0]:
while t.is_alive():
print(".", end="")
sys.stdout.flush()
yield 0.5

if hwf.returncode[0]:
self.dialog.dismiss()
self.dialog = MDDialog(
title="Successful!",
Expand Down Expand Up @@ -1544,7 +1550,7 @@ def closeDialogReturnToSubscriptions(self,inst):
self.dialog.dismiss()
self.dialog = None
mw = Meile.app.root.get_screen(WindowNames.MAIN_WINDOW)
mw.SubResult = None
mw.NodeTree.SubResult = None

if mw.SubCaller:
mw.switch_to_sub_window()
Expand All @@ -1561,7 +1567,7 @@ def closeDialog(self, inst):
self.dialog = None

#class WalletCoinRow(MDCard,RectangularElevationBehavior,ThemableBehavior, HoverBehavior):
class WalletCoinRow(MDCard,ThemableBehavior, HoverBehavior):
class WalletCoinRow(MDCard,HoverBehavior):
logo = StringProperty('')
text = StringProperty('')

Expand All @@ -1573,7 +1579,7 @@ class RowContainer(MDBoxLayout):
Recycler of the node cards after clicking country
'''
#class RecycleViewRow(MDCard,RectangularElevationBehavior,ThemableBehavior, HoverBehavior):
class RecycleViewRow(MDCard,ThemableBehavior, HoverBehavior):
class RecycleViewRow(MDCard,HoverBehavior):
dialog = None
node_data = ObjectProperty()
#node_types = ObjectProperty()
Expand Down Expand Up @@ -1614,7 +1620,7 @@ def switch_to_node_carousel(self, node_data):
mw.carousel.add_widget(NodeWidget)
mw.carousel.load_slide(NodeWidget)

class MDMapCountryButton(MDFillRoundFlatButton,ThemableBehavior, HoverBehavior):
class MDMapCountryButton(MDFillRoundFlatButton, HoverBehavior):
def on_enter(self, *args):
self.md_bg_color = get_color_from_hex("#fcb711")
Window.set_system_cursor('arrow')
Expand Down

0 comments on commit 30fba28

Please sign in to comment.