2015-12-25 22:42:14 +01:00
|
|
|
/*
|
|
|
|
This file is part of TALER
|
|
|
|
(C) 2015 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
|
2016-07-07 17:59:29 +02:00
|
|
|
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
|
2015-12-25 22:42:14 +01:00
|
|
|
*/
|
|
|
|
|
2016-03-01 19:46:20 +01:00
|
|
|
/**
|
|
|
|
* Page shown to the user to confirm entering
|
|
|
|
* a contract.
|
|
|
|
*
|
|
|
|
* @author Florian Dold
|
|
|
|
*/
|
|
|
|
|
2015-12-16 10:45:16 +01:00
|
|
|
|
2016-03-02 02:16:18 +01:00
|
|
|
/// <reference path="../lib/decl/handlebars/handlebars.d.ts" />
|
|
|
|
import MithrilComponent = _mithril.MithrilComponent;
|
2016-02-11 11:29:57 +01:00
|
|
|
import {substituteFulfillmentUrl} from "../lib/wallet/helpers";
|
2016-03-02 02:16:18 +01:00
|
|
|
import m from "mithril";
|
2016-09-12 20:25:56 +02:00
|
|
|
import {Contract, AmountJson} from "../lib/wallet/types";
|
2016-09-29 16:31:55 +02:00
|
|
|
import {renderContract, prettyAmount} from "../lib/wallet/renderHtml";
|
2016-03-02 02:16:18 +01:00
|
|
|
"use strict";
|
2015-12-16 10:45:16 +01:00
|
|
|
|
2016-03-02 02:16:18 +01:00
|
|
|
const Details = {
|
|
|
|
controller() {
|
|
|
|
return {collapsed: m.prop(true)};
|
|
|
|
},
|
2016-09-12 20:25:56 +02:00
|
|
|
view(ctrl: any, contract: Contract) {
|
2016-03-02 02:16:18 +01:00
|
|
|
if (ctrl.collapsed()) {
|
|
|
|
return m("div", [
|
|
|
|
m("button.linky", {
|
|
|
|
onclick: () => {
|
|
|
|
ctrl.collapsed(false);
|
|
|
|
}
|
|
|
|
}, "show more details")
|
|
|
|
]);
|
|
|
|
} else {
|
|
|
|
return m("div", [
|
|
|
|
m("button.linky", {
|
|
|
|
onclick: () => {
|
|
|
|
ctrl.collapsed(true);
|
|
|
|
}
|
|
|
|
}, "show less details"),
|
|
|
|
m("div", [
|
|
|
|
"Accepted exchanges:",
|
2016-10-03 17:43:51 +02:00
|
|
|
m("ul",
|
|
|
|
contract.exchanges.map(e => m("li", `${e.url}: ${e.master_pub}`)))
|
2016-03-02 02:16:18 +01:00
|
|
|
])
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-01-26 17:21:17 +01:00
|
|
|
export function main() {
|
|
|
|
let url = URI(document.location.href);
|
|
|
|
let query: any = URI.parseQuery(url.query());
|
2015-12-17 13:30:34 +01:00
|
|
|
let offer = JSON.parse(query.offer);
|
|
|
|
console.dir(offer);
|
2016-01-26 17:21:17 +01:00
|
|
|
let contract = offer.contract;
|
2016-09-12 20:25:56 +02:00
|
|
|
let error: string|null = null;
|
2016-04-27 06:03:04 +02:00
|
|
|
let payDisabled = true;
|
2016-01-26 17:21:17 +01:00
|
|
|
|
|
|
|
var Contract = {
|
2016-09-12 20:25:56 +02:00
|
|
|
view(ctrl: any) {
|
2016-01-26 17:21:17 +01:00
|
|
|
return [
|
2016-09-29 16:31:55 +02:00
|
|
|
renderContract(contract),
|
2016-10-03 17:43:51 +02:00
|
|
|
m("button.accept",
|
|
|
|
{onclick: doPayment, disabled: payDisabled},
|
|
|
|
i18n`Confirm Payment`),
|
2016-04-27 06:03:04 +02:00
|
|
|
(error ? m("p.errorbox", error) : []),
|
2016-03-02 02:16:18 +01:00
|
|
|
m(Details, contract)
|
2016-01-26 17:21:17 +01:00
|
|
|
];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-09-14 15:55:10 +02:00
|
|
|
m.mount(document.getElementById("contract")!, Contract);
|
2016-01-26 17:21:17 +01:00
|
|
|
|
2016-04-27 06:03:04 +02:00
|
|
|
function checkPayment() {
|
|
|
|
chrome.runtime.sendMessage({type: 'check-pay', detail: {offer}}, (resp) => {
|
|
|
|
if (resp.error) {
|
|
|
|
console.log("check-pay error", JSON.stringify(resp));
|
|
|
|
switch (resp.error) {
|
|
|
|
case "coins-insufficient":
|
2016-10-03 17:43:51 +02:00
|
|
|
error = i18n`You have insufficient funds of the requested currency in your wallet.`;
|
2016-04-27 06:03:04 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error = `Error: ${resp.error}`;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
payDisabled = true;
|
|
|
|
} else {
|
|
|
|
payDisabled = false;
|
|
|
|
error = null;
|
|
|
|
}
|
|
|
|
m.redraw();
|
|
|
|
window.setTimeout(checkPayment, 300);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
checkPayment();
|
|
|
|
|
|
|
|
|
2016-01-26 17:21:17 +01:00
|
|
|
function doPayment() {
|
2016-02-15 15:53:59 +01:00
|
|
|
let d = {offer};
|
2016-01-26 17:21:17 +01:00
|
|
|
chrome.runtime.sendMessage({type: 'confirm-pay', detail: d}, (resp) => {
|
2016-02-15 15:53:59 +01:00
|
|
|
if (resp.error) {
|
2016-01-26 17:21:17 +01:00
|
|
|
console.log("confirm-pay error", JSON.stringify(resp));
|
2016-02-15 15:53:59 +01:00
|
|
|
switch (resp.error) {
|
|
|
|
case "coins-insufficient":
|
|
|
|
error = "You do not have enough coins of the requested currency.";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error = `Error: ${resp.error}`;
|
|
|
|
break;
|
|
|
|
}
|
2016-02-01 15:10:20 +01:00
|
|
|
m.redraw();
|
2015-12-17 22:56:24 +01:00
|
|
|
return;
|
2015-12-16 10:45:16 +01:00
|
|
|
}
|
2016-01-26 17:21:17 +01:00
|
|
|
let c = d.offer.contract;
|
|
|
|
console.log("contract", c);
|
2016-02-15 15:53:59 +01:00
|
|
|
document.location.href = substituteFulfillmentUrl(c.fulfillment_url,
|
|
|
|
offer);
|
2015-12-16 10:45:16 +01:00
|
|
|
});
|
2016-01-26 17:21:17 +01:00
|
|
|
}
|
2016-03-01 19:46:20 +01:00
|
|
|
}
|