diff options
author | Florian Dold <florian.dold@gmail.com> | 2016-01-05 15:42:46 +0100 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2016-01-05 15:42:46 +0100 |
commit | 3bf1846ed81b7c137a3d751400a74546f502a37b (patch) | |
tree | 6ad34a806865b9e15c572755e08b612f394477e5 /extension | |
parent | b459ffb4241877670fb7f820a67d959fec2d995c (diff) | |
download | wallet-core-3bf1846ed81b7c137a3d751400a74546f502a37b.tar.xz |
fix query abstraction
Diffstat (limited to 'extension')
-rw-r--r-- | extension/background/db.ts | 2 | ||||
-rw-r--r-- | extension/background/emscriptif.js | 6 | ||||
-rw-r--r-- | extension/background/emscriptif.ts | 8 | ||||
-rw-r--r-- | extension/background/http.ts | 8 | ||||
-rw-r--r-- | extension/background/messaging.ts | 4 | ||||
-rw-r--r-- | extension/background/query.ts | 16 | ||||
-rw-r--r-- | extension/background/wallet.js | 15 | ||||
-rw-r--r-- | extension/background/wallet.ts | 19 | ||||
-rw-r--r-- | extension/tsconfig.json | 3 |
9 files changed, 63 insertions, 18 deletions
diff --git a/extension/background/db.ts b/extension/background/db.ts index 1dd399907..df24e1471 100644 --- a/extension/background/db.ts +++ b/extension/background/db.ts @@ -20,6 +20,8 @@ * Declarations and helpers for * things that are stored in the wallet's * database. + * @module Db + * @author Florian Dold */ diff --git a/extension/background/emscriptif.js b/extension/background/emscriptif.js index 83bf8b5bb..6cf22420e 100644 --- a/extension/background/emscriptif.js +++ b/extension/background/emscriptif.js @@ -13,6 +13,12 @@ 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/> */ +/** + * High-level interface to emscripten-compiled modules used + * by the wallet. + * @module EmscriptIf + * @author Florian Dold + */ "use strict"; // Size of a native pointer. const PTR_SIZE = 4; diff --git a/extension/background/emscriptif.ts b/extension/background/emscriptif.ts index 46937d088..0e35bc9b1 100644 --- a/extension/background/emscriptif.ts +++ b/extension/background/emscriptif.ts @@ -14,6 +14,14 @@ TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/> */ +/** + * High-level interface to emscripten-compiled modules used + * by the wallet. + * @module EmscriptIf + * @author Florian Dold + */ + + "use strict"; declare var Module: EmscModule; diff --git a/extension/background/http.ts b/extension/background/http.ts index 9a064e974..9355add6f 100644 --- a/extension/background/http.ts +++ b/extension/background/http.ts @@ -14,6 +14,12 @@ TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/> */ +/** + * Helpers for doing XMLHttpRequest-s that are based on ES6 promises. + * @module Http + * @author Florian Dold + */ + "use strict"; interface HttpResponse { @@ -37,6 +43,8 @@ function httpReq(method: string, myRequest.open(method, urlString); if (options && options.req) { myRequest.send(options.req); + } else { + myRequest.send(); } myRequest.addEventListener("readystatechange", (e) => { if (myRequest.readyState == XMLHttpRequest.DONE) { diff --git a/extension/background/messaging.ts b/extension/background/messaging.ts index fc513bd04..4bd5ec24e 100644 --- a/extension/background/messaging.ts +++ b/extension/background/messaging.ts @@ -34,7 +34,7 @@ let handlers = { exportDb(db).then(sendResponse); return true; }, - ["reset-db"]: function(db, detail, sendResponse) { + ["reset"]: function(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(); @@ -47,7 +47,7 @@ let handlers = { }, ["confirm-reserve"]: function(db, detail, sendResponse) { return confirmReserveHandler(db, detail, sendResponse); - } + }, }; diff --git a/extension/background/query.ts b/extension/background/query.ts index 1a61c66ca..75201c2d4 100644 --- a/extension/background/query.ts +++ b/extension/background/query.ts @@ -187,7 +187,7 @@ class QueryRoot { function doPut() { this.tx.objectStore(storeName).put(val); } - this.work.push(doPut); + this.work.push(doPut.bind(this)); return this; } @@ -198,7 +198,7 @@ class QueryRoot { this.tx.objectStore(storeName).put(obj); } } - this.work.push(doPutAll); + this.work.push(doPutAll.bind(this)); return this; } @@ -207,7 +207,7 @@ class QueryRoot { function doAdd() { this.tx.objectStore(storeName).add(val); } - this.work.push(doAdd); + this.work.push(doAdd.bind(this)); return this; } @@ -224,11 +224,13 @@ class QueryRoot { function doGet() { let req = this.tx.objectStore(storeName).get(key); req.onsuccess = (r) => { - leakedResolve(r); + leakedResolve(req.result); }; } - this.work.push(doGet); - return p; + this.work.push(doGet.bind(this)); + return Promise.resolve().then(() => { + return this.finish().then(() => p); + }); } finish(): Promise<void> { @@ -253,7 +255,7 @@ class QueryRoot { function doDelete() { this.tx.objectStore(storeName).delete(key); } - this.work.push(doDelete); + this.work.push(doDelete.bind(this)); return this; } }
\ No newline at end of file diff --git a/extension/background/wallet.js b/extension/background/wallet.js index 971da7195..beb66c57a 100644 --- a/extension/background/wallet.js +++ b/extension/background/wallet.js @@ -13,6 +13,12 @@ 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/> */ +/** + * High-level wallet operations that should be indepentent from the underlying + * browser extension interface. + * @module Wallet + * @author Florian Dold + */ /// <reference path="../decl/urijs/URIjs.d.ts" /> /// <reference path="../decl/chrome/chrome.d.ts" /> 'use strict'; @@ -247,12 +253,13 @@ function confirmReserveHandler(db, detail, sendResponse) { .then(() => { // Do this in the background updateMintFromUrl(db, reserveRecord.mint_base_url) - .then((mint) => { - updateReserve(db, reservePub, mint) - .then((reserve) => depleteReserve(db, reserve, mint)); - }); + .then((mint) => updateReserve(db, reservePub, mint) + .then((reserve) => depleteReserve(db, reserve, mint))); return resp; }); + }) + .then((resp) => { + sendResponse(resp); }); // Allow async response return true; diff --git a/extension/background/wallet.ts b/extension/background/wallet.ts index b3593f682..6231baad0 100644 --- a/extension/background/wallet.ts +++ b/extension/background/wallet.ts @@ -14,6 +14,14 @@ TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/> */ +/** + * High-level wallet operations that should be indepentent from the underlying + * browser extension interface. + * @module Wallet + * @author Florian Dold + */ + + /// <reference path="../decl/urijs/URIjs.d.ts" /> /// <reference path="../decl/chrome/chrome.d.ts" /> 'use strict'; @@ -364,12 +372,15 @@ function confirmReserveHandler(db, detail, sendResponse) { .then(() => { // Do this in the background updateMintFromUrl(db, reserveRecord.mint_base_url) - .then((mint) => { + .then((mint) => updateReserve(db, reservePub, mint) - .then((reserve) => depleteReserve(db, reserve, mint)); - }); + .then((reserve) => depleteReserve(db, reserve, mint)) + ); return resp; }); + }) + .then((resp) => { + sendResponse(resp); }); // Allow async response @@ -516,7 +527,7 @@ function withdraw(db, denom, reserve): Promise<void> { /** * Withdraw coins from a reserve until it is empty. */ -function depleteReserve(db, reserve, mint) { +function depleteReserve(db, reserve, mint): void { let denoms = copy(mint.keys.denoms); let remaining = new Amount(reserve.current_amount); denoms.sort(rankDenom); diff --git a/extension/tsconfig.json b/extension/tsconfig.json index 2b88688d9..2d166debd 100644 --- a/extension/tsconfig.json +++ b/extension/tsconfig.json @@ -1,7 +1,8 @@ { "compilerOptions": { "target": "es6", - "jsx": "react" + "jsx": "react", + "experimentalDecorators": true }, "files": [ "background/wallet.ts", |