Straw-man for dev process
[novacoin.git] / ui.cpp
diff --git a/ui.cpp b/ui.cpp
index d72e1a0..1cb922f 100644 (file)
--- a/ui.cpp
+++ b/ui.cpp
@@ -196,7 +196,7 @@ int ThreadSafeMessageBox(const string& message, const string& caption, int style
 
 bool ThreadSafeAskFee(int64 nFeeRequired, const string& strCaption, wxWindow* parent)
 {
-    if (nFeeRequired < CENT || fDaemon)
+    if (nFeeRequired < CENT || nFeeRequired <= nTransactionFee || fDaemon)
         return true;
     string strMessage = strprintf(
         _("This transaction is over the size limit.  You can still send it for a fee of %s, "
@@ -391,7 +391,7 @@ void CMainFrame::OnIconize(wxIconizeEvent& event)
     if (!event.Iconized())
         fClosedToTray = false;
 #if defined(__WXGTK__) || defined(__WXMAC_OSX__)
-    if (mapArgs.count("-minimizetotray")) {
+    if (GetBoolArg("-minimizetotray")) {
 #endif
     // The tray icon sometimes disappears on ubuntu karmic
     // Hiding the taskbar button doesn't work cleanly on ubuntu lucid
@@ -697,16 +697,13 @@ bool CMainFrame::InsertTransaction(const CWalletTx& wtx, bool fNew, int nIndex)
         if (fAllFromMe && fAllToMe)
         {
             // Payment to self
-            int64 nValue = wtx.vout[0].nValue;
+            int64 nChange = wtx.GetChange();
             InsertLine(fNew, nIndex, hash, strSort, colour,
                        strStatus,
                        nTime ? DateTimeStr(nTime) : "",
                        _("Payment to yourself"),
-                       "",
-                       "");
-            /// issue: can't tell which is the payment and which is the change anymore
-            //           FormatMoney(nNet - nValue, true),
-            //           FormatMoney(nValue, true));
+                       FormatMoney(-(nDebit - nChange), true),
+                       FormatMoney(nCredit - nChange, true));
         }
         else if (fAllFromMe)
         {
@@ -749,6 +746,12 @@ bool CMainFrame::InsertTransaction(const CWalletTx& wtx, bool fNew, int nIndex)
                         strDescription += " - ";
                     strDescription += mapValue["message"];
                 }
+                else if (!mapValue["comment"].empty())
+                {
+                    if (!strDescription.empty())
+                        strDescription += " - ";
+                    strDescription += mapValue["comment"];
+                }
 
                 int64 nValue = txout.nValue;
                 if (nTxFee > 0)
@@ -763,6 +766,7 @@ bool CMainFrame::InsertTransaction(const CWalletTx& wtx, bool fNew, int nIndex)
                            SingleLine(strDescription),
                            FormatMoney(-nValue, true),
                            "");
+                nIndex = -1;
                 wtx.nLinesDisplayed++;
             }
         }
@@ -1170,7 +1174,7 @@ void CMainFrame::OnButtonNew(wxCommandEvent& event)
     string strName = dialog.GetValue();
 
     // Generate new key
-    string strAddress = PubKeyToAddress(CWalletDB().GetKeyFromKeyPool());
+    string strAddress = PubKeyToAddress(GetKeyFromKeyPool());
 
     // Save
     SetAddressBookName(strAddress, strName);
@@ -1375,10 +1379,10 @@ CTxDetailsDialog::CTxDetailsDialog(wxWindow* parent, CWalletTx wtx) : CTxDetails
                 if (fAllToMe)
                 {
                     // Payment to self
-                    /// issue: can't tell which is the payment and which is the change anymore
-                    //int64 nValue = wtx.vout[0].nValue;
-                    //strHTML += _("<b>Debit:</b> ") + FormatMoney(-nValue) + "<br>";
-                    //strHTML += _("<b>Credit:</b> ") + FormatMoney(nValue) + "<br>";
+                    int64 nChange = wtx.GetChange();
+                    int64 nValue = nCredit - nChange;
+                    strHTML += _("<b>Debit:</b> ") + FormatMoney(-nValue) + "<br>";
+                    strHTML += _("<b>Credit:</b> ") + FormatMoney(nValue) + "<br>";
                 }
 
                 int64 nTxFee = nDebit - wtx.GetValueOut();
@@ -1407,6 +1411,8 @@ CTxDetailsDialog::CTxDetailsDialog(wxWindow* parent, CWalletTx wtx) : CTxDetails
         //
         if (!wtx.mapValue["message"].empty())
             strHTML += string() + "<br><b>" + _("Message:") + "</b><br>" + HtmlEscape(wtx.mapValue["message"], true) + "<br>";
+        if (!wtx.mapValue["comment"].empty())
+            strHTML += string() + "<br><b>" + _("Comment:") + "</b><br>" + HtmlEscape(wtx.mapValue["comment"], true) + "<br>";
 
         if (wtx.IsCoinBase())
             strHTML += string() + "<br>" + _("Generated coins must wait 120 blocks before they can be spent.  When you generated this block, it was broadcast to the network to be added to the block chain.  If it fails to get into the chain, it will change to \"not accepted\" and not be spendable.  This may occasionally happen if another node generates a block within a few seconds of yours.") + "<br>";
@@ -1630,9 +1636,12 @@ COptionsDialog::COptionsDialog(wxWindow* parent) : COptionsDialogBase(parent)
     //m_listBox->Append(_("Test 2"));
     m_listBox->SetSelection(0);
     SelectPage(0);
+#ifndef __WXMSW__
+    SetSize(1.0 * GetSize().GetWidth(), 1.2 * GetSize().GetHeight());
+#endif
 #if defined(__WXGTK__) || defined(__WXMAC_OSX__)
     m_checkBoxStartOnSystemStartup->SetLabel(_("&Start Bitcoin on window system startup"));
-    if (!mapArgs.count("-minimizetotray"))
+    if (!GetBoolArg("-minimizetotray"))
     {
         // Minimize to tray is just too buggy on Linux
         fMinimizeToTray = false;
@@ -1795,7 +1804,7 @@ void COptionsDialog::OnButtonApply(wxCommandEvent& event)
 
 CAboutDialog::CAboutDialog(wxWindow* parent) : CAboutDialogBase(parent)
 {
-    m_staticTextVersion->SetLabel(strprintf(_("version %s%s beta"), FormatVersion(VERSION).c_str(), pszSubVer));
+    m_staticTextVersion->SetLabel(strprintf(_("version %s%s BETA"), FormatVersion(VERSION).c_str(), pszSubVer));
 
     // Change (c) into UTF-8 or ANSI copyright symbol
     wxString str = m_staticTextMain->GetLabel();
@@ -1928,69 +1937,78 @@ void CSendDialog::OnButtonPaste(wxCommandEvent& event)
 
 void CSendDialog::OnButtonSend(wxCommandEvent& event)
 {
-    CWalletTx wtx;
-    string strAddress = (string)m_textCtrlAddress->GetValue();
-
-    // Parse amount
-    int64 nValue = 0;
-    if (!ParseMoney(m_textCtrlAmount->GetValue(), nValue) || nValue <= 0)
-    {
-        wxMessageBox(_("Error in amount  "), _("Send Coins"));
-        return;
-    }
-    if (nValue > GetBalance())
+    static CCriticalSection cs_sendlock;
+    TRY_CRITICAL_BLOCK(cs_sendlock)
     {
-        wxMessageBox(_("Amount exceeds your balance  "), _("Send Coins"));
-        return;
-    }
-    if (nValue + nTransactionFee > GetBalance())
-    {
-        wxMessageBox(string(_("Total exceeds your balance when the ")) + FormatMoney(nTransactionFee) + _(" transaction fee is included  "), _("Send Coins"));
-        return;
-    }
+        CWalletTx wtx;
+        string strAddress = (string)m_textCtrlAddress->GetValue();
 
-    // Parse bitcoin address
-    uint160 hash160;
-    bool fBitcoinAddress = AddressToHash160(strAddress, hash160);
+        // Parse amount
+        int64 nValue = 0;
+        if (!ParseMoney(m_textCtrlAmount->GetValue(), nValue) || nValue <= 0)
+        {
+            wxMessageBox(_("Error in amount  "), _("Send Coins"));
+            return;
+        }
+        if (nValue > GetBalance())
+        {
+            wxMessageBox(_("Amount exceeds your balance  "), _("Send Coins"));
+            return;
+        }
+        if (nValue + nTransactionFee > GetBalance())
+        {
+            wxMessageBox(string(_("Total exceeds your balance when the ")) + FormatMoney(nTransactionFee) + _(" transaction fee is included  "), _("Send Coins"));
+            return;
+        }
 
-    if (fBitcoinAddress)
-    {
-        // Send to bitcoin address
-        CScript scriptPubKey;
-        scriptPubKey << OP_DUP << OP_HASH160 << hash160 << OP_EQUALVERIFY << OP_CHECKSIG;
+        // Parse bitcoin address
+        uint160 hash160;
+        bool fBitcoinAddress = AddressToHash160(strAddress, hash160);
 
-        string strError = SendMoney(scriptPubKey, nValue, wtx, true);
-        if (strError == "")
-            wxMessageBox(_("Payment sent  "), _("Sending..."));
-        else if (strError != "ABORTED")
-            wxMessageBox(strError + "  ", _("Sending..."));
-    }
-    else
-    {
-        // Parse IP address
-        CAddress addr(strAddress);
-        if (!addr.IsValid())
+        if (fBitcoinAddress)
         {
-            wxMessageBox(_("Invalid address  "), _("Send Coins"));
-            return;
+            // Send to bitcoin address
+            CScript scriptPubKey;
+            scriptPubKey << OP_DUP << OP_HASH160 << hash160 << OP_EQUALVERIFY << OP_CHECKSIG;
+
+            string strError = SendMoney(scriptPubKey, nValue, wtx, true);
+            if (strError == "")
+                wxMessageBox(_("Payment sent  "), _("Sending..."));
+            else if (strError == "ABORTED")
+                return; // leave send dialog open
+            else
+            {
+                wxMessageBox(strError + "  ", _("Sending..."));
+                EndModal(false);
+            }
         }
+        else
+        {
+            // Parse IP address
+            CAddress addr(strAddress);
+            if (!addr.IsValid())
+            {
+                wxMessageBox(_("Invalid address  "), _("Send Coins"));
+                return;
+            }
 
-        // Message
-        wtx.mapValue["to"] = strAddress;
-        wtx.mapValue["from"] = m_textCtrlFrom->GetValue();
-        wtx.mapValue["message"] = m_textCtrlMessage->GetValue();
+            // Message
+            wtx.mapValue["to"] = strAddress;
+            wtx.mapValue["from"] = m_textCtrlFrom->GetValue();
+            wtx.mapValue["message"] = m_textCtrlMessage->GetValue();
 
-        // Send to IP address
-        CSendingDialog* pdialog = new CSendingDialog(this, addr, nValue, wtx);
-        if (!pdialog->ShowModal())
-            return;
-    }
+            // Send to IP address
+            CSendingDialog* pdialog = new CSendingDialog(this, addr, nValue, wtx);
+            if (!pdialog->ShowModal())
+                return;
+        }
 
-    CRITICAL_BLOCK(cs_mapAddressBook)
-        if (!mapAddressBook.count(strAddress))
-            SetAddressBookName(strAddress, "");
+        CRITICAL_BLOCK(cs_mapAddressBook)
+            if (!mapAddressBook.count(strAddress))
+                SetAddressBookName(strAddress, "");
 
-    EndModal(true);
+        EndModal(true);
+    }
 }
 
 void CSendDialog::OnButtonCancel(wxCommandEvent& event)
@@ -2565,7 +2583,7 @@ void CAddressBookDialog::OnButtonNew(wxCommandEvent& event)
         strName = dialog.GetValue();
 
         // Generate new key
-        strAddress = PubKeyToAddress(CWalletDB().GetKeyFromKeyPool());
+        strAddress = PubKeyToAddress(GetKeyFromKeyPool());
     }
 
     // Add to list and select it
@@ -2731,10 +2749,10 @@ wxMenu* CMyTaskBarIcon::CreatePopupMenu()
 void CreateMainWindow()
 {
     pframeMain = new CMainFrame(NULL);
-    if (mapArgs.count("-min"))
+    if (GetBoolArg("-min"))
         pframeMain->Iconize(true);
 #if defined(__WXGTK__) || defined(__WXMAC_OSX__)
-    if (!mapArgs.count("-minimizetotray"))
+    if (!GetBoolArg("-minimizetotray"))
         fMinimizeToTray = false;
 #endif
     pframeMain->Show(true);  // have to show first to get taskbar button to hide