From ac34109da365839fe652cb80ec4491bdf5ba58e5 Mon Sep 17 00:00:00 2001 From: Umar Bolatov Date: Tue, 21 Sep 2021 21:10:52 -0700 Subject: [PATCH] Support preview/codegen for custom currencies in pay button (#2896) --- BTCPayServer/wwwroot/paybutton/paybutton.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/BTCPayServer/wwwroot/paybutton/paybutton.js b/BTCPayServer/wwwroot/paybutton/paybutton.js index 1c9055700..6f6a9adf1 100644 --- a/BTCPayServer/wwwroot/paybutton/paybutton.js +++ b/BTCPayServer/wwwroot/paybutton/paybutton.js @@ -224,8 +224,17 @@ function addInputPrice(name, price, widthInput, customFn, type, min, max, step) } function addSelectCurrency(currency) { + // Remove all non-alphabet characters from input string and uppercase it for display + var safeCurrency = currency.replace(/[^a-z]/gi, '').toUpperCase(); + var defaultCurrencies = ['USD', 'GBP', 'EUR', 'BTC']; + var options = defaultCurrencies.map(c => ' '); + // If user provided a currency not in our default currencies list, add it to the top of the options as a selected option + if (defaultCurrencies.indexOf(safeCurrency) === -1) { + options.unshift(' ') + } + return ' \n' }