Browse Source

Add QR code scanning (#1)

master
Skylar Ittner 3 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 @@
21 21
         <preference name="android-minSdkVersion" value="21" />
22 22
         <preference name="android-targetSdkVersion" value="27" />
23 23
         <allow-intent href="market:*" />
24
-        <preference name="HeaderColor" value="#F44336" />
25
-        <preference name="StatusBarBackgroundColor" value="#D32F2F" />
24
+        <preference name="HeaderColor" value="#FF9800" />
25
+        <preference name="StatusBarBackgroundColor" value="#F57C00" />
26 26
         <edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application">
27 27
             <application android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher_round" />
28 28
         </edit-config>

+ 4
- 1
package.json View File

@@ -12,6 +12,8 @@
12 12
   "dependencies": {
13 13
     "cordova-android": "^8.0.0",
14 14
     "cordova-plugin-app-version": "^0.1.9",
15
+    "cordova-plugin-barcodescanner": "^0.7.4",
16
+    "cordova-plugin-compat": "^1.2.0",
15 17
     "cordova-plugin-headercolor": "^1.0.0",
16 18
     "cordova-plugin-inappbrowser": "^3.0.0",
17 19
     "cordova-plugin-statusbar": "^2.4.2",
@@ -23,7 +25,8 @@
23 25
       "cordova-plugin-statusbar": {},
24 26
       "cordova-plugin-headercolor": {},
25 27
       "cordova-plugin-app-version": {},
26
-      "cordova-plugin-inappbrowser": {}
28
+      "cordova-plugin-inappbrowser": {},
29
+      "cordova-plugin-barcodescanner": {}
27 30
     },
28 31
     "platforms": [
29 32
       "android"

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

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

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

@@ -148,10 +148,10 @@ if (localStorage.getItem("configured") == null) {
148 148
                     } catch (ex) {
149 149
                         router.navigate("/home");
150 150
                     }
151
-                    
151
+
152 152
                     setupKeyRefresh();
153 153
                 } else {
154
-                    //router.navigate("/setup/0");
154
+                    router.navigate("/setup/0");
155 155
                 }
156 156
             });
157 157
         }

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

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

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

@@ -23,6 +23,30 @@ $("#typecodebtn").on("click", function () {
23 23
     });
24 24
 });
25 25
 
26
+$("#scanqrcodebtn").on("click", function () {
27
+    cordova.plugins.barcodeScanner.scan(
28
+            function (result) {
29
+                if (!result.cancelled) {
30
+                    console.log("Barcode: ", result);
31
+                    if (result.format == "QR_CODE" && result.text.startsWith(SETTINGS['webapp_url'])) {
32
+                        var url = new URL(result.text);
33
+                        if (typeof url.searchParams.get("sendto") == "string") {
34
+                            $("#publicid").val(url.searchParams.get("sendto"));
35
+                            loadSendMoneyPage();
36
+                        } else {
37
+                            app.dialog.alert("Not a valid payment code.", "Scan Error");
38
+                        }
39
+                    } else {
40
+                        app.dialog.alert("Not a valid payment code.", "Scan Error");
41
+                    }
42
+                }
43
+            },
44
+            function (error) {
45
+                app.dialog.alert(error, "Scan Error");
46
+            }
47
+    );
48
+});
49
+
26 50
 function sendMoney(id, amount, name) {
27 51
     if (id == "0") {
28 52
         return;

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

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

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

@@ -8,5 +8,6 @@
8 8
  * Array of global settings.
9 9
  */
10 10
 var SETTINGS = {
11
-    server: "http://localhost/helpinghelena/api"
11
+    server: "http://localhost/helpinghelena/api",
12
+    webapp_url: "https://app.helpinghelena.org/"
12 13
 };

Loading…
Cancel
Save