New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wallet transactions: Add label manager #4796
Merged
NicolasDorier
merged 10 commits into
btcpayserver:master
from
dennisreimann:wallet-transactions-labels
Mar 26, 2023
Merged
Changes from 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f5eb3e1
Wallet transactions: Add label manager
dennisreimann 3e4daee
Update BTCPayServer/Views/UIWallets/WalletTransactions.cshtml
dennisreimann e5c5cdc
Add rich label info
dennisreimann 469894a
Fixes
dennisreimann 437438f
support labels in wallet send
Kukks 9b701b4
add labels to tx info page
Kukks 6bc92b8
Remove noscript parts
dennisreimann ac66129
Allow click on transaction label info
dennisreimann bb04edd
update psbt info labelstyling
Kukks 88548c3
revert red pixel fix as it broke all
Kukks File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,104 +1,21 @@ | ||
@using NBitcoin.DataEncoders | ||
@using NBitcoin | ||
@using BTCPayServer.Abstractions.TagHelpers | ||
@model BTCPayServer.Components.LabelManager.LabelViewModel | ||
@inject Microsoft.AspNetCore.Antiforgery.IAntiforgery Antiforgery | ||
@{ | ||
var commonCall = Model.ObjectId.Type + Model.ObjectId.Id; | ||
var elementId = "a" + Encoders.Base58.EncodeData(RandomUtils.GetBytes(16)); | ||
var fetchUrl = Url.Action("GetLabels", "UIWallets", new { | ||
walletId = Model.WalletObjectId.WalletId, | ||
excludeTypes = Safe.Json(Model.ExcludeTypes) | ||
}); | ||
var updateUrl = Url.Action("UpdateLabels", "UIWallets", new { | ||
walletId = Model.WalletObjectId.WalletId | ||
}); | ||
} | ||
|
||
<link href="~/vendor/tom-select/tom-select.bootstrap5.min.css" rel="stylesheet"> | ||
<script src="~/vendor/tom-select/tom-select.complete.min.js"></script> | ||
<script> | ||
const updateUrl = @Safe.Json(Url.Action("UpdateLabels", "UIWallets", new { | ||
Model.ObjectId.WalletId | ||
})); | ||
const getUrl = @Safe.Json(@Url.Action("GetLabels", "UIWallets", new { | ||
walletId = Model.ObjectId.WalletId, | ||
excludeTypes = true | ||
})); | ||
const commonCall = @Safe.Json(commonCall); | ||
const elementId = @Safe.Json(elementId); | ||
if (!window[commonCall]) { | ||
window[commonCall] = fetch(getUrl, { | ||
method: 'GET', | ||
credentials: 'include', | ||
headers: { | ||
'Content-Type': 'application/json' | ||
}, | ||
}).then(response => { | ||
return response.json(); | ||
}); | ||
} | ||
|
||
document.addEventListener("DOMContentLoaded", async () => { | ||
const element = document.querySelector(`#${elementId}`); | ||
|
||
if (element) { | ||
const labelsFetchTask = await window[commonCall]; | ||
const config = { | ||
create: true, | ||
items: @Safe.Json(Model.SelectedLabels), | ||
options: labelsFetchTask, | ||
valueField: "label", | ||
labelField: "label", | ||
searchField: "label", | ||
allowEmptyOption: false, | ||
closeAfterSelect: false, | ||
persist: true, | ||
render: { | ||
option: function(data, escape) { | ||
return `<div ${data.color? `style='background-color:${data.color}; color:${data.textColor}'`: ""}>${escape(data.label)}</div>`; | ||
}, | ||
item: function(data, escape) { | ||
return `<div ${data.color? `style='background-color:${data.color}; color:${data.textColor}'`: ""}>${escape(data.label)}</div>`; | ||
} | ||
}, | ||
onItemAdd: (val) => { | ||
window[commonCall] = window[commonCall].then(labels => { | ||
return [...labels, { label: val }] | ||
}); | ||
|
||
document.dispatchEvent(new CustomEvent(`${commonCall}-option-added`, { | ||
detail: val | ||
})); | ||
}, | ||
onChange: async (values) => { | ||
select.lock(); | ||
try { | ||
const response = await fetch(updateUrl, { | ||
method: "POST", | ||
credentials: "include", | ||
headers: { | ||
'Content-Type': 'application/json' | ||
}, | ||
body: JSON.stringify({ | ||
address: @Safe.Json(Model.ObjectId.Id), | ||
labels: select.items | ||
}) | ||
}); | ||
if (!response.ok) { | ||
throw new Error('Network response was not OK'); | ||
} | ||
} catch (error) { | ||
console.error('There has been a problem with your fetch operation:', error); | ||
} finally { | ||
select.unlock(); | ||
} | ||
} | ||
}; | ||
const select = new TomSelect(element, config); | ||
|
||
document.addEventListener(`${commonCall}-option-added`, evt => { | ||
if (!(evt.detail in select.options)) { | ||
select.addOption({ | ||
label: evt.detail | ||
}) | ||
} | ||
}) | ||
} | ||
}) | ||
</script> | ||
|
||
<input id="@elementId" placeholder="Select labels to associate with this object" autocomplete="off" class="form-control label-manager"/> | ||
<input id="@elementId" placeholder="Select labels" autocomplete="off" value="@string.Join(",", Model.SelectedLabels)" | ||
class="only-for-js form-control label-manager ts-wrapper @(Model.DisplayInline ? "ts-inline" : "")" | ||
data-fetch-url="@fetchUrl" | ||
data-update-url="@updateUrl" | ||
data-wallet-id="@Model.WalletObjectId.WalletId" | ||
data-wallet-object-id="@Model.WalletObjectId.Id" | ||
data-wallet-object-type="@Model.WalletObjectId.Type" | ||
data-labels='@Safe.Json(Model.RichLabelInfo)' /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,28 @@ | ||
using System.Collections.Generic; | ||
using BTCPayServer.Services; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace BTCPayServer.Components.LabelManager | ||
{ | ||
public class LabelManager : ViewComponent | ||
{ | ||
public IViewComponentResult Invoke(WalletObjectId walletObjectId, string[] selectedLabels) | ||
public IViewComponentResult Invoke(WalletObjectId walletObjectId, string[] selectedLabels, bool excludeTypes = true, bool displayInline = false, Dictionary<string, RichLabelInfo> richLabelInfo = null) | ||
{ | ||
var vm = new LabelViewModel | ||
{ | ||
ObjectId = walletObjectId, | ||
SelectedLabels = selectedLabels | ||
ExcludeTypes = excludeTypes, | ||
WalletObjectId = walletObjectId, | ||
SelectedLabels = selectedLabels, | ||
DisplayInline = displayInline, | ||
RichLabelInfo = richLabelInfo | ||
}; | ||
return View(vm); | ||
} | ||
} | ||
|
||
public class RichLabelInfo | ||
{ | ||
public string Link { get; set; } | ||
public string Tooltip { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
using System.Collections.Generic; | ||
using BTCPayServer.Services; | ||
|
||
namespace BTCPayServer.Components.LabelManager | ||
{ | ||
public class LabelViewModel | ||
{ | ||
public string[] SelectedLabels { get; set; } | ||
public WalletObjectId ObjectId { get; set; } | ||
public WalletObjectId WalletObjectId { get; set; } | ||
public bool ExcludeTypes { get; set; } | ||
public bool DisplayInline { get; set; } | ||
public Dictionary<string, RichLabelInfo> RichLabelInfo { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,8 @@ | |
} | ||
|
||
@section PageHeadContent { | ||
<script src="~/vendor/tom-select/tom-select.complete.min.js" asp-append-version="true"></script> | ||
<link href="~/vendor/tom-select/tom-select.bootstrap5.min.css" asp-append-version="true" rel="stylesheet"> | ||
<style> | ||
.smMaxWidth { | ||
max-width: 125px; | ||
|
@@ -45,7 +47,6 @@ | |
@section PageFootContent { | ||
@*Without async, somehow selenium do not manage to click on links in this page*@ | ||
<script src="~/modal/btcpay.js" asp-append-version="true" async></script> | ||
|
||
@* Custom Range Modal *@ | ||
<script> | ||
let observer = null; | ||
|
@@ -92,7 +93,7 @@ | |
|
||
if (response.ok) { | ||
const html = await response.text(); | ||
$list.innerHTML += html; | ||
$list.insertAdjacentHTML('beforeend', html); | ||
Comment on lines
-95
to
+96
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This did the trick on not removing event listeners from existing TomSelect instances. @Kukks |
||
skip = skipNext; | ||
|
||
if ($loadMore) { | ||
|
@@ -122,6 +123,7 @@ | |
|
||
$indicator.classList.add('d-none'); | ||
formatDateTimes(document.getElementById('switchTimeFormat').dataset.mode); | ||
initLabelManagers(); | ||
dennisreimann marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
</script> | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It turned out I didn't need this, but this makes it more flexible so that one can request either labels for the whole wallet or individual wallet objects.