UI improvements and error handling
This commit is contained in:
parent
526e88695f
commit
0c760bc2a1
@ -554,16 +554,19 @@ export class Wallet {
|
|||||||
* but do not send them yet.
|
* but do not send them yet.
|
||||||
*/
|
*/
|
||||||
confirmPay(offer: Offer): Promise<any> {
|
confirmPay(offer: Offer): Promise<any> {
|
||||||
|
console.log("executing confirmPay");
|
||||||
return Promise.resolve().then(() => {
|
return Promise.resolve().then(() => {
|
||||||
return this.getPossibleMintCoins(offer.contract.amount,
|
return this.getPossibleMintCoins(offer.contract.amount,
|
||||||
offer.contract.max_fee,
|
offer.contract.max_fee,
|
||||||
offer.contract.mints)
|
offer.contract.mints)
|
||||||
}).then((mcs) => {
|
}).then((mcs) => {
|
||||||
if (Object.keys(mcs).length == 0) {
|
if (Object.keys(mcs).length == 0) {
|
||||||
|
console.log("not confirming payment, insufficient coins");
|
||||||
return {
|
return {
|
||||||
error: "coins-insufficient",
|
error: "coins-insufficient",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
console.log("about to record ...");
|
||||||
let mintUrl = Object.keys(mcs)[0];
|
let mintUrl = Object.keys(mcs)[0];
|
||||||
let ds = Wallet.signDeposit(offer, mcs[mintUrl]);
|
let ds = Wallet.signDeposit(offer, mcs[mintUrl]);
|
||||||
return this.recordConfirmPay(offer, ds, mintUrl)
|
return this.recordConfirmPay(offer, ds, mintUrl)
|
||||||
@ -738,27 +741,6 @@ export class Wallet {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
updateBadge() {
|
|
||||||
function countNonEmpty(c, n) {
|
|
||||||
if (c.currentAmount.fraction != 0 || c.currentAmount.value != 0) {
|
|
||||||
return n + 1;
|
|
||||||
}
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
function doBadge(n) {
|
|
||||||
this.badge.setText(n.toString());
|
|
||||||
this.badge.setColor("#0F0");
|
|
||||||
}
|
|
||||||
|
|
||||||
Query(this.db)
|
|
||||||
.iter("coins")
|
|
||||||
.reduce(countNonEmpty, 0)
|
|
||||||
.then(doBadge.bind(this));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
storeCoin(coin: Coin): Promise<void> {
|
storeCoin(coin: Coin): Promise<void> {
|
||||||
let historyEntry = {
|
let historyEntry = {
|
||||||
type: "withdraw",
|
type: "withdraw",
|
||||||
@ -771,10 +753,7 @@ export class Wallet {
|
|||||||
.delete("precoins", coin.coinPub)
|
.delete("precoins", coin.coinPub)
|
||||||
.add("coins", coin)
|
.add("coins", coin)
|
||||||
.add("history", historyEntry)
|
.add("history", historyEntry)
|
||||||
.finish()
|
.finish();
|
||||||
.then(() => {
|
|
||||||
this.updateBadge();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -86,10 +86,11 @@ System.register(["./wallet", "./db", "./http"], function(exports_1, context_1) {
|
|||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
_a["confirm-pay"] = function (db, detail, sendResponse) {
|
_a["confirm-pay"] = function (db, detail, sendResponse) {
|
||||||
|
console.log("in confirm-pay handler");
|
||||||
var offer = wallet_1.Offer.checked(detail.offer);
|
var offer = wallet_1.Offer.checked(detail.offer);
|
||||||
wallet.confirmPay(offer)
|
wallet.confirmPay(offer)
|
||||||
.then(function () {
|
.then(function (r) {
|
||||||
sendResponse({});
|
sendResponse(r);
|
||||||
})
|
})
|
||||||
.catch(function (e) {
|
.catch(function (e) {
|
||||||
console.error("exception during 'confirm-pay'");
|
console.error("exception during 'confirm-pay'");
|
||||||
@ -138,7 +139,6 @@ System.register(["./wallet", "./db", "./http"], function(exports_1, context_1) {
|
|||||||
var badge = new ChromeBadge();
|
var badge = new ChromeBadge();
|
||||||
var wallet = new wallet_1.Wallet(db, http, badge);
|
var wallet = new wallet_1.Wallet(db, http, badge);
|
||||||
var handlers = makeHandlers(wallet);
|
var handlers = makeHandlers(wallet);
|
||||||
wallet.updateBadge();
|
|
||||||
chrome.runtime.onMessage.addListener(function (req, sender, onresponse) {
|
chrome.runtime.onMessage.addListener(function (req, sender, onresponse) {
|
||||||
if (req.type in handlers) {
|
if (req.type in handlers) {
|
||||||
return handlers[req.type](db, req.detail, onresponse);
|
return handlers[req.type](db, req.detail, onresponse);
|
||||||
|
@ -92,10 +92,11 @@ function makeHandlers(wallet: Wallet) {
|
|||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
["confirm-pay"]: function(db, detail, sendResponse) {
|
["confirm-pay"]: function(db, detail, sendResponse) {
|
||||||
|
console.log("in confirm-pay handler");
|
||||||
const offer = Offer.checked(detail.offer);
|
const offer = Offer.checked(detail.offer);
|
||||||
wallet.confirmPay(offer)
|
wallet.confirmPay(offer)
|
||||||
.then(() => {
|
.then((r) => {
|
||||||
sendResponse({})
|
sendResponse(r)
|
||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
console.error("exception during 'confirm-pay'");
|
console.error("exception during 'confirm-pay'");
|
||||||
@ -156,7 +157,6 @@ export function wxMain() {
|
|||||||
let badge = new ChromeBadge();
|
let badge = new ChromeBadge();
|
||||||
let wallet = new Wallet(db, http, badge);
|
let wallet = new Wallet(db, http, badge);
|
||||||
let handlers = makeHandlers(wallet);
|
let handlers = makeHandlers(wallet);
|
||||||
wallet.updateBadge();
|
|
||||||
chrome.runtime.onMessage.addListener(
|
chrome.runtime.onMessage.addListener(
|
||||||
function(req, sender, onresponse) {
|
function(req, sender, onresponse) {
|
||||||
if (req.type in handlers) {
|
if (req.type in handlers) {
|
||||||
|
@ -32,10 +32,10 @@ System.register(["../lib/wallet/helpers"], function(exports_1, context_1) {
|
|||||||
var Contract = {
|
var Contract = {
|
||||||
view: function (ctrl) {
|
view: function (ctrl) {
|
||||||
return [
|
return [
|
||||||
m("p", (_a = ["Hello, this is the wallet. The merchant \"", "\"\n wants to enter a contract over ", "\n with you."], _a.raw = ["Hello, this is the wallet. The merchant \"", "\"\n wants to enter a contract over ", "\n with you."], i18n(_a, contract.merchant.name, prettyAmount(contract.amount)))),
|
m("p", (_a = ["", "\n wants to enter a contract over ", "\n with you."], _a.raw = ["", "\n wants to enter a contract over ", "\n with you."], i18n.parts(_a, m("strong", contract.merchant.name), m("strong", prettyAmount(contract.amount))))),
|
||||||
m("p", (_b = ["The contract contains the following products:"], _b.raw = ["The contract contains the following products:"], i18n(_b))),
|
m("p", (_b = ["You are about to purchase:"], _b.raw = ["You are about to purchase:"], i18n(_b))),
|
||||||
m('ul', _.map(contract.products, function (p) { return m("li", p.description + ": " + prettyAmount(p.price)); })),
|
m('ul', _.map(contract.products, function (p) { return m("li", p.description + ": " + prettyAmount(p.price)); })),
|
||||||
m("button", { onclick: doPayment }, (_c = ["Confirm Payment"], _c.raw = ["Confirm Payment"], i18n(_c))),
|
m("button.confirm-pay", { onclick: doPayment }, (_c = ["Confirm Payment"], _c.raw = ["Confirm Payment"], i18n(_c))),
|
||||||
m("p", error ? error : []),
|
m("p", error ? error : []),
|
||||||
];
|
];
|
||||||
var _a, _b, _c;
|
var _a, _b, _c;
|
||||||
@ -43,13 +43,18 @@ System.register(["../lib/wallet/helpers"], function(exports_1, context_1) {
|
|||||||
};
|
};
|
||||||
m.mount(document.getElementById("contract"), Contract);
|
m.mount(document.getElementById("contract"), Contract);
|
||||||
function doPayment() {
|
function doPayment() {
|
||||||
var d = {
|
var d = { offer: offer };
|
||||||
offer: offer
|
|
||||||
};
|
|
||||||
chrome.runtime.sendMessage({ type: 'confirm-pay', detail: d }, function (resp) {
|
chrome.runtime.sendMessage({ type: 'confirm-pay', detail: d }, function (resp) {
|
||||||
if (!resp.success) {
|
if (resp.error) {
|
||||||
console.log("confirm-pay error", JSON.stringify(resp));
|
console.log("confirm-pay error", JSON.stringify(resp));
|
||||||
error = resp.message;
|
switch (resp.error) {
|
||||||
|
case "coins-insufficient":
|
||||||
|
error = "You do not have enough coins of the requested currency.";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
error = "Error: " + resp.error;
|
||||||
|
break;
|
||||||
|
}
|
||||||
m.redraw();
|
m.redraw();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -39,16 +39,17 @@ export function main() {
|
|||||||
view(ctrl) {
|
view(ctrl) {
|
||||||
return [
|
return [
|
||||||
m("p",
|
m("p",
|
||||||
i18n`Hello, this is the wallet. The merchant "${contract.merchant.name}"
|
i18n.parts`${m("strong", contract.merchant.name)}
|
||||||
wants to enter a contract over ${prettyAmount(contract.amount)}
|
wants to enter a contract over ${m("strong",
|
||||||
|
prettyAmount(contract.amount))}
|
||||||
with you.`),
|
with you.`),
|
||||||
m("p",
|
m("p",
|
||||||
i18n`The contract contains the following products:`),
|
i18n`You are about to purchase:`),
|
||||||
m('ul',
|
m('ul',
|
||||||
_.map(contract.products,
|
_.map(contract.products,
|
||||||
(p: any) => m("li",
|
(p: any) => m("li",
|
||||||
`${p.description}: ${prettyAmount(p.price)}`))),
|
`${p.description}: ${prettyAmount(p.price)}`))),
|
||||||
m("button", {onclick: doPayment}, i18n`Confirm Payment`),
|
m("button.confirm-pay", {onclick: doPayment}, i18n`Confirm Payment`),
|
||||||
m("p", error ? error : []),
|
m("p", error ? error : []),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@ -56,21 +57,26 @@ export function main() {
|
|||||||
|
|
||||||
m.mount(document.getElementById("contract"), Contract);
|
m.mount(document.getElementById("contract"), Contract);
|
||||||
|
|
||||||
|
|
||||||
function doPayment() {
|
function doPayment() {
|
||||||
let d = {
|
let d = {offer};
|
||||||
offer
|
|
||||||
};
|
|
||||||
chrome.runtime.sendMessage({type: 'confirm-pay', detail: d}, (resp) => {
|
chrome.runtime.sendMessage({type: 'confirm-pay', detail: d}, (resp) => {
|
||||||
if (!resp.success) {
|
if (resp.error) {
|
||||||
console.log("confirm-pay error", JSON.stringify(resp));
|
console.log("confirm-pay error", JSON.stringify(resp));
|
||||||
error = resp.message;
|
switch (resp.error) {
|
||||||
|
case "coins-insufficient":
|
||||||
|
error = "You do not have enough coins of the requested currency.";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
error = `Error: ${resp.error}`;
|
||||||
|
break;
|
||||||
|
}
|
||||||
m.redraw();
|
m.redraw();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let c = d.offer.contract;
|
let c = d.offer.contract;
|
||||||
console.log("contract", c);
|
console.log("contract", c);
|
||||||
document.location.href = substituteFulfillmentUrl(c.fulfillment_url, offer);
|
document.location.href = substituteFulfillmentUrl(c.fulfillment_url,
|
||||||
|
offer);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -52,7 +52,8 @@ System.register(["../lib/wallet/helpers", "../lib/wallet/types", "mithril"], fun
|
|||||||
// TODO: make this request go to the wallet backend
|
// TODO: make this request go to the wallet backend
|
||||||
// Right now, this is a stub.
|
// Right now, this is a stub.
|
||||||
var defaultMint = {
|
var defaultMint = {
|
||||||
"KUDOS": "http://mint.test.taler.net"
|
"KUDOS": "http://mint.demo.taler.net",
|
||||||
|
"PUDOS": "http://mint.test.taler.net",
|
||||||
};
|
};
|
||||||
var mint = defaultMint[currency];
|
var mint = defaultMint[currency];
|
||||||
if (!mint) {
|
if (!mint) {
|
||||||
|
@ -204,7 +204,8 @@ function getSuggestedMint(currency: string): Promise<string> {
|
|||||||
// TODO: make this request go to the wallet backend
|
// TODO: make this request go to the wallet backend
|
||||||
// Right now, this is a stub.
|
// Right now, this is a stub.
|
||||||
const defaultMint = {
|
const defaultMint = {
|
||||||
"KUDOS": "http://mint.test.taler.net"
|
"KUDOS": "http://mint.demo.taler.net",
|
||||||
|
"PUDOS": "http://mint.test.taler.net",
|
||||||
};
|
};
|
||||||
|
|
||||||
let mint = defaultMint[currency];
|
let mint = defaultMint[currency];
|
||||||
|
@ -102,6 +102,10 @@ button {
|
|||||||
padding: 0.5em;
|
padding: 0.5em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
button.confirm-pay {
|
||||||
|
float: right;
|
||||||
|
}
|
||||||
|
|
||||||
/* We use fading to hide slower DOM updates */
|
/* We use fading to hide slower DOM updates */
|
||||||
.fade {
|
.fade {
|
||||||
-webkit-animation: fade 0.7s;
|
-webkit-animation: fade 0.7s;
|
||||||
|
Loading…
Reference in New Issue
Block a user