Skip to content

Commit

Permalink
Merge #3bb17ec into 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
freQniK committed Oct 9, 2024
1 parent f8958ce commit 14f9710
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 50 deletions.
4 changes: 3 additions & 1 deletion src/cli/sentinel.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import time
from urllib.parse import urlparse
import copy
from copy import deepcopy
import random

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

return SubsFinalResult
self.SubResult = deepcopy(SubsFinalResult)


def GetQuota(self, id):
Expand Down
37 changes: 26 additions & 11 deletions src/cli/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,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 @@ -437,7 +439,9 @@ 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")
#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 @@ -446,8 +450,9 @@ 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:]}")

#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
tx_params = TxParams(
# denom="udvpn", # TODO: from ConfParams
# fee_amount=20000, # TODO: from ConfParams
Expand All @@ -466,23 +471,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 @@ -541,7 +552,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 @@ -613,7 +626,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
1 change: 1 addition & 0 deletions src/kv/meile.kv
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,7 @@ WindowManager:
markup: True
size_hint_x: 1
font_name: root.get_font()
font_size: sp(11)
HSeparator:
HSeparator:
HSeparator:
Expand Down
66 changes: 35 additions & 31 deletions src/ui/screens.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,6 @@ class MainWindow(Screen):
warpd = False
warpd_disconnected = True
NodeTree = None
SubResult = None
MeileConfig = None
ConnectedNode = None
menu = None
Expand Down Expand Up @@ -1197,7 +1196,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 @@ -1616,56 +1615,56 @@ 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
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()

for sub in mw.SubResult:
self.add_sub_rv_data(sub)

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.NodeTree.SubResult:
self.add_sub_rv_data(sub)
except TypeError:
print("Connection Error")

self.remove_loading_widget(None)

# 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 @@ -1748,9 +1747,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
22 changes: 15 additions & 7 deletions src/ui/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
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.theming import ThemableBehavior
from kivyoav.delayed import delayable

from functools import partial
Expand All @@ -37,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 @@ -1473,9 +1474,16 @@ 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()

while t.is_alive():
print(".", end="")
sys.stdout.flush()
yield 0.5
#returncode = hwf.subscribe(KEYNAME, sub_node[1], deposit, sub_node[3], sub_node[4])

if returncode[0]:
if hwf.returncode[0]:
self.dialog.dismiss()
self.dialog = MDDialog(
title="Successful!",
Expand Down Expand Up @@ -1543,7 +1551,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 @@ -1559,7 +1567,7 @@ def closeDialog(self, inst):
print(str(e))
self.dialog = None

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

Expand All @@ -1570,7 +1578,7 @@ class RowContainer(MDBoxLayout):
'''
Recycler of the node cards after clicking country
'''
class RecycleViewRow(MDCard,ThemableBehavior, HoverBehavior):
class RecycleViewRow(MDCard, HoverBehavior):
dialog = None
node_data = ObjectProperty()
#node_types = ObjectProperty()
Expand Down Expand Up @@ -1611,7 +1619,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 14f9710

Please sign in to comment.