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.
HelenaExpressApp/www/assets/js/home.js

64 lines
2.3 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/.
*/
function openGenericBarcodeScanner() {
scanBarcode(function (result) {
var code = "";
var action = "";
if (result.startsWith("https://helena.express/track#")) {
// tracking code from receipt
code = result.split("#")[1];
action = "track";
} else if (result.startsWith("https://helena.express/dropandsend#")) {
code = result.split("#")[1];
action = "pickupcode";
} else if (result.startsWith("https://helena.express/das/pickup#")) {
code = result.split("#")[1];
action = "pickupcode";
} else if (result.startsWith("http") && result.includes("#")) {
if (trackingcoderegex.test(result.split("#")[1])) {
code = result.split("#")[1];
action = "track";
}
} else if (paymentRequestRegex.test(result)) {
code = encodeURIComponent(result);
action = "sendcrypto";
} else if (walletPubKeyRegex.test(result)) {
code = result;
action = "cryptowallet";
} else if (trackingcoderegex.test(result)) {
code = result;
action = "track";
} else if (result.startsWith("https://helena.express/")) {
action = "hlnexurl";
}
switch (action) {
case "track":
openTrackingInfoPage(code);
break;
case "pickupcode":
sendPickupCode(code);
break;
case "cryptowallet":
router.navigate("/crypto/" + code);
break;
case "sendcrypto":
router.navigate("/crypto?paymenturi=" + code);
//app.dialog.alert("Not implemented.");
break;
case "hlnexurl":
handleDeepLink(result);
break;
default:
app.dialog.alert("This app can't understand what's in that barcode.", "Error");
return;
}
}, function () {
app.dialog.alert("Something went wrong and we can't scan right now.", "Error");
});
}