remove dead code and add comments

This commit is contained in:
Florian Dold 2017-05-24 16:14:23 +02:00
parent fc53a08bb0
commit 1c8206f8c0
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
11 changed files with 77 additions and 57 deletions

View File

@ -20,7 +20,9 @@
* @author Florian Dold
*/
/**
* Imports.
*/
import {wxMain} from "./../wxBackend";
window.addEventListener("load", () => {

View File

@ -32,6 +32,9 @@
* name: string;
* @Checkable.Number
* age: number;
*
* // Method will be implemented automatically
* static checked(obj: any): Person;
* }
* ```
*/

View File

@ -16,11 +16,15 @@
/**
* General helper components
* General helper React components.
*
* @author Florian Dold
*/
/**
* Imports.
*/
import * as React from "react";
export interface StateHolder<T> {

View File

@ -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;

View File

@ -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();

View File

@ -14,21 +14,26 @@
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
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;

View File

@ -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<T, U>(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) {

View File

@ -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<HttpResponse>;
get(url: string): Promise<HttpResponse>;
postJson(url: string, body: any): Promise<HttpResponse>;
@ -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<HttpResponse> {
return new Promise<HttpResponse>((resolve, reject) => {
@ -82,8 +85,10 @@ export class BrowserHttpLib {
}
/**
* Exception thrown on request errors.
*/
export class RequestException {
constructor(detail: any) {
constructor(public detail: any) {
}
}

View File

@ -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<ContractPromptProps, ContractPrompt
}
let c = d.offer!.contract;
console.log("contract", c);
document.location.href = substituteFulfillmentUrl(c.fulfillment_url,
this.state.offer);
document.location.href = c.fulfillment_url;
});
}

View File

@ -25,7 +25,6 @@
"use strict";
import {substituteFulfillmentUrl} from "../helpers";
import BrowserClickedEvent = chrome.browserAction.BrowserClickedEvent;
import {HistoryRecord, HistoryLevel} from "../wallet";
import {
@ -372,8 +371,7 @@ function formatHistoryItem(historyItem: HistoryRecord) {
);
}
case "pay": {
let url = substituteFulfillmentUrl(d.fulfillmentUrl,
{H_contract: d.contractHash});
let url = d.fulfillmentUrl;
let merchantElem = <em>{abbrev(d.merchantName, 15)}</em>;
let fulfillmentLinkElem = <a href={url} onClick={openTab(url)}>view product</a>;
return (

7
tooling/README Normal file
View File

@ -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.