lint for unused variables, fix query bug detected by this

This commit is contained in:
Florian Dold 2017-05-29 18:27:50 +02:00
parent b5c90d1221
commit 94d111a945
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
21 changed files with 28 additions and 107 deletions

View File

@ -111,6 +111,7 @@ const tsBaseArgs = {
noImplicitAny: true, noImplicitAny: true,
allowJs: true, allowJs: true,
checkJs: true, checkJs: true,
noUnusedLocals: true,
}; };

View File

@ -94,6 +94,7 @@ test("precoin creation", async (t) => {
}; };
const precoin = await crypto.createPreCoin(denomValid1, r); const precoin = await crypto.createPreCoin(denomValid1, r);
t.truthy(precoin);
t.pass(); t.pass();
}); });

View File

@ -100,7 +100,7 @@ export class CryptoApi {
/** /**
* Start a worker (if not started) and set as busy. * Start a worker (if not started) and set as busy.
*/ */
wake<T>(ws: WorkerState, work: WorkItem): void { wake(ws: WorkerState, work: WorkItem): void {
if (ws.currentWorkItem !== null) { if (ws.currentWorkItem !== null) {
throw Error("assertion failed"); throw Error("assertion failed");
} }
@ -238,7 +238,7 @@ export class CryptoApi {
continue; continue;
} }
this.wake<T>(ws, workItem); this.wake(ws, workItem);
return; return;
} }

View File

@ -114,6 +114,8 @@ test("withdraw-request", (t) => {
test("ecdsa", (t) => { test("ecdsa", (t) => {
const priv = native.EcdsaPrivateKey.create(); const priv = native.EcdsaPrivateKey.create();
const pub1 = priv.getPublicKey(); const pub1 = priv.getPublicKey();
t.truthy(priv);
t.truthy(pub1);
t.pass(); t.pass();
}); });
@ -121,5 +123,7 @@ test("ecdsa", (t) => {
test("ecdhe", (t) => { test("ecdhe", (t) => {
const priv = native.EcdhePrivateKey.create(); const priv = native.EcdhePrivateKey.create();
const pub = priv.getPublicKey(); const pub = priv.getPublicKey();
t.truthy(priv);
t.truthy(pub);
t.pass(); t.pass();
}); });

View File

@ -40,9 +40,6 @@ const emscLib = getLib();
const PTR_SIZE = 4; const PTR_SIZE = 4;
const GNUNET_OK = 1; const GNUNET_OK = 1;
const GNUNET_YES = 1;
const GNUNET_NO = 0;
const GNUNET_SYSERR = -1;
/** /**

View File

@ -49,6 +49,7 @@ export class Store<T> {
} }
} }
/** /**
* Definition of an index. * Definition of an index.
*/ */
@ -61,6 +62,13 @@ export class Index<S extends IDBValidKey, T> {
constructor(s: Store<T>, public indexName: string, public keyPath: string | string[]) { constructor(s: Store<T>, public indexName: string, public keyPath: string | string[]) {
this.storeName = s.name; this.storeName = s.name;
} }
/**
* We want to have the key type parameter in use somewhere,
* because otherwise the compiler complains. In iterIndex the
* key type is pretty useful.
*/
protected _dummyKey: S|undefined;
} }
/** /**
@ -315,7 +323,6 @@ abstract class QueryStreamBase<T> implements QueryStream<T>, PromiseLike<void> {
type FilterFn = (e: any) => boolean; type FilterFn = (e: any) => boolean;
type SubscribeFn = (done: boolean, value: any, tx: IDBTransaction) => void; type SubscribeFn = (done: boolean, value: any, tx: IDBTransaction) => void;
type SubscribeOneFn = (value: any, tx: IDBTransaction) => void; type SubscribeOneFn = (value: any, tx: IDBTransaction) => void;
type FlatMapFn<T> = (v: T) => T[];
class QueryStreamFilter<T> extends QueryStreamBase<T> { class QueryStreamFilter<T> extends QueryStreamBase<T> {
constructor(public s: QueryStreamBase<T>, public filterFn: FilterFn) { constructor(public s: QueryStreamBase<T>, public filterFn: FilterFn) {
@ -349,7 +356,7 @@ class QueryStreamFlatMap<T, S> extends QueryStreamBase<S> {
} }
const values = this.flatMapFn(value); const values = this.flatMapFn(value);
for (const v in values) { for (const v in values) {
f(false, value, tx); f(false, v, tx);
} }
}); });
} }

View File

@ -899,40 +899,12 @@ export interface WalletBalanceEntry {
} }
/**
* Information about a merchant.
*/
interface Merchant {
/**
* label for a location with the business address of the merchant
*/
address: string;
/**
* the merchant's legal name of business
*/
name: string;
/**
* label for a location that denotes the jurisdiction for disputes.
* Some of the typical fields for a location (such as a street address) may be absent.
*/
jurisdiction: string;
/**
* Instance of the merchant, in case one merchant
* represents multiple receivers.
*/
instance?: string;
}
/** /**
* Contract terms from a merchant. * Contract terms from a merchant.
*/ */
@Checkable.Class({validate: true}) @Checkable.Class({validate: true})
export class Contract { export class Contract {
private validate() { validate() {
if (this.exchanges.length === 0) { if (this.exchanges.length === 0) {
throw Error("no exchanges in contract"); throw Error("no exchanges in contract");
} }

View File

@ -28,13 +28,10 @@ import {
amountToPretty, amountToPretty,
canonicalJson, canonicalJson,
canonicalizeBaseUrl, canonicalizeBaseUrl,
deepEquals,
flatMap,
getTalerStampSec, getTalerStampSec,
} from "./helpers"; } from "./helpers";
import { import {
HttpRequestLibrary, HttpRequestLibrary,
HttpResponse,
RequestException, RequestException,
} from "./http"; } from "./http";
import { import {
@ -49,7 +46,6 @@ import {
AmountJson, AmountJson,
Amounts, Amounts,
Auditor, Auditor,
AuditorRecord,
CheckPayResult, CheckPayResult,
CoinPaySig, CoinPaySig,
CoinRecord, CoinRecord,
@ -1045,7 +1041,6 @@ export class Wallet {
this.startOperation(opId); this.startOperation(opId);
try { try {
const exchange = await this.updateExchangeFromUrl(reserveRecord.exchange_base_url);
const reserve = await this.updateReserve(reserveRecord.reserve_pub); const reserve = await this.updateReserve(reserveRecord.reserve_pub);
const n = await this.depleteReserve(reserve); const n = await this.depleteReserve(reserve);
@ -1381,12 +1376,14 @@ export class Wallet {
requestedAmount: reserve.requested_amount, requestedAmount: reserve.requested_amount,
reservePub, reservePub,
}, },
level: HistoryLevel.Developer,
subjectId: `reserve-progress-${reserve.reserve_pub}`, subjectId: `reserve-progress-${reserve.reserve_pub}`,
timestamp: (new Date()).getTime(), timestamp: (new Date()).getTime(),
type: "reserve-update", type: "reserve-update",
}; };
await this.q() await this.q()
.put(Stores.reserves, reserve) .put(Stores.reserves, reserve)
.put(Stores.history, historyEntry)
.finish(); .finish();
this.notifier.notify(); this.notifier.notify();
return reserve; return reserve;

View File

@ -27,12 +27,8 @@
*/ */
import URI = require("urijs"); import URI = require("urijs");
import * as wxApi from "./wxApi";
declare var cloneInto: any; declare var cloneInto: any;
const PROTOCOL_VERSION = 1;
let logVerbose: boolean = false; let logVerbose: boolean = false;
try { try {
logVerbose = !!localStorage.getItem("taler-log-verbose"); logVerbose = !!localStorage.getItem("taler-log-verbose");
@ -45,12 +41,6 @@ if (document.documentElement.getAttribute("data-taler-nojs")) {
} }
function subst(url: string, H_contract: string) {
url = url.replace("${H_contract}", H_contract);
url = url.replace("${$}", "$");
return url;
}
interface Handler { interface Handler {
type: string; type: string;
listener: (e: CustomEvent) => void|Promise<void>; listener: (e: CustomEvent) => void|Promise<void>;

View File

@ -21,16 +21,8 @@
*/ */
import { getTalerStampDate } from "../../helpers";
import { import {
AuditorRecord,
CoinRecord,
CurrencyRecord, CurrencyRecord,
Denomination,
DenominationRecord,
ExchangeRecord,
PreCoinRecord,
ReserveRecord,
} from "../../types"; } from "../../types";
import { ImplicitStateComponent, StateHolder } from "../components"; import { ImplicitStateComponent, StateHolder } from "../components";

View File

@ -21,20 +21,12 @@
*/ */
import { getTalerStampDate } from "../../helpers";
import { import {
AuditorRecord, AuditorRecord,
CoinRecord,
CurrencyRecord, CurrencyRecord,
Denomination,
DenominationRecord,
ExchangeForCurrencyRecord, ExchangeForCurrencyRecord,
ExchangeRecord,
PreCoinRecord,
ReserveRecord,
} from "../../types"; } from "../../types";
import { ImplicitStateComponent, StateHolder } from "../components";
import { import {
getCurrencies, getCurrencies,
updateCurrency, updateCurrency,

View File

@ -25,7 +25,6 @@
*/ */
import * as i18n from "../../i18n"; import * as i18n from "../../i18n";
import { import {
AmountJson,
Contract, Contract,
ExchangeRecord, ExchangeRecord,
OfferRecord, OfferRecord,

View File

@ -29,7 +29,6 @@ import {
Amounts, Amounts,
CreateReserveResponse, CreateReserveResponse,
CurrencyRecord, CurrencyRecord,
Denomination,
DenominationRecord, DenominationRecord,
ReserveCreationInfo, ReserveCreationInfo,
} from "../../types"; } from "../../types";
@ -229,16 +228,6 @@ function renderReserveCreationDetails(rci: ReserveCreationInfo|null) {
} }
function WithdrawFee(props: {reserveCreationInfo: ReserveCreationInfo|null}): JSX.Element {
if (props.reserveCreationInfo) {
const {overhead, withdrawFee} = props.reserveCreationInfo;
const totalCost = Amounts.add(overhead, withdrawFee).amount;
return <p>{i18n.str`Withdraw fees:`} {amountToPretty(totalCost)}</p>;
}
return <p />;
}
interface ExchangeSelectionProps { interface ExchangeSelectionProps {
suggestedExchangeUrl: string; suggestedExchangeUrl: string;
amount: AmountJson; amount: AmountJson;
@ -298,7 +287,7 @@ class ManualSelection extends ImplicitStateComponent<ManualSelectionProps> {
} }
try { try {
const url = canonicalizeBaseUrl(this.url()!); const url = canonicalizeBaseUrl(this.url()!);
const r = await getExchangeInfo(url); await getExchangeInfo(url);
console.log("getExchangeInfo returned"); console.log("getExchangeInfo returned");
this.isOkay(true); this.isOkay(true);
} catch (e) { } catch (e) {
@ -596,7 +585,6 @@ async function main() {
throw Error(i18n.str`Can't parse amount: ${e.message}`); throw Error(i18n.str`Can't parse amount: ${e.message}`);
} }
const callback_url = query.callback_url; const callback_url = query.callback_url;
const bank_url = query.bank_url;
let wt_types; let wt_types;
try { try {
wt_types = JSON.parse(query.wt_types); wt_types = JSON.parse(query.wt_types);

View File

@ -22,8 +22,6 @@
* @author Florian Dold * @author Florian Dold
*/ */
import {ImplicitStateComponent, StateHolder} from "../components";
import * as React from "react"; import * as React from "react";
import * as ReactDOM from "react-dom"; import * as ReactDOM from "react-dom";
import URI = require("urijs"); import URI = require("urijs");
@ -59,3 +57,5 @@ async function main() {
console.error(`got error "${e.message}"`, e); console.error(`got error "${e.message}"`, e);
} }
} }
document.addEventListener("DOMContentLoaded", () => main());

View File

@ -24,25 +24,14 @@
/** /**
* Imports. * Imports.
*/ */
import { amountToPretty, getTalerStampDate } from "../../helpers"; import { amountToPretty } from "../../helpers";
import { import {
AuditorRecord,
CoinRecord,
CurrencyRecord,
Denomination,
DenominationRecord,
ExchangeForCurrencyRecord,
ExchangeRecord,
PreCoinRecord,
ReserveRecord, ReserveRecord,
WalletBalance,
} from "../../types"; } from "../../types";
import { ImplicitStateComponent, StateHolder } from "../components"; import { ImplicitStateComponent, StateHolder } from "../components";
import { import {
getCurrencies,
getPaybackReserves, getPaybackReserves,
updateCurrency,
withdrawPaybackReserve, withdrawPaybackReserve,
} from "../wxApi"; } from "../wxApi";

View File

@ -325,7 +325,6 @@ class WalletBalanceView extends React.Component<any, any> {
}); });
const link = chrome.extension.getURL("/src/webex/pages/auditors.html"); const link = chrome.extension.getURL("/src/webex/pages/auditors.html");
const linkElem = <a className="actionLink" href={link} target="_blank">Trusted Auditors and Exchanges</a>; const linkElem = <a className="actionLink" href={link} target="_blank">Trusted Auditors and Exchanges</a>;
const paybackLink = chrome.extension.getURL("/src/webex/pages/payback.html");
const paybackLinkElem = <a className="actionLink" href={link} target="_blank">Trusted Auditors and Exchanges</a>; const paybackLinkElem = <a className="actionLink" href={link} target="_blank">Trusted Auditors and Exchanges</a>;
return ( return (
<div> <div>
@ -340,7 +339,6 @@ class WalletBalanceView extends React.Component<any, any> {
function formatHistoryItem(historyItem: HistoryRecord) { function formatHistoryItem(historyItem: HistoryRecord) {
const d = historyItem.detail; const d = historyItem.detail;
const t = historyItem.timestamp;
console.log("hist item", historyItem); console.log("hist item", historyItem);
switch (historyItem.type) { switch (historyItem.type) {
case "create-reserve": case "create-reserve":
@ -365,8 +363,6 @@ function formatHistoryItem(historyItem: HistoryRecord) {
} }
case "offer-contract": { case "offer-contract": {
const link = chrome.extension.getURL("view-contract.html"); const link = chrome.extension.getURL("view-contract.html");
const linkElem = <a href={link}>{abbrev(d.contractHash)}</a>;
const merchantElem = <em>{abbrev(d.merchantName, 15)}</em>;
return ( return (
<i18n.Translate wrap="p"> <i18n.Translate wrap="p">
Merchant <em>{abbrev(d.merchantName, 15)}</em> offered contract <a href={link}>{abbrev(d.contractHash)}</a>; Merchant <em>{abbrev(d.merchantName, 15)}</em> offered contract <a href={link}>{abbrev(d.contractHash)}</a>;

View File

@ -25,7 +25,6 @@ import { amountToPretty, getTalerStampDate } from "../../helpers";
import { import {
CoinRecord, CoinRecord,
CoinStatus, CoinStatus,
Denomination,
DenominationRecord, DenominationRecord,
ExchangeRecord, ExchangeRecord,
PreCoinRecord, PreCoinRecord,

View File

@ -27,8 +27,6 @@
import { amountToPretty } from "../helpers"; import { amountToPretty } from "../helpers";
import * as i18n from "../i18n"; import * as i18n from "../i18n";
import { import {
AmountJson,
Amounts,
Contract, Contract,
} from "../types"; } from "../types";

View File

@ -33,12 +33,10 @@ import {
} from "../query"; } from "../query";
import { import {
AmountJson, AmountJson,
Contract,
Notifier, Notifier,
OfferRecord, OfferRecord,
} from "../types"; } from "../types";
import { import {
Badge,
ConfirmReserveRequest, ConfirmReserveRequest,
CreateReserveRequest, CreateReserveRequest,
Stores, Stores,
@ -701,7 +699,6 @@ function importDb(db: IDBDatabase, dump: any): Promise<void> {
} }
console.log(`importing ${objects.length} records into ${storeName}`); console.log(`importing ${objects.length} records into ${storeName}`);
const store = tx.objectStore(storeName); const store = tx.objectStore(storeName);
const clearReq = store.clear();
for (const obj of objects) { for (const obj of objects) {
store.put(obj); store.put(obj);
} }

View File

@ -16,7 +16,8 @@
"outDir": "build/src/", "outDir": "build/src/",
"noImplicitAny": true, "noImplicitAny": true,
"allowJs": true, "allowJs": true,
"checkJs": true "checkJs": true,
"noUnusedLocals": true
}, },
"files": [ "files": [
"decl/chrome/chrome.d.ts", "decl/chrome/chrome.d.ts",

View File

@ -55,7 +55,8 @@
"namespaces": { "namespaces": {
"visibilities": ["exported"] "visibilities": ["exported"]
} }
}] }],
"no-unused-variable": true
}, },
"rulesDirectory": [] "rulesDirectory": []
} }