From d0a4f9f934cea5bbb3da90ea13ccf91d9fb1c933 Mon Sep 17 00:00:00 2001
From: Florian Dold <florian.dold@gmail.com>
Date: Wed, 27 Apr 2016 06:03:04 +0200
Subject: UI fixes

---
 pages/confirm-contract.tsx | 30 ++++++++++++++++++++++++++++--
 1 file changed, 28 insertions(+), 2 deletions(-)

(limited to 'pages/confirm-contract.tsx')

diff --git a/pages/confirm-contract.tsx b/pages/confirm-contract.tsx
index 9e15841e9..2e055d4f1 100644
--- a/pages/confirm-contract.tsx
+++ b/pages/confirm-contract.tsx
@@ -72,6 +72,7 @@ export function main() {
   console.dir(offer);
   let contract = offer.contract;
   let error = null;
+  let payDisabled = true;
 
   var Contract = {
     view(ctrl) {
@@ -87,8 +88,8 @@ export function main() {
           _.map(contract.products,
                 (p: any) => m("li",
                               `${p.description}: ${prettyAmount(p.price)}`))),
-        m("button.accept", {onclick: doPayment}, i18n`Confirm Payment`),
-        m("p", error ? error : []),
+        m("button.accept", {onclick: doPayment, disabled: payDisabled}, i18n`Confirm Payment`),
+        (error ? m("p.errorbox", error) : []),
         m(Details, contract)
       ];
     }
@@ -96,6 +97,31 @@ export function main() {
 
   m.mount(document.getElementById("contract"), Contract);
 
+  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":
+            error = "You do not have enough coins of the requested currency.";
+            break;
+          default:
+            error = `Error: ${resp.error}`;
+            break;
+        }
+        payDisabled = true;
+      } else {
+        payDisabled = false;
+        error = null;
+      }
+      m.redraw();
+      window.setTimeout(checkPayment, 300);
+    });
+  }
+
+  checkPayment();
+
+
   function doPayment() {
     let d = {offer};
     chrome.runtime.sendMessage({type: 'confirm-pay', detail: d}, (resp) => {
-- 
cgit v1.2.3

