Skip to content

Commit

Permalink
gui: add unpaid mining balance indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
YoRyan committed Oct 13, 2019
1 parent 78263b5 commit 9729a20
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 18 deletions.
32 changes: 16 additions & 16 deletions nuxhash/gui/mining.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __init__(self, parent, *args, devices=[], **kwargs):

pub.subscribe(self._OnClose, 'app.close')

pub.subscribe(self._OnNewBalance, 'nicehash.balance')
pub.subscribe(self._OnNewUnpaidBalance, 'nicehash.unpaid')
pub.subscribe(self._OnMiningStatus, 'mining.status')

sizer = wx.BoxSizer(orient=wx.VERTICAL)
Expand Down Expand Up @@ -78,11 +78,11 @@ def __init__(self, parent, *args, devices=[], **kwargs):
self._Revenue.SetFont(self.GetFont().Bold())
balances.Add(self._Revenue, wx.SizerFlags().Expand())

balances.Add(wx.StaticText(self, label='Address balance'))
self._Balance = wx.StaticText(
balances.Add(wx.StaticText(self, label='Unpaid mining balance'))
self._Unpaid = wx.StaticText(
self, style=wx.ALIGN_RIGHT|wx.ST_NO_AUTORESIZE)
self._Balance.SetFont(self.GetFont().Bold())
balances.Add(self._Balance, wx.SizerFlags().Expand())
self._Unpaid.SetFont(self.GetFont().Bold())
balances.Add(self._Unpaid, wx.SizerFlags().Expand())

bottomSizer.AddSpacer(main.PADDING_PX)

Expand All @@ -95,7 +95,7 @@ def __init__(self, parent, *args, devices=[], **kwargs):
def _OnSettings(self, settings):
if settings != self._Settings:
self._Settings = settings
self._UpdateBalance()
self._UpdateBalances()
self._UpdateMining()

def _OnBenchmarks(self, benchmarks):
Expand Down Expand Up @@ -131,18 +131,18 @@ def _OnClose(self):
self._Thread.stop()

def _OnBalanceTimer(self, event):
self._UpdateBalance()
self._UpdateBalances()

def _UpdateBalance(self):
def _UpdateBalances(self):
address = self._Settings['nicehash']['wallet']
if check_bc(address):
def request(address, target):
balance = unpaid_balance(address)
main.sendMessage(target, 'nicehash.balance', balance=balance)
thread = threading.Thread(target=request, args=(address, self))
def do_requests(address, target):
unpaid = unpaid_balance(address)
main.sendMessage(target, 'nicehash.unpaid', balance=unpaid)
thread = threading.Thread(target=do_requests, args=(address, self))
thread.start()
else:
pub.sendMessage('nicehash.balance', balance=None)
pub.sendMessage('nicehash.unpaid', balance=None)

def OnStartStop(self, event):
if not self._Thread:
Expand All @@ -166,12 +166,12 @@ def _StopMining(self):
self._Thread.stop()
self._Thread = None

def _OnNewBalance(self, balance):
def _OnNewUnpaidBalance(self, balance):
if balance is None:
self._Balance.SetLabel('')
self._Unpaid.SetLabel('')
else:
unit = self._Settings['gui']['units']
self._Balance.SetLabel(utils.format_balance(balance, unit))
self._Unpaid.SetLabel(utils.format_balance(balance, unit))

def _OnMiningStatus(self, speeds, revenue, devices):
totalRevenue = sum(revenue.values())
Expand Down
7 changes: 5 additions & 2 deletions nuxhash/nicehash.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ def stratums(nx_settings):
return {algorithm: f'{algorithm}.{region}.nicehash.com:{port}'
for algorithm, port in ports.items()}

def unpaid_balance(nx_settings, address):
return None
def unpaid_balance(address):
api = nh.public_api(HOST)
response = api.request(
'GET', f'/main/api/v2/mining/external/{address}/rigs/', '', None)
return float(response['unpaidAmount'])

9 changes: 9 additions & 0 deletions tests/test_nicehash.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import nuxhash.nicehash as nh
from nuxhash.settings import DEFAULT_SETTINGS
from nuxhash.daemon import DONATE_ADDRESS


class TestNHMultialgo(TestCase):
Expand All @@ -18,6 +19,14 @@ def test_stratum(self):
stratums = nh.stratums(self.settings)
self.assertIn('cryptonight.eu.nicehash.com', stratums['cryptonight'])


class TestNHBalances(TestCase):

def test_unpaid_balance(self):
balance = nh.unpaid_balance(DONATE_ADDRESS)
self.assertGreaterEqual(balance, 0.0)


if __name__ == '__main__':
main()

0 comments on commit 9729a20

Please sign in to comment.