diff --git a/BTCPayServer/Hubs/CrowdfundHub.cs b/BTCPayServer/Hubs/CrowdfundHub.cs
index 23be12ddb..ef265fbf9 100644
--- a/BTCPayServer/Hubs/CrowdfundHub.cs
+++ b/BTCPayServer/Hubs/CrowdfundHub.cs
@@ -38,10 +38,6 @@ namespace BTCPayServer.Hubs
await Groups.AddToGroupAsync(Context.ConnectionId, appId);
}
- public async Task PushUpdatedCrowdfundInfo()
- {
-
- }
public async Task CreateInvoice(ContributeToCrowdfund model)
{
@@ -54,11 +50,6 @@ namespace BTCPayServer.Hubs
}
}
-
- public async Task PaymentReceived()
- {
-
- }
}
public class CrowdfundHubStreamer
@@ -134,7 +125,7 @@ namespace BTCPayServer.Hubs
var appId = invoiceEvent.Invoice.OrderId.Replace(CrowdfundInvoiceOrderIdPrefix, "", StringComparison.InvariantCultureIgnoreCase);
if (invoiceEvent.Name == InvoiceEvent.ReceivedPayment)
{
- _HubContext.Clients.Group(appId).SendCoreAsync(nameof(CrowdfundHub.PaymentReceived), new object[]{ invoiceEvent.Invoice.AmountPaid } );
+ _HubContext.Clients.Group(appId).SendCoreAsync("PaymentReceived", new object[]{ invoiceEvent.Invoice.AmountPaid } );
}
}
diff --git a/BTCPayServer/Views/AppsPublic/Crowdfund/VueCrowdfund.cshtml b/BTCPayServer/Views/AppsPublic/Crowdfund/VueCrowdfund.cshtml
index 270c3ecd3..4062e4cf8 100644
--- a/BTCPayServer/Views/AppsPublic/Crowdfund/VueCrowdfund.cshtml
+++ b/BTCPayServer/Views/AppsPublic/Crowdfund/VueCrowdfund.cshtml
@@ -23,8 +23,14 @@
+ -
+ {{started}} {{ended}}
+
+ -
+ Starts {{startDate}}
+
-
- Ends {{srvModel.endDate}}
+ Ends {{endDate}}
No specific end date
-
@@ -55,8 +61,7 @@
-
{{srvModel.info.daysLeft}}
- Days left
+ Ends {{endDateRelativeTime}}
diff --git a/BTCPayServer/wwwroot/crowdfund/app.js b/BTCPayServer/wwwroot/crowdfund/app.js
index 1df250cc0..4b440d632 100644
--- a/BTCPayServer/wwwroot/crowdfund/app.js
+++ b/BTCPayServer/wwwroot/crowdfund/app.js
@@ -1,17 +1,61 @@
var app = null;
var eventAggregator = new Vue();
window.onload = function (ev) {
-
-
app = new Vue({
el: '#app',
- data: function () {
+ data: function(){
return {
- srvModel: window.srvModel
+ srvModel: window.srvModel,
+ connectionStatus: "",
+ endDate: "",
+ startDate: "",
+ startDateRelativeTime: "",
+ endDateRelativeTime: "",
+ started: false,
+ ended: false
+ }
+ },
+ computed: {},
+ methods: {
+ updateComputed: function () {
+ if (this.srvModel.endDate) {
+ var endDateM = moment(this.srvModel.endDate);
+ this.endDate = endDateM.format('MMMM Do YYYY');
+ this.endDateRelativeTime = endDateM.fromNow();
+ this.ended = endDateM.isBefore(moment());
+ }else{
+ this.ended = true;
+ }
+
+ if (this.srvModel.startDate) {
+ var startDateM = moment(this.srvModel.startDate);
+ this.startDate = moment(startDateM).format('MMMM Do YYYY');
+ this.startDateRelativeTime = moment(startDateM).fromNow();
+ this.started = startDateM.isBefore(moment());
+ }else{
+ this.started = true;
+ }
+ setTimeout(this.updateComputed, 1000);
}
},
mounted: function () {
hubListener.connect();
+ eventAggregator.$on("invoice-created", function (invoiceId) {
+ btcpay.showInvoice(invoiceId);
+ });
+ eventAggregator.$on("info-updated", function (model) {
+ this.srvModel = model;
+ });
+ eventAggregator.$on("connection-pending", function () {
+ this.connectionStatus = "pending";
+ });
+ eventAggregator.$on("connection-failed", function () {
+ this.connectionStatus = "failed";
+ });
+ eventAggregator.$on("connection-lost", function () {
+ this.connectionStatus = "connection lost";
+ });
+ this.updateComputed();
}
});
};
diff --git a/BTCPayServer/wwwroot/crowdfund/services/listener.js b/BTCPayServer/wwwroot/crowdfund/services/listener.js
index b15015a51..77cd8ea0a 100644
--- a/BTCPayServer/wwwroot/crowdfund/services/listener.js
+++ b/BTCPayServer/wwwroot/crowdfund/services/listener.js
@@ -8,10 +8,15 @@ var hubListener = function(){
console.error("Connection was closed. Attempting reconnect in 2s");
setTimeout(connect, 2000);
});
-
+ connection.on("PaymentReceived", function(amount){
+ eventAggregator.$emit("payment-received", amount);
+ });
connection.on("InvoiceCreated", function(invoiceId){
eventAggregator.$emit("invoice-created", invoiceId);
});
+ connection.on("InfoUpdated", function(model){
+ eventAggregator.$emit("info-updated", model);
+ });
function connect(){