diff --git a/www/css/styles.css b/www/css/styles.css index 70c02b9..75af6eb 100644 --- a/www/css/styles.css +++ b/www/css/styles.css @@ -74,4 +74,26 @@ html.md .navbar { html.md .navbar .link { color: white; +} + +.card-expandable .card-header { + min-height: var(--f7-card-header-min-height); + color: var(--f7-card-header-text-color); + font-size: var(--f7-card-header-font-size); + font-weight: var(--f7-card-header-font-weight); + padding: var(--f7-card-header-padding-vertical) var(--f7-card-header-padding-horizontal); +} + +.card-expandable .card-header:after { + display: block !important; +} + +#qrcode { + max-width: 100%; + max-height: 12em; +} + +.card-expandable #qrcode { + height: 50em; + max-height: 50vh; } \ No newline at end of file diff --git a/www/index.html b/www/index.html index 9e52f71..921a90f 100644 --- a/www/index.html +++ b/www/index.html @@ -27,6 +27,7 @@ + diff --git a/www/js/home.js b/www/js/home.js index b0f5ba0..208c8d6 100644 --- a/www/js/home.js +++ b/www/js/home.js @@ -8,31 +8,89 @@ var accountBalance = 0.0; $(".view-main").on("ptr:refresh", ".ptr-content", function () { loadHomePage(function () { - setTimeout(app.ptr.done, 750); + app.ptr.done(); }); }); +$(".view-main").on("card:open", ".card-expandable", function () { + $(".ptr-preloader").addClass("display-none"); + $(".card-expandable .navbar").removeClass("display-none"); +}); + +$(".view-main").on("card:close", ".card-expandable", function () { + $(".card-expandable .navbar").addClass("display-none"); +}); + +$(".view-main").on("card:closed", ".card-expandable", function () { + $(".ptr-preloader").removeClass("display-none"); + $("#receive-card").removeClass("card-expandable"); +}); + function loadBalance(callback) { - $("#balance-error-icon").css("display", "none"); - $("#balance-loading").css("display", ""); + $("#balance-error-icon").addClass("display-none"); + $("#balance-loading").removeClass("display-none"); callAPI("checkbalance", { key: localStorage.getItem("key") }, function (data) { accountBalance = data.balance; $("#balance-amount").text(data.balance); - $("#balance-loading").css("display", "none"); + $("#balance-loading").addClass("display-none"); $("#balance-error").text(""); callback(true); }, function (msg) { - $("#balance-loading").css("display", "none"); + $("#balance-loading").addClass("display-none"); $("#balance-error-icon").css("display", ""); $("#balance-error").text(msg); - callback(false); + callback(false, msg); + }); +} + +function openReceiveCard() { + $("#receive-card").addClass("card-expandable"); + app.card.open("#receive-card"); +} + +function loadQrCode(callback) { + $("#receive-loading").removeClass("display-none"); + callAPI("getprofile", { + key: localStorage.getItem("key"), + }, function (data) { + app.preloader.hide(); + //if (data.profile.type * 1 > 1) { + var typeNumber = 4; + var errorCorrectionLevel = 'L'; + var qr = qrcode(typeNumber, errorCorrectionLevel); + qr.addData('https://app.helpinghelena.org/?sendto=' + data.profile.publicid); + qr.make(); + var svg = qr.createSvgTag({ + margin: 6, + scalable: true + }); + var base64 = window.btoa(svg); + $("#qrcode").attr("src", 'data:image/svg+xml;base64,' + base64); + $("#publicid").text(data.profile.publicid); + $("#receive-loading").addClass("display-none"); + callback(true); + //} + }, function (msg) { + $("#receive-loading").addClass("display-none"); + callback(false, msg); }); } function loadHomePage(callback) { + var done = 0; + var total = 2; loadBalance(function () { - callback(); + done++; + if (done >= total) { + callback(); + } + }); + loadQrCode(function () { + done++; + if (done >= total) { + callback(); + } }); } \ No newline at end of file diff --git a/www/js/main.js b/www/js/main.js index 20c3379..5f9ce7f 100644 --- a/www/js/main.js +++ b/www/js/main.js @@ -100,6 +100,22 @@ function refreshKey(callback) { }); } +function setupKeyRefresh() { + // Check and refresh API key as needed + // Should mitigate key expiration if the app is left open for + // a long time when the key is almost expired + setInterval(function () { + checkKey(function (valid) { + if (!valid) { + refreshKey(function (ok) { + if (!ok) { + router.navigate("/setup/0"); + } + }); + } + }); + }, 1000 * 60 * 5); +} if (localStorage.getItem("configured") == null) { // Open the setup page @@ -107,26 +123,33 @@ if (localStorage.getItem("configured") == null) { } else { checkKey(function (valid) { if (valid) { - router.navigate("/home"); - - // Check and refresh API key as needed - // Should mitigate key expiration if the app is left open for - // a long time when the key is almost expired - setInterval(function () { - checkKey(function (valid) { - if (!valid) { - refreshKey(function (ok) { - if (!ok) { - router.navigate("/setup/0"); - } - }); - } - }); - }, 1000 * 60 * 5); + try { + var url = new URL(window.location.href); + if (typeof url.searchParams.get("sendto") == "string") { + router.navigate("/sendmoney/" + url.searchParams.get("sendto")); + } else { + router.navigate("/home"); + } + } catch (ex) { + router.navigate("/home"); + } + + setupKeyRefresh(); } else { refreshKey(function (ok) { if (ok) { - router.navigate("/home"); + try { + var url = new URL(window.location.href); + if (typeof url.searchParams.get("sendto") == "string") { + router.navigate("/sendmoney/" + url.searchParams.get("sendto")); + } else { + router.navigate("/home"); + } + } catch (ex) { + router.navigate("/home"); + } + + setupKeyRefresh(); } else { //router.navigate("/setup/0"); } diff --git a/www/package.json b/www/package.json index 49a5276..2da52bf 100644 --- a/www/package.json +++ b/www/package.json @@ -8,6 +8,7 @@ "dependencies": { "@fortawesome/fontawesome-free": "^5.6.3", "framework7": "^4", - "jquery": "^3.3.1" + "jquery": "^3.3.1", + "qrcode-generator": "^1.4.3" } } diff --git a/www/pages/home.html b/www/pages/home.html index d16b0ea..5aeeddf 100644 --- a/www/pages/home.html +++ b/www/pages/home.html @@ -50,6 +50,35 @@ + +
+
+ +
+ Receive Money +
+ +
+
+ +
+ + + +

+
+
+
@@ -58,7 +87,7 @@
- + add
diff --git a/www/pages/sendmoney.html b/www/pages/sendmoney.html index 989ca4e..13b070d 100644 --- a/www/pages/sendmoney.html +++ b/www/pages/sendmoney.html @@ -7,7 +7,7 @@ - + diff --git a/www/yarn.lock b/www/yarn.lock index 2156df0..16ddee5 100644 --- a/www/yarn.lock +++ b/www/yarn.lock @@ -34,6 +34,11 @@ path-to-regexp@^3.0.0: resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-3.0.0.tgz#c981a218f3df543fa28696be2f88e0c58d2e012a" integrity sha512-ZOtfhPttCrqp2M1PBBH4X13XlvnfhIwD7yCLx+GoGoXRPQyxGOTdQMpIzPSPKXAJT/JQrdfFrgdJOyAzvgpQ9A== +qrcode-generator@^1.4.3: + version "1.4.3" + resolved "https://registry.yarnpkg.com/qrcode-generator/-/qrcode-generator-1.4.3.tgz#4876e8f280e65b6c94615f4c19c484f6b964b199" + integrity sha512-++rVRvMRq5BlHfmAafl8a4ppUntzUxCCUTT2t0siUgqKwdnqRzY8IH6f6WSX5dZUhD2Ul5/MIKuTJddflwrGzw== + ssr-window@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/ssr-window/-/ssr-window-1.0.1.tgz#30752a6a4666e7767f0b7e6aa6fc2fdbd0d9b369"