diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-01-10 19:39:37 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-01-10 19:43:50 +0800 |
commit | e34b0af25133629ad4c177c4d7d5050bd6ac19b8 (patch) | |
tree | 936eae17521984e5ccc28057973461e707322326 /packages/website | |
parent | fa7237fde7acea32c5492f0dcdef4d55b3ade6e1 (diff) | |
download | dexon-sol-tools-e34b0af25133629ad4c177c4d7d5050bd6ac19b8.tar dexon-sol-tools-e34b0af25133629ad4c177c4d7d5050bd6ac19b8.tar.gz dexon-sol-tools-e34b0af25133629ad4c177c4d7d5050bd6ac19b8.tar.bz2 dexon-sol-tools-e34b0af25133629ad4c177c4d7d5050bd6ac19b8.tar.lz dexon-sol-tools-e34b0af25133629ad4c177c4d7d5050bd6ac19b8.tar.xz dexon-sol-tools-e34b0af25133629ad4c177c4d7d5050bd6ac19b8.tar.zst dexon-sol-tools-e34b0af25133629ad4c177c4d7d5050bd6ac19b8.zip |
Fix ts error in portal after enabling more strict checks
Diffstat (limited to 'packages/website')
-rw-r--r-- | packages/website/ts/blockchain.ts | 6 | ||||
-rw-r--r-- | packages/website/ts/components/dialogs/ledger_config_dialog.tsx | 10 | ||||
-rw-r--r-- | packages/website/ts/components/fill_warning_dialog.tsx | 2 | ||||
-rw-r--r-- | packages/website/ts/components/inputs/allowance_toggle.tsx | 7 | ||||
-rw-r--r-- | packages/website/ts/components/inputs/token_amount_input.tsx | 2 | ||||
-rw-r--r-- | packages/website/ts/components/portal.tsx | 10 | ||||
-rw-r--r-- | packages/website/ts/components/top_bar.tsx | 12 | ||||
-rw-r--r-- | packages/website/ts/containers/portal.tsx | 8 | ||||
-rw-r--r-- | packages/website/ts/local_storage/tracked_token_storage.ts | 10 | ||||
-rw-r--r-- | packages/website/ts/types.ts | 6 | ||||
-rw-r--r-- | packages/website/ts/utils/doc_utils.ts | 4 | ||||
-rw-r--r-- | packages/website/tsconfig.json | 3 |
12 files changed, 42 insertions, 38 deletions
diff --git a/packages/website/ts/blockchain.ts b/packages/website/ts/blockchain.ts index 50cac6d29..1320fbeb9 100644 --- a/packages/website/ts/blockchain.ts +++ b/packages/website/ts/blockchain.ts @@ -66,12 +66,12 @@ export class Blockchain { private _cachedProvider: Web3.Provider; private _ledgerSubprovider: LedgerWalletSubprovider; private _zrxPollIntervalId: NodeJS.Timer; - private static async _onPageLoadAsync() { + private static async _onPageLoadAsync(): Promise<void> { if (document.readyState === 'complete') { return; // Already loaded } - return new Promise((resolve, reject) => { - window.onload = resolve; + return new Promise<void>((resolve, reject) => { + window.onload = () => resolve(); }); } private static _getNameGivenProvider(provider: Web3.Provider): string { diff --git a/packages/website/ts/components/dialogs/ledger_config_dialog.tsx b/packages/website/ts/components/dialogs/ledger_config_dialog.tsx index c8547694a..60db93c52 100644 --- a/packages/website/ts/components/dialogs/ledger_config_dialog.tsx +++ b/packages/website/ts/components/dialogs/ledger_config_dialog.tsx @@ -134,7 +134,7 @@ export class LedgerConfigDialog extends React.Component<LedgerConfigDialogProps, labelReady="Update" labelLoading="Updating..." labelComplete="Updated!" - onClickAsyncFn={this._onFetchAddressesForDerivationPathAsync.bind(this, true)} + onClickAsyncFn={this._onFetchAddressesForDerivationPathAsync.bind(this)} /> </div> </div> @@ -191,13 +191,15 @@ export class LedgerConfigDialog extends React.Component<LedgerConfigDialogProps, const isOpen = false; this.props.toggleDialogFn(isOpen); } - private async _onFetchAddressesForDerivationPathAsync() { + private async _onFetchAddressesForDerivationPathAsync(): Promise<boolean> { const currentlySetPath = this.props.blockchain.getLedgerDerivationPathIfExists(); + let didSucceed; if (currentlySetPath === this.state.derivationPath) { - return; + didSucceed = true; + return didSucceed; } this.props.blockchain.updateLedgerDerivationPathIfExists(this.state.derivationPath); - const didSucceed = await this._fetchAddressesAndBalancesAsync(); + didSucceed = await this._fetchAddressesAndBalancesAsync(); if (!didSucceed) { this.setState({ derivationErrMsg: 'Failed to connect to Ledger.', diff --git a/packages/website/ts/components/fill_warning_dialog.tsx b/packages/website/ts/components/fill_warning_dialog.tsx index 38c10870b..165d21b34 100644 --- a/packages/website/ts/components/fill_warning_dialog.tsx +++ b/packages/website/ts/components/fill_warning_dialog.tsx @@ -5,7 +5,7 @@ import { colors } from 'ts/utils/colors'; interface FillWarningDialogProps { isOpen: boolean; - onToggleDialog: () => void; + onToggleDialog: (didUserCancel: boolean) => void; } export function FillWarningDialog(props: FillWarningDialogProps) { diff --git a/packages/website/ts/components/inputs/allowance_toggle.tsx b/packages/website/ts/components/inputs/allowance_toggle.tsx index b29511390..1be441e17 100644 --- a/packages/website/ts/components/inputs/allowance_toggle.tsx +++ b/packages/website/ts/components/inputs/allowance_toggle.tsx @@ -47,7 +47,7 @@ export class AllowanceToggle extends React.Component<AllowanceToggleProps, Allow <Toggle disabled={this.state.isSpinnerVisible} toggled={this._isAllowanceSet()} - onToggle={this._onToggleAllowanceAsync.bind(this, this.props.token)} + onToggle={this._onToggleAllowanceAsync.bind(this)} /> </div> {this.state.isSpinnerVisible && ( @@ -58,10 +58,9 @@ export class AllowanceToggle extends React.Component<AllowanceToggleProps, Allow </div> ); } - private async _onToggleAllowanceAsync() { + private async _onToggleAllowanceAsync(): Promise<void> { if (this.props.userAddress === '') { this.props.dispatcher.updateShouldBlockchainErrDialogBeOpen(true); - return false; } this.setState({ @@ -80,7 +79,7 @@ export class AllowanceToggle extends React.Component<AllowanceToggleProps, Allow }); const errMsg = '' + err; if (_.includes(errMsg, 'User denied transaction')) { - return false; + return; } utils.consoleLog(`Unexpected error encountered: ${err}`); utils.consoleLog(err.stack); diff --git a/packages/website/ts/components/inputs/token_amount_input.tsx b/packages/website/ts/components/inputs/token_amount_input.tsx index f3f522ce3..63966d759 100644 --- a/packages/website/ts/components/inputs/token_amount_input.tsx +++ b/packages/website/ts/components/inputs/token_amount_input.tsx @@ -63,6 +63,8 @@ export class TokenAmountInput extends React.Component<TokenAmountInputProps, Tok </Link> </span> ); + } else { + return undefined; } } } diff --git a/packages/website/ts/components/portal.tsx b/packages/website/ts/components/portal.tsx index 22cdcbf20..e2e28e8b6 100644 --- a/packages/website/ts/components/portal.tsx +++ b/packages/website/ts/components/portal.tsx @@ -322,10 +322,10 @@ export class Portal extends React.Component<PortalAllProps, PortalAllState> { isWethNoticeDialogOpen: false, }); } - private _getSharedOrderIfExists(): Order { + private _getSharedOrderIfExists(): Order | undefined { const queryString = window.location.search; if (queryString.length === 0) { - return; + return undefined; } const queryParams = queryString.substring(1).split('&'); const orderQueryParam = _.find(queryParams, queryParam => { @@ -333,11 +333,11 @@ export class Portal extends React.Component<PortalAllProps, PortalAllState> { return queryPair[0] === 'order'; }); if (_.isUndefined(orderQueryParam)) { - return; + return undefined; } const orderPair = orderQueryParam.split('='); if (orderPair.length !== 2) { - return; + return undefined; } const validator = new SchemaValidator(); @@ -345,7 +345,7 @@ export class Portal extends React.Component<PortalAllProps, PortalAllState> { const validationResult = validator.validate(order, orderSchema); if (validationResult.errors.length > 0) { utils.consoleLog(`Invalid shared order: ${validationResult.errors}`); - return; + return undefined; } return order; } diff --git a/packages/website/ts/components/top_bar.tsx b/packages/website/ts/components/top_bar.tsx index cd835930b..601471222 100644 --- a/packages/website/ts/components/top_bar.tsx +++ b/packages/website/ts/components/top_bar.tsx @@ -238,12 +238,12 @@ export class TopBar extends React.Component<TopBarProps, TopBarState> { </Drawer> ); } - private _renderDocsMenu() { + private _renderDocsMenu(): React.ReactNode { if ( (!this._isViewing0xjsDocs() && !this._isViewingSmartContractsDocs() && !this._isViewingConnectDocs()) || _.isUndefined(this.props.menu) ) { - return; + return undefined; } const sectionTitle = `${this.props.docsInfo.displayName} Docs`; @@ -264,9 +264,9 @@ export class TopBar extends React.Component<TopBarProps, TopBarState> { </div> ); } - private _renderWiki() { + private _renderWiki(): React.ReactNode { if (!this._isViewingWiki()) { - return; + return undefined; } return ( @@ -283,9 +283,9 @@ export class TopBar extends React.Component<TopBarProps, TopBarState> { </div> ); } - private _renderPortalMenu() { + private _renderPortalMenu(): React.ReactNode { if (!this._isViewingPortal()) { - return; + return undefined; } return ( diff --git a/packages/website/ts/containers/portal.tsx b/packages/website/ts/containers/portal.tsx index cdf5fc268..f0247935b 100644 --- a/packages/website/ts/containers/portal.tsx +++ b/packages/website/ts/containers/portal.tsx @@ -3,11 +3,7 @@ import * as _ from 'lodash'; import * as React from 'react'; import { connect } from 'react-redux'; import { Dispatch } from 'redux'; -import { - Portal as PortalComponent, - PortalAllProps as PortalComponentAllProps, - PortalPassedProps as PortalComponentPassedProps, -} from 'ts/components/portal'; +import { Portal as PortalComponent, PortalAllProps as PortalComponentAllProps } from 'ts/components/portal'; import { Dispatcher } from 'ts/redux/dispatcher'; import { State } from 'ts/redux/reducer'; import { BlockchainErrs, HashData, Order, ScreenWidths, Side, TokenByAddress, TokenStateByAddress } from 'ts/types'; @@ -80,6 +76,6 @@ const mapDispatchToProps = (dispatch: Dispatch<State>): ConnectedDispatch => ({ dispatcher: new Dispatcher(dispatch), }); -export const Portal: React.ComponentClass<PortalComponentPassedProps> = connect(mapStateToProps, mapDispatchToProps)( +export const Portal: React.ComponentClass<PortalComponentAllProps> = connect(mapStateToProps, mapDispatchToProps)( PortalComponent, ); diff --git a/packages/website/ts/local_storage/tracked_token_storage.ts b/packages/website/ts/local_storage/tracked_token_storage.ts index 0cc384791..7733e8436 100644 --- a/packages/website/ts/local_storage/tracked_token_storage.ts +++ b/packages/website/ts/local_storage/tracked_token_storage.ts @@ -1,6 +1,6 @@ import * as _ from 'lodash'; import { localStorage } from 'ts/local_storage/local_storage'; -import { Token, TrackedTokensByNetworkId } from 'ts/types'; +import { Token, TrackedTokensByUserAddress } from 'ts/types'; import { configs } from 'ts/utils/configs'; const TRACKED_TOKENS_KEY = 'trackedTokens'; @@ -9,14 +9,14 @@ const TRACKED_TOKENS_CLEAR_KEY = 'lastClearTrackedTokensDate'; export const trackedTokenStorage = { // Clear trackedTokens localStorage if we've updated the config variable in an update // that introduced a backward incompatible change requiring the tracked tokens to be re-set - clearIfRequired() { + clearIfRequired(): void { const lastClearFillDate = localStorage.getItemIfExists(TRACKED_TOKENS_CLEAR_KEY); if (lastClearFillDate !== configs.LAST_LOCAL_STORAGE_TRACKED_TOKEN_CLEARANCE_DATE) { localStorage.removeItem(TRACKED_TOKENS_KEY); } localStorage.setItem(TRACKED_TOKENS_CLEAR_KEY, configs.LAST_LOCAL_STORAGE_TRACKED_TOKEN_CLEARANCE_DATE); }, - addTrackedTokenToUser(userAddress: string, networkId: number, token: Token) { + addTrackedTokenToUser(userAddress: string, networkId: number, token: Token): void { const trackedTokensByUserAddress = this.getTrackedTokensByUserAddress(); let trackedTokensByNetworkId = trackedTokensByUserAddress[userAddress]; if (_.isUndefined(trackedTokensByNetworkId)) { @@ -31,7 +31,7 @@ export const trackedTokenStorage = { const trackedTokensByUserAddressJSONString = JSON.stringify(trackedTokensByUserAddress); localStorage.setItem(TRACKED_TOKENS_KEY, trackedTokensByUserAddressJSONString); }, - getTrackedTokensByUserAddress(): TrackedTokensByNetworkId { + getTrackedTokensByUserAddress(): TrackedTokensByUserAddress { const trackedTokensJSONString = localStorage.getItemIfExists(TRACKED_TOKENS_KEY); if (_.isEmpty(trackedTokensJSONString)) { return {}; @@ -52,7 +52,7 @@ export const trackedTokenStorage = { const trackedTokens = trackedTokensByNetworkId[networkId]; return trackedTokens; }, - removeTrackedToken(userAddress: string, networkId: number, tokenAddress: string) { + removeTrackedToken(userAddress: string, networkId: number, tokenAddress: string): void { const trackedTokensByUserAddress = this.getTrackedTokensByUserAddress(); const trackedTokensByNetworkId = trackedTokensByUserAddress[userAddress]; const trackedTokens = trackedTokensByNetworkId[networkId]; diff --git a/packages/website/ts/types.ts b/packages/website/ts/types.ts index 7f82fded9..f873f95fa 100644 --- a/packages/website/ts/types.ts +++ b/packages/website/ts/types.ts @@ -155,7 +155,11 @@ export interface Action { } export interface TrackedTokensByNetworkId { - [networkId: number]: Token; + [networkId: number]: Token[]; +} + +export interface TrackedTokensByUserAddress { + [userAddress: string]: TrackedTokensByNetworkId; } export interface Styles { diff --git a/packages/website/ts/utils/doc_utils.ts b/packages/website/ts/utils/doc_utils.ts index 0bc670d76..1f5f75ee2 100644 --- a/packages/website/ts/utils/doc_utils.ts +++ b/packages/website/ts/utils/doc_utils.ts @@ -20,7 +20,7 @@ export const docUtils = { // TODO: Show the user an error message when the docs fail to load const errMsg = await response.text(); utils.consoleLog(`Failed to load JSON file list: ${response.status} ${errMsg}`); - return; + throw new Error(errMsg); } const responseXML = await response.text(); const responseJSONString = convert.xml2json(responseXML, { @@ -43,7 +43,7 @@ export const docUtils = { // TODO: Show the user an error message when the docs fail to load const errMsg = await response.text(); utils.consoleLog(`Failed to load Doc JSON: ${response.status} ${errMsg}`); - return; + throw new Error(errMsg); } const jsonDocObj = await response.json(); return jsonDocObj; diff --git a/packages/website/tsconfig.json b/packages/website/tsconfig.json index 0e14e5450..38b177d0b 100644 --- a/packages/website/tsconfig.json +++ b/packages/website/tsconfig.json @@ -7,10 +7,11 @@ "baseUrl": "./", "allowJs": true, "strictNullChecks": false, + "noImplicitThis": false, "declaration": false, "paths": { "*": ["node_modules/@types/*", "*"] } }, - "include": ["./ts/**/*"] + "include": ["./ts/**/*", "../../node_modules/web3-typescript-typings/index.d.ts"] } |