From 26f0c488e502c991384cb2ec1637fa3eb96c9773 Mon Sep 17 00:00:00 2001 From: Kukks Date: Fri, 28 Dec 2018 23:12:16 +0100 Subject: [PATCH] hook up proper payments to events and super crazy ux shit --- BTCPayServer.Tests/docker-compose.yml | 18 +- BTCPayServer/BTCPayServer.csproj | 2 + BTCPayServer/Events/InvoiceEvent.cs | 2 + BTCPayServer/Hubs/CrowdfundHub.cs | 18 +- .../Payments/Bitcoin/NBXplorerListener.cs | 2 +- .../Payments/Lightning/LightningListener.cs | 2 +- .../AppsPublic/Crowdfund/VueCrowdfund.cshtml | 184 ++-- .../Views/AppsPublic/ViewCrowdfund.cshtml | 1 + BTCPayServer/bundleconfig.json | 1 + BTCPayServer/wwwroot/crowdfund/app.js | 25 +- .../wwwroot/crowdfund/services/audioplayer.js | 65 ++ .../wwwroot/crowdfund/services/fireworks.js | 231 ++++ .../wwwroot/crowdfund/services/listener.js | 4 +- .../wwwroot/crowdfund/styles/main.css | 6 + BTCPayServer/wwwroot/vendor/animejs/anime.js | 993 ++++++++++++++++++ 15 files changed, 1444 insertions(+), 110 deletions(-) create mode 100644 BTCPayServer/wwwroot/crowdfund/services/audioplayer.js create mode 100644 BTCPayServer/wwwroot/crowdfund/services/fireworks.js create mode 100644 BTCPayServer/wwwroot/vendor/animejs/anime.js diff --git a/BTCPayServer.Tests/docker-compose.yml b/BTCPayServer.Tests/docker-compose.yml index f76d5e023..da7035644 100644 --- a/BTCPayServer.Tests/docker-compose.yml +++ b/BTCPayServer.Tests/docker-compose.yml @@ -2,7 +2,7 @@ version: "3" # Run `docker-compose up dev` for bootstrapping your development environment # Doing so will expose NBXplorer, Bitcoind RPC and postgres port to the host so that tests can Run, -# The Visual Studio launch setting `Docker-Regtest` is configured to use this environment. +# The Visual Studio launch setting `Docker-testnet` is configured to use this environment. services: tests: @@ -76,7 +76,7 @@ services: expose: - "32838" environment: - NBXPLORER_NETWORK: regtest + NBXPLORER_NETWORK: testnet NBXPLORER_CHAINS: "btc,ltc" NBXPLORER_BTCRPCURL: http://bitcoind:43782/ NBXPLORER_BTCNODEENDPOINT: bitcoind:39388 @@ -98,7 +98,7 @@ services: restart: unless-stopped image: btcpayserver/bitcoin:0.17.0 environment: - BITCOIN_NETWORK: regtest + BITCOIN_NETWORK: testnet BITCOIN_EXTRA_ARGS: |- rpcuser=ceiwHEbqWI83 rpcpassword=DwubwWsoo3 @@ -127,7 +127,7 @@ services: LIGHTNINGD_OPT: | bitcoin-datadir=/etc/bitcoin bitcoin-rpcconnect=bitcoind - network=regtest + network=testnet bind-addr=0.0.0.0 announce-addr=customer_lightningd log-level=debug @@ -148,7 +148,7 @@ services: image: shesek/lightning-charge:0.4.6-standalone restart: unless-stopped environment: - NETWORK: regtest + NETWORK: testnet API_TOKEN: foiewnccewuify BITCOIND_RPCCONNECT: bitcoind volumes: @@ -174,7 +174,7 @@ services: bitcoin-rpcconnect=bitcoind bind-addr=0.0.0.0 announce-addr=merchant_lightningd - network=regtest + network=testnet log-level=debug dev-broadcast-interval=1000 ports: @@ -195,7 +195,7 @@ services: BITCOIN_EXTRA_ARGS: |- rpcuser=ceiwHEbqWI83 rpcpassword=DwubwWsoo3 - regtest=1 + testnet=1 rpcport=43782 port=39388 whitelist=0.0.0.0/0 @@ -226,7 +226,7 @@ services: restart: unless-stopped environment: LND_CHAIN: "btc" - LND_ENVIRONMENT: "regtest" + LND_ENVIRONMENT: "testnet" LND_EXPLORERURL: "http://nbxplorer:32838/" LND_EXTRA_ARGS: | restlisten=0.0.0.0:8080 @@ -256,7 +256,7 @@ services: restart: unless-stopped environment: LND_CHAIN: "btc" - LND_ENVIRONMENT: "regtest" + LND_ENVIRONMENT: "testnet" LND_EXPLORERURL: "http://nbxplorer:32838/" LND_EXTRA_ARGS: | restlisten=0.0.0.0:8080 diff --git a/BTCPayServer/BTCPayServer.csproj b/BTCPayServer/BTCPayServer.csproj index 304fc2429..a6b644661 100644 --- a/BTCPayServer/BTCPayServer.csproj +++ b/BTCPayServer/BTCPayServer.csproj @@ -124,6 +124,8 @@ + + diff --git a/BTCPayServer/Events/InvoiceEvent.cs b/BTCPayServer/Events/InvoiceEvent.cs index 616b5c404..88b3c26b5 100644 --- a/BTCPayServer/Events/InvoiceEvent.cs +++ b/BTCPayServer/Events/InvoiceEvent.cs @@ -31,6 +31,8 @@ namespace BTCPayServer.Events public int EventCode { get; set; } public string Name { get; set; } + public PaymentEntity Payment { get; set; } + public override string ToString() { return $"Invoice {Invoice.Id} new event: {Name} ({EventCode})"; diff --git a/BTCPayServer/Hubs/CrowdfundHub.cs b/BTCPayServer/Hubs/CrowdfundHub.cs index f4a6405a3..ee7dc46ee 100644 --- a/BTCPayServer/Hubs/CrowdfundHub.cs +++ b/BTCPayServer/Hubs/CrowdfundHub.cs @@ -7,6 +7,7 @@ using BTCPayServer.Controllers; using BTCPayServer.Data; using BTCPayServer.Events; using BTCPayServer.Models.AppViewModels; +using BTCPayServer.Payments; using BTCPayServer.Rating; using BTCPayServer.Services.Apps; using BTCPayServer.Services.Invoices; @@ -96,8 +97,8 @@ namespace BTCPayServer.Hubs var token = new CancellationTokenSource(); _CacheTokens.Add(key, token); entry.AddExpirationToken(new CancellationChangeToken(token.Token)); - entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(5); - + entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(1); + var app = await _AppsHelper.GetApp(appId, AppType.Crowdfund, true); var result = await GetInfo(app, _InvoiceRepository, _RateFetcher, _BtcPayNetworkProvider); @@ -131,7 +132,16 @@ namespace BTCPayServer.Hubs switch (invoiceEvent.Name) { case InvoiceEvent.ReceivedPayment: - _HubContext.Clients.Group(appId).SendCoreAsync("PaymentReceived", new object[]{ invoiceEvent.Invoice.CryptoInfo.First().Paid } ); + + _HubContext.Clients.Group(appId).SendCoreAsync("PaymentReceived", new object[] + { + invoiceEvent.Payment.GetCryptoPaymentData().GetValue(), + invoiceEvent.Payment.GetCryptoCode(), + Enum.GetName(typeof(PaymentTypes), + invoiceEvent.Payment.GetPaymentMethodId().PaymentType) + } ); + + InvalidateCacheForApp(appId); break; case InvoiceEvent.Completed: InvalidateCacheForApp(appId); @@ -145,7 +155,7 @@ namespace BTCPayServer.Hubs { _CacheTokens[appId].Cancel(); } - _HubContext.Clients.Group(appId).SendCoreAsync("InfoUpdated", new object[]{} ); + _HubContext.Clients.Group(appId).SendCoreAsync("InfoUpdated", Array.Empty() ); } private static async Task GetCurrentContributionAmount(InvoiceEntity[] invoices, string primaryCurrency, diff --git a/BTCPayServer/Payments/Bitcoin/NBXplorerListener.cs b/BTCPayServer/Payments/Bitcoin/NBXplorerListener.cs index ca0860629..a8c278146 100644 --- a/BTCPayServer/Payments/Bitcoin/NBXplorerListener.cs +++ b/BTCPayServer/Payments/Bitcoin/NBXplorerListener.cs @@ -373,7 +373,7 @@ namespace BTCPayServer.Payments.Bitcoin invoice.SetPaymentMethod(paymentMethod); } wallet.InvalidateCache(strategy); - _Aggregator.Publish(new InvoiceEvent(invoice.EntityToDTO(_NetworkProvider), 1002, "invoice_receivedPayment")); + _Aggregator.Publish(new InvoiceEvent(invoice.EntityToDTO(_NetworkProvider), 1002, InvoiceEvent.ReceivedPayment){Payment = payment}); return invoice; } public Task StopAsync(CancellationToken cancellationToken) diff --git a/BTCPayServer/Payments/Lightning/LightningListener.cs b/BTCPayServer/Payments/Lightning/LightningListener.cs index b800f5d96..0fb0d9526 100644 --- a/BTCPayServer/Payments/Lightning/LightningListener.cs +++ b/BTCPayServer/Payments/Lightning/LightningListener.cs @@ -197,7 +197,7 @@ namespace BTCPayServer.Payments.Lightning { var invoice = await _InvoiceRepository.GetInvoice(listenedInvoice.InvoiceId); if (invoice != null) - _Aggregator.Publish(new InvoiceEvent(invoice.EntityToDTO(_NetworkProvider), 1002, "invoice_receivedPayment")); + _Aggregator.Publish(new InvoiceEvent(invoice.EntityToDTO(_NetworkProvider), 1002, InvoiceEvent.ReceivedPayment){Payment = payment}); } } diff --git a/BTCPayServer/Views/AppsPublic/Crowdfund/VueCrowdfund.cshtml b/BTCPayServer/Views/AppsPublic/Crowdfund/VueCrowdfund.cshtml index 9853832d5..cb9fb14c5 100644 --- a/BTCPayServer/Views/AppsPublic/Crowdfund/VueCrowdfund.cshtml +++ b/BTCPayServer/Views/AppsPublic/Crowdfund/VueCrowdfund.cshtml @@ -2,99 +2,107 @@
+
+

+ {{srvModel.title}} + + Starts {{startDateRelativeTime}} + + + Ends {{endDateRelativeTime}} + + + Currently Active! + +

+ + + {{srvModel.targetAmount}} {{targetCurrency}} + + Hardcap Goal ? + Softcap Goal ? + + + +
+
+
+ +
+
+ +
+
+ +
-
+ +
- - {{srvModel.title}} - - Starts {{startDateRelativeTime}} - - - Ends {{endDateRelativeTime}} - - - Currently Active! - - - - + +

{{srvModel.tagline}}

-
+
- - + + +
-
-
    -
  • -
    -
    - {{srvModel.info.currentAmount + srvModel.info.currentPendingAmount }} {{targetCurrency}} - raised by {{srvModel.info.totalContributors}} contributors -
    -
    - -
    -
    - -
    -
    - -
    -
    - -
  • -
  • - {{srvModel.targetAmount}} {{targetCurrency}} - - Hardcap Goal - No contributions allowed after the goal has been reached - Softcap Goal - Contributions allowed after goal is reached - - - -
  • -
  • - - - -
  • - - -
-

@@ -109,11 +117,9 @@
- -
- +