Skip to content

Commit 027d668

Browse files
authored
Merge pull request #84 from MathNodes/main
Update to 1.8.0
2 parents 4004625 + 80a3a40 commit 027d668

File tree

7 files changed

+118
-59
lines changed

7 files changed

+118
-59
lines changed

src/cli/sentinel.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def get_nodes(self, latency, *kwargs):
126126

127127

128128
def GetHealthCheckData(self):
129-
Request = HTTPRequests.MakeRequest(TIMEOUT=2)
129+
Request = HTTPRequests.MakeRequest(TIMEOUT=4)
130130
http = Request.hadapter()
131131
try:
132132
r = http.get(HTTParams.HEALTH_CHECK) #specify a constant in konstants.py
@@ -150,7 +150,7 @@ def GetHealthCheckData(self):
150150
print(str(e))
151151

152152
def GetNodeScores(self):
153-
Request = HTTPRequests.MakeRequest(TIMEOUT=2)
153+
Request = HTTPRequests.MakeRequest(TIMEOUT=4)
154154
http = Request.hadapter()
155155
try:
156156
r = http.get(HTTParams.SERVER_URL + HTTParams.NODE_SCORE_ENDPOINT)
@@ -163,7 +163,7 @@ def GetNodeScores(self):
163163
print(str(e))
164164

165165
def GetNodeLocations(self):
166-
Request = HTTPRequests.MakeRequest(TIMEOUT=2)
166+
Request = HTTPRequests.MakeRequest(TIMEOUT=4)
167167
http = Request.hadapter()
168168
try:
169169
r = http.get(HTTParams.SERVER_URL + HTTParams.NODE_LOCATION_ENDPOINT)

src/fiat/fiat_interface.py

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
import requests
2222
from requests.auth import HTTPBasicAuth
2323

24-
import stripe
24+
import stripe
25+
import time
2526
from stripe.error import CardError
2627
from fiat.stripe_pay.charge import HotwalletFuncs as HandleWalletFunctions
2728
import fiat.stripe_pay.charge as Charge
@@ -61,7 +62,8 @@ class FiatInterface(Screen):
6162

6263
def __init__(self, **kwargs):
6364
super(FiatInterface, self).__init__()
64-
65+
self.price_api = GetPriceAPI()
66+
self.price_cache = {}
6567
self.CoinOptions = self.DynamicCoinOptions()
6668
self.DVPNOptions = self.CoinOptions['dvpn']
6769
self.DECOptions = self.CoinOptions['dec']
@@ -177,7 +179,6 @@ def DynamicCoinOptions(self):
177179
MAX_SPEND = 25
178180
coins = self.TokenOptions
179181
CoinOptions = {coins[0] : None, coins[1] : None, coins[2] : None}
180-
api = GetPriceAPI()
181182

182183
Request = HTTPRequests.MakeRequest()
183184
http = Request.hadapter()
@@ -189,11 +190,15 @@ def DynamicCoinOptions(self):
189190
pass
190191

191192
for c in coins:
192-
response = api.get_usd(c)
193-
194-
qty = int(MAX_SPEND/float(response['price']))
193+
self.refresh_price(c, cache=30)
194+
195+
if self.price_cache[c]["price"] == 0:
196+
x = 0
197+
qty = 0
198+
else:
199+
x = 1 /self.price_cache[c]["price"]
200+
qty = int(MAX_SPEND/self.price_cache[c]["price"])
195201

196-
x = 1 / float(response['price'])
197202

198203
if x < 1:
199204
factor = 0.1
@@ -223,33 +228,32 @@ def DynamicCoinOptions(self):
223228

224229
return CoinOptions
225230

226-
231+
def refresh_price(self, mu_coin: str = "dvpn", cache: int = 30):
232+
# Need check on cache or trought GetPrice api
233+
# We don't need to call the price api if the cache is younger that 30s
234+
235+
if mu_coin not in self.price_cache or time.time() - self.price_cache[mu_coin]["time"] > cache:
236+
response = self.price_api.get_usd(mu_coin)
237+
if response['success']:
238+
self.price_cache[mu_coin] = {
239+
"price": float(response['price']),
240+
"time": time.time()
241+
}
242+
else:
243+
self.price_cache[mu_coin] = {
244+
"price": float(0),
245+
"time": time.time()
246+
}
247+
227248
def set_token_price(self, token, dt):
228249
self.ids.dvpn_price.text = "%s: $" % token.upper() + str(self.get_token_price(token))
229250

230251
def get_token_price(self, token):
231-
232-
'''
233-
cg_api_keyword = self.CoinGeckoAPI[self.TokenOptions[0]]
234-
235-
for key,value in self.CoinGeckoAPI.items():
236-
if token == key:
237-
cg_api_keyword = value
238-
239-
try:
240-
cg = CoinGeckoAPI()
241-
cg_price = cg.get_price(ids=[cg_api_keyword], vs_currencies='usd')
242-
token_price = cg_price[cg_api_keyword]['usd']
243-
'''
244-
245-
api = GetPriceAPI()
246-
247252
try:
248-
response = api.get_usd(token)
249-
if response['success']:
250-
token_price = response['price']
251-
else:
252-
raise Exception("Error getting price from CoinStats or AscenDEX")
253+
self.refresh_price(token, cache=30)
254+
token_price = self.price_cache[token]["price"]
255+
if token_price == 0:
256+
raise Exception("Error getting price from CoinStats")
253257
except Exception as e:
254258
print(str(e))
255259
print("Getting price from CryptoCompare...")
@@ -258,7 +262,7 @@ def get_token_price(self, token):
258262
HEADERS = {'authorization' : "Apikey %s" % scrtsxx.CCOMPAREAPI}
259263
try:
260264
r = http.get(scrtsxx.CCOMPARE_API_URL % token.upper(), headers=HEADERS)
261-
sentinel_price = r.json()['USD']
265+
token_price = r.json()['USD']
262266
except Exception as e:
263267
print(str(e))
264268
return 0

src/fonts/Roboto-BoldItalic.ttf

-170 KB
Binary file not shown.

src/typedef/konstants.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ class HTTParams():
3333
SERVER_URL = "https://aimokoivunen.mathnodes.com:5000"
3434
RPC = "https://rpc.mathnodes.com:443"
3535
# Note http://128.199.90.172:26657 is testnet ONLY!
36-
RPCS = ['https://rpc.mathnodes.com:443', 'https://rpc.sentinel.co:443', 'https://sentinel-rpc.badgerbite.io:443',
37-
'https://sentinel-rpc2.badgerbite.io:443', 'https://rpc.sentinel.quokkastake.io:443', 'https://rpc-sentinel.whispernode.com:443',
38-
'https://rpc-sentinel-ia.cosmosia.notional.ventures:443']
36+
RPCS = ['https://rpc.mathnodes.com:443', 'https://rpc.dvpn.me:443', 'https://rpc.sentinel.co:443', 'https://sentinel-rpc.badgerbite.io:443',
37+
'https://sentinel-rpc2.badgerbite.io:443', 'https://rpc.sentinel.quokkastake.io:443', 'https://rpc-sentinel.whispernode.com:443']
3938
GRPC = "grpc+http://aimokoivunen.mathnodes.com:9090/"
4039
#GRPC = "grpc+http://128.199.90.172:9090/"
4140
HEALTH_CHECK = "https://api.health.sentinel.co/v1/records"
@@ -46,6 +45,10 @@ class HTTParams():
4645
API_RATING_ENDPOINT = "/api/rating"
4746
SESSIONS_API_URL = '/sentinel/accounts/%s/sessions'
4847
BALANCES_ENDPOINT = "/bank/balances/"
48+
ICANHAZURL = "https://icanhazip.com"
49+
ICANHAZDNS = "icanhazip.com"
50+
IFCONFIGDNS = "ifconfig.co"
51+
IFCONFIGURL = "https://ifconfig.co/json"
4952

5053

5154
class IBCTokens():
@@ -77,6 +80,7 @@ class MeileColors():
7780
MAP_MARKER = "../imgs/location_pin.png"
7881
HEALTH_ICON = "shield-plus"
7982
SICK_ICON = "emoticon-sick"
83+
ARCGIS_MAP = "https://server.arcgisonline.com/arcgis/rest/services/Canvas/World_Dark_Gray_Base/MapServer/tile/{z}/{y}/{x}.png"
8084

8185
class NodeKeys():
8286
NodesInfoKeys = ["Moniker","Address","Price","Hourly Price", "Country","Speed","Latency","Peers","Handshake","Type","Version","Status"]

src/typedef/win.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
ICANHAZURL = "https://icanhazip.com"
2-
ICANHAZDNS = "icanhazip.com"
31

42
class WindowNames():
53
WALLET_RESTORE = "walletrestore"

src/ui/screens.py

Lines changed: 70 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from geography.continents import OurWorld
2-
from ui.interfaces import Tab, LatencyContent, TooltipMDIconButton
3-
from typedef.win import WindowNames, ICANHAZURL, ICANHAZDNS
2+
from ui.interfaces import Tab, LatencyContent, TooltipMDIconButton, ConnectionDialog
3+
from typedef.win import WindowNames
44
from cli.sentinel import NodeTreeData
55
from typedef.konstants import NodeKeys, TextStrings, MeileColors, HTTParams, IBCTokens
66
from cli.sentinel import disconnect as Disconnect
@@ -219,16 +219,16 @@ def runNodeThread(self):
219219
yield 0.6
220220
thread2 = Thread(target=lambda: self.progress_load())
221221
thread2.start()
222-
thread = Thread(target=lambda: self.NodeTree.get_nodes("13s"))
222+
thread = Thread(target=lambda: self.NodeTree.get_nodes("23s"))
223223
thread.start()
224224

225225
Clock.schedule_interval(partial(self.update_status_text, thread), 1.6)
226226

227227
@delayable
228228
def progress_load(self):
229-
for k in range(1,1000):
229+
for k in range(1,2000):
230230
yield 0.0375
231-
self.manager.get_screen(WindowNames.PRELOAD).ids.pb.value += 0.001
231+
self.manager.get_screen(WindowNames.PRELOAD).ids.pb.value += 0.0005
232232

233233

234234
def CopyBin(self):
@@ -341,6 +341,7 @@ class MainWindow(Screen):
341341
ConnectedDict = {'v2ray_pid' : None, 'result' : False}
342342
NodeWidget = None
343343
Markers = []
344+
LatLong = []
344345

345346

346347
def __init__(self, node_tree, **kwargs):
@@ -392,9 +393,9 @@ def build_meile_map(self):
392393

393394
if not self.MeileMapBuilt:
394395
self.MeileMap = MapView(lat=50.6394, lon=3.057, zoom=2)
395-
source = MapSource(url="https://server.arcgisonline.com/arcgis/rest/services/Canvas/World_Dark_Gray_Base/MapServer/tile/{z}/{y}/{x}.png",
396-
cache_key="meile-map-canvas-dark-grey-base",
397-
tile_size=512,
396+
source = MapSource(url=MeileColors.ARCGIS_MAP,
397+
cache_key="meile-map-canvas-dark-grey-base-2",
398+
tile_size=256,
398399
image_ext="png",
399400
attribution="@ Meile",
400401
size_hint=(.7,1))
@@ -415,7 +416,7 @@ def AddCountryNodePins(self, clear):
415416
try:
416417

417418
if clear:
418-
for m in self.Makers:
419+
for m in self.Markers:
419420
self.MeileMap.remove_marker(m)
420421
self.Markers.clear()
421422

@@ -570,16 +571,33 @@ def get_ip_address(self, dt):
570571

571572
self.old_ip = self.ip
572573
try:
573-
resolver = DNSRequests.MakeDNSRequest(domain=ICANHAZDNS, timeout=1.5, lifetime=2.5)
574-
icanhazip = resolver.DNSRequest()
575-
if icanhazip:
576-
print("%s:%s" % (ICANHAZDNS, icanhazip))
574+
resolver = DNSRequests.MakeDNSRequest(domain=HTTParams.IFCONFIGDNS, timeout=3.5, lifetime=3.5)
575+
ifconfig = resolver.DNSRequest()
576+
if ifconfig:
577+
print("%s:%s" % (HTTParams.IFCONFIGDNS, ifconfig))
577578
Request = HTTPRequests.MakeRequest()
578579
http = Request.hadapter()
579-
req = http.get(ICANHAZURL)
580-
self.ip = req.text
581-
582-
self.manager.get_screen(WindowNames.MAIN_WINDOW).ids.new_ip.text = self.ip
580+
req = http.get(HTTParams.IFCONFIGURL)
581+
ifJSON = req.json()
582+
print(ifJSON)
583+
self.ip = str(ifJSON['ip'])
584+
self.ids.new_ip.text = self.ip
585+
self.LatLong.clear()
586+
try:
587+
self.LatLong.append(ifJSON['latitude'])
588+
self.LatLong.append(ifJSON['longitude'])
589+
except:
590+
print("No Lat/Long")
591+
try:
592+
country = ifJSON['country']
593+
loc = self.MeileLand.CountryLatLong[country]
594+
self.LatLong.append(loc[0])
595+
self.LatLong.append(loc[1])
596+
except:
597+
print("No Country...Defaulting to my dream.")
598+
loc = self.MeileLand.CountryLatLong["Seychelles"]
599+
self.LatLong.append(loc[0])
600+
self.LatLong.append(loc[1])
583601
return True
584602
#self.manager.get_screen(WindowNames.MAIN_WINDOW).ids.old_ip.text = "Old IP: " + self.old_ip
585603
else:
@@ -761,13 +779,21 @@ def Refresh(self, latency, *kwargs):
761779
self.remove_loading_widget(None)
762780
self.AddCountryNodePins(True)
763781
yield 0.314
764-
self.add_loading_popup("Reloading Nodes...")
782+
cd = ConnectionDialog()
783+
self.set_conn_dialog(cd, "Reloading Nodes...")
765784
yield 0.314
766785
try:
767786
self.NodeTree.NodeTree = None
768-
thread = ThreadWithResult(target=self.NodeTree.get_nodes, args=(latency.return_latency(),))
769-
thread.start()
770-
thread.join()
787+
t = Thread(target=lambda: self.NodeTree.get_nodes(latency.return_latency()))
788+
t.start()
789+
l = int(latency.return_latency().split('s')[0])
790+
pool = l*100
791+
inc = float(1/pool)
792+
while t.is_alive():
793+
yield 0.0365
794+
cd.ids.pb.value += inc
795+
796+
cd.ids.pb.value = 1
771797
except Exception as e:
772798
print(str(e))
773799
pass
@@ -817,6 +843,7 @@ def on_tab_switch(self, instance_tabs, instance_tab, instance_tabs_label, tab_te
817843
pass
818844
def get_continent_coordinates(self, c):
819845
loc = self.MeileLand.ContinentLatLong[c]
846+
self.MeileMap.zoom = 4
820847
self.MeileMap.center_on(loc[0], loc[1])
821848

822849
def build_node_data(self, ncountry):
@@ -872,6 +899,28 @@ def switch_to_sub_window(self):
872899
self.carousel.add_widget(self.NodeWidget)
873900
self.carousel.load_slide(self.NodeWidget)
874901

902+
def close_sub_window(self):
903+
self.carousel.remove_widget(self.NodeWidget)
904+
self.carousel.load_previous()
905+
906+
def zoom_country_map(self):
907+
try:
908+
self.MeileMap.zoom = 7
909+
self.MeileMap.center_on(self.LatLong[0],self.LatLong[1])
910+
except Exception as e:
911+
print(str(e))
912+
pass
913+
914+
def set_conn_dialog(self, cd, title):
915+
self.dialog = None
916+
self.dialog = MDDialog(
917+
title=title,
918+
type="custom",
919+
content_cls=cd,
920+
md_bg_color=get_color_from_hex(MeileColors.DIALOG_BG_COLOR),
921+
)
922+
self.dialog.open()
923+
875924
def load_country_nodes(self, country, *kwargs):
876925
mw = Meile.app.root.get_screen(WindowNames.MAIN_WINDOW)
877926
NodeTree = NodeTreeData(Meile.app.root.get_screen(WindowNames.MAIN_WINDOW).NodeTree.NodeTree)

src/ui/widgets.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -936,8 +936,12 @@ def call_ip_get(self,result, moniker, *kwargs):
936936
if not mw.get_ip_address(None):
937937
self.remove_loading_widget()
938938
self.change_dns()
939+
mw.close_sub_window()
940+
mw.zoom_country_map()
939941
else:
940942
self.remove_loading_widget()
943+
mw.close_sub_window()
944+
mw.zoom_country_map()
941945

942946
@delayable
943947
def change_dns(self):

0 commit comments

Comments
 (0)