diff --git a/src/background/background.ts b/src/background/background.ts index 9b50caf9c..aca27ef47 100644 --- a/src/background/background.ts +++ b/src/background/background.ts @@ -20,7 +20,9 @@ * @author Florian Dold */ - +/** + * Imports. + */ import {wxMain} from "./../wxBackend"; window.addEventListener("load", () => { diff --git a/src/checkable.ts b/src/checkable.ts index 8eb5e1520..6bfaea013 100644 --- a/src/checkable.ts +++ b/src/checkable.ts @@ -32,6 +32,9 @@ * name: string; * @Checkable.Number * age: number; + * + * // Method will be implemented automatically + * static checked(obj: any): Person; * } * ``` */ diff --git a/src/components.ts b/src/components.ts index 569810f3a..bef3cff42 100644 --- a/src/components.ts +++ b/src/components.ts @@ -16,11 +16,15 @@ /** - * General helper components + * General helper React components. * * @author Florian Dold */ + +/** + * Imports. + */ import * as React from "react"; export interface StateHolder { diff --git a/src/content_scripts/notify.ts b/src/content_scripts/notify.ts index 498331630..64414e0b9 100644 --- a/src/content_scripts/notify.ts +++ b/src/content_scripts/notify.ts @@ -16,13 +16,14 @@ /** - * Script that is injected into (all!) pages to allow them + * Module that is injected into (all!) pages to allow them * to interact with the GNU Taler wallet via DOM Events. - * - * @author Florian Dold */ +/** + * Imports. + */ import URI = require("urijs"); declare var cloneInto: any; diff --git a/src/cryptoWorker.ts b/src/cryptoWorker.ts index aab7d3343..bf802a32b 100644 --- a/src/cryptoWorker.ts +++ b/src/cryptoWorker.ts @@ -16,11 +16,12 @@ /** * Web worker for crypto operations. - * @author Florian Dold */ -"use strict"; +/** + * Imports. + */ import * as native from "./emscriptif"; import { PreCoinRecord, @@ -386,6 +387,9 @@ namespace RpcFunctions { return refreshSession; } + /** + * Hash a string including the zero terminator. + */ export function hashString(str: string): string { const b = native.ByteArray.fromStringWithNull(str); return b.hash().toCrock(); diff --git a/src/emscriptif.ts b/src/emscriptif.ts index caa0fb8cc..60653b66e 100644 --- a/src/emscriptif.ts +++ b/src/emscriptif.ts @@ -14,21 +14,26 @@ TALER; see the file COPYING. If not, see */ -import {AmountJson} from "./types"; -import * as emscLib from "./emscripten/taler-emscripten-lib"; /** * Medium-level interface to emscripten-compiled modules used - * by the wallet. + * by the wallet. Handles memory management by allocating by allocating + * objects in arenas that then can be disposed of all at once. * * The high-level interface (using WebWorkers) is exposed in src/cryptoApi.ts. - * - * @author Florian Dold */ -"use strict"; +/** + * Imports. + */ +import {AmountJson} from "./types"; +import * as emscLib from "./emscripten/taler-emscripten-lib"; -// Size of a native pointer. + +/** + * Size of a native pointer. Must match the size + * use when compiling via emscripten. + */ const PTR_SIZE = 4; const GNUNET_OK = 1; diff --git a/src/helpers.ts b/src/helpers.ts index 7b9470271..8b2b265cc 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -17,20 +17,19 @@ /** * Smaller helper functions that do not depend * on the emscripten machinery. - * - * @author Florian Dold */ +/** + * Imports. + */ import {AmountJson, Amounts} from "./types"; import URI = require("urijs"); -export function substituteFulfillmentUrl(url: string, vars: any) { - url = url.replace("${H_contract}", vars.H_contract); - url = url.replace("${$}", "$"); - return url; -} - - +/** + * Show an amount in a form suitable for the user. + * FIXME: In the future, this should consider currency-specific + * settings such as significant digits or currency symbols. + */ export function amountToPretty(amount: AmountJson): string { let x = amount.value + amount.fraction / Amounts.fractionalBase; return `${x} ${amount.currency}`; @@ -54,20 +53,6 @@ export function canonicalizeBaseUrl(url: string) { } -export function parsePrettyAmount(pretty: string): AmountJson|undefined { - const res = /([0-9]+)(.[0-9]+)?\s*(\w+)/.exec(pretty); - if (!res) { - return undefined; - } - return { - value: parseInt(res[1], 10), - fraction: res[2] ? (parseFloat(`0.${res[2]}`) / Amounts.fractionalBase) : 0, - currency: res[3] - } -} - - - /** * Convert object to JSON with canonical ordering of keys * and whitespace omitted. @@ -119,6 +104,10 @@ export function flatMap(xs: T[], f: (x: T) => U[]): U[] { } +/** + * Extract a numeric timstamp (in seconds) from the Taler date format + * ("/Date([n])/"). Returns null if input is not in the right format. + */ export function getTalerStampSec(stamp: string): number | null { const m = stamp.match(/\/?Date\(([0-9]*)\)\/?/); if (!m) { @@ -128,6 +117,10 @@ export function getTalerStampSec(stamp: string): number | null { } +/** + * Get a JavaScript Date object from a Taler date string. + * Returns null if input is not in the right format. + */ export function getTalerStampDate(stamp: string): Date | null { let sec = getTalerStampSec(stamp); if (sec == null) { diff --git a/src/http.ts b/src/http.ts index 5e6580016..965a44a97 100644 --- a/src/http.ts +++ b/src/http.ts @@ -16,23 +16,22 @@ /** * Helpers for doing XMLHttpRequest-s that are based on ES6 promises. - * @module Http - * @author Florian Dold + * Allows for easy mocking for test cases. */ -"use strict"; - +/** + * An HTTP response that is returned by all request methods of this library. + */ export interface HttpResponse { status: number; responseText: string; } +/** + * The request library is bundled into an interface to make mocking easy. + */ export interface HttpRequestLibrary { - req(method: string, - url: string, - options?: any): Promise; - get(url: string): Promise; postJson(url: string, body: any): Promise; @@ -41,8 +40,12 @@ export interface HttpRequestLibrary { } +/** + * An implementation of the [[HttpRequestLibrary]] using the + * browser's XMLHttpRequest. + */ export class BrowserHttpLib { - req(method: string, + private req(method: string, url: string, options?: any): Promise { return new Promise((resolve, reject) => { @@ -82,8 +85,10 @@ export class BrowserHttpLib { } +/** + * Exception thrown on request errors. + */ export class RequestException { - constructor(detail: any) { - + constructor(public detail: any) { } } diff --git a/src/pages/confirm-contract.tsx b/src/pages/confirm-contract.tsx index d8f72ba01..6c2480c1e 100644 --- a/src/pages/confirm-contract.tsx +++ b/src/pages/confirm-contract.tsx @@ -17,13 +17,12 @@ /** * Page shown to the user to confirm entering * a contract. - * - * @author Florian Dold */ -"use strict"; -import {substituteFulfillmentUrl} from "../helpers"; +/** + * Imports. + */ import {Contract, AmountJson, ExchangeRecord} from "../types"; import {OfferRecord} from "../wallet"; import {renderContract, prettyAmount} from "../renderHtml"; @@ -201,8 +200,7 @@ class ContractPrompt extends React.Component{abbrev(d.merchantName, 15)}; let fulfillmentLinkElem = view product; return ( diff --git a/tooling/README b/tooling/README new file mode 100644 index 000000000..dd14496a5 --- /dev/null +++ b/tooling/README @@ -0,0 +1,7 @@ +This directory contains NPM packages that are used by the wallet. + +At some point they should be published to the registry, right now we don't +bother and simply add them to the top-level wallet project via file URL. + +Due to this, the JavaScript files compiled from TypeScript are currently +checked into git.