diff options
Diffstat (limited to 'extension/lib')
-rw-r--r-- | extension/lib/wallet/types.ts | 4 | ||||
-rw-r--r-- | extension/lib/wallet/wallet.ts | 15 | ||||
-rw-r--r-- | extension/lib/wallet/wxmessaging.ts | 31 |
3 files changed, 45 insertions, 5 deletions
diff --git a/extension/lib/wallet/types.ts b/extension/lib/wallet/types.ts index fd4ca8b01..3b0cb2638 100644 --- a/extension/lib/wallet/types.ts +++ b/extension/lib/wallet/types.ts @@ -105,4 +105,8 @@ export interface ReserveCreationInfo { mintInfo: IMintInfo; selectedDenoms: Denomination[]; withdrawFee: AmountJson; +} + +export interface Notifier { + notify(); }
\ No newline at end of file diff --git a/extension/lib/wallet/wallet.ts b/extension/lib/wallet/wallet.ts index eca937ff1..2d4a29c8d 100644 --- a/extension/lib/wallet/wallet.ts +++ b/extension/lib/wallet/wallet.ts @@ -22,7 +22,7 @@ */ import * as native from "./emscriptif"; -import {AmountJson, CreateReserveResponse, IMintInfo, Denomination} from "./types"; +import {AmountJson, CreateReserveResponse, IMintInfo, Denomination, Notifier} from "./types"; import {HttpResponse, RequestException} from "./http"; import {Query} from "./query"; import {Checkable} from "./checkable"; @@ -492,12 +492,17 @@ export class Wallet { private db: IDBDatabase; private http: HttpRequestLibrary; private badge: Badge; + private notifier: Notifier; - constructor(db: IDBDatabase, http: HttpRequestLibrary, badge: Badge) { + constructor(db: IDBDatabase, + http: HttpRequestLibrary, + badge: Badge, + notifier: Notifier) { this.db = db; this.http = http; this.badge = badge; + this.notifier = notifier; } @@ -687,7 +692,8 @@ export class Wallet { .put("transactions", t) .put("history", historyEntry) .putAll("coins", payCoinInfo.map((pci) => pci.updatedCoin)) - .finish(); + .finish() + .then(() => { this.notifier.notify(); }); } @@ -896,7 +902,8 @@ export class Wallet { .delete("precoins", coin.coinPub) .add("coins", coin) .add("history", historyEntry) - .finish(); + .finish() + .then(() => { this.notifier.notify(); }); } diff --git a/extension/lib/wallet/wxmessaging.ts b/extension/lib/wallet/wxmessaging.ts index 1267167d2..fc99a2054 100644 --- a/extension/lib/wallet/wxmessaging.ts +++ b/extension/lib/wallet/wxmessaging.ts @@ -20,6 +20,8 @@ import {deleteDb, exportDb, openTalerDb} from "./db"; import {BrowserHttpLib} from "./http"; import {Checkable} from "./checkable"; import {AmountJson} from "./types"; +import Port = chrome.runtime.Port; +import {Notifier} from "./types"; "use strict"; @@ -155,6 +157,32 @@ function dispatch(handlers, req, sendResponse) { } } +class ChromeNotifier implements Notifier { + ports: Port[] = []; + + constructor() { + chrome.runtime.onConnect.addListener((port) => { + console.log("got connect!"); + this.ports.push(port); + port.onDisconnect.addListener(() => { + let i = this.ports.indexOf(port); + if (i >= 0) { + this.ports.splice(i, 1); + } else { + console.error("port already removed"); + } + }); + }); + } + + notify() { + console.log("notifying all ports"); + for (let p of this.ports) { + p.postMessage({notify: true}); + } + } +} + export function wxMain() { chrome.browserAction.setBadgeText({text: ""}); @@ -170,7 +198,8 @@ export function wxMain() { .then((db) => { let http = new BrowserHttpLib(); let badge = new ChromeBadge(); - let wallet = new Wallet(db, http, badge); + let notifier = new ChromeNotifier(); + let wallet = new Wallet(db, http, badge, notifier); let handlers = makeHandlers(db, wallet); chrome.runtime.onMessage.addListener((req, sender, sendResponse) => { try { |