Merge pull request #1916 from Kukks/morelabels

Add more labels (payment requests, apps, better payout label)
This commit is contained in:
Nicolas Dorier 2020-09-19 11:14:21 +09:00 committed by GitHub
commit f6252b73f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 100 additions and 3 deletions

View File

@ -768,7 +768,7 @@ namespace BTCPayServer.Tests
s.Driver.Navigate().Refresh();
Assert.Contains("badge transactionLabel", s.Driver.PageSource);
});
Assert.Equal("Payout", s.Driver.FindElement(By.ClassName("transactionLabel")).Text);
Assert.Equal("payout", s.Driver.FindElement(By.ClassName("transactionLabel")).Text);
s.GoToWallet(navPages: WalletsNavPages.Payouts);
TestUtils.Eventually(() =>

View File

@ -38,6 +38,21 @@ namespace BTCPayServer.Controllers
private readonly InvoiceController _InvoiceController;
private readonly UserManager<ApplicationUser> _UserManager;
[HttpGet("/apps/{appId}")]
public async Task<IActionResult> RedirectToApp(string appId)
{
switch (await _AppService.GetAppInfo(appId))
{
case ViewCrowdfundViewModel _:
return RedirectToAction("ViewCrowdfund", new {appId});
case ViewPointOfSaleViewModel _:
return RedirectToAction("ViewPointOfSale", new {appId});
}
return NotFound();
}
[HttpGet]
[Route("/apps/{appId}/pos/{viewType?}")]
[XFrameOptionsAttribute(XFrameOptionsAttribute.XFrameOptions.AllowAll)]

View File

@ -1,5 +1,7 @@
using BTCPayServer;
using BTCPayServer.Controllers;
using BTCPayServer.Services.Apps;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
@ -31,6 +33,15 @@ namespace Microsoft.AspNetCore.Mvc
scheme, host, pathbase);
}
public static string AppLink(this LinkGenerator urlHelper, string appId, string scheme, HostString host, string pathbase)
{
return urlHelper.GetUriByAction(
action: nameof(AppsPublicController.RedirectToApp),
controller: "AppsPublic",
values: new { appId },
scheme, host, pathbase);
}
public static string InvoiceLink(this LinkGenerator urlHelper, string invoiceId, string scheme, HostString host, string pathbase)
{
return urlHelper.GetUriByAction(
@ -39,5 +50,14 @@ namespace Microsoft.AspNetCore.Mvc
values: new { invoiceId = invoiceId },
scheme, host, pathbase);
}
public static string PayoutLink(this LinkGenerator urlHelper, string walletId,string pullPaymentId, string scheme, HostString host, string pathbase)
{
return urlHelper.GetUriByAction(
action: nameof(WalletsController.Payouts),
controller: "Wallets",
values: new {walletId, pullPaymentId},
scheme, host, pathbase);
}
}
}

View File

@ -405,9 +405,10 @@ namespace BTCPayServer.HostedServices
if (proof.TransactionId is null)
proof.TransactionId = txId;
payout.SetProofBlob(proof, _jsonSerializerSettings);
_eventAggregator.Publish(new UpdateTransactionLabel(new WalletId(payout.PullPaymentData.StoreId, newTransaction.CryptoCode),
var walletId = new WalletId(payout.PullPaymentData.StoreId, newTransaction.CryptoCode);
_eventAggregator.Publish(new UpdateTransactionLabel(walletId,
newTransaction.NewTransactionEvent.TransactionData.TransactionHash,
("#3F88AF", "Payout")));
UpdateTransactionLabel.PayoutTemplate(payout.Id,payout.PullPaymentDataId, walletId.ToString())));
}
}
await ctx.SaveChangesAsync();

View File

@ -8,6 +8,8 @@ using BTCPayServer.Events;
using BTCPayServer.Payments;
using BTCPayServer.Payments.Bitcoin;
using BTCPayServer.Services;
using BTCPayServer.Services.Apps;
using BTCPayServer.Services.PaymentRequests;
using NBitcoin;
using Newtonsoft.Json.Linq;
@ -50,6 +52,17 @@ namespace BTCPayServer.HostedServices
labels.Add(UpdateTransactionLabel.PayjoinLabelTemplate());
}
foreach (var paymentId in PaymentRequestRepository.GetPaymentIdsFromInternalTags(invoiceEvent.Invoice))
{
labels.Add(UpdateTransactionLabel.PaymentRequestLabelTemplate(paymentId));
}
foreach (var appId in AppService.GetAppInternalTags(invoiceEvent.Invoice))
{
labels.Add(UpdateTransactionLabel.AppLabelTemplate(appId));
}
_eventAggregator.Publish(new UpdateTransactionLabel(walletId, transactionId, labels));
}
else if (evt is UpdateTransactionLabel updateTransactionLabel)
@ -115,6 +128,14 @@ namespace BTCPayServer.HostedServices
public static (string color, string label) InvoiceLabelTemplate(string invoice)
{
return ("#cedc21", JObject.FromObject(new { value = "invoice", id = invoice }).ToString());
}
public static (string color, string label) PaymentRequestLabelTemplate(string paymentRequestId)
{
return ("#489D77", JObject.FromObject(new { value = "payment-request", id = paymentRequestId }).ToString());
}
public static (string color, string label) AppLabelTemplate(string appId)
{
return ("#5093B6", JObject.FromObject(new { value = "app", id = appId }).ToString());
}
public static (string color, string label) PayjoinExposedLabelTemplate(string invoice)
@ -122,6 +143,10 @@ namespace BTCPayServer.HostedServices
return ("#51b13e", JObject.FromObject(new { value = "pj-exposed", id = invoice }).ToString());
}
public static (string color, string label) PayoutTemplate(string payoutId, string pullPaymentId, string walletId)
{
return ("#3F88AF", JObject.FromObject(new { value = "payout", id = payoutId, pullPaymentId, walletId }).ToString());
}
public WalletId WalletId { get; set; }
public Dictionary<uint256, List<(string color, string label)>> TransactionLabels { get; set; }
public override string ToString()

View File

@ -50,6 +50,7 @@ namespace BTCPayServer.Services.Labels
{
var id = jObj.ContainsKey("id") ? jObj["id"].Value<string>() : string.Empty;
var idInLabel = string.IsNullOrEmpty(id) ? string.Empty : $"({id})";
switch (jObj["value"].Value<string>())
{
case "invoice":
@ -63,6 +64,28 @@ namespace BTCPayServer.Services.Labels
? null
: _linkGenerator.InvoiceLink(id, request.Scheme, request.Host, request.PathBase)
};
case "payment-request":
return new Label()
{
RawValue = value,
Value = "payment-request",
Color = color,
Tooltip = $"Received through a payment request {idInLabel}",
Link = string.IsNullOrEmpty(id)
? null
: _linkGenerator.PaymentRequestLink(id, request.Scheme, request.Host, request.PathBase)
};
case "app":
return new Label()
{
RawValue = value,
Value = "app",
Color = color,
Tooltip = $"Received through an app {idInLabel}",
Link = string.IsNullOrEmpty(id)
? null
: _linkGenerator.AppLink(id, request.Scheme, request.Host, request.PathBase)
};
case "pj-exposed":
return new Label()
{
@ -74,6 +97,19 @@ namespace BTCPayServer.Services.Labels
? null
: _linkGenerator.InvoiceLink(id, request.Scheme, request.Host, request.PathBase)
};
case "payout":
return new Label()
{
RawValue = value,
Value = "payout",
Color = color,
Tooltip = $"Paid a payout of a pull payment ({jObj["pullPaymentId"].Value<string>()})",
Link = string.IsNullOrEmpty(id)
? null
: _linkGenerator.PayoutLink(jObj["walletId"].Value<string>(),
jObj["pullPaymentId"].Value<string>(), request.Scheme, request.Host,
request.PathBase)
};
}
}
}