style, deduplication and doc comments
This commit is contained in:
parent
39cca9f8f6
commit
8f35362dad
@ -15,8 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Smaller helper functions that do not depend
|
* Small helper functions that don't fit anywhere else.
|
||||||
* on the emscripten machinery.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -36,7 +36,6 @@ import {
|
|||||||
getCurrencies,
|
getCurrencies,
|
||||||
updateCurrency,
|
updateCurrency,
|
||||||
} from "../wxApi";
|
} from "../wxApi";
|
||||||
import { prettyAmount } from "../renderHtml";
|
|
||||||
import { getTalerStampDate } from "../helpers";
|
import { getTalerStampDate } from "../helpers";
|
||||||
|
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
|
@ -37,7 +37,6 @@ import {
|
|||||||
getCurrencies,
|
getCurrencies,
|
||||||
updateCurrency,
|
updateCurrency,
|
||||||
} from "../wxApi";
|
} from "../wxApi";
|
||||||
import { prettyAmount } from "../renderHtml";
|
|
||||||
import { getTalerStampDate } from "../helpers";
|
import { getTalerStampDate } from "../helpers";
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import * as ReactDOM from "react-dom";
|
import * as ReactDOM from "react-dom";
|
||||||
|
@ -23,10 +23,10 @@
|
|||||||
/**
|
/**
|
||||||
* Imports.
|
* Imports.
|
||||||
*/
|
*/
|
||||||
import {Contract, AmountJson, ExchangeRecord} from "../types";
|
import { Contract, AmountJson, ExchangeRecord } from "../types";
|
||||||
import {OfferRecord} from "../wallet";
|
import { OfferRecord } from "../wallet";
|
||||||
import {renderContract, prettyAmount} from "../renderHtml";
|
import { renderContract } from "../renderHtml";
|
||||||
import {getExchanges} from "../wxApi";
|
import { getExchanges } from "../wxApi";
|
||||||
import * as i18n from "../i18n";
|
import * as i18n from "../i18n";
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import * as ReactDOM from "react-dom";
|
import * as ReactDOM from "react-dom";
|
||||||
|
@ -40,8 +40,7 @@ import {
|
|||||||
getPaybackReserves,
|
getPaybackReserves,
|
||||||
withdrawPaybackReserve,
|
withdrawPaybackReserve,
|
||||||
} from "../wxApi";
|
} from "../wxApi";
|
||||||
import { prettyAmount } from "../renderHtml";
|
import { amountToPretty, getTalerStampDate } from "../helpers";
|
||||||
import { getTalerStampDate } from "../helpers";
|
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import * as ReactDOM from "react-dom";
|
import * as ReactDOM from "react-dom";
|
||||||
|
|
||||||
@ -80,7 +79,7 @@ class Payback extends ImplicitStateComponent<any> {
|
|||||||
<div>
|
<div>
|
||||||
{reserves.map(r => (
|
{reserves.map(r => (
|
||||||
<div>
|
<div>
|
||||||
<h2>Reserve for ${prettyAmount(r.current_amount!)}</h2>
|
<h2>Reserve for ${amountToPretty(r.current_amount!)}</h2>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Exchange: ${r.exchange_base_url}</li>
|
<li>Exchange: ${r.exchange_base_url}</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
@ -26,12 +26,13 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
import BrowserClickedEvent = chrome.browserAction.BrowserClickedEvent;
|
import BrowserClickedEvent = chrome.browserAction.BrowserClickedEvent;
|
||||||
import {HistoryRecord, HistoryLevel} from "../wallet";
|
import { HistoryRecord, HistoryLevel } from "../wallet";
|
||||||
import {
|
import {
|
||||||
AmountJson, WalletBalance, Amounts,
|
AmountJson, WalletBalance, Amounts,
|
||||||
WalletBalanceEntry
|
WalletBalanceEntry
|
||||||
} from "../types";
|
} from "../types";
|
||||||
import {abbrev, prettyAmount} from "../renderHtml";
|
import { amountToPretty } from "../helpers";
|
||||||
|
import { abbrev } from "../renderHtml";
|
||||||
import * as i18n from "../i18n";
|
import * as i18n from "../i18n";
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import * as ReactDOM from "react-dom";
|
import * as ReactDOM from "react-dom";
|
||||||
@ -249,15 +250,15 @@ class WalletBalanceView extends React.Component<any, any> {
|
|||||||
let incoming: JSX.Element | undefined;
|
let incoming: JSX.Element | undefined;
|
||||||
let payment: JSX.Element | undefined;
|
let payment: JSX.Element | undefined;
|
||||||
|
|
||||||
console.log("available: ", entry.pendingIncoming ? prettyAmount(entry.available) : null);
|
console.log("available: ", entry.pendingIncoming ? amountToPretty(entry.available) : null);
|
||||||
console.log("incoming: ", entry.pendingIncoming ? prettyAmount(entry.pendingIncoming) : null);
|
console.log("incoming: ", entry.pendingIncoming ? amountToPretty(entry.pendingIncoming) : null);
|
||||||
|
|
||||||
if (Amounts.isNonZero(entry.pendingIncoming)) {
|
if (Amounts.isNonZero(entry.pendingIncoming)) {
|
||||||
incoming = (
|
incoming = (
|
||||||
<i18n.Translate wrap="span">
|
<i18n.Translate wrap="span">
|
||||||
<span style={{color: "darkgreen"}}>
|
<span style={{color: "darkgreen"}}>
|
||||||
{"+"}
|
{"+"}
|
||||||
{prettyAmount(entry.pendingIncoming)}
|
{amountToPretty(entry.pendingIncoming)}
|
||||||
</span>
|
</span>
|
||||||
{" "}
|
{" "}
|
||||||
incoming
|
incoming
|
||||||
@ -269,7 +270,7 @@ class WalletBalanceView extends React.Component<any, any> {
|
|||||||
payment = (
|
payment = (
|
||||||
<i18n.Translate wrap="span">
|
<i18n.Translate wrap="span">
|
||||||
<span style={{color: "darkblue"}}>
|
<span style={{color: "darkblue"}}>
|
||||||
{prettyAmount(entry.pendingPayment)}
|
{amountToPretty(entry.pendingPayment)}
|
||||||
</span>
|
</span>
|
||||||
{" "}
|
{" "}
|
||||||
being spent
|
being spent
|
||||||
@ -335,7 +336,7 @@ function formatHistoryItem(historyItem: HistoryRecord) {
|
|||||||
case "create-reserve":
|
case "create-reserve":
|
||||||
return (
|
return (
|
||||||
<i18n.Translate wrap="p">
|
<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>
|
</i18n.Translate>
|
||||||
);
|
);
|
||||||
case "confirm-reserve": {
|
case "confirm-reserve": {
|
||||||
@ -345,7 +346,7 @@ function formatHistoryItem(historyItem: HistoryRecord) {
|
|||||||
return (
|
return (
|
||||||
<i18n.Translate wrap="p">
|
<i18n.Translate wrap="p">
|
||||||
Started to withdraw
|
Started to withdraw
|
||||||
{" "}{prettyAmount(d.requestedAmount)}{" "}
|
{" "}{amountToPretty(d.requestedAmount)}{" "}
|
||||||
from <span>{exchange}</span> (<span>{pub}</span>).
|
from <span>{exchange}</span> (<span>{pub}</span>).
|
||||||
</i18n.Translate>
|
</i18n.Translate>
|
||||||
);
|
);
|
||||||
@ -362,7 +363,7 @@ function formatHistoryItem(historyItem: HistoryRecord) {
|
|||||||
}
|
}
|
||||||
case "depleted-reserve": {
|
case "depleted-reserve": {
|
||||||
let exchange = d.exchangeBaseUrl ? (new URI(d.exchangeBaseUrl)).host() : "??";
|
let exchange = d.exchangeBaseUrl ? (new URI(d.exchangeBaseUrl)).host() : "??";
|
||||||
let amount = prettyAmount(d.requestedAmount);
|
let amount = amountToPretty(d.requestedAmount);
|
||||||
let pub = abbrev(d.reservePub);
|
let pub = abbrev(d.reservePub);
|
||||||
return (
|
return (
|
||||||
<i18n.Translate wrap="p">
|
<i18n.Translate wrap="p">
|
||||||
@ -376,7 +377,7 @@ function formatHistoryItem(historyItem: HistoryRecord) {
|
|||||||
let fulfillmentLinkElem = <a href={url} onClick={openTab(url)}>view product</a>;
|
let fulfillmentLinkElem = <a href={url} onClick={openTab(url)}>view product</a>;
|
||||||
return (
|
return (
|
||||||
<i18n.Translate wrap="p">
|
<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>
|
</i18n.Translate>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -35,8 +35,7 @@ import {
|
|||||||
getReserves, getExchanges, getCoins, getPreCoins,
|
getReserves, getExchanges, getCoins, getPreCoins,
|
||||||
refresh, getDenoms, payback,
|
refresh, getDenoms, payback,
|
||||||
} from "../wxApi";
|
} from "../wxApi";
|
||||||
import { prettyAmount } from "../renderHtml";
|
import { amountToPretty, getTalerStampDate } from "../helpers";
|
||||||
import { getTalerStampDate } from "../helpers";
|
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import * as ReactDOM from "react-dom";
|
import * as ReactDOM from "react-dom";
|
||||||
|
|
||||||
@ -52,8 +51,8 @@ class ReserveView extends React.Component<ReserveViewProps, void> {
|
|||||||
<ul>
|
<ul>
|
||||||
<li>Key: {r.reserve_pub}</li>
|
<li>Key: {r.reserve_pub}</li>
|
||||||
<li>Created: {(new Date(r.created * 1000).toString())}</li>
|
<li>Created: {(new Date(r.created * 1000).toString())}</li>
|
||||||
<li>Current: {r.current_amount ? prettyAmount(r.current_amount!) : "null"}</li>
|
<li>Current: {r.current_amount ? amountToPretty(r.current_amount!) : "null"}</li>
|
||||||
<li>Requested: {prettyAmount(r.requested_amount)}</li>
|
<li>Requested: {amountToPretty(r.requested_amount)}</li>
|
||||||
<li>Confirmed: {r.confirmed}</li>
|
<li>Confirmed: {r.confirmed}</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
@ -130,7 +129,7 @@ class CoinView extends React.Component<CoinViewProps, void> {
|
|||||||
<div className="tree-item">
|
<div className="tree-item">
|
||||||
<ul>
|
<ul>
|
||||||
<li>Key: {c.coinPub}</li>
|
<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>Denomination: <ExpanderText text={c.denomPub} /></li>
|
||||||
<li>Suspended: {(c.suspended || false).toString()}</li>
|
<li>Suspended: {(c.suspended || false).toString()}</li>
|
||||||
<li>Status: {CoinStatus[c.status]}</li>
|
<li>Status: {CoinStatus[c.status]}</li>
|
||||||
@ -300,11 +299,11 @@ class DenominationList extends ImplicitStateComponent<DenominationListProps> {
|
|||||||
<div className="tree-item">
|
<div className="tree-item">
|
||||||
<ul>
|
<ul>
|
||||||
<li>Offered: {d.isOffered ? "yes" : "no"}</li>
|
<li>Offered: {d.isOffered ? "yes" : "no"}</li>
|
||||||
<li>Value: {prettyAmount(d.value)}</li>
|
<li>Value: {amountToPretty(d.value)}</li>
|
||||||
<li>Withdraw fee: {prettyAmount(d.feeWithdraw)}</li>
|
<li>Withdraw fee: {amountToPretty(d.feeWithdraw)}</li>
|
||||||
<li>Refresh fee: {prettyAmount(d.feeRefresh)}</li>
|
<li>Refresh fee: {amountToPretty(d.feeRefresh)}</li>
|
||||||
<li>Deposit fee: {prettyAmount(d.feeDeposit)}</li>
|
<li>Deposit fee: {amountToPretty(d.feeDeposit)}</li>
|
||||||
<li>Refund fee: {prettyAmount(d.feeRefund)}</li>
|
<li>Refund fee: {amountToPretty(d.feeRefund)}</li>
|
||||||
<li>Start: {getTalerStampDate(d.stampStart)!.toString()}</li>
|
<li>Start: {getTalerStampDate(d.stampStart)!.toString()}</li>
|
||||||
<li>Withdraw expiration: {getTalerStampDate(d.stampExpireWithdraw)!.toString()}</li>
|
<li>Withdraw expiration: {getTalerStampDate(d.stampExpireWithdraw)!.toString()}</li>
|
||||||
<li>Legal expiration: {getTalerStampDate(d.stampExpireLegal)!.toString()}</li>
|
<li>Legal expiration: {getTalerStampDate(d.stampExpireLegal)!.toString()}</li>
|
||||||
|
@ -21,14 +21,18 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
import {AmountJson, Contract, Amounts} from "./types";
|
/**
|
||||||
|
* Imports.
|
||||||
|
*/
|
||||||
|
import {
|
||||||
|
AmountJson,
|
||||||
|
Amounts,
|
||||||
|
Contract,
|
||||||
|
} from "./types";
|
||||||
import * as i18n from "./i18n";
|
import * as i18n from "./i18n";
|
||||||
|
import { amountToPretty } from "./helpers";
|
||||||
import * as React from "react";
|
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 {
|
export function renderContract(contract: Contract): JSX.Element {
|
||||||
let merchantName;
|
let merchantName;
|
||||||
@ -37,7 +41,7 @@ export function renderContract(contract: Contract): JSX.Element {
|
|||||||
} else {
|
} else {
|
||||||
merchantName = <strong>(pub: {contract.merchant_pub})</strong>;
|
merchantName = <strong>(pub: {contract.merchant_pub})</strong>;
|
||||||
}
|
}
|
||||||
let amount = <strong>{prettyAmount(contract.amount)}</strong>;
|
let amount = <strong>{amountToPretty(contract.amount)}</strong>;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
@ -49,7 +53,7 @@ export function renderContract(contract: Contract): JSX.Element {
|
|||||||
<p>{i18n.str`You are about to purchase:`}</p>
|
<p>{i18n.str`You are about to purchase:`}</p>
|
||||||
<ul>
|
<ul>
|
||||||
{contract.products.map(
|
{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>
|
</ul>
|
||||||
</div>
|
</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) {
|
export function abbrev(s: string, n: number = 5) {
|
||||||
let sAbbrev = s;
|
let sAbbrev = s;
|
||||||
if (s.length > n) {
|
if (s.length > n) {
|
||||||
|
Loading…
Reference in New Issue
Block a user