Browse Source

Add QR code scanning (#1)

master
Skylar Ittner 2 years ago
parent
commit
16d55af2ae
  1. 4
      config.xml
  2. 5
      package.json
  3. 4
      www/js/home.js
  4. 4
      www/js/main.js
  5. 2
      www/js/platform.js
  6. 24
      www/js/sendmoney.js
  7. 2
      www/pages/sendmoney.html
  8. 3
      www/settings.template.js

4
config.xml

@ -21,8 +21,8 @@
<preference name="android-minSdkVersion" value="21" />
<preference name="android-targetSdkVersion" value="27" />
<allow-intent href="market:*" />
<preference name="HeaderColor" value="#F44336" />
<preference name="StatusBarBackgroundColor" value="#D32F2F" />
<preference name="HeaderColor" value="#FF9800" />
<preference name="StatusBarBackgroundColor" value="#F57C00" />
<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application">
<application android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher_round" />
</edit-config>

5
package.json

@ -12,6 +12,8 @@
"dependencies": {
"cordova-android": "^8.0.0",
"cordova-plugin-app-version": "^0.1.9",
"cordova-plugin-barcodescanner": "^0.7.4",
"cordova-plugin-compat": "^1.2.0",
"cordova-plugin-headercolor": "^1.0.0",
"cordova-plugin-inappbrowser": "^3.0.0",
"cordova-plugin-statusbar": "^2.4.2",
@ -23,7 +25,8 @@
"cordova-plugin-statusbar": {},
"cordova-plugin-headercolor": {},
"cordova-plugin-app-version": {},
"cordova-plugin-inappbrowser": {}
"cordova-plugin-inappbrowser": {},
"cordova-plugin-barcodescanner": {}
},
"platforms": [
"android"

4
www/js/home.js

@ -8,7 +8,7 @@ var accountBalance = 0.0;
$(".view-main").on("ptr:refresh", ".ptr-content", function () {
loadHomePage(function () {
app.ptr.done();
setTimeout(app.ptr.done, 500);
});
});
@ -60,7 +60,7 @@ function loadQrCode(callback) {
var typeNumber = 4;
var errorCorrectionLevel = 'L';
var qr = qrcode(typeNumber, errorCorrectionLevel);
qr.addData('https://app.helpinghelena.org/?sendto=' + data.profile.publicid);
qr.addData(SETTINGS['webapp_url'] + '?sendto=' + data.profile.publicid);
qr.make();
var svg = qr.createSvgTag({
margin: 6,

4
www/js/main.js

@ -148,10 +148,10 @@ if (localStorage.getItem("configured") == null) {
} catch (ex) {
router.navigate("/home");
}
setupKeyRefresh();
} else {
//router.navigate("/setup/0");
router.navigate("/setup/0");
}
});
}

2
www/js/platform.js

@ -30,7 +30,7 @@ function initCordova() {
document.addEventListener("deviceready", function () {
if (cordova.platformId == 'android') {
StatusBar.backgroundColorByHexString("#D32F2F");
StatusBar.backgroundColorByHexString("#F57C00");
StatusBar.styleLightContent();
}
}, false);

24
www/js/sendmoney.js

@ -23,6 +23,30 @@ $("#typecodebtn").on("click", function () {
});
});
$("#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");
}
);
});
function sendMoney(id, amount, name) {
if (id == "0") {
return;

2
www/pages/sendmoney.html

@ -25,7 +25,7 @@
<div class="row justify-content-center">
{{#if @global.qrenabled}}
<div class="col-100 tablet-50 desktop-25">
<div class="button button-large button-fill button-round">
<div class="button button-large button-fill button-round" id="scanqrcodebtn">
<i class="fas fa-qrcode"></i> Scan Code
</div>
</div>

3
www/settings.template.js

@ -8,5 +8,6 @@
* Array of global settings.
*/
var SETTINGS = {
server: "http://localhost/helpinghelena/api"
server: "http://localhost/helpinghelena/api",
webapp_url: "https://app.helpinghelena.org/"
};
Loading…
Cancel
Save