From efbfee2aa5304a62ee2bf9eb059e457a9c162786 Mon Sep 17 00:00:00 2001
From: Inso <insomniak.fr@gmail.com>
Date: Thu, 29 May 2014 12:45:03 +0200
Subject: [PATCH] Quantitative and relative display

---
 res/ui/transferDialog.ui                      | 20 +++++++++----------
 src/cutecoin/gui/processConfigureAccount.py   |  1 -
 src/cutecoin/gui/processConfigureCommunity.py |  3 ---
 src/cutecoin/gui/processCreateWallet.py       |  2 --
 src/cutecoin/gui/transferMoneyDialog.py       | 15 +++++++++-----
 src/cutecoin/models/coin/__init__.py          |  2 +-
 src/cutecoin/models/wallet/__init__.py        | 17 ++++++++++++----
 7 files changed, 34 insertions(+), 26 deletions(-)

diff --git a/res/ui/transferDialog.ui b/res/ui/transferDialog.ui
index 2ac25e29..42436b5f 100644
--- a/res/ui/transferDialog.ui
+++ b/res/ui/transferDialog.ui
@@ -7,7 +7,7 @@
     <x>0</x>
     <y>0</y>
     <width>400</width>
-    <height>489</height>
+    <height>486</height>
    </rect>
   </property>
   <property name="windowTitle">
@@ -69,13 +69,6 @@
           </property>
          </widget>
         </item>
-        <item>
-         <widget class="QPushButton" name="button_get_trusts">
-          <property name="text">
-           <string>Get trusts nodes</string>
-          </property>
-         </widget>
-        </item>
        </layout>
       </item>
      </layout>
@@ -103,7 +96,14 @@
          </widget>
         </item>
         <item>
-         <widget class="QComboBox" name="combo_wallets"/>
+         <widget class="QComboBox" name="combo_wallets">
+          <property name="minimumSize">
+           <size>
+            <width>0</width>
+            <height>30</height>
+           </size>
+          </property>
+         </widget>
         </item>
        </layout>
       </item>
@@ -199,7 +199,7 @@
            <item>
             <widget class="QLabel" name="label_total">
              <property name="text">
-              <string>Total money transfered : 0 </string>
+              <string/>
              </property>
             </widget>
            </item>
diff --git a/src/cutecoin/gui/processConfigureAccount.py b/src/cutecoin/gui/processConfigureAccount.py
index 6e1cbeb0..a29982d1 100644
--- a/src/cutecoin/gui/processConfigureAccount.py
+++ b/src/cutecoin/gui/processConfigureAccount.py
@@ -86,7 +86,6 @@ class StepPageCommunities(Step):
         account = self.config_dialog.account
         self.config_dialog.community = account.communities.add_community(
             default_node)
-        #TODO: Get existing Wallet from ucoin node
         account.wallets.add_wallet(account.keyid,
                                    self.config_dialog.community)
         self.config_dialog.refresh()
diff --git a/src/cutecoin/gui/processConfigureCommunity.py b/src/cutecoin/gui/processConfigureCommunity.py
index 9ea87a89..fd55ab0e 100644
--- a/src/cutecoin/gui/processConfigureCommunity.py
+++ b/src/cutecoin/gui/processConfigureCommunity.py
@@ -60,7 +60,6 @@ class StepPageAddNodes(Step):
     def __init__(self, config_dialog):
         super().__init__(config_dialog)
 
-    #TODO: Check page validity
     def is_valid(self):
         return True
 
@@ -88,7 +87,6 @@ class StepPageSetWallets(Step):
     def __init__(self, config_dialog):
         super().__init__(config_dialog)
 
-    #TODO: Check page validity
     def is_valid(self):
         return True
 
@@ -221,7 +219,6 @@ class ProcessConfigureCommunity(QDialog, Ui_CommunityConfigurationDialog):
             QMessageBox.critical(self, "Pubkey publishing error",
                               result)
 
-        #TODO: Push wht only if changed
         for wallet in self.account.wallets:
             if self.wallet_edit[wallet.name]:
                 result = wallet.push_wht(self.account.gpg)
diff --git a/src/cutecoin/gui/processCreateWallet.py b/src/cutecoin/gui/processCreateWallet.py
index 9d35e98e..23d2f68d 100644
--- a/src/cutecoin/gui/processCreateWallet.py
+++ b/src/cutecoin/gui/processCreateWallet.py
@@ -52,7 +52,6 @@ class StepPageKey(Step):
     def __init__(self, config_dialog):
         super().__init__(config_dialog)
 
-    #TODO: Check page validity
     def is_valid(self):
         return self.config_dialog.keyid != ''
 
@@ -70,7 +69,6 @@ class StepPageNode(Step):
     def __init__(self, config_dialog):
         super().__init__(config_dialog)
 
-    #TODO: Check page validity
     def is_valid(self):
         address = self.config_dialog.edit_address.text()
         port = self.config_dialog.spinbox_port.value()
diff --git a/src/cutecoin/gui/transferMoneyDialog.py b/src/cutecoin/gui/transferMoneyDialog.py
index 173e375d..1ba5dba3 100644
--- a/src/cutecoin/gui/transferMoneyDialog.py
+++ b/src/cutecoin/gui/transferMoneyDialog.py
@@ -42,16 +42,22 @@ class TransferMoneyDialog(QDialog, Ui_TransferMoneyDialog):
         for select in selection:
             coins = self.list_coins_sent.model().remove_coins(select, 1)
             self.list_wallet.model().add_coins(coins)
-        self.label_total.setText("Total : %d" %
-                                 self.list_coins_sent.model().total())
+        self.refresh_total()
 
     def add_coins_to_transfer(self):
         selection = self.list_wallet.selectedIndexes()
         for select in selection:
             coins = self.list_wallet.model().remove_coins(select, 1)
             self.list_coins_sent.model().add_coins(coins)
-        self.label_total.setText("Total : %d"
-                                 % self.list_coins_sent.model().total())
+        self.refresh_total()
+
+    def refresh_total(self):
+        dividend = self.wallet.get_amendment(None)['dividend']
+        total = self.list_coins_sent.model().total()
+        relative_total = total / int(dividend)
+        self.label_total.setText("Total : \n \
+%d %s \n \
+%.2f UD" % (total, self.wallet.currency, relative_total))
 
     def accept(self):
         sent_coins = self.list_coins_sent.model().to_list()
@@ -64,7 +70,6 @@ class TransferMoneyDialog(QDialog, Ui_TransferMoneyDialog):
                 self.combo_contact.currentIndex()]
 
         message = self.edit_message.text()
-        # TODO: All nodes trusted by recipient
         error = self.wallet.transfer_coins(recipient, sent_coins, message)
         if error:
             QErrorMessage(self).showMessage("Cannot transfer coins " + error)
diff --git a/src/cutecoin/models/coin/__init__.py b/src/cutecoin/models/coin/__init__.py
index 5c31cd02..614010e2 100644
--- a/src/cutecoin/models/coin/__init__.py
+++ b/src/cutecoin/models/coin/__init__.py
@@ -38,7 +38,7 @@ class Coin(object):
     def value(self, wallet):
         amendment = wallet.get_amendment(self.am_number)
         if 'CoinAlgo' in amendment:
-            coin_algo_name = self.amendment['CoinAlgo']
+            coin_algo_name = amendment['CoinAlgo']
         else:
             coin_algo_name = 'Base2Draft'
 
diff --git a/src/cutecoin/models/wallet/__init__.py b/src/cutecoin/models/wallet/__init__.py
index 1af9a279..16469333 100644
--- a/src/cutecoin/models/wallet/__init__.py
+++ b/src/cutecoin/models/wallet/__init__.py
@@ -11,6 +11,7 @@ import json
 import time
 import hashlib
 import importlib
+from decimal import Decimal
 from cutecoin.models.coin import Coin
 from cutecoin.models.coin import algorithms
 from cutecoin.models.node import Node
@@ -60,7 +61,12 @@ class Wallet(object):
     def __eq__(self, other):
         return (self.keyid == other.keyid)
 
-    #TODO: Relative and quantitative value
+    def relative_value(self):
+        value = self.value()
+        amendment = self.get_amendment(None)
+        relative_value = value / float(amendment['dividend'])
+        return relative_value
+
     def value(self):
         value = 0
         for coin in self.coins:
@@ -295,7 +301,8 @@ Hosters:
         else:
             amendment_req = ucoin.hdc.amendments.Promoted(am_number)
             new_am = self.request(amendment_req)
-            self.amendments_cache[am_number] = new_am
+            number = int(new_am['number'])
+            self.amendments_cache[number] = new_am
             return new_am
 
     def fingerprint(self, gpg):
@@ -308,8 +315,10 @@ Hosters:
         return ""
 
     def get_text(self):
-        return self.name + " : " + \
-            str(self.value()) + " " + self.currency
+        return "%s : \n \
+%d %s \n \
+%.2f UD" % (self.name, self.value(), self.currency,
+                          self.relative_value())
 
     def jsonify_coins_list(self):
         data = []
-- 
GitLab