diff --git a/BTCPayServer/wwwroot/js/StoreAddDerivationScheme.js b/BTCPayServer/wwwroot/js/StoreAddDerivationScheme.js
index 7379e4f3c..9a96571a1 100644
--- a/BTCPayServer/wwwroot/js/StoreAddDerivationScheme.js
+++ b/BTCPayServer/wwwroot/js/StoreAddDerivationScheme.js
@@ -1,6 +1,16 @@
$(function () {
var ledgerDetected = false;
- var bridge = new ledgerwebsocket.LedgerWebSocketBridge(srvModel);
+
+ var loc = window.location, new_uri;
+ if (loc.protocol === "https:") {
+ new_uri = "wss:";
+ } else {
+ new_uri = "ws:";
+ }
+ new_uri += "//" + loc.host;
+ new_uri += loc.pathname + "/ledger/ws";
+
+ var bridge = new ledgerwebsocket.LedgerWebSocketBridge(new_uri);
var cryptoSelector = $("#CryptoCurrency");
function GetSelectedCryptoCode() {
diff --git a/BTCPayServer/wwwroot/js/StoreWallet.js b/BTCPayServer/wwwroot/js/StoreWallet.js
deleted file mode 100644
index 5408a5b77..000000000
--- a/BTCPayServer/wwwroot/js/StoreWallet.js
+++ /dev/null
@@ -1,160 +0,0 @@
-
-function updateFiatValue() {
- if (srvModel.rate !== null) {
- var fiatValue = $("#fiatValue");
- fiatValue.css("display", "inline");
- var amountValue = parseFloat($("#amount-textbox").val());
- if (!isNaN(amountValue)) {
- fiatValue.text("= " + (srvModel.rate * amountValue).toFixed(srvModel.divisibility) + " " + srvModel.fiat);
- }
- }
-}
-$(function () {
- var ledgerDetected = false;
- var bridge = new ledgerwebsocket.LedgerWebSocketBridge(srvModel.serverUrl);
- var recommendedFees = "";
- var recommendedBalance = "";
- var cryptoCode = $("#cryptoCode").val();
- if (srvModel.defaultAddress !== null) {
- $("#destination-textbox").val(srvModel.defaultAddress);
- }
- if (srvModel.defaultAmount !== null) {
- $("#amount-textbox").val(srvModel.defaultAmount);
- }
- function WriteAlert(type, message) {
- $("#walletAlert").removeClass("alert-danger");
- $("#walletAlert").removeClass("alert-warning");
- $("#walletAlert").removeClass("alert-success");
- $("#walletAlert").addClass("alert-" + type);
- $("#walletAlert").css("display", "block");
- $("#alertMessage").text(message);
- }
-
- function Write(prefix, type, message) {
-
- $("#" + prefix + "-loading").css("display", "none");
- $("#" + prefix + "-error").css("display", "none");
- $("#" + prefix + "-success").css("display", "none");
-
- $("#" + prefix + "-" + type).css("display", "block");
-
- $("." + prefix + "-label").text(message);
- }
-
- $("#sendform").on("submit", function (elem) {
- elem.preventDefault();
-
- if ($("#amount-textbox").val() === "") {
- $("#amount-textbox").val(recommendedBalance);
- $("#substract-checkbox").prop("checked", true);
- }
-
- if ($("#fee-textbox").val() === "") {
- $("#fee-textbox").val(recommendedFees);
- }
-
- var args = "";
- args += "cryptoCode=" + cryptoCode;
- args += "&destination=" + $("#destination-textbox").val();
- args += "&amount=" + $("#amount-textbox").val();
- args += "&feeRate=" + $("#fee-textbox").val();
- args += "&substractFees=" + $("#substract-checkbox").prop("checked");
-
- WriteAlert("warning", 'Please validate the transaction on your ledger');
-
- var confirmButton = $("#confirm-button");
- confirmButton.prop("disabled", true);
- confirmButton.addClass("disabled");
-
- bridge.sendCommand('sendtoaddress', args, 60 * 10 /* timeout */)
- .catch(function (reason) {
- WriteAlert("danger", reason);
- confirmButton.prop("disabled", false);
- confirmButton.removeClass("disabled");
- })
- .then(function (result) {
- if (!result)
- return;
- confirmButton.prop("disabled", false);
- confirmButton.removeClass("disabled");
- if (result.error) {
- WriteAlert("danger", result.error);
- } else {
- WriteAlert("success", 'Transaction broadcasted (' + result.transactionId + ')');
- $("#fee-textbox").val("");
- $("#amount-textbox").val("");
- $("#destination-textbox").val("");
- $("#substract-checkbox").prop("checked", false);
- updateInfo();
- }
- });
- return false;
- });
-
- $("#crypto-balance-link").on("click", function (elem) {
- elem.preventDefault();
- var val = $("#crypto-balance-link").text();
- $("#amount-textbox").val(val);
- $("#substract-checkbox").prop('checked', true);
- return false;
- });
-
- $("#crypto-fee-link").on("click", function (elem) {
- elem.preventDefault();
- var val = $("#crypto-fee-link").text();
- $("#fee-textbox").val(val);
- return false;
- });
-
- var updateInfo = function () {
- if (!ledgerDetected)
- return false;
- $(".crypto-info").css("display", "none");
- bridge.sendCommand("getinfo", "cryptoCode=" + cryptoCode)
- .catch(function (reason) { Write('check', 'error', reason); })
- .then(function (result) {
- if (!result)
- return;
- if (result.error) {
- Write('check', 'error', result.error);
- return;
- }
- else {
- Write('check', 'success', 'This store is configured to use your ledger');
- $(".crypto-info").css("display", "block");
- recommendedFees = result.recommendedSatoshiPerByte;
- recommendedBalance = result.balance;
- $("#crypto-fee").text(result.recommendedSatoshiPerByte);
- $("#crypto-balance").text(result.balance);
- $("#crypto-code").text(cryptoCode);
- }
- });
- };
-
- bridge.isSupported()
- .then(function (supported) {
- if (!supported) {
- Write('hw', 'error', 'U2F or Websocket are not supported by this browser');
- }
- else {
- bridge.sendCommand('test', null, 5)
- .catch(function (reason) {
- if (reason.name === "TransportError")
- reason = "Are you running the ledger app with version equals or above 1.2.4?";
- Write('hw', 'error', reason);
- })
- .then(function (result) {
- if (!result)
- return;
- if (result.error) {
- Write('hw', 'error', result.error);
- } else {
- Write('hw', 'success', 'Ledger detected');
- $("#sendform").css("display", "block");
- ledgerDetected = true;
- updateInfo();
- }
- });
- }
- });
-});
diff --git a/BTCPayServer/wwwroot/js/WalletSend.js b/BTCPayServer/wwwroot/js/WalletSend.js
new file mode 100644
index 000000000..f855c6ae5
--- /dev/null
+++ b/BTCPayServer/wwwroot/js/WalletSend.js
@@ -0,0 +1,32 @@
+function updateFiatValue() {
+ var rateStr = $("#Rate").val();
+ var divisibilityStr = $("#Divisibility").val();
+ var fiat = $("#Fiat").val();
+ var rate = parseFloat(rateStr);
+ var divisibility = parseInt(divisibilityStr);
+ if (!isNaN(rate) && !isNaN(divisibility)) {
+ var fiatValue = $("#fiatValue");
+ var amountValue = parseFloat($("#Amount").val());
+ if (!isNaN(amountValue)) {
+ fiatValue.css("display", "inline");
+ fiatValue.text("= " + (rate * amountValue).toFixed(divisibility) + " " + fiat);
+ }
+ }
+}
+$(function () {
+ updateFiatValue();
+ $("#crypto-fee-link").on("click", function (elem) {
+ elem.preventDefault();
+ var val = $("#crypto-fee-link").text();
+ $("#FeeSatoshiPerByte").val(val);
+ return false;
+ });
+
+ $("#crypto-balance-link").on("click", function (elem) {
+ elem.preventDefault();
+ var val = $("#crypto-balance-link").text();
+ $("#Amount").val(val);
+ $("#SubstractFees").prop('checked', true);
+ return false;
+ });
+});
diff --git a/BTCPayServer/wwwroot/js/WalletSendLedger.js b/BTCPayServer/wwwroot/js/WalletSendLedger.js
new file mode 100644
index 000000000..e0c3577bd
--- /dev/null
+++ b/BTCPayServer/wwwroot/js/WalletSendLedger.js
@@ -0,0 +1,120 @@
+$(function () {
+ var destination = $("#Destination").val();
+ var amount = $("#Amount").val();
+ var fee = $("#FeeSatoshiPerByte").val();
+ var substractFee = $("#SubstractFees").val();
+
+ var loc = window.location, ws_uri;
+ if (loc.protocol === "https:") {
+ ws_uri = "wss:";
+ } else {
+ ws_uri = "ws:";
+ }
+ ws_uri += "//" + loc.host;
+ ws_uri += loc.pathname + "/ws";
+
+ var successCallback = loc.protocol + "//" + loc.host + loc.pathname + "/success";
+
+ var ledgerDetected = false;
+ var bridge = new ledgerwebsocket.LedgerWebSocketBridge(ws_uri);
+ var cryptoCode = $("#cryptoCode").val();
+ function WriteAlert(type, message) {
+ $("#walletAlert").removeClass("alert-danger");
+ $("#walletAlert").removeClass("alert-warning");
+ $("#walletAlert").removeClass("alert-success");
+ $("#walletAlert").addClass("alert-" + type);
+ $("#walletAlert").css("display", "block");
+ $("#alertMessage").text(message);
+ }
+
+ function Write(prefix, type, message) {
+
+ $("#" + prefix + "-loading").css("display", "none");
+ $("#" + prefix + "-error").css("display", "none");
+ $("#" + prefix + "-success").css("display", "none");
+
+ $("#" + prefix + "-" + type).css("display", "block");
+
+ $("." + prefix + "-label").text(message);
+ }
+
+ var updateInfo = function () {
+ if (!ledgerDetected)
+ return false;
+ $(".crypto-info").css("display", "none");
+ bridge.sendCommand("getinfo", "cryptoCode=" + cryptoCode)
+ .catch(function (reason) { Write('check', 'error', reason); })
+ .then(function (result) {
+ if (!result)
+ return;
+ if (result.error) {
+ Write('check', 'error', result.error);
+ return;
+ }
+ else {
+ Write('check', 'success', 'This store is configured to use your ledger');
+ $(".crypto-info").css("display", "block");
+
+
+ var args = "";
+ args += "cryptoCode=" + cryptoCode;
+ args += "&destination=" + destination;
+ args += "&amount=" + amount;
+ args += "&feeRate=" + fee;
+ args += "&substractFees=" + substractFee;
+
+ WriteAlert("warning", 'Please validate the transaction on your ledger');
+
+ var confirmButton = $("#confirm-button");
+ confirmButton.prop("disabled", true);
+ confirmButton.addClass("disabled");
+
+ bridge.sendCommand('sendtoaddress', args, 60 * 10 /* timeout */)
+ .catch(function (reason) {
+ WriteAlert("danger", reason);
+ confirmButton.prop("disabled", false);
+ confirmButton.removeClass("disabled");
+ })
+ .then(function (result) {
+ if (!result)
+ return;
+ confirmButton.prop("disabled", false);
+ confirmButton.removeClass("disabled");
+ if (result.error) {
+ WriteAlert("danger", result.error);
+ } else {
+ WriteAlert("success", 'Transaction broadcasted (' + result.transactionId + ')');
+ window.location.replace(successCallback + "?txid=" + result.transactionId);
+ }
+ });
+ }
+ });
+ };
+
+ bridge.isSupported()
+ .then(function (supported) {
+ if (!supported) {
+ Write('hw', 'error', 'U2F or Websocket are not supported by this browser');
+ }
+ else {
+ bridge.sendCommand('test', null, 5)
+ .catch(function (reason) {
+ if (reason.name === "TransportError")
+ reason = "Are you running the ledger app with version equals or above 1.2.4?";
+ Write('hw', 'error', reason);
+ })
+ .then(function (result) {
+ if (!result)
+ return;
+ if (result.error) {
+ Write('hw', 'error', result.error);
+ } else {
+ Write('hw', 'success', 'Ledger detected');
+ $("#sendform").css("display", "block");
+ ledgerDetected = true;
+ updateInfo();
+ }
+ });
+ }
+ });
+});