Skip to content
Snippets Groups Projects
Commit 97e228e2 authored by inso's avatar inso
Browse files

Referentials added. Need to understand the "to zero" to validate it.

parent 10a31e15
No related branches found
No related tags found
No related merge requests found
...@@ -41,6 +41,7 @@ class Account(object): ...@@ -41,6 +41,7 @@ class Account(object):
self.dead_communities = dead_communities self.dead_communities = dead_communities
self.wallets = wallets self.wallets = wallets
self.contacts = contacts self.contacts = contacts
self.referential = 0
@classmethod @classmethod
def create(cls, name, communities, wallets, confpath): def create(cls, name, communities, wallets, confpath):
...@@ -103,8 +104,32 @@ class Account(object): ...@@ -103,8 +104,32 @@ class Account(object):
return community return community
def set_display_referential(self, index): def set_display_referential(self, index):
for w in self.wallets: self.referential = index
w.set_display_referential(index)
def units_to_ref(self):
def units(units, community):
return units
def relative(units, community):
ud = community.dividend()
relative_value = units / float(ud)
return relative_value
def units_to_zero(units, community):
monetary_mass = community.monetary_mass()
to_zero_value = units - (monetary_mass / 2)
return to_zero_value
def relative_to_zero(units, community):
monetary_mass = community.monetary_mass()
ud = community.dividend()
relative_mass = monetary_mass / float(ud)
relative_value = units / float(ud)
to_zero_value = relative_value - (relative_mass / 2)
return to_zero_value
referentials = [units, relative, units_to_zero, relative_to_zero]
return referentials[self.referential]
def set_walletpool_size(self, size, password): def set_walletpool_size(self, size, password):
logging.debug("Defining wallet pool size") logging.debug("Defining wallet pool size")
......
...@@ -131,6 +131,14 @@ class Community(object): ...@@ -131,6 +131,14 @@ class Community(object):
else: else:
return 1 return 1
def monetary_mass(self):
try:
block = self.request(bma.blockchain.Current)
return block['monetaryMass']
except ValueError as e:
if '404' in e:
return 0
def _peering_traversal(self, peer, found_peers, traversed_pubkeys): def _peering_traversal(self, peer, found_peers, traversed_pubkeys):
logging.debug("Read {0} peering".format(peer.pubkey)) logging.debug("Read {0} peering".format(peer.pubkey))
traversed_pubkeys.append(peer.pubkey) traversed_pubkeys.append(peer.pubkey)
......
...@@ -146,12 +146,6 @@ class Wallet(object): ...@@ -146,12 +146,6 @@ class Wallet(object):
self.pubkey = pubkey self.pubkey = pubkey
self.name = name self.name = name
self.caches = {} self.caches = {}
self.referentials = [self.value,
self.relative_value,
self.value_from_zero,
self.relative_from_zero
]
self.referential = self.referentials[0]
@classmethod @classmethod
def create(cls, walletid, salt, password, name): def create(cls, walletid, salt, password, name):
...@@ -210,21 +204,6 @@ class Wallet(object): ...@@ -210,21 +204,6 @@ class Wallet(object):
value += s.amount value += s.amount
return value return value
def relative_from_zero(self, community):
value = self.value(community)
ud = community.dividend()
relative_value = value / float(ud)
return relative_value
def value_from_zero(self, community):
value = 0
for s in self.sources(community):
value += s.amount
return value
def set_display_referential(self, index):
self.referential = self.referentials[index]
def tx_inputs(self, amount, community): def tx_inputs(self, amount, community):
value = 0 value = 0
inputs = [] inputs = []
......
...@@ -221,3 +221,10 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget): ...@@ -221,3 +221,10 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget):
if self.table_history.model(): if self.table_history.model():
self.table_history.model().set_period(ts_from, ts_to) self.table_history.model().set_period(ts_from, ts_to)
self.table_history.model().invalidate() self.table_history.model().invalidate()
def referential_changed(self):
if self.table_history.model():
self.table_history.model().dataChanged.emit(
QModelIndex(),
QModelIndex(),
[])
...@@ -109,6 +109,7 @@ class MainWindow(QMainWindow, Ui_MainWindow): ...@@ -109,6 +109,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
def referential_changed(self, index): def referential_changed(self, index):
if self.app.current_account: if self.app.current_account:
self.app.current_account.set_display_referential(index) self.app.current_account.set_display_referential(index)
self.currencies_tabwidget.currentWidget().referential_changed()
def action_change_account(self, account_name): def action_change_account(self, account_name):
self.busybar.show() self.busybar.show()
......
...@@ -89,7 +89,9 @@ class HistoryTableModel(QAbstractTableModel): ...@@ -89,7 +89,9 @@ class HistoryTableModel(QAbstractTableModel):
date_ts = self.community.get_block(tx[0]).mediantime date_ts = self.community.get_block(tx[0]).mediantime
date = QDateTime.fromTime_t(date_ts) date = QDateTime.fromTime_t(date_ts)
return (date.date(), sender, "", "{0}".format(amount), comment) amount_ref = self.account.units_to_ref()(amount, self.community)
return (date.date(), sender, "", "{0}".format(amount_ref), comment)
def data_sent(self, tx): def data_sent(self, tx):
amount = 0 amount = 0
...@@ -109,7 +111,9 @@ class HistoryTableModel(QAbstractTableModel): ...@@ -109,7 +111,9 @@ class HistoryTableModel(QAbstractTableModel):
date_ts = self.community.get_block(tx[0]).mediantime date_ts = self.community.get_block(tx[0]).mediantime
date = QDateTime.fromTime_t(date_ts) date = QDateTime.fromTime_t(date_ts)
return (date.date(), receiver, "-{0}".format(amount), "", comment) amount_ref = self.account.units_to_ref()(-amount, self.community)
return (date.date(), receiver, "{0}".format(amount_ref), "", comment)
def data(self, index, role): def data(self, index, role):
row = index.row() row = index.row()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment