|
|
|
/*
|
|
|
|
* 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/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
var accountBalance = 0.0;
|
|
|
|
|
|
|
|
$(".view-main").on("ptr:refresh", ".ptr-content", function () {
|
|
|
|
loadHomePage(function () {
|
|
|
|
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").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").addClass("display-none");
|
|
|
|
$("#balance-error").text("");
|
|
|
|
callback(true);
|
|
|
|
}, function (msg) {
|
|
|
|
$("#balance-loading").addClass("display-none");
|
|
|
|
$("#balance-error-icon").css("display", "");
|
|
|
|
$("#balance-error").text(msg);
|
|
|
|
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 () {
|
|
|
|
done++;
|
|
|
|
if (done >= total) {
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
loadQrCode(function () {
|
|
|
|
done++;
|
|
|
|
if (done >= total) {
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|