2016-01-10 20:07:42 +01:00
|
|
|
/*
|
|
|
|
This file is part of TALER
|
|
|
|
(C) 2016 GNUnet e.V.
|
|
|
|
|
|
|
|
TALER is free software; you can redistribute it and/or modify it under the
|
|
|
|
terms of the GNU General Public License as published by the Free Software
|
|
|
|
Foundation; either version 3, or (at your option) any later version.
|
|
|
|
|
|
|
|
TALER is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
|
|
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
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/>
|
|
|
|
*/
|
2016-02-17 15:56:48 +01:00
|
|
|
System.register(["./wallet", "./db", "./http", "./checkable"], function(exports_1, context_1) {
|
2016-01-10 20:07:42 +01:00
|
|
|
"use strict";
|
2016-02-10 02:03:31 +01:00
|
|
|
var __moduleName = context_1 && context_1.id;
|
2016-02-17 15:56:48 +01:00
|
|
|
var wallet_1, db_1, http_1, checkable_1;
|
2016-01-10 20:07:42 +01:00
|
|
|
var ChromeBadge;
|
2016-02-17 15:56:48 +01:00
|
|
|
function makeHandlers(db, wallet) {
|
2016-01-10 20:07:42 +01:00
|
|
|
return (_a = {},
|
2016-02-17 15:56:48 +01:00
|
|
|
_a["balances"] = function (detail) {
|
|
|
|
return wallet.getBalances();
|
2016-01-10 20:07:42 +01:00
|
|
|
},
|
2016-02-17 15:56:48 +01:00
|
|
|
_a["dump-db"] = function (detail) {
|
|
|
|
return db_1.exportDb(db);
|
2016-01-10 20:07:42 +01:00
|
|
|
},
|
2016-02-17 15:56:48 +01:00
|
|
|
_a["reset"] = function (detail) {
|
2016-01-10 20:07:42 +01:00
|
|
|
var tx = db.transaction(db.objectStoreNames, 'readwrite');
|
|
|
|
for (var i = 0; i < db.objectStoreNames.length; i++) {
|
|
|
|
tx.objectStore(db.objectStoreNames[i]).clear();
|
|
|
|
}
|
2016-02-10 02:03:31 +01:00
|
|
|
db_1.deleteDb();
|
2016-01-10 20:07:42 +01:00
|
|
|
chrome.browserAction.setBadgeText({ text: "" });
|
|
|
|
console.log("reset done");
|
|
|
|
// Response is synchronous
|
2016-02-17 15:56:48 +01:00
|
|
|
return Promise.resolve({});
|
2016-01-10 20:07:42 +01:00
|
|
|
},
|
2016-02-17 15:56:48 +01:00
|
|
|
_a["create-reserve"] = function (detail) {
|
2016-02-09 21:56:06 +01:00
|
|
|
var d = {
|
|
|
|
mint: detail.mint,
|
|
|
|
amount: detail.amount,
|
|
|
|
};
|
2016-02-10 02:03:31 +01:00
|
|
|
var req = wallet_1.CreateReserveRequest.checked(d);
|
2016-02-17 15:56:48 +01:00
|
|
|
return wallet.createReserve(req);
|
2016-02-09 21:56:06 +01:00
|
|
|
},
|
2016-02-17 15:56:48 +01:00
|
|
|
_a["confirm-reserve"] = function (detail) {
|
2016-01-10 20:07:42 +01:00
|
|
|
// TODO: make it a checkable
|
2016-02-09 21:56:06 +01:00
|
|
|
var d = {
|
|
|
|
reservePub: detail.reservePub
|
2016-01-10 20:07:42 +01:00
|
|
|
};
|
2016-02-10 02:03:31 +01:00
|
|
|
var req = wallet_1.ConfirmReserveRequest.checked(d);
|
2016-02-17 15:56:48 +01:00
|
|
|
return wallet.confirmReserve(req);
|
2016-01-10 20:07:42 +01:00
|
|
|
},
|
2016-02-17 15:56:48 +01:00
|
|
|
_a["confirm-pay"] = function (detail) {
|
|
|
|
var offer;
|
|
|
|
try {
|
|
|
|
offer = wallet_1.Offer.checked(detail.offer);
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
if (e instanceof checkable_1.Checkable.SchemaError) {
|
|
|
|
console.error("schema error:", e.message);
|
|
|
|
return Promise.resolve({ error: "invalid contract", hint: e.message });
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return wallet.confirmPay(offer);
|
2016-01-10 20:07:42 +01:00
|
|
|
},
|
2016-02-17 15:56:48 +01:00
|
|
|
_a["execute-payment"] = function (detail) {
|
|
|
|
return wallet.executePayment(detail.H_contract);
|
2016-01-10 20:07:42 +01:00
|
|
|
},
|
2016-02-17 15:56:48 +01:00
|
|
|
_a["get-history"] = function (detail) {
|
2016-01-24 02:29:13 +01:00
|
|
|
// TODO: limit history length
|
2016-02-17 15:56:48 +01:00
|
|
|
return wallet.getHistory();
|
2016-01-26 17:21:17 +01:00
|
|
|
},
|
2016-01-10 20:07:42 +01:00
|
|
|
_a
|
|
|
|
);
|
|
|
|
var _a;
|
|
|
|
}
|
2016-02-17 15:56:48 +01:00
|
|
|
function dispatch(handlers, db, req, sendResponse) {
|
|
|
|
if (req.type in handlers) {
|
|
|
|
Promise
|
|
|
|
.resolve()
|
|
|
|
.then(function () {
|
|
|
|
var p = handlers[req.type](db, req.detail);
|
|
|
|
return p.then(function (r) {
|
|
|
|
sendResponse(r);
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch(function (e) {
|
|
|
|
console.log("exception during wallet handler'");
|
|
|
|
console.error(e.stack);
|
|
|
|
sendResponse({
|
|
|
|
error: "exception",
|
|
|
|
hint: e.message,
|
|
|
|
stack: e.stack.toString()
|
|
|
|
});
|
|
|
|
});
|
|
|
|
// The sendResponse call is async
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
console.error("Request type " + JSON.stringify(req) + " unknown, req " + req.type);
|
|
|
|
sendResponse({ error: "request unknown" });
|
|
|
|
// The sendResponse call is sync
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2016-01-10 20:07:42 +01:00
|
|
|
function wxMain() {
|
|
|
|
chrome.browserAction.setBadgeText({ text: "" });
|
2016-02-17 15:56:48 +01:00
|
|
|
Promise.resolve()
|
|
|
|
.then(function () {
|
|
|
|
return db_1.openTalerDb();
|
|
|
|
})
|
|
|
|
.catch(function (e) {
|
|
|
|
console.error("could not open database");
|
|
|
|
console.error(e);
|
|
|
|
})
|
2016-01-24 02:29:13 +01:00
|
|
|
.then(function (db) {
|
2016-01-10 20:07:42 +01:00
|
|
|
var http = new http_1.BrowserHttpLib();
|
|
|
|
var badge = new ChromeBadge();
|
|
|
|
var wallet = new wallet_1.Wallet(db, http, badge);
|
2016-02-17 15:56:48 +01:00
|
|
|
var handlers = makeHandlers(db, wallet);
|
|
|
|
chrome.runtime.onMessage.addListener(function (req, sender, sendResponse) {
|
|
|
|
return dispatch(handlers, db, req, sendResponse);
|
2016-01-10 20:07:42 +01:00
|
|
|
});
|
2016-01-24 02:29:13 +01:00
|
|
|
})
|
|
|
|
.catch(function (e) {
|
2016-02-17 15:56:48 +01:00
|
|
|
console.error("could not initialize wallet messaging");
|
|
|
|
console.error(e);
|
2016-01-10 20:07:42 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
exports_1("wxMain", wxMain);
|
|
|
|
return {
|
|
|
|
setters:[
|
|
|
|
function (wallet_1_1) {
|
|
|
|
wallet_1 = wallet_1_1;
|
|
|
|
},
|
|
|
|
function (db_1_1) {
|
|
|
|
db_1 = db_1_1;
|
|
|
|
},
|
|
|
|
function (http_1_1) {
|
|
|
|
http_1 = http_1_1;
|
2016-02-17 15:56:48 +01:00
|
|
|
},
|
|
|
|
function (checkable_1_1) {
|
|
|
|
checkable_1 = checkable_1_1;
|
2016-01-10 20:07:42 +01:00
|
|
|
}],
|
|
|
|
execute: function() {
|
|
|
|
"use strict";
|
|
|
|
ChromeBadge = (function () {
|
|
|
|
function ChromeBadge() {
|
|
|
|
}
|
|
|
|
ChromeBadge.prototype.setText = function (s) {
|
|
|
|
chrome.browserAction.setBadgeText({ text: s });
|
|
|
|
};
|
|
|
|
ChromeBadge.prototype.setColor = function (c) {
|
|
|
|
chrome.browserAction.setBadgeBackgroundColor({ color: c });
|
|
|
|
};
|
|
|
|
return ChromeBadge;
|
|
|
|
}());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
//# sourceMappingURL=wxmessaging.js.map
|