fix problems found by newer TypeScript compiler

This commit is contained in:
Florian Dold 2017-12-10 23:02:00 +01:00
parent 0469abd4a9
commit 3c882c44b5
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
12 changed files with 66 additions and 51 deletions

View File

@ -218,7 +218,7 @@ export class CryptoApi {
...args: any[]): Promise<T> { ...args: any[]): Promise<T> {
const start = timer.performanceNow(); const start = timer.performanceNow();
const p = new Promise((resolve, reject) => { const p: Promise<T> = new Promise<T>((resolve, reject) => {
const rpcId = this.nextRpcId++; const rpcId = this.nextRpcId++;
const workItem: WorkItem = {operation, args, resolve, reject, rpcId}; const workItem: WorkItem = {operation, args, resolve, reject, rpcId};

View File

@ -127,9 +127,15 @@ export interface QueryStream<T> {
filter(f: (x: T) => boolean): QueryStream<T>; filter(f: (x: T) => boolean): QueryStream<T>;
/** /**
* Reduce the stream, resulting in a single value. * Fold the stream, resulting in a single value.
*/ */
reduce<S>(f: (v: T, acc?: S) => S, start?: S): Promise<S>; fold<S>(f: (v: T, acc: S) => S, start: S): Promise<S>;
/**
* Execute a function for every value of the stream, for the
* side-effects of the function.
*/
forEach(f: (v: T) => void): Promise<void>;
/** /**
* Map each element of the stream using a function, resulting in another * Map each element of the stream using a function, resulting in another
@ -324,7 +330,7 @@ abstract class QueryStreamBase<T> implements QueryStream<T> {
.then(() => promise); .then(() => promise);
} }
reduce<A>(f: (x: any, acc?: A) => A, init?: A): Promise<any> { fold<A>(f: (x: T, acc: A) => A, init: A): Promise<A> {
const {resolve, promise} = openPromise(); const {resolve, promise} = openPromise();
let acc = init; let acc = init;
@ -341,6 +347,22 @@ abstract class QueryStreamBase<T> implements QueryStream<T> {
.then(() => promise); .then(() => promise);
} }
forEach(f: (x: T) => void): Promise<void> {
const {resolve, promise} = openPromise();
this.subscribe((isDone, value) => {
if (isDone) {
resolve();
return;
}
f(value);
});
return Promise.resolve()
.then(() => this.root.finish())
.then(() => promise);
}
run(): Promise<void> { run(): Promise<void> {
const {resolve, promise} = openPromise(); const {resolve, promise} = openPromise();
@ -699,7 +721,7 @@ export class QueryRoot {
* If the mutation function throws AbortTransaction, the whole transaction will be aborted. * If the mutation function throws AbortTransaction, the whole transaction will be aborted.
* If the mutation function returns undefined or null, no modification will be made. * If the mutation function returns undefined or null, no modification will be made.
*/ */
mutate<T>(store: Store<T>, key: any, f: (v: T|undefined) => T|undefined): QueryRoot { mutate<T>(store: Store<T>, key: any, f: (v: T) => T|undefined): QueryRoot {
this.checkFinished(); this.checkFinished();
const doPut = (tx: IDBTransaction) => { const doPut = (tx: IDBTransaction) => {
const req = tx.objectStore(store.name).openCursor(IDBKeyRange.only(key)); const req = tx.objectStore(store.name).openCursor(IDBKeyRange.only(key));

View File

@ -730,34 +730,34 @@ export class Wallet {
this.q() this.q()
.iter(Stores.reserves) .iter(Stores.reserves)
.reduce((reserve) => { .forEach((reserve) => {
console.log("resuming reserve", reserve.reserve_pub); console.log("resuming reserve", reserve.reserve_pub);
this.processReserve(reserve); this.processReserve(reserve);
}); });
this.q() this.q()
.iter(Stores.precoins) .iter(Stores.precoins)
.reduce((preCoin) => { .forEach((preCoin) => {
console.log("resuming precoin"); console.log("resuming precoin");
this.processPreCoin(preCoin); this.processPreCoin(preCoin);
}); });
this.q() this.q()
.iter(Stores.refresh) .iter(Stores.refresh)
.reduce((r: RefreshSessionRecord) => { .forEach((r: RefreshSessionRecord) => {
this.continueRefreshSession(r); this.continueRefreshSession(r);
}); });
this.q() this.q()
.iter(Stores.coinsReturns) .iter(Stores.coinsReturns)
.reduce((r: CoinsReturnRecord) => { .forEach((r: CoinsReturnRecord) => {
this.depositReturnedCoins(r); this.depositReturnedCoins(r);
}); });
// FIXME: optimize via index // FIXME: optimize via index
this.q() this.q()
.iter(Stores.coins) .iter(Stores.coins)
.reduce((c: CoinRecord) => { .forEach((c: CoinRecord) => {
if (c.status === CoinStatus.Dirty) { if (c.status === CoinStatus.Dirty) {
console.log("resuming pending refresh for coin", c); console.log("resuming pending refresh for coin", c);
this.refresh(c.coinPub); this.refresh(c.coinPub);
@ -1536,7 +1536,6 @@ export class Wallet {
); );
let allValid = false; let allValid = false;
let currentPossibleDenoms = possibleDenoms;
let selectedDenoms: DenominationRecord[]; let selectedDenoms: DenominationRecord[];
@ -1561,7 +1560,6 @@ export class Wallet {
nextPossibleDenoms.push(denom); nextPossibleDenoms.push(denom);
} }
} }
currentPossibleDenoms = nextPossibleDenoms;
} while (selectedDenoms.length > 0 && !allValid); } while (selectedDenoms.length > 0 && !allValid);
return selectedDenoms; return selectedDenoms;
@ -1709,7 +1707,7 @@ export class Wallet {
.iterIndex(Stores.coins.exchangeBaseUrlIndex, exchangeInfo.baseUrl) .iterIndex(Stores.coins.exchangeBaseUrlIndex, exchangeInfo.baseUrl)
.indexJoinLeft(Stores.denominations.exchangeBaseUrlIndex, .indexJoinLeft(Stores.denominations.exchangeBaseUrlIndex,
(e) => e.exchangeBaseUrl) (e) => e.exchangeBaseUrl)
.reduce((cd: JoinLeftResult<CoinRecord, DenominationRecord>, .fold((cd: JoinLeftResult<CoinRecord, DenominationRecord>,
suspendedCoins: CoinRecord[]) => { suspendedCoins: CoinRecord[]) => {
if ((!cd.right) || (!cd.right.isOffered)) { if ((!cd.right) || (!cd.right.isOffered)) {
return Array.prototype.concat(suspendedCoins, [cd.left]); return Array.prototype.concat(suspendedCoins, [cd.left]);
@ -1718,7 +1716,7 @@ export class Wallet {
}, [])); }, []));
const q = this.q(); const q = this.q();
resultSuspendedCoins.map((c) => { resultSuspendedCoins.map((c: CoinRecord) => {
console.log("suspending coin", c); console.log("suspending coin", c);
c.suspended = true; c.suspended = true;
q.put(Stores.coins, c); q.put(Stores.coins, c);
@ -1851,7 +1849,7 @@ export class Wallet {
const existingDenoms: {[denomPub: string]: DenominationRecord} = await ( const existingDenoms: {[denomPub: string]: DenominationRecord} = await (
this.q().iterIndex(Stores.denominations.exchangeBaseUrlIndex, this.q().iterIndex(Stores.denominations.exchangeBaseUrlIndex,
exchangeInfo.baseUrl) exchangeInfo.baseUrl)
.reduce((x: DenominationRecord, .fold((x: DenominationRecord,
acc: typeof existingDenoms) => (acc[x.denomPub] = x, acc), acc: typeof existingDenoms) => (acc[x.denomPub] = x, acc),
{}) {})
); );
@ -1995,19 +1993,19 @@ export class Wallet {
.iter(Stores.exchanges) .iter(Stores.exchanges)
.indexJoin(Stores.denominations.exchangeBaseUrlIndex, .indexJoin(Stores.denominations.exchangeBaseUrlIndex,
(x) => x.baseUrl) (x) => x.baseUrl)
.reduce(collectSmallestWithdraw, {})); .fold(collectSmallestWithdraw, {}));
const tx = this.q(); const tx = this.q();
tx.iter(Stores.coins) tx.iter(Stores.coins)
.reduce(collectBalances, balanceStore); .fold(collectBalances, balanceStore);
tx.iter(Stores.refresh) tx.iter(Stores.refresh)
.reduce(collectPendingRefresh, balanceStore); .fold(collectPendingRefresh, balanceStore);
tx.iter(Stores.reserves) tx.iter(Stores.reserves)
.reduce(collectPendingWithdraw, balanceStore); .fold(collectPendingWithdraw, balanceStore);
tx.iter(Stores.reserves) tx.iter(Stores.reserves)
.reduce(collectPaybacks, balanceStore); .fold(collectPaybacks, balanceStore);
tx.iter(Stores.purchases) tx.iter(Stores.purchases)
.reduce(collectPayments, balanceStore); .fold(collectPayments, balanceStore);
await tx.finish(); await tx.finish();
return balanceStore; return balanceStore;
} }

View File

@ -49,7 +49,7 @@ if (document.documentElement.getAttribute("data-taler-nojs")) {
interface Handler { interface Handler {
type: string; type: string;
listener: (e: CustomEvent) => void|Promise<void>; listener: (e: Event) => void|Promise<void>;
} }
const handlers: Handler[] = []; const handlers: Handler[] = [];
@ -230,13 +230,6 @@ async function processProposal(proposal: any) {
return; return;
} }
let merchantName = "(unknown)";
try {
merchantName = proposal.data.merchant.name;
} catch (e) {
// bad contract / name not included
}
const proposalId = await wxApi.saveProposal({ const proposalId = await wxApi.saveProposal({
contractTerms: proposal.data, contractTerms: proposal.data,
contractTermsHash: proposal.hash, contractTermsHash: proposal.hash,
@ -400,7 +393,10 @@ function registerHandlers() {
* handles adding sequence numbers to responses. * handles adding sequence numbers to responses.
*/ */
function addHandler(type: string, handler: HandlerFn) { function addHandler(type: string, handler: HandlerFn) {
const handlerWrap = (e: CustomEvent) => { const handlerWrap = (e: Event) => {
if (!(e instanceof CustomEvent)) {
throw Error(`invariant violated`);
}
if (e.type !== type) { if (e.type !== type) {
throw Error(`invariant violated`); throw Error(`invariant violated`);
} }

View File

@ -44,8 +44,8 @@ interface ConfirmAuditorProps {
class ConfirmAuditor extends ImplicitStateComponent<ConfirmAuditorProps> { class ConfirmAuditor extends ImplicitStateComponent<ConfirmAuditorProps> {
private addDone: StateHolder<boolean> = this.makeState(false); private addDone: StateHolder<boolean> = this.makeState(false);
constructor() { constructor(props: ConfirmAuditorProps) {
super(); super(props);
} }
async add() { async add() {

View File

@ -39,9 +39,9 @@ interface CurrencyListState {
currencies?: CurrencyRecord[]; currencies?: CurrencyRecord[];
} }
class CurrencyList extends React.Component<any, CurrencyListState> { class CurrencyList extends React.Component<{}, CurrencyListState> {
constructor() { constructor(props: {}) {
super(); super(props);
const port = chrome.runtime.connect(); const port = chrome.runtime.connect();
port.onMessage.addListener((msg: any) => { port.onMessage.addListener((msg: any) => {
if (msg.notify) { if (msg.notify) {

View File

@ -118,8 +118,8 @@ interface ContractPromptState {
} }
class ContractPrompt extends React.Component<ContractPromptProps, ContractPromptState> { class ContractPrompt extends React.Component<ContractPromptProps, ContractPromptState> {
constructor() { constructor(props: ContractPromptProps) {
super(); super(props);
this.state = { this.state = {
alreadyPaid: false, alreadyPaid: false,
error: null, error: null,

View File

@ -55,9 +55,9 @@ interface LogsState {
logs: LogEntry[]|undefined; logs: LogEntry[]|undefined;
} }
class Logs extends React.Component<any, LogsState> { class Logs extends React.Component<{}, LogsState> {
constructor() { constructor(props: {}) {
super(); super({});
this.update(); this.update();
this.state = {} as any; this.state = {} as any;
} }

View File

@ -38,10 +38,10 @@ import {
import * as React from "react"; import * as React from "react";
import * as ReactDOM from "react-dom"; import * as ReactDOM from "react-dom";
class Payback extends ImplicitStateComponent<any> { class Payback extends ImplicitStateComponent<{}> {
private reserves: StateHolder<ReserveRecord[]|null> = this.makeState(null); private reserves: StateHolder<ReserveRecord[]|null> = this.makeState(null);
constructor() { constructor(props: {}) {
super(); super(props);
const port = chrome.runtime.connect(); const port = chrome.runtime.connect();
port.onMessage.addListener((msg: any) => { port.onMessage.addListener((msg: any) => {
if (msg.notify) { if (msg.notify) {

View File

@ -189,9 +189,9 @@ interface ReturnCoinsState {
lastConfirmedDetail: SelectedDetail | undefined; lastConfirmedDetail: SelectedDetail | undefined;
} }
class ReturnCoins extends React.Component<any, ReturnCoinsState> { class ReturnCoins extends React.Component<{}, ReturnCoinsState> {
constructor() { constructor(props: {}) {
super(); super(props);
const port = chrome.runtime.connect(); const port = chrome.runtime.connect();
port.onMessage.addListener((msg: any) => { port.onMessage.addListener((msg: any) => {
if (msg.notify) { if (msg.notify) {

View File

@ -360,9 +360,9 @@ interface ExchangesListState {
exchanges?: ExchangeRecord[]; exchanges?: ExchangeRecord[];
} }
class ExchangesList extends React.Component<any, ExchangesListState> { class ExchangesList extends React.Component<{}, ExchangesListState> {
constructor() { constructor(props: {}) {
super(); super(props);
const port = chrome.runtime.connect(); const port = chrome.runtime.connect();
port.onMessage.addListener((msg: any) => { port.onMessage.addListener((msg: any) => {
if (msg.notify) { if (msg.notify) {

View File

@ -497,9 +497,8 @@ function handleBankRequest(wallet: Wallet, headerList: chrome.webRequest.HttpHea
console.log("202 not understood (X-Taler-Callback-Url missing)"); console.log("202 not understood (X-Taler-Callback-Url missing)");
return; return;
} }
let amountParsed;
try { try {
amountParsed = JSON.parse(amount); JSON.parse(amount);
} catch (e) { } catch (e) {
const errUri = new URI(chrome.extension.getURL("/src/webex/pages/error.html")); const errUri = new URI(chrome.extension.getURL("/src/webex/pages/error.html"));
const p = { const p = {