aboutsummaryrefslogtreecommitdiff
path: root/extension/background/wallet.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2015-12-16 05:53:55 +0100
committerFlorian Dold <florian.dold@gmail.com>2015-12-16 05:53:55 +0100
commit331547059868a0e36acf5f2efac71ecbd1a96c8c (patch)
tree9dae9645110e7bcf3feb907876e7118256f76965 /extension/background/wallet.ts
parentccce0f9749f756fb4c681dc23d2386dc2f85dc6d (diff)
downloadwallet-core-331547059868a0e36acf5f2efac71ecbd1a96c8c.tar.xz
show badge
Diffstat (limited to 'extension/background/wallet.ts')
-rw-r--r--extension/background/wallet.ts33
1 files changed, 31 insertions, 2 deletions
diff --git a/extension/background/wallet.ts b/extension/background/wallet.ts
index a000855b6..d4dcec209 100644
--- a/extension/background/wallet.ts
+++ b/extension/background/wallet.ts
@@ -27,7 +27,7 @@ function openTalerDb(): Promise<IDBDatabase> {
db.createObjectStore("mints", { keyPath: "baseUrl" });
db.createObjectStore("reserves", { keyPath: "reserve_pub"});
db.createObjectStore("denoms", { keyPath: "denom_pub" });
- db.createObjectStore("coins", { keyPath: "coin_pub" });
+ db.createObjectStore("coins", { keyPath: "coinPub" });
db.createObjectStore("withdrawals", { keyPath: "id", autoIncrement: true });
db.createObjectStore("transactions", { keyPath: "id", autoIncrement: true });
db.createObjectStore("precoins", { keyPath: "coinPub", autoIncrement: true });
@@ -268,7 +268,34 @@ function withdrawExecute(db, pc: PreCoin): Promise<Coin> {
}
-function storeCoin(db, coin) {
+function updateBadge(db) {
+ let tx = db.transaction(['coins'], 'readwrite');
+ let req = tx.objectStore('coins').openCursor();
+ let n = 0;
+ req.onsuccess = (e) => {
+ let cursor = req.result;
+ if (cursor) {
+ n++;
+ cursor.continue();
+ } else {
+ console.log("badge");
+ chrome.browserAction.setBadgeText({text: ""+n});
+ chrome.browserAction.setBadgeBackgroundColor({color: "#0F0"});
+ }
+ }
+}
+
+
+function storeCoin(db, coin: Coin) {
+ let tx = db.transaction(['coins', 'precoins'], 'readwrite');
+ tx.objectStore('precoins').delete(coin.coinPub);
+ tx.objectStore('coins').add(coin);
+ return new Promise<void>((resolve, reject) => {
+ tx.oncomplete = (e) => {
+ resolve();
+ updateBadge(db);
+ }
+ });
}
@@ -424,6 +451,8 @@ function dumpDb(db, detail, sendResponse) {
}
+chrome.browserAction.setBadgeText({text: ""});
+
openTalerDb().then((db) => {
console.log("db loaded");
chrome.runtime.onMessage.addListener(