diff options
author | Florian Dold <florian.dold@gmail.com> | 2016-09-12 20:25:56 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2016-09-12 20:25:56 +0200 |
commit | 885285734733b71c88dfb0da513988eb8678aa14 (patch) | |
tree | dcaa19022de33210a97266fcb7a91055ea8e42c7 /pages | |
parent | e3cc9c59bcc36eee8c3234574cfdfda3f5eea658 (diff) |
fix compiler warnings
Diffstat (limited to 'pages')
-rw-r--r-- | pages/confirm-contract.tsx | 10 | ||||
-rw-r--r-- | pages/confirm-create-reserve.tsx | 49 | ||||
-rw-r--r-- | pages/show-db.ts | 27 |
3 files changed, 42 insertions, 44 deletions
diff --git a/pages/confirm-contract.tsx b/pages/confirm-contract.tsx index fadbc3233..e88336a2d 100644 --- a/pages/confirm-contract.tsx +++ b/pages/confirm-contract.tsx @@ -26,11 +26,11 @@ import MithrilComponent = _mithril.MithrilComponent; import {substituteFulfillmentUrl} from "../lib/wallet/helpers"; import m from "mithril"; -import {Contract} from "../lib/wallet/types"; +import {Contract, AmountJson} from "../lib/wallet/types"; "use strict"; -function prettyAmount(amount) { +function prettyAmount(amount: AmountJson) { let v = amount.value + amount.fraction / 1e6; return `${v.toFixed(2)} ${amount.currency}`; } @@ -40,7 +40,7 @@ const Details = { controller() { return {collapsed: m.prop(true)}; }, - view(ctrl, contract: Contract) { + view(ctrl: any, contract: Contract) { if (ctrl.collapsed()) { return m("div", [ m("button.linky", { @@ -71,11 +71,11 @@ export function main() { let offer = JSON.parse(query.offer); console.dir(offer); let contract = offer.contract; - let error = null; + let error: string|null = null; let payDisabled = true; var Contract = { - view(ctrl) { + view(ctrl: any) { return [ m("p", i18n.parts`${m("strong", contract.merchant.name)} diff --git a/pages/confirm-create-reserve.tsx b/pages/confirm-create-reserve.tsx index dafd3ef33..b965f35c9 100644 --- a/pages/confirm-create-reserve.tsx +++ b/pages/confirm-create-reserve.tsx @@ -41,10 +41,10 @@ import {getReserveCreationInfo} from "../lib/wallet/wxApi"; */ class DelayTimer { ms: number; - f; - timerId: number = null; + f: () => void; + timerId: number|undefined = undefined; - constructor(ms: number, f) { + constructor(ms: number, f: () => void) { this.f = f; this.ms = ms; } @@ -58,7 +58,7 @@ class DelayTimer { } stop() { - if (this.timerId !== null) { + if (this.timerId != undefined) { window.clearTimeout(this.timerId); } } @@ -67,11 +67,10 @@ class DelayTimer { class Controller { url = m.prop<string>(); - statusString = null; + statusString: string | null = null; isValidExchange = false; - reserveCreationInfo: ReserveCreationInfo = null; + reserveCreationInfo?: ReserveCreationInfo; private timer: DelayTimer; - private request: XMLHttpRequest; amount: AmountJson; callbackUrl: string; wtTypes: string[]; @@ -97,7 +96,7 @@ class Controller { private update() { this.timer.stop(); const doUpdate = () => { - this.reserveCreationInfo = null; + this.reserveCreationInfo = undefined; if (!this.url()) { this.statusString = i18n`Error: URL is empty`; m.redraw(true); @@ -126,7 +125,7 @@ class Controller { .catch((e) => { console.log("get exchange info rejected"); if (e.hasOwnProperty("httpStatus")) { - this.statusString = `Error: request failed with status ${this.request.status}`; + this.statusString = `Error: request failed with status ${e.httpStatus}`; } else if (e.hasOwnProperty("errorResponse")) { let resp = e.errorResponse; this.statusString = `Error: ${resp.error} (${resp.hint})`; @@ -143,11 +142,7 @@ class Controller { reset() { this.isValidExchange = false; this.statusString = null; - this.reserveCreationInfo = null; - if (this.request) { - this.request.abort(); - this.request = null; - } + this.reserveCreationInfo = undefined; } confirmReserve(rci: ReserveCreationInfo, @@ -155,7 +150,7 @@ class Controller { amount: AmountJson, callback_url: string) { const d = {exchange, amount}; - const cb = (rawResp) => { + const cb = (rawResp: any) => { if (!rawResp) { throw Error("empty response"); } @@ -195,8 +190,8 @@ class Controller { } function view(ctrl: Controller): any { - let controls = []; - let mx = (x, ...args) => controls.push(m(x, ...args)); + let controls: any[] = []; + let mx = (x: any, ...args: any[]) => controls.push(m(x, ...args)); mx("p", i18n.parts`You are about to withdraw ${m("strong", amountToPretty( @@ -210,8 +205,8 @@ function view(ctrl: Controller): any { } function viewSimple(ctrl: Controller) { - let controls = []; - let mx = (x, ...args) => controls.push(m(x, ...args)); + let controls: any[] = []; + let mx = (x: any, ...args: any[]) => controls.push(m(x, ...args)); if (ctrl.statusString) { mx("p", "Error: ", ctrl.statusString); @@ -221,9 +216,9 @@ function viewSimple(ctrl: Controller) { } }, "advanced options"); } - else if (ctrl.reserveCreationInfo) { + else if (ctrl.reserveCreationInfo != undefined) { mx("button.accept", { - onclick: () => ctrl.confirmReserve(ctrl.reserveCreationInfo, + onclick: () => ctrl.confirmReserve(ctrl.reserveCreationInfo!, ctrl.url(), ctrl.amount, ctrl.callbackUrl), @@ -249,11 +244,11 @@ function viewSimple(ctrl: Controller) { function viewComplex(ctrl: Controller) { - let controls = []; - let mx = (x, ...args) => controls.push(m(x, ...args)); + let controls: any[] = []; + let mx = (x: any, ...args: any[]) => controls.push(m(x, ...args)); mx("button.accept", { - onclick: () => ctrl.confirmReserve(ctrl.reserveCreationInfo, + onclick: () => ctrl.confirmReserve(ctrl.reserveCreationInfo!, ctrl.url(), ctrl.amount, ctrl.callbackUrl), @@ -314,8 +309,8 @@ function viewComplex(ctrl: Controller) { function renderReserveCreationDetails(rci: ReserveCreationInfo) { let denoms = rci.selectedDenoms; - let countByPub = {}; - let uniq = []; + let countByPub: {[s: string]: number} = {}; + let uniq: Denomination[] = []; denoms.forEach((x: Denomination) => { let c = countByPub[x.denom_pub] || 0; @@ -358,7 +353,7 @@ function renderReserveCreationDetails(rci: ReserveCreationInfo) { function getSuggestedExchange(currency: string): Promise<string> { // TODO: make this request go to the wallet backend // Right now, this is a stub. - const defaultExchange = { + const defaultExchange: {[s: string]: string} = { "KUDOS": "https://exchange.demo.taler.net", "PUDOS": "https://exchange.test.taler.net", }; diff --git a/pages/show-db.ts b/pages/show-db.ts index 9a7b315cf..0a3a5bd46 100644 --- a/pages/show-db.ts +++ b/pages/show-db.ts @@ -21,30 +21,33 @@ * @author Florian Dold */ -function replacer(match, pIndent, pKey, pVal, pEnd) { +function replacer(match: string, pIndent: string, pKey: string, pVal: string, + pEnd: string) { var key = '<span class=json-key>'; var val = '<span class=json-value>'; var str = '<span class=json-string>'; var r = pIndent || ''; - if (pKey) - r = r + key + pKey.replace(/[": ]/g, '') + '</span>: '; - if (pVal) - r = r + (pVal[0] == '"' ? str : val) + pVal + '</span>'; + if (pKey) { + r = r + key + pKey.replace(/[": ]/g, '') + '</span>: '; + } + if (pVal) { + r = r + (pVal[0] == '"' ? str : val) + pVal + '</span>'; + } return r + (pEnd || ''); } -function prettyPrint(obj) { +function prettyPrint(obj: any) { var jsonLine = /^( *)("[\w]+": )?("[^"]*"|[\w.+-]*)?([,[{])?$/mg; - return JSON.stringify(obj, null, 3) - .replace(/&/g, '&').replace(/\\"/g, '"') - .replace(/</g, '<').replace(/>/g, '>') - .replace(jsonLine, replacer); + return JSON.stringify(obj, null as any, 3) + .replace(/&/g, '&').replace(/\\"/g, '"') + .replace(/</g, '<').replace(/>/g, '>') + .replace(jsonLine, replacer); } -document.addEventListener("DOMContentLoaded", (e) => { - chrome.runtime.sendMessage({type:'dump-db'}, (resp) => { +document.addEventListener("DOMContentLoaded", () => { + chrome.runtime.sendMessage({type: 'dump-db'}, (resp) => { document.getElementById('dump').innerHTML = prettyPrint(resp); }); }); |