gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [taler-wallet-webex] branch master updated (0fb77c25 -> 8f3


From: gnunet
Subject: [GNUnet-SVN] [taler-wallet-webex] branch master updated (0fb77c25 -> 8f35362d)
Date: Wed, 24 May 2017 16:45:50 +0200

This is an automated email from the git hooks/post-receive script.

dold pushed a change to branch master
in repository wallet-webex.

    from 0fb77c25 remove obsolete test wrappers
     new 39cca9f8 imports and comments; expose wallet for debugging
     new 8f35362d style, deduplication and doc comments

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/helpers.ts                 |  3 +-
 src/pages/add-auditor.tsx      |  1 -
 src/pages/auditors.tsx         |  1 -
 src/pages/confirm-contract.tsx |  8 +++---
 src/pages/payback.tsx          |  5 ++--
 src/pages/popup.tsx            | 21 +++++++-------
 src/pages/tree.tsx             | 19 ++++++-------
 src/renderHtml.tsx             | 22 ++++++++++-----
 src/wxBackend.ts               | 63 +++++++++++++++++++++++-------------------
 9 files changed, 76 insertions(+), 67 deletions(-)

diff --git a/src/helpers.ts b/src/helpers.ts
index 8b2b265c..5e3ef06d 100644
--- a/src/helpers.ts
+++ b/src/helpers.ts
@@ -15,8 +15,7 @@
  */
 
 /**
- * Smaller helper functions that do not depend
- * on the emscripten machinery.
+ * Small helper functions that don't fit anywhere else.
  */
 
 /**
diff --git a/src/pages/add-auditor.tsx b/src/pages/add-auditor.tsx
index db283ead..8bef557d 100644
--- a/src/pages/add-auditor.tsx
+++ b/src/pages/add-auditor.tsx
@@ -36,7 +36,6 @@ import {
   getCurrencies,
   updateCurrency,
 } from "../wxApi";
-import { prettyAmount } from "../renderHtml";
 import { getTalerStampDate } from "../helpers";
 
 import * as React from "react";
diff --git a/src/pages/auditors.tsx b/src/pages/auditors.tsx
index 762d22ad..f263d2ec 100644
--- a/src/pages/auditors.tsx
+++ b/src/pages/auditors.tsx
@@ -37,7 +37,6 @@ import {
   getCurrencies,
   updateCurrency,
 } from "../wxApi";
-import { prettyAmount } from "../renderHtml";
 import { getTalerStampDate } from "../helpers";
 import * as React from "react";
 import * as ReactDOM from "react-dom";
diff --git a/src/pages/confirm-contract.tsx b/src/pages/confirm-contract.tsx
index 6c2480c1..47db94ee 100644
--- a/src/pages/confirm-contract.tsx
+++ b/src/pages/confirm-contract.tsx
@@ -23,10 +23,10 @@
 /**
  * Imports.
  */
-import {Contract, AmountJson, ExchangeRecord} from "../types";
-import {OfferRecord} from "../wallet";
-import {renderContract, prettyAmount} from "../renderHtml";
-import {getExchanges} from "../wxApi";
+import { Contract, AmountJson, ExchangeRecord } from "../types";
+import { OfferRecord } from "../wallet";
+import { renderContract } from "../renderHtml";
+import { getExchanges } from "../wxApi";
 import * as i18n from "../i18n";
 import * as React from "react";
 import * as ReactDOM from "react-dom";
diff --git a/src/pages/payback.tsx b/src/pages/payback.tsx
index 9e463d4a..01f5a64e 100644
--- a/src/pages/payback.tsx
+++ b/src/pages/payback.tsx
@@ -40,8 +40,7 @@ import {
   getPaybackReserves,
   withdrawPaybackReserve,
 } from "../wxApi";
-import { prettyAmount } from "../renderHtml";
-import { getTalerStampDate } from "../helpers";
+import { amountToPretty, getTalerStampDate } from "../helpers";
 import * as React from "react";
 import * as ReactDOM from "react-dom";
 
@@ -80,7 +79,7 @@ class Payback extends ImplicitStateComponent<any> {
       <div>
         {reserves.map(r => (
           <div>
-            <h2>Reserve for ${prettyAmount(r.current_amount!)}</h2>
+            <h2>Reserve for ${amountToPretty(r.current_amount!)}</h2>
             <ul>
               <li>Exchange: ${r.exchange_base_url}</li>
             </ul>
diff --git a/src/pages/popup.tsx b/src/pages/popup.tsx
index c0d280db..aef5a3df 100644
--- a/src/pages/popup.tsx
+++ b/src/pages/popup.tsx
@@ -26,12 +26,13 @@
 "use strict";
 
 import BrowserClickedEvent = chrome.browserAction.BrowserClickedEvent;
-import {HistoryRecord, HistoryLevel} from "../wallet";
+import { HistoryRecord, HistoryLevel } from "../wallet";
 import {
   AmountJson, WalletBalance, Amounts,
   WalletBalanceEntry
 } from "../types";
-import {abbrev, prettyAmount} from "../renderHtml";
+import { amountToPretty } from "../helpers";
+import { abbrev } from "../renderHtml";
 import * as i18n from "../i18n";
 import * as React from "react";
 import * as ReactDOM from "react-dom";
@@ -249,15 +250,15 @@ class WalletBalanceView extends React.Component<any, any> 
{
     let incoming: JSX.Element | undefined;
     let payment: JSX.Element | undefined;
 
-    console.log("available: ", entry.pendingIncoming ? 
prettyAmount(entry.available) : null);
-    console.log("incoming: ", entry.pendingIncoming ? 
prettyAmount(entry.pendingIncoming) : null);
+    console.log("available: ", entry.pendingIncoming ? 
amountToPretty(entry.available) : null);
+    console.log("incoming: ", entry.pendingIncoming ? 
amountToPretty(entry.pendingIncoming) : null);
 
     if (Amounts.isNonZero(entry.pendingIncoming)) {
       incoming = (
         <i18n.Translate wrap="span">
           <span style={{color: "darkgreen"}}>
             {"+"}
-            {prettyAmount(entry.pendingIncoming)}
+            {amountToPretty(entry.pendingIncoming)}
           </span>
           {" "}
           incoming
@@ -269,7 +270,7 @@ class WalletBalanceView extends React.Component<any, any> {
       payment = (
         <i18n.Translate wrap="span">
           <span style={{color: "darkblue"}}>
-            {prettyAmount(entry.pendingPayment)}
+            {amountToPretty(entry.pendingPayment)}
           </span>
           {" "}
           being spent
@@ -335,7 +336,7 @@ function formatHistoryItem(historyItem: HistoryRecord) {
     case "create-reserve":
       return (
         <i18n.Translate wrap="p">
-          Bank requested reserve (<span>{abbrev(d.reservePub)}</span>) for 
<span>{prettyAmount(d.requestedAmount)}</span>.
+          Bank requested reserve (<span>{abbrev(d.reservePub)}</span>) for 
<span>{amountToPretty(d.requestedAmount)}</span>.
         </i18n.Translate>
       );
     case "confirm-reserve": {
@@ -345,7 +346,7 @@ function formatHistoryItem(historyItem: HistoryRecord) {
       return (
         <i18n.Translate wrap="p">
           Started to withdraw
-          {" "}{prettyAmount(d.requestedAmount)}{" "}
+          {" "}{amountToPretty(d.requestedAmount)}{" "}
           from <span>{exchange}</span> (<span>{pub}</span>).
         </i18n.Translate>
       );
@@ -362,7 +363,7 @@ function formatHistoryItem(historyItem: HistoryRecord) {
     }
     case "depleted-reserve": {
       let exchange = d.exchangeBaseUrl ? (new URI(d.exchangeBaseUrl)).host() : 
"??";
-      let amount = prettyAmount(d.requestedAmount);
+      let amount = amountToPretty(d.requestedAmount);
       let pub = abbrev(d.reservePub);
       return (
         <i18n.Translate wrap="p">
@@ -376,7 +377,7 @@ function formatHistoryItem(historyItem: HistoryRecord) {
       let fulfillmentLinkElem = <a href={url} onClick={openTab(url)}>view 
product</a>;
       return (
         <i18n.Translate wrap="p">
-          Paid <span>{prettyAmount(d.amount)}</span> to merchant 
<span>{merchantElem}</span>.  (<span>{fulfillmentLinkElem}</span>)
+          Paid <span>{amountToPretty(d.amount)}</span> to merchant 
<span>{merchantElem}</span>.  (<span>{fulfillmentLinkElem}</span>)
         </i18n.Translate>
       );
     }
diff --git a/src/pages/tree.tsx b/src/pages/tree.tsx
index 201d411a..8d1258c5 100644
--- a/src/pages/tree.tsx
+++ b/src/pages/tree.tsx
@@ -35,8 +35,7 @@ import {
   getReserves, getExchanges, getCoins, getPreCoins,
   refresh, getDenoms, payback,
 } from "../wxApi";
-import { prettyAmount } from "../renderHtml";
-import { getTalerStampDate } from "../helpers";
+import { amountToPretty, getTalerStampDate } from "../helpers";
 import * as React from "react";
 import * as ReactDOM from "react-dom";
 
@@ -52,8 +51,8 @@ class ReserveView extends React.Component<ReserveViewProps, 
void> {
         <ul>
           <li>Key: {r.reserve_pub}</li>
           <li>Created: {(new Date(r.created * 1000).toString())}</li>
-          <li>Current: {r.current_amount ? prettyAmount(r.current_amount!) : 
"null"}</li>
-          <li>Requested: {prettyAmount(r.requested_amount)}</li>
+          <li>Current: {r.current_amount ? amountToPretty(r.current_amount!) : 
"null"}</li>
+          <li>Requested: {amountToPretty(r.requested_amount)}</li>
           <li>Confirmed: {r.confirmed}</li>
         </ul>
       </div>
@@ -130,7 +129,7 @@ class CoinView extends React.Component<CoinViewProps, void> 
{
       <div className="tree-item">
         <ul>
           <li>Key: {c.coinPub}</li>
-          <li>Current amount: {prettyAmount(c.currentAmount)}</li>
+          <li>Current amount: {amountToPretty(c.currentAmount)}</li>
           <li>Denomination: <ExpanderText text={c.denomPub} /></li>
           <li>Suspended: {(c.suspended || false).toString()}</li>
           <li>Status: {CoinStatus[c.status]}</li>
@@ -300,11 +299,11 @@ class DenominationList extends 
ImplicitStateComponent<DenominationListProps> {
       <div className="tree-item">
         <ul>
           <li>Offered: {d.isOffered ? "yes" : "no"}</li>
-          <li>Value: {prettyAmount(d.value)}</li>
-          <li>Withdraw fee: {prettyAmount(d.feeWithdraw)}</li>
-          <li>Refresh fee: {prettyAmount(d.feeRefresh)}</li>
-          <li>Deposit fee: {prettyAmount(d.feeDeposit)}</li>
-          <li>Refund fee: {prettyAmount(d.feeRefund)}</li>
+          <li>Value: {amountToPretty(d.value)}</li>
+          <li>Withdraw fee: {amountToPretty(d.feeWithdraw)}</li>
+          <li>Refresh fee: {amountToPretty(d.feeRefresh)}</li>
+          <li>Deposit fee: {amountToPretty(d.feeDeposit)}</li>
+          <li>Refund fee: {amountToPretty(d.feeRefund)}</li>
           <li>Start: {getTalerStampDate(d.stampStart)!.toString()}</li>
           <li>Withdraw expiration: 
{getTalerStampDate(d.stampExpireWithdraw)!.toString()}</li>
           <li>Legal expiration: 
{getTalerStampDate(d.stampExpireLegal)!.toString()}</li>
diff --git a/src/renderHtml.tsx b/src/renderHtml.tsx
index 1e6c5a8e..9d14d6cb 100644
--- a/src/renderHtml.tsx
+++ b/src/renderHtml.tsx
@@ -21,14 +21,18 @@
  */
 
 
-import {AmountJson, Contract, Amounts} from "./types";
+/**
+ * Imports.
+ */
+import {
+  AmountJson,
+  Amounts,
+  Contract,
+} from "./types";
 import * as i18n from "./i18n";
+import { amountToPretty } from "./helpers";
 import * as React from "react";
 
-export function prettyAmount(amount: AmountJson) {
-  let v = amount.value + amount.fraction / Amounts.fractionalBase;
-  return `${v} ${amount.currency}`;
-}
 
 export function renderContract(contract: Contract): JSX.Element {
   let merchantName;
@@ -37,7 +41,7 @@ export function renderContract(contract: Contract): 
JSX.Element {
   } else {
     merchantName = <strong>(pub: {contract.merchant_pub})</strong>;
   }
-  let amount = <strong>{prettyAmount(contract.amount)}</strong>;
+  let amount = <strong>{amountToPretty(contract.amount)}</strong>;
 
   return (
     <div>
@@ -49,7 +53,7 @@ export function renderContract(contract: Contract): 
JSX.Element {
       <p>{i18n.str`You are about to purchase:`}</p>
       <ul>
         {contract.products.map(
-          (p: any, i: number) => (<li key={i}>{`${p.description}: 
${prettyAmount(p.price)}`}</li>))
+          (p: any, i: number) => (<li key={i}>{`${p.description}: 
${amountToPretty(p.price)}`}</li>))
         }
       </ul>
     </div>
@@ -57,6 +61,10 @@ export function renderContract(contract: Contract): 
JSX.Element {
 }
 
 
+/**
+ * Abbreviate a string to a given length, and show the full
+ * string on hover as a tooltip.
+ */
 export function abbrev(s: string, n: number = 5) {
   let sAbbrev = s;
   if (s.length > n) {
diff --git a/src/wxBackend.ts b/src/wxBackend.ts
index 089526a4..a5b8c667 100644
--- a/src/wxBackend.ts
+++ b/src/wxBackend.ts
@@ -14,41 +14,48 @@
  TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
  */
 
+/**
+ * Messaging for the WebExtensions wallet.  Should contain
+ * parts that are specific for WebExtensions, but as little business
+ * logic as possible.
+ */
+
 
+/**
+ * Imports.
+ */
 import {
-  Wallet,
-  OfferRecord,
   Badge,
   ConfirmReserveRequest,
-  CreateReserveRequest
+  CreateReserveRequest,
+  OfferRecord,
+  Stores,
+  Wallet,
 } from "./wallet";
-import { BrowserHttpLib } from "./http";
-import { Checkable } from "./checkable";
-import { AmountJson } from "./types";
-import Port = chrome.runtime.Port;
-import { Notifier } from "./types";
-import { Contract } from "./types";
+import {
+  AmountJson,
+  Contract,
+  Notifier,
+} from "./types";
 import MessageSender = chrome.runtime.MessageSender;
 import { ChromeBadge } from "./chromeBadge";
 import * as logging from "./logging";
+import { Store, Index } from "./query";
+import { BrowserHttpLib } from "./http";
+import { Checkable } from "./checkable";
+import Port = chrome.runtime.Port;
 import URI = require("urijs");
 
-"use strict";
 
 const DB_NAME = "taler";
-const DB_VERSION = 17;
-
-import {Stores} from "./wallet";
-import {Store, Index} from "./query";
 
 /**
- * Messaging for the WebExtensions wallet.  Should contain
- * parts that are specific for WebExtensions, but as little business
- * logic as possible.
- *
- * @author Florian Dold
+ * Current database version, should be incremented
+ * each time we do incompatible schema changes on the database.
+ * In the future we might consider adding migration functions for
+ * each version increment.
  */
-
+const DB_VERSION = 17;
 
 type Handler = (detail: any, sender: MessageSender) => Promise<any>;
 
@@ -466,10 +473,6 @@ function handleBankRequest(wallet: Wallet, headerList: 
chrome.webRequest.HttpHea
   // no known headers found, not a taler request ...
 }
 
-// Useful for debugging ...
-export let wallet: Wallet | undefined = undefined;
-export let badge: ChromeBadge | undefined = undefined;
-export let log = logging.log;
 
 // Rate limit cache for executePayment operations, to break redirect loops
 let rateLimitCache: { [n: number]: number } = {};
@@ -484,7 +487,7 @@ export async function wxMain() {
   }
 
   chrome.browserAction.setBadgeText({ text: "" });
-  badge = new ChromeBadge();
+  const badge = new ChromeBadge();
 
   chrome.tabs.query({}, function (tabs) {
     for (let tab of tabs) {
@@ -566,14 +569,16 @@ export async function wxMain() {
     console.error("could not open database", e);
     return;
   }
-  let http = new BrowserHttpLib();
-  let notifier = new ChromeNotifier();
+  const http = new BrowserHttpLib();
+  const notifier = new ChromeNotifier();
   console.log("setting wallet");
-  wallet = new Wallet(db, http, badge!, notifier);
+  const wallet = new Wallet(db, http, badge!, notifier);
+  // Useful for debugging in the background page.
+  (window as any).talerWallet = wallet;
 
   // Handlers for messages coming directly from the content
   // script on the page
-  let handlers = makeHandlers(db, wallet!);
+  const handlers = makeHandlers(db, wallet!);
   chrome.runtime.onMessage.addListener((req, sender, sendResponse) => {
     dispatch(handlers, req, sender, sendResponse);
     return true;

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]