<commit_before>﻿$(function () {
    var ledgerDetected = false;

    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() {
        return cryptoSelector.val();
    }

    function WriteAlert(type, message) {
        
    }
    function showFeedback(id) {
        $("#ledger-loading").css("display", id === "ledger-loading" ? "block" : "none");
        $("#no-ledger-info").css("display", id === "no-ledger-info" ? "block" : "none");
        $("#ledger-validate").css("display", id === "ledger-validate" ? "block" : "none");
        $("#ledger-info").css("display", id === "ledger-info" ? "block" : "none");
    }
    function Write(prefix, type, message) {
        if (type === "error") {
            showFeedback("no-ledger-info");
        }
    }

    $(".ledger-info-recommended").on("click", function (elem) {
        elem.preventDefault();

        showFeedback("ledger-validate");

        var account = elem.currentTarget.getAttribute("data-ledgeraccount");
        var cryptoCode = GetSelectedCryptoCode();
        bridge.sendCommand("getxpub", "cryptoCode=" + cryptoCode + "&account=" + account)
            .then(function (result) {
                if (cryptoCode !== GetSelectedCryptoCode())
                    return;

                showFeedback("ledger-info");

                $("#DerivationScheme").val(result.extPubKey);
                $("#DerivationSchemeFormat").val("BTCPay");
            })
            .catch(function (reason) { Write('check', 'error', reason); });
        return false;
    });

    var updateInfo = function () {
        if (!ledgerDetected)
            return false;
        var cryptoCode = GetSelectedCryptoCode();
        bridge.sendCommand("getxpub", "cryptoCode=" + cryptoCode)
            .catch(function (reason) { Write('check', 'error', reason); })
            .then(function (result) {
                if (!result)
                    return;
                if (cryptoCode !== GetSelectedCryptoCode())
                    return;
                if (result.error) {
                    Write('check', 'error', result.error);
                    return;
                }
                else {
                    Write('check', 'success', 'This store is configured to use your ledger');
                    showFeedback("ledger-info");
                }
            });
    };

    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 = "Have you forgot to activate browser support in your ledger app?";
                        Write('hw', 'error', reason);
                    })
                    .then(function (result) {
                        if (!result)
                            return;
                        if (result.error) {
                            Write('hw', 'error', result.error);
                        } else {
                            Write('hw', 'success', 'Ledger detected');
                            ledgerDetected = true;
                            updateInfo();
                        }
                    });
            }
        });
});
<commit_msg>Remove useless query to ledger xpub in the Add derivation scheme screen<commit_after>﻿$(function () {
    var ledgerDetected = false;

    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() {
        return cryptoSelector.val();
    }

    function WriteAlert(type, message) {
        
    }
    function showFeedback(id) {
        $("#ledger-loading").css("display", id === "ledger-loading" ? "block" : "none");
        $("#no-ledger-info").css("display", id === "no-ledger-info" ? "block" : "none");
        $("#ledger-validate").css("display", id === "ledger-validate" ? "block" : "none");
        $("#ledger-info").css("display", id === "ledger-info" ? "block" : "none");
    }
    function Write(prefix, type, message) {
        if (type === "error") {
            showFeedback("no-ledger-info");
        }
    }

    $(".ledger-info-recommended").on("click", function (elem) {
        elem.preventDefault();

        showFeedback("ledger-validate");

        var account = elem.currentTarget.getAttribute("data-ledgeraccount");
        var cryptoCode = GetSelectedCryptoCode();
        bridge.sendCommand("getxpub", "cryptoCode=" + cryptoCode + "&account=" + account)
            .then(function (result) {
                if (cryptoCode !== GetSelectedCryptoCode())
                    return;

                showFeedback("ledger-info");

                $("#DerivationScheme").val(result.extPubKey);
                $("#DerivationSchemeFormat").val("BTCPay");
            })
            .catch(function (reason) { Write('check', 'error', reason); });
        return false;
    });

    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 = "Have you forgot to activate browser support in your ledger app?";
                        Write('hw', 'error', reason);
                    })
                    .then(function (result) {
                        if (!result)
                            return;
                        if (result.error) {
                            Write('hw', 'error', result.error);
                        } else {
                            Write('hw', 'success', 'Ledger detected');
                            ledgerDetected = true;
                            showFeedback("ledger-info");
                        }
                    });
            }
        });
});

{'fraction_non_alphanumeric': 0.14753123140987506, 'fraction_numerical': 0.000594883997620464, 'mean_word_length': 1.5805832693783577, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1784768', 'n_tokens_mistral': 1811, 'n_tokens_neox': 1741, 'n_words': 366}