private ColoredLabel CreateLabel(Label uncoloredLabel, string color, HttpRequest request) { if (uncoloredLabel == null) { throw new ArgumentNullException(nameof(uncoloredLabel)); } color = color ?? DefaultColor; ColoredLabel coloredLabel = new ColoredLabel() { Text = uncoloredLabel.Text, Color = color }; if (uncoloredLabel is ReferenceLabel refLabel) { var refInLabel = string.IsNullOrEmpty(refLabel.Reference) ? string.Empty : $"({refLabel.Reference})"; switch (uncoloredLabel.Type) { case "invoice": coloredLabel.Tooltip = $"Received through an invoice {refInLabel}"; coloredLabel.Link = string.IsNullOrEmpty(refLabel.Reference) ? null : _linkGenerator.InvoiceLink(refLabel.Reference, request.Scheme, request.Host, request.PathBase); break; case "payment-request": coloredLabel.Tooltip = $"Received through a payment request {refInLabel}"; coloredLabel.Link = string.IsNullOrEmpty(refLabel.Reference) ? null : _linkGenerator.PaymentRequestLink(refLabel.Reference, request.Scheme, request.Host, request.PathBase); break; case "app": coloredLabel.Tooltip = $"Received through an app {refInLabel}"; coloredLabel.Link = string.IsNullOrEmpty(refLabel.Reference) ? null : _linkGenerator.AppLink(refLabel.Reference, request.Scheme, request.Host, request.PathBase); break; case "pj-exposed": coloredLabel.Tooltip = $"This utxo was exposed through a payjoin proposal for an invoice {refInLabel}"; coloredLabel.Link = string.IsNullOrEmpty(refLabel.Reference) ? null : _linkGenerator.InvoiceLink(refLabel.Reference, request.Scheme, request.Host, request.PathBase); break; } } else if (uncoloredLabel is PayoutLabel payoutLabel) { coloredLabel.Tooltip = $"Paid a payout of a pull payment ({payoutLabel.PullPaymentId})"; coloredLabel.Link = string.IsNullOrEmpty(payoutLabel.PullPaymentId) || string.IsNullOrEmpty(payoutLabel.WalletId) ? null : _linkGenerator.PayoutLink(payoutLabel.WalletId, payoutLabel.PullPaymentId, request.Scheme, request.Host, request.PathBase); } return(coloredLabel); }
private ColoredLabel CreateLabel(LabelData uncoloredLabel, string?color, HttpRequest request) { ArgumentNullException.ThrowIfNull(uncoloredLabel); color ??= DefaultColor; ColoredLabel coloredLabel = new ColoredLabel { Text = uncoloredLabel.Text, Color = color, TextColor = TextColor(color) }; if (uncoloredLabel is ReferenceLabel refLabel) { var refInLabel = string.IsNullOrEmpty(refLabel.Reference) ? string.Empty : $"({refLabel.Reference})"; switch (uncoloredLabel.Type) { case "invoice": coloredLabel.Tooltip = $"Received through an invoice {refInLabel}"; coloredLabel.Link = string.IsNullOrEmpty(refLabel.Reference) ? null : _linkGenerator.InvoiceLink(refLabel.Reference, request.Scheme, request.Host, request.PathBase); break; case "payment-request": coloredLabel.Tooltip = $"Received through a payment request {refInLabel}"; coloredLabel.Link = string.IsNullOrEmpty(refLabel.Reference) ? null : _linkGenerator.PaymentRequestLink(refLabel.Reference, request.Scheme, request.Host, request.PathBase); break; case "app": coloredLabel.Tooltip = $"Received through an app {refInLabel}"; coloredLabel.Link = string.IsNullOrEmpty(refLabel.Reference) ? null : _linkGenerator.AppLink(refLabel.Reference, request.Scheme, request.Host, request.PathBase); break; case "pj-exposed": coloredLabel.Tooltip = $"This UTXO was exposed through a PayJoin proposal for an invoice {refInLabel}"; coloredLabel.Link = string.IsNullOrEmpty(refLabel.Reference) ? null : _linkGenerator.InvoiceLink(refLabel.Reference, request.Scheme, request.Host, request.PathBase); break; } } else if (uncoloredLabel is PayoutLabel payoutLabel) { coloredLabel.Tooltip = $"Paid a payout{(payoutLabel.PullPaymentId is null ? string.Empty : $" of a pull payment ({payoutLabel.PullPaymentId})")}"; coloredLabel.Link = string.IsNullOrEmpty(payoutLabel.WalletId) ? null : _linkGenerator.PayoutLink(payoutLabel.WalletId, payoutLabel.PullPaymentId, PayoutState.Completed, request.Scheme, request.Host, request.PathBase); }
private Label CreateLabel(string value, string color, HttpRequest request) { if (value == null) { throw new ArgumentNullException(nameof(value)); } if (color == null) { throw new ArgumentNullException(nameof(color)); } if (value.StartsWith("{", StringComparison.InvariantCultureIgnoreCase)) { var jObj = JObject.Parse(value); if (jObj.ContainsKey("value")) { 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": return(new Label() { RawValue = value, Value = "invoice", Color = color, Tooltip = $"Received through an invoice {idInLabel}", Link = string.IsNullOrEmpty(id) ? 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() { RawValue = value, Value = "payjoin-exposed", Color = color, Tooltip = $"This utxo was exposed through a payjoin proposal for an invoice {idInLabel}", Link = string.IsNullOrEmpty(id) ? 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) }); } } } return(new Label() { RawValue = value, Value = value, Color = color }); }
private ColoredLabel CreateLabel(LabelData uncoloredLabel, string?color, HttpRequest request) { ArgumentNullException.ThrowIfNull(uncoloredLabel); color ??= DefaultColor; ColoredLabel coloredLabel = new ColoredLabel { Text = uncoloredLabel.Text, Color = color, TextColor = TextColor(color) }; string PayoutLabelText(KeyValuePair <string, List <string> > pair) { if (pair.Value.Count == 1) { return($"Paid a payout of a pull payment ({pair.Key})"); } else { return($"Paid payouts of a pull payment ({pair.Key})"); } } if (uncoloredLabel is ReferenceLabel refLabel) { var refInLabel = string.IsNullOrEmpty(refLabel.Reference) ? string.Empty : $"({refLabel.Reference})"; switch (uncoloredLabel.Type) { case "invoice": coloredLabel.Tooltip = $"Received through an invoice {refInLabel}"; coloredLabel.Link = string.IsNullOrEmpty(refLabel.Reference) ? null : _linkGenerator.InvoiceLink(refLabel.Reference, request.Scheme, request.Host, request.PathBase); break; case "payment-request": coloredLabel.Tooltip = $"Received through a payment request {refInLabel}"; coloredLabel.Link = string.IsNullOrEmpty(refLabel.Reference) ? null : _linkGenerator.PaymentRequestLink(refLabel.Reference, request.Scheme, request.Host, request.PathBase); break; case "app": coloredLabel.Tooltip = $"Received through an app {refInLabel}"; coloredLabel.Link = string.IsNullOrEmpty(refLabel.Reference) ? null : _linkGenerator.AppLink(refLabel.Reference, request.Scheme, request.Host, request.PathBase); break; case "pj-exposed": coloredLabel.Tooltip = $"This UTXO was exposed through a PayJoin proposal for an invoice {refInLabel}"; coloredLabel.Link = string.IsNullOrEmpty(refLabel.Reference) ? null : _linkGenerator.InvoiceLink(refLabel.Reference, request.Scheme, request.Host, request.PathBase); break; } } else if (uncoloredLabel is PayoutLabel payoutLabel) { coloredLabel.Tooltip = payoutLabel.PullPaymentPayouts.Count > 1 ? $"<ul>{string.Join(string.Empty, payoutLabel.PullPaymentPayouts.Select(pair => $"<li>{PayoutLabelText(pair)}</li>"))}</ul>" : payoutLabel.PullPaymentPayouts.Select(PayoutLabelText).ToString(); coloredLabel.Link = string.IsNullOrEmpty(payoutLabel.WalletId) ? null : _linkGenerator.PayoutLink(payoutLabel.WalletId, null, PayoutState.Completed, request.Scheme, request.Host, request.PathBase); } return(coloredLabel); }