Browse Source

Add QR code scanning (#1)

master
Skylar Ittner 5 months ago
parent
commit
16d55af2ae
8 changed files with 38 additions and 10 deletions
  1. 2
    2
      config.xml
  2. 4
    1
      package.json
  3. 2
    2
      www/js/home.js
  4. 2
    2
      www/js/main.js
  5. 1
    1
      www/js/platform.js
  6. 24
    0
      www/js/sendmoney.js
  7. 1
    1
      www/pages/sendmoney.html
  8. 2
    1
      www/settings.template.js

+ 2
- 2
config.xml View File

@@ -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>

+ 4
- 1
package.json View File

@@ -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"

+ 2
- 2
www/js/home.js View File

@@ -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,

+ 2
- 2
www/js/main.js View File

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

+ 1
- 1
www/js/platform.js View File

@@ -30,7 +30,7 @@ function initCordova() {

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

+ 24
- 0
www/js/sendmoney.js View File

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

+ 1
- 1
www/pages/sendmoney.html View File

@@ -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>

+ 2
- 1
www/settings.template.js View File

@@ -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