aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2016-03-02 00:47:00 +0100
committerFlorian Dold <florian.dold@gmail.com>2016-03-02 00:49:10 +0100
commit7c03db9ba0fcbf10da8fc37ff55b6d987aab8541 (patch)
tree396ad80cf28680ff1fe21a9fb60ec4b190899464 /lib
parentff3cea6b64704af2af824b074eadd32a00d2e72e (diff)
downloadwallet-core-7c03db9ba0fcbf10da8fc37ff55b6d987aab8541.tar.xz
db versioning
Diffstat (limited to 'lib')
-rw-r--r--lib/wallet/db.ts14
-rw-r--r--lib/wallet/wallet.ts7
-rw-r--r--lib/wallet/wxMessaging.ts8
3 files changed, 22 insertions, 7 deletions
diff --git a/lib/wallet/db.ts b/lib/wallet/db.ts
index 2503468d5..9374aa447 100644
--- a/lib/wallet/db.ts
+++ b/lib/wallet/db.ts
@@ -25,7 +25,7 @@
*/
const DB_NAME = "taler";
-const DB_VERSION = 1;
+const DB_VERSION = 5;
/**
* Return a promise that resolves
@@ -45,7 +45,8 @@ export function openTalerDb(): Promise<IDBDatabase> {
console.log("DB: upgrade needed: oldVersion = " + e.oldVersion);
switch (e.oldVersion) {
case 0: // DB does not exist yet
- const exchanges = db.createObjectStore("exchanges", {keyPath: "baseUrl"});
+ const exchanges = db.createObjectStore("exchanges",
+ {keyPath: "baseUrl"});
exchanges.createIndex("pubKey", "masterPublicKey");
db.createObjectStore("reserves", {keyPath: "reserve_pub"});
db.createObjectStore("denoms", {keyPath: "denomPub"});
@@ -68,6 +69,15 @@ export function openTalerDb(): Promise<IDBDatabase> {
});
history.createIndex("timestamp", "timestamp");
break;
+ default:
+ if (e.oldVersion != DB_VERSION) {
+ window.alert("Incompatible wallet dababase version, please reset" +
+ " db.");
+ chrome.browserAction.setBadgeText({text: "R!"});
+ chrome.browserAction.setBadgeBackgroundColor({color: "#F00"});
+ throw Error("incompatible DB");
+ }
+ break;
}
};
});
diff --git a/lib/wallet/wallet.ts b/lib/wallet/wallet.ts
index 94ac8ee8a..3764edfbc 100644
--- a/lib/wallet/wallet.ts
+++ b/lib/wallet/wallet.ts
@@ -912,7 +912,10 @@ export class Wallet {
return Query(this.db)
.iter("coins")
- .reduce(collectBalances, {});
+ .reduce(collectBalances, {})
+ .then(byCurrency => {
+ return {balances: byCurrency};
+ });
}
@@ -922,7 +925,7 @@ export class Wallet {
getHistory(): Promise<any[]> {
function collect(x, acc) {
acc.push(x);
- return acc;
+ return {history: acc};
}
return Query(this.db)
diff --git a/lib/wallet/wxMessaging.ts b/lib/wallet/wxMessaging.ts
index a6b3f9d1b..d49a80efb 100644
--- a/lib/wallet/wxMessaging.ts
+++ b/lib/wallet/wxMessaging.ts
@@ -47,9 +47,11 @@ function makeHandlers(db: IDBDatabase,
return exportDb(db);
},
["reset"]: function(detail) {
- let tx = db.transaction(db.objectStoreNames, 'readwrite');
- for (let i = 0; i < db.objectStoreNames.length; i++) {
- tx.objectStore(db.objectStoreNames[i]).clear();
+ if (db) {
+ let tx = db.transaction(db.objectStoreNames, 'readwrite');
+ for (let i = 0; i < db.objectStoreNames.length; i++) {
+ tx.objectStore(db.objectStoreNames[i]).clear();
+ }
}
deleteDb();