Allow setting amount in crypto or USD

master
Skylar Ittner 2 years ago
parent 004285e67f
commit ff87f00f71

@ -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));
});

@ -73,6 +73,7 @@
<li class="item-content">
<div class="button hapticbtn button-fill" onclick="scanWalletQrCode(function (d) {
$('#walletFromAddress').val(d);
setupFiatConversion(d);
});"><i class="fa-solid fa-inbox-out"></i> &nbsp; Scan Your Wallet Address
</div>
</li>
@ -127,17 +128,27 @@
<li class="item-divider">Step 4</li>
<li class="item-content">
<div class="item-inner">
Enter the amount to send, in cryptocurrency (not in dollars).
Enter the amount to send.
</div>
</li>
<li class="item-content item-input">
<div class="item-inner">
<div class="item-title item-label" id="cryptoAmountSendCurrencyLabel"></div>
<div class="item-input-wrap">
<input type="number" id="transactionAmount" step="0.00000001" min="0.00000001" max="999999.99999999"/>
<span class="input-clear-button"></span>
</div>
</div>
</li>
<li class="item-content item-input" id="cryptoFiatInputItem" style="display: none;">
<div class="item-inner">
<div class="item-title item-label" id="cryptoAmountSendFiatLabel"></div>
<div class="item-input-wrap">
<input type="number" id="transactionAmountFiat" step="0.01" min="0.01" max="9999.99"/>
<span class="input-clear-button"></span>
</div>
</div>
</li>
<!--
TODO: add conversion tool here
<li class="item-content">

Loading…
Cancel
Save