remove dead code and add comments
This commit is contained in:
parent
fc53a08bb0
commit
1c8206f8c0
@ -20,7 +20,9 @@
|
|||||||
* @author Florian Dold
|
* @author Florian Dold
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Imports.
|
||||||
|
*/
|
||||||
import {wxMain} from "./../wxBackend";
|
import {wxMain} from "./../wxBackend";
|
||||||
|
|
||||||
window.addEventListener("load", () => {
|
window.addEventListener("load", () => {
|
||||||
|
@ -32,6 +32,9 @@
|
|||||||
* name: string;
|
* name: string;
|
||||||
* @Checkable.Number
|
* @Checkable.Number
|
||||||
* age: number;
|
* age: number;
|
||||||
|
*
|
||||||
|
* // Method will be implemented automatically
|
||||||
|
* static checked(obj: any): Person;
|
||||||
* }
|
* }
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
|
@ -16,11 +16,15 @@
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* General helper components
|
* General helper React components.
|
||||||
*
|
*
|
||||||
* @author Florian Dold
|
* @author Florian Dold
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Imports.
|
||||||
|
*/
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
|
|
||||||
export interface StateHolder<T> {
|
export interface StateHolder<T> {
|
||||||
|
@ -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.
|
* to interact with the GNU Taler wallet via DOM Events.
|
||||||
*
|
|
||||||
* @author Florian Dold
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Imports.
|
||||||
|
*/
|
||||||
import URI = require("urijs");
|
import URI = require("urijs");
|
||||||
|
|
||||||
declare var cloneInto: any;
|
declare var cloneInto: any;
|
||||||
|
@ -16,11 +16,12 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Web worker for crypto operations.
|
* Web worker for crypto operations.
|
||||||
* @author Florian Dold
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Imports.
|
||||||
|
*/
|
||||||
import * as native from "./emscriptif";
|
import * as native from "./emscriptif";
|
||||||
import {
|
import {
|
||||||
PreCoinRecord,
|
PreCoinRecord,
|
||||||
@ -386,6 +387,9 @@ namespace RpcFunctions {
|
|||||||
return refreshSession;
|
return refreshSession;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hash a string including the zero terminator.
|
||||||
|
*/
|
||||||
export function hashString(str: string): string {
|
export function hashString(str: string): string {
|
||||||
const b = native.ByteArray.fromStringWithNull(str);
|
const b = native.ByteArray.fromStringWithNull(str);
|
||||||
return b.hash().toCrock();
|
return b.hash().toCrock();
|
||||||
|
@ -14,21 +14,26 @@
|
|||||||
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
|
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
|
* 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.
|
* 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 PTR_SIZE = 4;
|
||||||
|
|
||||||
const GNUNET_OK = 1;
|
const GNUNET_OK = 1;
|
||||||
|
@ -17,20 +17,19 @@
|
|||||||
/**
|
/**
|
||||||
* Smaller helper functions that do not depend
|
* Smaller helper functions that do not depend
|
||||||
* on the emscripten machinery.
|
* on the emscripten machinery.
|
||||||
*
|
|
||||||
* @author Florian Dold
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Imports.
|
||||||
|
*/
|
||||||
import {AmountJson, Amounts} from "./types";
|
import {AmountJson, Amounts} from "./types";
|
||||||
import URI = require("urijs");
|
import URI = require("urijs");
|
||||||
|
|
||||||
export function substituteFulfillmentUrl(url: string, vars: any) {
|
/**
|
||||||
url = url.replace("${H_contract}", vars.H_contract);
|
* Show an amount in a form suitable for the user.
|
||||||
url = url.replace("${$}", "$");
|
* FIXME: In the future, this should consider currency-specific
|
||||||
return url;
|
* settings such as significant digits or currency symbols.
|
||||||
}
|
*/
|
||||||
|
|
||||||
|
|
||||||
export function amountToPretty(amount: AmountJson): string {
|
export function amountToPretty(amount: AmountJson): string {
|
||||||
let x = amount.value + amount.fraction / Amounts.fractionalBase;
|
let x = amount.value + amount.fraction / Amounts.fractionalBase;
|
||||||
return `${x} ${amount.currency}`;
|
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
|
* Convert object to JSON with canonical ordering of keys
|
||||||
* and whitespace omitted.
|
* 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 {
|
export function getTalerStampSec(stamp: string): number | null {
|
||||||
const m = stamp.match(/\/?Date\(([0-9]*)\)\/?/);
|
const m = stamp.match(/\/?Date\(([0-9]*)\)\/?/);
|
||||||
if (!m) {
|
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 {
|
export function getTalerStampDate(stamp: string): Date | null {
|
||||||
let sec = getTalerStampSec(stamp);
|
let sec = getTalerStampSec(stamp);
|
||||||
if (sec == null) {
|
if (sec == null) {
|
||||||
|
27
src/http.ts
27
src/http.ts
@ -16,23 +16,22 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Helpers for doing XMLHttpRequest-s that are based on ES6 promises.
|
* Helpers for doing XMLHttpRequest-s that are based on ES6 promises.
|
||||||
* @module Http
|
* Allows for easy mocking for test cases.
|
||||||
* @author Florian Dold
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
/**
|
||||||
|
* An HTTP response that is returned by all request methods of this library.
|
||||||
|
*/
|
||||||
export interface HttpResponse {
|
export interface HttpResponse {
|
||||||
status: number;
|
status: number;
|
||||||
responseText: string;
|
responseText: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The request library is bundled into an interface to make mocking easy.
|
||||||
|
*/
|
||||||
export interface HttpRequestLibrary {
|
export interface HttpRequestLibrary {
|
||||||
req(method: string,
|
|
||||||
url: string,
|
|
||||||
options?: any): Promise<HttpResponse>;
|
|
||||||
|
|
||||||
get(url: string): Promise<HttpResponse>;
|
get(url: string): Promise<HttpResponse>;
|
||||||
|
|
||||||
postJson(url: string, body: any): 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 {
|
export class BrowserHttpLib {
|
||||||
req(method: string,
|
private req(method: string,
|
||||||
url: string,
|
url: string,
|
||||||
options?: any): Promise<HttpResponse> {
|
options?: any): Promise<HttpResponse> {
|
||||||
return new Promise<HttpResponse>((resolve, reject) => {
|
return new Promise<HttpResponse>((resolve, reject) => {
|
||||||
@ -82,8 +85,10 @@ export class BrowserHttpLib {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exception thrown on request errors.
|
||||||
|
*/
|
||||||
export class RequestException {
|
export class RequestException {
|
||||||
constructor(detail: any) {
|
constructor(public detail: any) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,13 +17,12 @@
|
|||||||
/**
|
/**
|
||||||
* Page shown to the user to confirm entering
|
* Page shown to the user to confirm entering
|
||||||
* a contract.
|
* a contract.
|
||||||
*
|
|
||||||
* @author Florian Dold
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
import {substituteFulfillmentUrl} from "../helpers";
|
/**
|
||||||
|
* 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, prettyAmount} from "../renderHtml";
|
||||||
@ -201,8 +200,7 @@ class ContractPrompt extends React.Component<ContractPromptProps, ContractPrompt
|
|||||||
}
|
}
|
||||||
let c = d.offer!.contract;
|
let c = d.offer!.contract;
|
||||||
console.log("contract", c);
|
console.log("contract", c);
|
||||||
document.location.href = substituteFulfillmentUrl(c.fulfillment_url,
|
document.location.href = c.fulfillment_url;
|
||||||
this.state.offer);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +25,6 @@
|
|||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
import {substituteFulfillmentUrl} from "../helpers";
|
|
||||||
import BrowserClickedEvent = chrome.browserAction.BrowserClickedEvent;
|
import BrowserClickedEvent = chrome.browserAction.BrowserClickedEvent;
|
||||||
import {HistoryRecord, HistoryLevel} from "../wallet";
|
import {HistoryRecord, HistoryLevel} from "../wallet";
|
||||||
import {
|
import {
|
||||||
@ -372,8 +371,7 @@ function formatHistoryItem(historyItem: HistoryRecord) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
case "pay": {
|
case "pay": {
|
||||||
let url = substituteFulfillmentUrl(d.fulfillmentUrl,
|
let url = d.fulfillmentUrl;
|
||||||
{H_contract: d.contractHash});
|
|
||||||
let merchantElem = <em>{abbrev(d.merchantName, 15)}</em>;
|
let merchantElem = <em>{abbrev(d.merchantName, 15)}</em>;
|
||||||
let fulfillmentLinkElem = <a href={url} onClick={openTab(url)}>view product</a>;
|
let fulfillmentLinkElem = <a href={url} onClick={openTab(url)}>view product</a>;
|
||||||
return (
|
return (
|
||||||
|
7
tooling/README
Normal file
7
tooling/README
Normal 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.
|
Loading…
Reference in New Issue
Block a user