2015-12-16 10:45:16 +01:00
|
|
|
/// <reference path="../decl/handlebars/handlebars.d.ts" />
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
let url = URI(document.location.href);
|
|
|
|
let query: any = URI.parseQuery(url.query());
|
|
|
|
|
|
|
|
let $_ = (x) => document.getElementById(x);
|
|
|
|
|
|
|
|
function renderContract(contract) {
|
|
|
|
let showAmount = document.getElementById("show-amount");
|
|
|
|
$_('merchant-name').innerText = contract.merchant.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
function clone(obj) {
|
|
|
|
// This is faster than it looks ...
|
|
|
|
return JSON.parse(JSON.stringify(obj));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handlebars.registerHelper('prettyAmount', function(amount) {
|
|
|
|
let v = amount.value + amount.fraction / 10e6;
|
|
|
|
return v.toFixed(2) + " " + amount.currency;
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
document.addEventListener("DOMContentLoaded", (e) => {
|
2015-12-17 13:30:34 +01:00
|
|
|
let offer = JSON.parse(query.offer);
|
|
|
|
console.dir(offer);
|
2015-12-16 10:45:16 +01:00
|
|
|
|
|
|
|
let source = $_("contract-template").innerHTML;
|
|
|
|
let template = Handlebars.compile(source);
|
2015-12-17 13:30:34 +01:00
|
|
|
let html = template(offer.contract);
|
2015-12-16 10:45:16 +01:00
|
|
|
|
|
|
|
$_("render-contract").innerHTML = html;
|
|
|
|
|
2015-12-17 13:30:34 +01:00
|
|
|
document.getElementById("confirm-pay").addEventListener("click", (e) => {
|
2015-12-17 22:56:24 +01:00
|
|
|
let d = {
|
|
|
|
offer: JSON.parse(query.offer)
|
|
|
|
};
|
2015-12-17 13:30:34 +01:00
|
|
|
chrome.runtime.sendMessage({type:'confirm-pay', detail: d}, (resp) => {
|
2015-12-17 22:56:24 +01:00
|
|
|
console.log("got response", resp);
|
|
|
|
if ("error" in resp) {
|
|
|
|
let source = $_("error-template").innerHTML;
|
|
|
|
let template = Handlebars.compile(source);
|
|
|
|
$_("status").innerHTML = template(resp);
|
|
|
|
return;
|
2015-12-16 10:45:16 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|