Making the balance appear

This commit is contained in:
Marcello Stanisci 2015-12-16 17:52:25 +01:00
parent 1c5cb38197
commit a16589a5d9
7 changed files with 33 additions and 16 deletions

View File

@ -0,0 +1,15 @@
"use strict";
Handlebars.registerHelper('prettyAmount', function (amount) {
let v = amount.value + amount.fraction / 10e6;
return v.toFixed(2) + " " + amount.currency;
});
Handlebars.registerHelper('prettyAmountNoCurrency', function (amount) {
let v = amount.value + amount.fraction / 10e6;
return v.toFixed(2);
});
Handlebars.registerHelper('objectStringifier', function (o) {
return JSON.stringify(o);
});

View File

@ -5,6 +5,7 @@
<title>Taler Wallet: Confirm Reserve Creation</title>
<script src="../lib/URI.js"></script>
<script src="../lib/handlebars-v4.0.5.js"></script>
<script src="../lib/commonHelpers.js"></script>
<script src="confirm-contract.js"></script>
<link rel="stylesheet" type="text/css" href="../style/wallet.css">

View File

@ -6,14 +6,13 @@
<link rel="stylesheet" href="popup.css" type="text/css">
<script src="../lib/util.js" type="text/javascript"></script>
<script src="../lib/handlebars-v4.0.5.js"></script>
<script src="../lib/commonHelpers.js"></script>
<script src="balance-overview.js" type="text/javascript"></script>
<script id="balance-template" type="text/x-handlebars-template">
<div>
{{#each this}}
<p>{{this.value + this.fraction / 10e6 + <a> this.currency}}</a></p>
{{/each}}
</div>
{{#each this}}
<p>{{prettyAmountNoCurrency this}} <a>{{@key}}</a></p>
{{/each}}
</script>
</head>

View File

@ -19,16 +19,17 @@ document.addEventListener('DOMContentLoaded', (e) => {
chrome.runtime.sendMessage({ type: "balances" }, function (wallet) {
console.log("got balance");
let n = 0;
/*let table = <div />;*/
let table = React.createElement("div", null);
let source = document.getElementById("balance-template").innerHTML;
console.log("size", Object.keys(wallet).length);
if (Object.keys(wallet).length > 0) {
let template = Handlebars.compile(source);
console.log("DB error? ", chrome.runtime.lastError);
console.log("wallet ", JSON.stringify(wallet));
let html = template({ wallet: wallet, walletEmpty: wallet.length == 0 });
let html = template(wallet);
console.log("Hb generated html", html);
document.getElementById("content").innerHTML = html;
table.innerHTML = html;
let p = document.getElementById("content");
p.replaceChild(table, p.firstElementChild);
}
/*
for (let curr in wallet) {

View File

@ -21,17 +21,18 @@ document.addEventListener('DOMContentLoaded', (e) => {
chrome.runtime.sendMessage({type: "balances"}, function(wallet) {
console.log("got balance");
let n = 0;
/*let table = <div />;*/
let table = <div />;
let source = document.getElementById("balance-template").innerHTML;
console.log("size", Object.keys(wallet).length);
if (Object.keys(wallet).length > 0){
let template = Handlebars.compile(source);
console.log("DB error? ", chrome.runtime.lastError);
console.log("wallet ", JSON.stringify(wallet));
let html = template({wallet: wallet, walletEmpty: wallet.length == 0});
let html = template(wallet);
console.log("Hb generated html", html);
document.getElementById("content").innerHTML = html;
table.innerHTML = html;
let p = document.getElementById("content");
p.replaceChild(table, p.firstElementChild);
}
/*

View File

@ -8,7 +8,7 @@
<body>
<div id="header" class="nav">
<a href="wallet.html">Wallet</a>
<a href="balance-overview.html">Wallet</a>
<a href="transactions.html">Transactions</a>
<a href="reserves.html" class="active">Reserves</a>
</div>

View File

@ -10,7 +10,7 @@
<body>
<div id="header" class="nav">
<a href="wallet.html">Wallet</a>
<a href="balance-overview.html">Wallet</a>
<a href="transactions.html" class="active">Transactions</a>
<a href="reserves.html">Reserves</a>
</div>