db versioning
This commit is contained in:
parent
ff3cea6b64
commit
7c03db9ba0
@ -13,12 +13,14 @@
|
|||||||
You should have received a copy of the GNU General Public License along with
|
You should have received a copy of the GNU General Public License along with
|
||||||
TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
|
TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
|
||||||
*/
|
*/
|
||||||
/// <reference path="../lib/decl/chrome/chrome.d.ts" />
|
|
||||||
"use strict";
|
|
||||||
/**
|
/**
|
||||||
* Script that is injected into (all!) pages to allow them
|
* Script that is injected into (all!) pages to allow them
|
||||||
* to interact with the GNU Taler wallet via DOM Events.
|
* to interact with the GNU Taler wallet via DOM Events.
|
||||||
|
*
|
||||||
|
* @author Florian Dold
|
||||||
*/
|
*/
|
||||||
|
/// <reference path="../lib/decl/chrome/chrome.d.ts" />
|
||||||
|
"use strict";
|
||||||
// Make sure we don't pollute the namespace too much.
|
// Make sure we don't pollute the namespace too much.
|
||||||
var TalerNotify;
|
var TalerNotify;
|
||||||
(function (TalerNotify) {
|
(function (TalerNotify) {
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
const DB_NAME = "taler";
|
const DB_NAME = "taler";
|
||||||
const DB_VERSION = 1;
|
const DB_VERSION = 5;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a promise that resolves
|
* Return a promise that resolves
|
||||||
@ -45,7 +45,8 @@ export function openTalerDb(): Promise<IDBDatabase> {
|
|||||||
console.log("DB: upgrade needed: oldVersion = " + e.oldVersion);
|
console.log("DB: upgrade needed: oldVersion = " + e.oldVersion);
|
||||||
switch (e.oldVersion) {
|
switch (e.oldVersion) {
|
||||||
case 0: // DB does not exist yet
|
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");
|
exchanges.createIndex("pubKey", "masterPublicKey");
|
||||||
db.createObjectStore("reserves", {keyPath: "reserve_pub"});
|
db.createObjectStore("reserves", {keyPath: "reserve_pub"});
|
||||||
db.createObjectStore("denoms", {keyPath: "denomPub"});
|
db.createObjectStore("denoms", {keyPath: "denomPub"});
|
||||||
@ -68,6 +69,15 @@ export function openTalerDb(): Promise<IDBDatabase> {
|
|||||||
});
|
});
|
||||||
history.createIndex("timestamp", "timestamp");
|
history.createIndex("timestamp", "timestamp");
|
||||||
break;
|
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;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
@ -912,7 +912,10 @@ export class Wallet {
|
|||||||
|
|
||||||
return Query(this.db)
|
return Query(this.db)
|
||||||
.iter("coins")
|
.iter("coins")
|
||||||
.reduce(collectBalances, {});
|
.reduce(collectBalances, {})
|
||||||
|
.then(byCurrency => {
|
||||||
|
return {balances: byCurrency};
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -922,7 +925,7 @@ export class Wallet {
|
|||||||
getHistory(): Promise<any[]> {
|
getHistory(): Promise<any[]> {
|
||||||
function collect(x, acc) {
|
function collect(x, acc) {
|
||||||
acc.push(x);
|
acc.push(x);
|
||||||
return acc;
|
return {history: acc};
|
||||||
}
|
}
|
||||||
|
|
||||||
return Query(this.db)
|
return Query(this.db)
|
||||||
|
@ -47,10 +47,12 @@ function makeHandlers(db: IDBDatabase,
|
|||||||
return exportDb(db);
|
return exportDb(db);
|
||||||
},
|
},
|
||||||
["reset"]: function(detail) {
|
["reset"]: function(detail) {
|
||||||
|
if (db) {
|
||||||
let tx = db.transaction(db.objectStoreNames, 'readwrite');
|
let tx = db.transaction(db.objectStoreNames, 'readwrite');
|
||||||
for (let i = 0; i < db.objectStoreNames.length; i++) {
|
for (let i = 0; i < db.objectStoreNames.length; i++) {
|
||||||
tx.objectStore(db.objectStoreNames[i]).clear();
|
tx.objectStore(db.objectStoreNames[i]).clear();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
deleteDb();
|
deleteDb();
|
||||||
|
|
||||||
chrome.browserAction.setBadgeText({text: ""});
|
chrome.browserAction.setBadgeText({text: ""});
|
||||||
|
@ -95,6 +95,7 @@ namespace WalletBalance {
|
|||||||
|
|
||||||
class Controller {
|
class Controller {
|
||||||
myWallet;
|
myWallet;
|
||||||
|
gotError = false;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.updateBalance();
|
this.updateBalance();
|
||||||
@ -104,9 +105,16 @@ namespace WalletBalance {
|
|||||||
|
|
||||||
updateBalance() {
|
updateBalance() {
|
||||||
m.startComputation();
|
m.startComputation();
|
||||||
chrome.runtime.sendMessage({type: "balances"}, (wallet) => {
|
chrome.runtime.sendMessage({type: "balances"}, (resp) => {
|
||||||
console.log("got wallet", wallet);
|
if (resp.error) {
|
||||||
this.myWallet = wallet;
|
this.gotError = true;
|
||||||
|
console.error("could not retrieve balances", resp);
|
||||||
|
m.endComputation();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.gotError = false;
|
||||||
|
console.log("got wallet", resp);
|
||||||
|
this.myWallet = resp.balances;
|
||||||
m.endComputation();
|
m.endComputation();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -114,6 +122,9 @@ namespace WalletBalance {
|
|||||||
|
|
||||||
export function view(ctrl: Controller) {
|
export function view(ctrl: Controller) {
|
||||||
let wallet = ctrl.myWallet;
|
let wallet = ctrl.myWallet;
|
||||||
|
if (ctrl.gotError) {
|
||||||
|
return i18n`Error: could not retrieve balance information.`;
|
||||||
|
}
|
||||||
if (!wallet) {
|
if (!wallet) {
|
||||||
throw Error("Could not retrieve wallet");
|
throw Error("Could not retrieve wallet");
|
||||||
}
|
}
|
||||||
@ -200,6 +211,7 @@ namespace WalletHistory {
|
|||||||
|
|
||||||
class Controller {
|
class Controller {
|
||||||
myHistory;
|
myHistory;
|
||||||
|
gotError = false;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.update();
|
this.update();
|
||||||
@ -209,8 +221,15 @@ namespace WalletHistory {
|
|||||||
update() {
|
update() {
|
||||||
m.startComputation();
|
m.startComputation();
|
||||||
chrome.runtime.sendMessage({type: "get-history"}, (resp) => {
|
chrome.runtime.sendMessage({type: "get-history"}, (resp) => {
|
||||||
console.log("got history", history);
|
if (resp.error) {
|
||||||
this.myHistory = resp;
|
this.gotError = true;
|
||||||
|
console.error("could not retrieve history", resp);
|
||||||
|
m.endComputation();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.gotError = false;
|
||||||
|
console.log("got history", resp.history);
|
||||||
|
this.myHistory = resp.history;
|
||||||
m.endComputation();
|
m.endComputation();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -218,6 +237,9 @@ namespace WalletHistory {
|
|||||||
|
|
||||||
export function view(ctrl: Controller) {
|
export function view(ctrl: Controller) {
|
||||||
let history = ctrl.myHistory;
|
let history = ctrl.myHistory;
|
||||||
|
if (ctrl.gotError) {
|
||||||
|
return i18n`Error: could not retrieve event history`;
|
||||||
|
}
|
||||||
if (!history) {
|
if (!history) {
|
||||||
throw Error("Could not retrieve history");
|
throw Error("Could not retrieve history");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user