aboutsummaryrefslogtreecommitdiff
path: root/extension/background/wallet.js
diff options
context:
space:
mode:
Diffstat (limited to 'extension/background/wallet.js')
-rw-r--r--extension/background/wallet.js57
1 files changed, 54 insertions, 3 deletions
diff --git a/extension/background/wallet.js b/extension/background/wallet.js
index 1cf180434..e5740e3b8 100644
--- a/extension/background/wallet.js
+++ b/extension/background/wallet.js
@@ -23,7 +23,7 @@ function openTalerDb() {
case 0:
db.createObjectStore("mints", { keyPath: "baseUrl" });
db.createObjectStore("reserves", { keyPath: "reserve_pub" });
- db.createObjectStore("denoms", { keyPath: "denom_pub" });
+ db.createObjectStore("denoms", { keyPath: "denomPub" });
db.createObjectStore("coins", { keyPath: "coinPub" });
db.createObjectStore("withdrawals", { keyPath: "id", autoIncrement: true });
db.createObjectStore("transactions", { keyPath: "id", autoIncrement: true });
@@ -343,8 +343,16 @@ function updateMintFromUrl(db, baseUrl) {
baseUrl: baseUrl,
keys: mintKeysJson
};
- let tx = db.transaction(['mints'], 'readwrite');
+ let tx = db.transaction(['mints', 'denoms'], 'readwrite');
tx.objectStore('mints').put(mint);
+ for (let d of mintKeysJson.denoms) {
+ // TODO: verify and complete
+ let di = {
+ denomPub: d.denom_pub,
+ value: d.value
+ };
+ tx.objectStore('denoms').put(di);
+ }
tx.oncomplete = (e) => {
resolve(mint);
};
@@ -384,13 +392,56 @@ function dumpDb(db, detail, sendResponse) {
}
return true;
}
+function reset(db, detail, sendResponse) {
+ let tx = db.transaction(db.objectStoreNames, 'readwrite');
+ for (let i = 0; i < db.objectStoreNames.length; i++) {
+ tx.objectStore(db.objectStoreNames[i]).clear();
+ }
+ indexedDB.deleteDatabase(DB_NAME);
+ console.log("reset done");
+ return false;
+}
+function balances(db, detail, sendResponse) {
+ let byCurrency = {};
+ let tx = db.transaction(['coins', 'denoms']);
+ let req = tx.objectStore('coins').openCursor();
+ req.onsuccess = (e) => {
+ let cursor = req.result;
+ if (cursor) {
+ tx.objectStore('denoms').get(cursor.value.denomPub).onsuccess = (e2) => {
+ let d = e2.target.result;
+ console.log("got denom", JSON.stringify(d));
+ let acc = byCurrency[d.value.currency];
+ if (!acc) {
+ acc = new Amount(d.value);
+ console.log("initial:", JSON.stringify(acc.toJson()));
+ byCurrency[d.value.currency] = acc.toJson();
+ }
+ else {
+ let am = new Amount(acc);
+ am.add(new Amount(d.value));
+ byCurrency[d.value.currency] = am.toJson();
+ console.log("then:", JSON.stringify(am.toJson()));
+ }
+ };
+ cursor.continue();
+ }
+ else {
+ sendResponse(byCurrency);
+ console.log("response", JSON.stringify(byCurrency));
+ }
+ };
+ return true;
+}
chrome.browserAction.setBadgeText({ text: "" });
openTalerDb().then((db) => {
console.log("db loaded");
chrome.runtime.onMessage.addListener(function (req, sender, onresponse) {
let dispatch = {
"confirm-reserve": confirmReserve,
- "dump-db": dumpDb
+ "dump-db": dumpDb,
+ "balances": balances,
+ "reset": reset
};
if (req.type in dispatch) {
return dispatch[req.type](db, req.detail, onresponse);