|
|
|
@ -246,4 +246,63 @@ function displayWalletBalance(address) {
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Setup an input for specifying amount to send in USD, with conversion to crypto.
|
|
|
|
|
* @param {string} walletAddress Detects cryptocurrency from wallet address
|
|
|
|
|
* @returns {undefined}
|
|
|
|
|
*/
|
|
|
|
|
function setupFiatConversion(walletAddress) {
|
|
|
|
|
apirequest(SETTINGS.apis.walletbalance, {
|
|
|
|
|
walletaddress: walletAddress
|
|
|
|
|
}, function (resp) {
|
|
|
|
|
if (resp.status != "OK") {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (resp.exchangerates.usd == -1) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
$("#cryptoFiatInputItem").css("display", "");
|
|
|
|
|
$("#cryptoAmountSendCurrencyLabel").text(resp.currency);
|
|
|
|
|
$("#cryptoAmountSendFiatLabel").text("$");
|
|
|
|
|
$("#transactionAmountFiat").data("exchange-rate", resp.exchangerates.usd);
|
|
|
|
|
$("#transactionAmountFiat").data("cryptocurrency", resp.currency);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Hides the fiat conversion input box.
|
|
|
|
|
* @returns {undefined}
|
|
|
|
|
*/
|
|
|
|
|
function unsetupFiatConversion() {
|
|
|
|
|
$("#cryptoFiatInputItem").css("display", "none");
|
|
|
|
|
$("#cryptoAmountSendCurrencyLabel").text("");
|
|
|
|
|
$("#transactionAmountFiat").removeData("exchange-rate");
|
|
|
|
|
$("#transactionAmountFiat").removeData("cryptocurrency");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$("#app").on("input change paste keyup", "#transactionAmountFiat", function () {
|
|
|
|
|
var fiatamount = parseFloat($("#transactionAmountFiat").val());
|
|
|
|
|
var exchangerate = parseFloat($("#transactionAmountFiat").data("exchange-rate"));
|
|
|
|
|
$("#transactionAmount").val((fiatamount / exchangerate).toFixed(8));
|
|
|
|
|
$("#transactionAmountFiat").val(fiatamount.toFixed(2));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$("#app").on("paste blur", "#walletFromAddress", function () {
|
|
|
|
|
if (walletPubKeyRegex.test($("#walletFromAddress").val())) {
|
|
|
|
|
setupFiatConversion($("#walletFromAddress").val());
|
|
|
|
|
} else {
|
|
|
|
|
unsetupFiatConversion();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$("#app").on("input change paste keyup", "#transactionAmount", function () {
|
|
|
|
|
if ($("#cryptoFiatInputItem").css("display") == "none") {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var amount = parseFloat($("#transactionAmount").val());
|
|
|
|
|
var exchangerate = parseFloat($("#transactionAmountFiat").data("exchange-rate"));
|
|
|
|
|
$("#transactionAmountFiat").val((amount * exchangerate).toFixed(2));
|
|
|
|
|
$("#transactionAmount").val(amount.toFixed(8));
|
|
|
|
|
});
|