btcpayserver/BTCPayServer/Views/UIStores/Rates.cshtml

213 lines
13 KiB
Text
Raw Normal View History

@using BTCPayServer.Abstractions.Models
@using BTCPayServer.Abstractions.TagHelpers
@using BTCPayServer.Client
@using Microsoft.AspNetCore.Mvc.TagHelpers
@model BTCPayServer.Models.StoreViewModels.RatesViewModel
2018-05-04 01:46:52 +09:00
@{
ViewData.SetActivePage(StoreNavPages.Rates, "Rates", Context.GetStoreData().Id);
2020-07-22 15:28:31 +02:00
}
<form method="post" permissioned="@Policies.CanModifyStoreSettings">
<div class="sticky-header">
<h2>@ViewData["Title"]</h2>
<button id="page-primary" name="command" type="submit" class="btn btn-primary" value="Save">Save</button>
</div>
<partial name="_StatusMessage" />
<div class="row">
<div class="col-xxl-constrain col-xl-8">
@if (!ViewContext.ModelState.IsValid)
{
<div asp-validation-summary="All"></div>
}
<input type="hidden" asp-for="ShowScripting" />
@if (Model.ShowScripting)
2018-05-04 01:46:52 +09:00
{
<div class="form-group">
<h5>Scripting</h5>
<p>Rate script allows you to express precisely how you want to calculate rates for currency pairs.</p>
<p>We are retrieving the rate of each exchange either directly, or via <a href="https://www.coingecko.com/" target="_blank" rel="noreferrer noopener">CoinGecko (free)</a>.</p>
<div class="accordion" id="accordion-info">
<div class="accordion-item">
<h2 class="accordion-header" id="direct-header">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#direct-content" aria-expanded="false" aria-controls="direct-content">
Direct integration
<vc:icon symbol="caret-down"/>
</button>
</h2>
<div id="direct-content" class="accordion-collapse collapse" aria-labelledby="direct-header" data-bs-parent="#accordion-info">
<div class="accordion-body">
@foreach (var exchange in Model.AvailableExchanges.Where(a => a.Source == BTCPayServer.Rating.RateSource.Direct))
{
<a href="@exchange.Url" rel="noreferrer noopener">@exchange.Id</a><span>&nbsp;</span>
}
</div>
</div>
</div>
<div class="accordion-item">
<h2 class="accordion-header" id="coingecko-header">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#coingecko-content" aria-expanded="false" aria-controls="coingecko-content">
Coingecko integration
<vc:icon symbol="caret-down"/>
</button>
</h2>
<div id="coingecko-content" class="accordion-collapse collapse" aria-labelledby="coingecko-header" data-bs-parent="#accordion-info">
<div class="accordion-body">
@foreach (var exchange in Model.AvailableExchanges.Where(a => a.Source == BTCPayServer.Rating.RateSource.Coingecko))
{
<a href="@exchange.Url" rel="noreferrer noopener">@exchange.Id</a><span>&nbsp;</span>
}
</div>
</div>
</div>
</div>
2018-05-04 01:46:52 +09:00
</div>
}
@if (Model.TestRateRules != null)
2018-05-04 01:46:52 +09:00
{
<h5>Test Results:</h5>
<div class="table-responsive-md">
<table class="table table-hover">
2018-05-04 01:46:52 +09:00
<tbody>
@foreach (var result in Model.TestRateRules)
{
<tr>
@if (result.Error)
{
<th class="small">
<vc:icon symbol="cross" css-class="text-danger" />
@result.CurrencyPair
</th>
}
else
{
<th class="small">
<vc:icon symbol="checkmark" css-class="text-success" />
@result.CurrencyPair
</th>
}
<td class="small">@result.Rule</td>
</tr>
}
2018-05-04 01:46:52 +09:00
</tbody>
</table>
</div>
}
@if (Model.ShowScripting)
2018-05-04 01:46:52 +09:00
{
Bootstrap v5 migration (#2490) * Swap bootstrap asset files * Update themes and color definitions * Move general bootstrap customizations * Theme updates Theme updates * Remove BuildBundlerMinifier This lead to an error, because BuildBundlerMinifier and BundlerMinifier.Core seem to conflict here. Details: https://stackoverflow.com/a/61119586 * Rewplace btn-block class with w-100 * Update badge classes * Remove old font family head variable * Update margin classes * Cleanups * Update float classes * Update text classes * Update padding classes * Update border classes * UPdate dropdown classes * Update select classes * Update neutral custom props * Update bootstrap and customizations * Update ChromeDriver; disable smooth scroll https://github.com/SeleniumHQ/selenium/issues/8295 * Improve alert messages * Improve bootstrap customizations * Disable reduced motion See also 7358282f * Update Bootstrap data attributes * Update file inputs * Update input groups * Replace deprecated jumbotron class * Update variables; re-add negative margin util classes * Update cards * Update form labels * Debug alerts * Fix aria-labelledby associations * Dropdown-related test fixes * Fix CanUseWebhooks test * Test fixes * Nav updates * Fix nav usage in wallet send and payouts * Update alert and modal close buttons * Re-add backdrop properties * Upgrade Bootstrap to v5 final * Update screen reader classes * Update font-weight classes * Update monospace font classes * Update accordians * Update close icon usage * Cleanup * Update scripts and style integrations * Update input group texts * Update LN node setup page * Update more form control classes * Update inline forms * Add js specific test * Upgrade Vue.js * Remove unused JS * Upgrade Bootstrap to v5.0.1 * Try container related test updates * Separate jQuery bundle * Remove jQuery from LND seed backup page * Remove unused code * Refactor email autofill js * Refactor camera scanner JS * Re-add tests * Re-add BuildBundlerMinifier * Do not minify bundles containing Bootstrap Details https://github.com/madskristensen/BundlerMinifier/issues/558 * Update bundles * Cleanup JS test * Cleanup tests involving dropdowns * Cleanup tests involving collapses * Cleanup locale additions in ConfigureCore * Cleanup bundles * Remove duplicate status message * Cleanup formatting * Fix missing validation scripts * Remove unused unminified Bootstrap js files * Fix classic theme * Fix Casa theme * Fix PoS validation
2021-05-19 04:39:27 +02:00
<div id="help" class="collapse text-start">
2018-05-04 01:46:52 +09:00
<p>
The script language is composed of several rules composed of a currency pair and a mathematic expression.
The example below will use <code>kraken</code> for both <code>LTC_USD</code> and <code>BTC_USD</code> pairs.
2018-05-04 01:46:52 +09:00
</p>
<pre><code class="text hljs">LTC_USD = kraken(LTC_USD);
BTC_USD = kraken(BTC_USD);</code></pre>
<p>However, explicitely setting specific pairs like this can be a bit difficult. Instead, you can define a rule <code>X_X</code> which will match any currency pair. The following example will use <code>kraken</code> for getting the rate of any currency pair.</p>
<pre><code class="text hljs">X_X = kraken(X_X);</code></pre>
<p>However, <code>kraken</code> does not support the <code>BTC_CAD</code> pair. For this reason you can add a rule mapping all <code>X_CAD</code> to <code>ndax</code>, a Canadian exchange.</p>
<pre><code class="text hljs">X_CAD = ndax(X_CAD);
X_X = kraken(X_X);</code></pre>
2018-05-04 01:46:52 +09:00
<p>A given currency pair match the most specific rule. If two rules are matching and are as specific, the first rule will be chosen.</p>
<p>
But now, what if you want to support <code>DOGE</code>? The problem with <code>DOGE</code> is that most exchange do not have any pair for it. But <code>bitpay</code> has a <code>DOGE_BTC</code> pair. <br />
2018-05-04 01:46:52 +09:00
Luckily, the rule engine allow you to reference rules:
</p>
<pre><code class="text hljs">DOGE_X = bitpay(DOGE_BTC) * BTC_X;
X_CAD = ndax(X_CAD);
X_X = kraken(X_X);</code></pre>
2018-08-01 23:38:52 +09:00
<p>
With <code>DOGE_USD</code> will be expanded to <code>bitpay(DOGE_BTC) * kraken(BTC_USD)</code>. And <code>DOGE_CAD</code> will be expanded to <code>bitpay(DOGE_BTC) * ndax(BTC_CAD)</code>. <br />
2018-08-01 23:38:52 +09:00
However, we advise you to write it that way to increase coverage so that <code>DOGE_BTC</code> is also supported:
</p>
<pre><code class="text hljs">DOGE_X = DOGE_BTC * BTC_X;
DOGE_BTC = bitpay(DOGE_BTC);
X_CAD = ndax(X_CAD);
X_X = kraken(X_X);</code></pre>
2018-08-01 23:38:52 +09:00
<p>
It is worth noting that the inverses of those pairs are automatically supported as well.<br />
It means that the rule <code>USD_DOGE = 1 / DOGE_USD</code> implicitely exists.
</p>
2018-05-04 01:46:52 +09:00
</div>
<div class="form-group">
<label asp-for="Script" class="form-label"></label>
2023-02-13 00:25:24 -08:00
<a href="#help" data-bs-toggle="collapse" title="More information...">
<vc:icon symbol="info"/>
</a>
2018-05-04 01:46:52 +09:00
<textarea asp-for="Script" rows="20" cols="80" class="form-control"></textarea>
<span asp-validation-for="Script" class="text-danger"></span>
<p>
<button type="button" class="btn btn-link text-secondary px-0" id="ResetDefaults">Set to default settings</button>
</p>
2018-05-04 01:46:52 +09:00
</div>
}
else
{
<div class="form-group">
<label asp-for="PreferredExchange" class="form-label"></label>
Bootstrap v5 migration (#2490) * Swap bootstrap asset files * Update themes and color definitions * Move general bootstrap customizations * Theme updates Theme updates * Remove BuildBundlerMinifier This lead to an error, because BuildBundlerMinifier and BundlerMinifier.Core seem to conflict here. Details: https://stackoverflow.com/a/61119586 * Rewplace btn-block class with w-100 * Update badge classes * Remove old font family head variable * Update margin classes * Cleanups * Update float classes * Update text classes * Update padding classes * Update border classes * UPdate dropdown classes * Update select classes * Update neutral custom props * Update bootstrap and customizations * Update ChromeDriver; disable smooth scroll https://github.com/SeleniumHQ/selenium/issues/8295 * Improve alert messages * Improve bootstrap customizations * Disable reduced motion See also 7358282f * Update Bootstrap data attributes * Update file inputs * Update input groups * Replace deprecated jumbotron class * Update variables; re-add negative margin util classes * Update cards * Update form labels * Debug alerts * Fix aria-labelledby associations * Dropdown-related test fixes * Fix CanUseWebhooks test * Test fixes * Nav updates * Fix nav usage in wallet send and payouts * Update alert and modal close buttons * Re-add backdrop properties * Upgrade Bootstrap to v5 final * Update screen reader classes * Update font-weight classes * Update monospace font classes * Update accordians * Update close icon usage * Cleanup * Update scripts and style integrations * Update input group texts * Update LN node setup page * Update more form control classes * Update inline forms * Add js specific test * Upgrade Vue.js * Remove unused JS * Upgrade Bootstrap to v5.0.1 * Try container related test updates * Separate jQuery bundle * Remove jQuery from LND seed backup page * Remove unused code * Refactor email autofill js * Refactor camera scanner JS * Re-add tests * Re-add BuildBundlerMinifier * Do not minify bundles containing Bootstrap Details https://github.com/madskristensen/BundlerMinifier/issues/558 * Update bundles * Cleanup JS test * Cleanup tests involving dropdowns * Cleanup tests involving collapses * Cleanup locale additions in ConfigureCore * Cleanup bundles * Remove duplicate status message * Cleanup formatting * Fix missing validation scripts * Remove unused unminified Bootstrap js files * Fix classic theme * Fix Casa theme * Fix PoS validation
2021-05-19 04:39:27 +02:00
<select asp-for="PreferredExchange" asp-items="Model.Exchanges" class="form-select"></select>
2018-05-04 01:46:52 +09:00
<span asp-validation-for="PreferredExchange" class="text-danger"></span>
<div id="PreferredExchangeHelpBlock" class="form-text">
Current Rates source is <a href="@Model.RateSource" target="_blank" rel="noreferrer noopener">@Model.PreferredResolvedExchange</a>.
</div>
2018-05-04 01:46:52 +09:00
</div>
}
<div class="form-group">
<label class="d-flex align-items-center">
<button type="submit" id="ShowScripting" class="btcpay-toggle me-3 @if (Model.ShowScripting) { @("btcpay-toggle--active") }" value="scripting-@(Model.ShowScripting ? "off" : "on")" name="command" data-bs-toggle="modal" data-bs-target="#ConfirmModal" permission="@Policies.CanModifyStoreSettings">@(Model.ShowScripting ? "Disable" : "Enable") advanced rate rule scripting</button>
<div>
<span>Advanced rate rule scripting</span>
<div class="form-text">
@(Model.ShowScripting ? "Disabling will delete your rate script." : "Enabling will modify your current rate sources. This is a feature for advanced users.")
</div>
</div>
</label>
</div>
2018-05-04 01:46:52 +09:00
<div class="form-group">
<label asp-for="Spread" class="form-label"></label>
2018-08-01 23:38:52 +09:00
<div class="input-group">
<input inputmode="decimal" asp-for="Spread" class="form-control" />
Bootstrap v5 migration (#2490) * Swap bootstrap asset files * Update themes and color definitions * Move general bootstrap customizations * Theme updates Theme updates * Remove BuildBundlerMinifier This lead to an error, because BuildBundlerMinifier and BundlerMinifier.Core seem to conflict here. Details: https://stackoverflow.com/a/61119586 * Rewplace btn-block class with w-100 * Update badge classes * Remove old font family head variable * Update margin classes * Cleanups * Update float classes * Update text classes * Update padding classes * Update border classes * UPdate dropdown classes * Update select classes * Update neutral custom props * Update bootstrap and customizations * Update ChromeDriver; disable smooth scroll https://github.com/SeleniumHQ/selenium/issues/8295 * Improve alert messages * Improve bootstrap customizations * Disable reduced motion See also 7358282f * Update Bootstrap data attributes * Update file inputs * Update input groups * Replace deprecated jumbotron class * Update variables; re-add negative margin util classes * Update cards * Update form labels * Debug alerts * Fix aria-labelledby associations * Dropdown-related test fixes * Fix CanUseWebhooks test * Test fixes * Nav updates * Fix nav usage in wallet send and payouts * Update alert and modal close buttons * Re-add backdrop properties * Upgrade Bootstrap to v5 final * Update screen reader classes * Update font-weight classes * Update monospace font classes * Update accordians * Update close icon usage * Cleanup * Update scripts and style integrations * Update input group texts * Update LN node setup page * Update more form control classes * Update inline forms * Add js specific test * Upgrade Vue.js * Remove unused JS * Upgrade Bootstrap to v5.0.1 * Try container related test updates * Separate jQuery bundle * Remove jQuery from LND seed backup page * Remove unused code * Refactor email autofill js * Refactor camera scanner JS * Re-add tests * Re-add BuildBundlerMinifier * Do not minify bundles containing Bootstrap Details https://github.com/madskristensen/BundlerMinifier/issues/558 * Update bundles * Cleanup JS test * Cleanup tests involving dropdowns * Cleanup tests involving collapses * Cleanup locale additions in ConfigureCore * Cleanup bundles * Remove duplicate status message * Cleanup formatting * Fix missing validation scripts * Remove unused unminified Bootstrap js files * Fix classic theme * Fix Casa theme * Fix PoS validation
2021-05-19 04:39:27 +02:00
<span class="input-group-text">%</span>
2018-08-01 23:38:52 +09:00
</div>
<span asp-validation-for="Spread" class="text-danger"></span>
2018-05-04 01:46:52 +09:00
</div>
<h3 class="mt-5 mb-3">Testing</h3>
2018-05-04 01:46:52 +09:00
<div class="form-group">
<label asp-for="ScriptTest" class="form-label">Currency pairs to test against your rule (e.g. <code>DOGE_USD,DOGE_CAD,BTC_CAD,BTC_USD</code>)</label>
<div class="d-flex">
<input asp-for="ScriptTest" class="form-control" placeholder="BTC_USD, BTC_CAD" />
<button name="command" value="Test" type="submit" class="btn btn-secondary ms-3" title="Test" permission="@Policies.CanModifyStoreSettings">Test</button>
</div>
2018-05-04 01:46:52 +09:00
<span asp-validation-for="ScriptTest" class="text-danger"></span>
</div>
<h3 class="mt-5 mb-3">Default Currency Pairs</h3>
<div class="form-group">
2021-11-11 13:03:08 +01:00
<label asp-for="DefaultCurrencyPairs" class="form-label">Query pairs via REST by querying <a asp-controller="BitpayRate" asp-action="GetRates2" asp-route-storeId="@Model.StoreId" target="_blank">this link</a> without the need to specify currencyPairs.</label>
<input asp-for="DefaultCurrencyPairs" class="form-control" placeholder="BTC_USD, BTC_CAD" />
<span asp-validation-for="DefaultCurrencyPairs" class="text-danger"></span>
</div>
</div>
2018-05-04 01:46:52 +09:00
</div>
</form>
<partial name="_Confirm" model="@(new ConfirmModel("Rate rule scripting", Model.ShowScripting ? "This action will delete your rate script. Are you sure to turn off rate rules scripting?" : "This action will modify your current rate sources. Are you sure to turn on rate rules scripting? (Advanced users)", "Continue", Model.ShowScripting ? "btn-danger" : "btn-primary"))" permission="@Policies.CanModifyStoreSettings" />
@section PageHeadContent {
<link rel="stylesheet" href="~/vendor/highlightjs/default.min.css" asp-append-version="true">
}
Bootstrap v5 migration (#2490) * Swap bootstrap asset files * Update themes and color definitions * Move general bootstrap customizations * Theme updates Theme updates * Remove BuildBundlerMinifier This lead to an error, because BuildBundlerMinifier and BundlerMinifier.Core seem to conflict here. Details: https://stackoverflow.com/a/61119586 * Rewplace btn-block class with w-100 * Update badge classes * Remove old font family head variable * Update margin classes * Cleanups * Update float classes * Update text classes * Update padding classes * Update border classes * UPdate dropdown classes * Update select classes * Update neutral custom props * Update bootstrap and customizations * Update ChromeDriver; disable smooth scroll https://github.com/SeleniumHQ/selenium/issues/8295 * Improve alert messages * Improve bootstrap customizations * Disable reduced motion See also 7358282f * Update Bootstrap data attributes * Update file inputs * Update input groups * Replace deprecated jumbotron class * Update variables; re-add negative margin util classes * Update cards * Update form labels * Debug alerts * Fix aria-labelledby associations * Dropdown-related test fixes * Fix CanUseWebhooks test * Test fixes * Nav updates * Fix nav usage in wallet send and payouts * Update alert and modal close buttons * Re-add backdrop properties * Upgrade Bootstrap to v5 final * Update screen reader classes * Update font-weight classes * Update monospace font classes * Update accordians * Update close icon usage * Cleanup * Update scripts and style integrations * Update input group texts * Update LN node setup page * Update more form control classes * Update inline forms * Add js specific test * Upgrade Vue.js * Remove unused JS * Upgrade Bootstrap to v5.0.1 * Try container related test updates * Separate jQuery bundle * Remove jQuery from LND seed backup page * Remove unused code * Refactor email autofill js * Refactor camera scanner JS * Re-add tests * Re-add BuildBundlerMinifier * Do not minify bundles containing Bootstrap Details https://github.com/madskristensen/BundlerMinifier/issues/558 * Update bundles * Cleanup JS test * Cleanup tests involving dropdowns * Cleanup tests involving collapses * Cleanup locale additions in ConfigureCore * Cleanup bundles * Remove duplicate status message * Cleanup formatting * Fix missing validation scripts * Remove unused unminified Bootstrap js files * Fix classic theme * Fix Casa theme * Fix PoS validation
2021-05-19 04:39:27 +02:00
@section PageFootContent {
<script>
const commandButton = document.querySelector('[data-bs-target="#ConfirmModal"]')
commandButton.dataset.action = window.location.href + '/confirm?scripting=@(!Model.ShowScripting)'
commandButton.addEventListener('click', event => {
event.preventDefault()
});
delegate('click', '#ResetDefaults', () => {
document.getElementById('Script').value = @Safe.Json(Model.DefaultScript);
});
Bootstrap v5 migration (#2490) * Swap bootstrap asset files * Update themes and color definitions * Move general bootstrap customizations * Theme updates Theme updates * Remove BuildBundlerMinifier This lead to an error, because BuildBundlerMinifier and BundlerMinifier.Core seem to conflict here. Details: https://stackoverflow.com/a/61119586 * Rewplace btn-block class with w-100 * Update badge classes * Remove old font family head variable * Update margin classes * Cleanups * Update float classes * Update text classes * Update padding classes * Update border classes * UPdate dropdown classes * Update select classes * Update neutral custom props * Update bootstrap and customizations * Update ChromeDriver; disable smooth scroll https://github.com/SeleniumHQ/selenium/issues/8295 * Improve alert messages * Improve bootstrap customizations * Disable reduced motion See also 7358282f * Update Bootstrap data attributes * Update file inputs * Update input groups * Replace deprecated jumbotron class * Update variables; re-add negative margin util classes * Update cards * Update form labels * Debug alerts * Fix aria-labelledby associations * Dropdown-related test fixes * Fix CanUseWebhooks test * Test fixes * Nav updates * Fix nav usage in wallet send and payouts * Update alert and modal close buttons * Re-add backdrop properties * Upgrade Bootstrap to v5 final * Update screen reader classes * Update font-weight classes * Update monospace font classes * Update accordians * Update close icon usage * Cleanup * Update scripts and style integrations * Update input group texts * Update LN node setup page * Update more form control classes * Update inline forms * Add js specific test * Upgrade Vue.js * Remove unused JS * Upgrade Bootstrap to v5.0.1 * Try container related test updates * Separate jQuery bundle * Remove jQuery from LND seed backup page * Remove unused code * Refactor email autofill js * Refactor camera scanner JS * Re-add tests * Re-add BuildBundlerMinifier * Do not minify bundles containing Bootstrap Details https://github.com/madskristensen/BundlerMinifier/issues/558 * Update bundles * Cleanup JS test * Cleanup tests involving dropdowns * Cleanup tests involving collapses * Cleanup locale additions in ConfigureCore * Cleanup bundles * Remove duplicate status message * Cleanup formatting * Fix missing validation scripts * Remove unused unminified Bootstrap js files * Fix classic theme * Fix Casa theme * Fix PoS validation
2021-05-19 04:39:27 +02:00
</script>
<partial name="_ValidationScriptsPartial"/>
2018-05-04 01:46:52 +09:00
}