Support preview/codegen for custom currencies in pay button (#2896)

This commit is contained in:
Umar Bolatov 2021-09-21 21:10:52 -07:00 committed by GitHub
parent d5c96eee32
commit ac34109da3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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 => ' <option value="' + c + '"' + (c === safeCurrency ? ' selected' : '') + '>' + c + '</option>');
// 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(' <option value="' + safeCurrency + '" selected>' + safeCurrency + '</option>')
}
return ' <select name="currency">\n' +
['USD', 'GBP', 'EUR', 'BTC'].map(c => ' <option value="' + c + '"' + (c === currency ? ' selected' : '') + '>' + c + '</option>').join('\n') + '\n' +
options.join('\n') + '\n' +
' </select>\n'
}