You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
113 lines
3.8 KiB
JavaScript
113 lines
3.8 KiB
JavaScript
/*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
|
|
$("#typecodebtn").on("click", function () {
|
|
app.dialog.prompt('Enter the recipient\'s code', 'Send Money', function (code) {
|
|
if (code != "") {
|
|
app.preloader.show();
|
|
callAPI("getprofile", {
|
|
key: localStorage.getItem("key"),
|
|
id: code
|
|
}, function (data) {
|
|
$("#publicid").val(code);
|
|
loadSendMoneyPage();
|
|
}, function (msg) {
|
|
app.preloader.hide();
|
|
app.dialog.alert(msg, "Error");
|
|
});
|
|
}
|
|
});
|
|
});
|
|
|
|
$("#scanqrcodebtn").on("click", function () {
|
|
cordova.plugins.barcodeScanner.scan(
|
|
function (result) {
|
|
if (!result.cancelled) {
|
|
console.log("Barcode: ", result);
|
|
if (result.format == "QR_CODE" && result.text.startsWith(SETTINGS['webapp_url'])) {
|
|
var url = new URL(result.text);
|
|
if (typeof url.searchParams.get("sendto") == "string") {
|
|
$("#publicid").val(url.searchParams.get("sendto"));
|
|
loadSendMoneyPage();
|
|
} else {
|
|
app.dialog.alert("Not a valid payment code.", "Scan Error");
|
|
}
|
|
} else {
|
|
app.dialog.alert("Not a valid payment code.", "Scan Error");
|
|
}
|
|
}
|
|
},
|
|
function (error) {
|
|
app.dialog.alert(error, "Scan Error");
|
|
},
|
|
{
|
|
showTorchButton : true,
|
|
prompt: "Scan a code to send money",
|
|
resultDisplayDuration: 0,
|
|
disableSuccessBeep: true
|
|
}
|
|
);
|
|
});
|
|
|
|
function sendMoney(id, amount, name) {
|
|
if (id == "0") {
|
|
return;
|
|
}
|
|
if (amount <= 0) {
|
|
app.dialog.alert("Please specify an amount.", "Error");
|
|
} else if (amount > 999.99) {
|
|
app.dialog.alert("Please specify an amount less than $999.99.", "Error");
|
|
}
|
|
app.preloader.show();
|
|
callAPI("sendmoney", {
|
|
key: localStorage.getItem("key"),
|
|
to: id,
|
|
amount: amount
|
|
}, function (data) {
|
|
app.preloader.hide();
|
|
router.navigate("/moneysent/" + (amount * 1.0).toFixed(2) + "/" + name);
|
|
}, function (msg) {
|
|
app.preloader.hide();
|
|
app.dialog.alert(msg, "Error");
|
|
});
|
|
}
|
|
|
|
function loadSendMoneyPage() {
|
|
app.preloader.show();
|
|
if ($("#publicid").val() == "0") {
|
|
app.preloader.hide();
|
|
$("#step1").removeClass("display-none");
|
|
$("#step2").addClass("display-none");
|
|
} else {
|
|
$("#step1").addClass("display-none");
|
|
$("#step2").removeClass("display-none");
|
|
callAPI("getprofile", {
|
|
key: localStorage.getItem("key"),
|
|
id: $("#publicid").val()
|
|
}, function (data) {
|
|
app.preloader.hide();
|
|
console.log("Profile", data.profile);
|
|
$("#person-name").text(data.profile.name);
|
|
if (data.profile.verified) {
|
|
$("#verified-badge").removeClass("display-none");
|
|
} else {
|
|
$("#unverified-badge").removeClass("display-none");
|
|
}
|
|
}, function (msg) {
|
|
app.preloader.hide();
|
|
app.dialog.alert(msg, "Error");
|
|
});
|
|
}
|
|
}
|
|
|
|
$(".preset-amount-button").click(function () {
|
|
$($(this).data("target")).val($(this).data("amount"));
|
|
});
|
|
|
|
$("#sendbtn").click(function () {
|
|
sendMoney($("#publicid").val(), $("#amount-box").val(), $("#person-name").text());
|
|
}); |