From 811d2b2c6b1c8d2bbbd7bbadbf57184b9ae6b0ad Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Mon, 20 Nov 2017 18:46:08 +0100 Subject: [PATCH] Testing part 5 --- .../Pages.Financial.designer.cs | 9 +++++++ Site/App_GlobalResources/Pages.Financial.resx | 4 +++ Site/Pages/v5/Financial/Donate.aspx | 25 ++++++++++++------- Site/Pages/v5/Financial/Donate.aspx.cs | 14 +++++++++-- .../v5/Financial/Donate.aspx.designer.cs | 13 ++-------- 5 files changed, 43 insertions(+), 22 deletions(-) diff --git a/Site/App_GlobalResources/Pages.Financial.designer.cs b/Site/App_GlobalResources/Pages.Financial.designer.cs index 0abdf7cf..55319e45 100644 --- a/Site/App_GlobalResources/Pages.Financial.designer.cs +++ b/Site/App_GlobalResources/Pages.Financial.designer.cs @@ -726,6 +726,15 @@ namespace Resources.Pages { } } + /// + /// Looks up a localized string similar to Funds Received ({0}). + /// + internal static string Donate_FundsReceivedLabel { + get { + return ResourceManager.GetString("Donate_FundsReceivedLabel", resourceCulture); + } + } + /// /// Looks up a localized string similar to Received {0} microcoins ("bits"). Thank you!. /// diff --git a/Site/App_GlobalResources/Pages.Financial.resx b/Site/App_GlobalResources/Pages.Financial.resx index 8ef2cff2..66da095d 100644 --- a/Site/App_GlobalResources/Pages.Financial.resx +++ b/Site/App_GlobalResources/Pages.Financial.resx @@ -642,4 +642,8 @@ Outbound Invoice #{0:N0} filed. + + Funds Received ({0}) + The {0} will be replaced with currency name. + \ No newline at end of file diff --git a/Site/Pages/v5/Financial/Donate.aspx b/Site/Pages/v5/Financial/Donate.aspx index b7416ca8..d6a0f209 100644 --- a/Site/Pages/v5/Financial/Donate.aspx +++ b/Site/Pages/v5/Financial/Donate.aspx @@ -21,13 +21,19 @@ }); socket.on(eventToListenTo, function(data) { - console.log(data); - console.log("txid: " + data.txid); var utxoCount = data.vout.length; for (var index = 0; index < utxoCount; index++) { - for (var address in data.vout[index]) { - console.log(" - address " + address + " gets " + data.vout[index][address]); + for (var outAddress in data.vout[index]) { + + if (outAddress == pageDonationAddress) { + + var donatedSatoshis = data.vout[index][outAddress]; + donatedFunds += (donatedSatoshis * conversionRateSatoshisToCents / 100.0); + odoDonatedCents.innerHTML = donatedFunds; // looks weird but $('#id') not used with odo + + // do an Ajax call as well here + } } } }); @@ -38,14 +44,13 @@ // This function is detected called by the Master Page; it is not // called from this page or anything visible here - // console.log("address: " + address); // console.log("hash: " + hash); // console.log("satoshis: " + satoshis); // console.log("cents: " + cents); // console.log("currencyCode: " + currencyCode); - if (address == addressUsed) { + if (address == pageDonationAddress) { // We have received a donation at this address donatedFunds += (cents / 100.0); @@ -74,8 +79,9 @@ var donatedFunds = 0.001; // the 0.1 cents are necessary for an odometer workaround - var addressUsed = ''; - var guid = ''; + var pageDonationAddress = SwarmopsJS.unescape(<%=this.BitcoinCashAddressUsed %>); + var guid = SwarmopsJS.unescape('<%=this.TransactionGuid%>'); + var conversionRateSatoshisToCents = <%= this.ConversionRateSatoshisToCents %>; var completed = false; @@ -85,7 +91,8 @@
-
0.001
Received funds (CUR)
+
0.001
+
diff --git a/Site/Pages/v5/Financial/Donate.aspx.cs b/Site/Pages/v5/Financial/Donate.aspx.cs index b7bb3cdb..bea33a39 100644 --- a/Site/Pages/v5/Financial/Donate.aspx.cs +++ b/Site/Pages/v5/Financial/Donate.aspx.cs @@ -54,10 +54,14 @@ namespace Swarmops.Frontend.Pages.v5.Financial HotBitcoinAddress address = HotBitcoinAddress.Create (this.CurrentOrganization, BitcoinChain.Cash, BitcoinUtility.BitcoinDonationsIndex, this.CurrentUser.Identity); - this.LiteralBitcoinAddress.Text = address.Address; string guid = Guid.NewGuid().ToString ("N"); GuidCache.Set (guid, address.Address); - this.LiteralGuid.Text = guid; + this.TransactionGuid = guid; + + // Calculate conversion rate (satoshi-cents to unit-cents, so we're good, even if the conversion rate + // is calculated on microbitcoin to whole units) + + this.ConversionRateSatoshisToCents = Currency.BitcoinCash.GetConversionRate(CurrentOrganization.Currency); // Add subscription to address /* --- RETIRED CODE -- THIS WAS NOT RELIABLE -- DONE CLIENT SIDE INSTEAD @@ -79,6 +83,8 @@ namespace Swarmops.Frontend.Pages.v5.Financial this.BoxTitle.Text = Resources.Pages.Financial.Donate_PageTitle; this.LabelExplainBitcoinDonation.Text = String.Format (Resources.Pages.Financial.Donate_Explain, CurrentOrganization.Name, address.Address); + this.LabelReceivedFunds.Text = String.Format(Resources.Pages.Financial.Donate_FundsReceivedLabel, + CurrentOrganization.Currency.DisplayCode); this.ImageBitcoinQr.ImageUrl = "https://chart.googleapis.com/chart?cht=qr&chs=400x400&chl=bitcoincash:" + @@ -87,6 +93,10 @@ namespace Swarmops.Frontend.Pages.v5.Financial CurrentOrganization.Name))); // URI scheme doesn't like &, = } + public string BitcoinCashAddressUsed { get; private set; } + public string TransactionGuid { get; private set; } + public double ConversionRateSatoshisToCents { get; private set; } + [WebMethod] static public AjaxCallResult ProcessTransactionReceived (string guid, string txHash) { diff --git a/Site/Pages/v5/Financial/Donate.aspx.designer.cs b/Site/Pages/v5/Financial/Donate.aspx.designer.cs index 4a4050b7..6f582f24 100644 --- a/Site/Pages/v5/Financial/Donate.aspx.designer.cs +++ b/Site/Pages/v5/Financial/Donate.aspx.designer.cs @@ -13,22 +13,13 @@ namespace Swarmops.Frontend.Pages.v5.Financial { public partial class Donate { /// - /// LiteralBitcoinAddress control. + /// LabelReceivedFunds control. /// /// /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// - protected global::System.Web.UI.WebControls.Literal LiteralBitcoinAddress; - - /// - /// LiteralGuid control. - /// - /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// - protected global::System.Web.UI.WebControls.Literal LiteralGuid; + protected global::System.Web.UI.WebControls.Label LabelReceivedFunds; /// /// PanelEnabled control.