From 109fc41474f5319a27052ab09234cc0426eb22ce Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Sun, 25 Mar 2018 00:22:06 +0000 Subject: Add error popover if TokenRegistry on network user is browsing on don't include the requisite default tokens for 0x Portal to function --- packages/website/ts/blockchain.ts | 16 ++++++++++++++++ .../ts/components/dialogs/blockchain_err_dialog.tsx | 14 ++++++++++++++ packages/website/ts/types.ts | 1 + 3 files changed, 31 insertions(+) (limited to 'packages/website') diff --git a/packages/website/ts/blockchain.ts b/packages/website/ts/blockchain.ts index a3427baee..2268bf1ab 100644 --- a/packages/website/ts/blockchain.ts +++ b/packages/website/ts/blockchain.ts @@ -544,6 +544,22 @@ export class Blockchain { ? {} : trackedTokenStorage.getTrackedTokensByAddress(this._userAddressIfExists, this.networkId); const tokenRegistryTokens = _.values(tokenRegistryTokensByAddress); + const tokenRegistryTokenSymbols = _.map(tokenRegistryTokens, t => t.symbol); + const defaultTrackedTokensInRegistry = _.intersection( + tokenRegistryTokenSymbols, + configs.DEFAULT_TRACKED_TOKEN_SYMBOLS, + ); + if (defaultTrackedTokensInRegistry.length !== configs.DEFAULT_TRACKED_TOKEN_SYMBOLS.length) { + this._dispatcher.updateShouldBlockchainErrDialogBeOpen(true); + this._dispatcher.encounteredBlockchainError(BlockchainErrs.DefaultTokensNotInTokenRegistry); + const err = new Error( + `Default tracked tokens (${JSON.stringify( + configs.DEFAULT_TRACKED_TOKEN_SYMBOLS, + )}) not found in tokenRegistry: ${JSON.stringify(tokenRegistryTokens)}`, + ); + await errorReporter.reportAsync(err); + return; + } if (_.isEmpty(trackedTokensByAddress)) { _.each(configs.DEFAULT_TRACKED_TOKEN_SYMBOLS, symbol => { const token = _.find(tokenRegistryTokens, t => t.symbol === symbol); diff --git a/packages/website/ts/components/dialogs/blockchain_err_dialog.tsx b/packages/website/ts/components/dialogs/blockchain_err_dialog.tsx index e71a0f7d1..1c3b7458d 100644 --- a/packages/website/ts/components/dialogs/blockchain_err_dialog.tsx +++ b/packages/website/ts/components/dialogs/blockchain_err_dialog.tsx @@ -52,6 +52,8 @@ export class BlockchainErrDialog extends React.Component ); } + private _renderDefaultTokenNotInTokenRegistry() { + return ( +
+ The TokenRegistry deployed on your network does not contain the needed default tokens for 0x Portal to + operate. Please try one of the supported networks (Mainnet, Kovan, Ropsten, Rinkeby). If on a local + Testnet, make sure the TokenRegistry contract is deployed and loaded with some default tokens (i.e WETH + & ZRX). +
+ ); + } private _renderUnexpectedErrorExplanation() { return
We encountered an unexpected error. Please try refreshing the page.
; } diff --git a/packages/website/ts/types.ts b/packages/website/ts/types.ts index 104d2e50f..901483327 100644 --- a/packages/website/ts/types.ts +++ b/packages/website/ts/types.ts @@ -223,6 +223,7 @@ export enum AlertTypes { export enum BlockchainErrs { AContractNotDeployedOnNetwork = 'A_CONTRACT_NOT_DEPLOYED_ON_NETWORK', DisconnectedFromEthereumNode = 'DISCONNECTED_FROM_ETHEREUM_NODE', + DefaultTokensNotInTokenRegistry = 'DEFAULT_TOKENS_NOT_IN_TOKEN_REGISTRY', NoError = 'NO_ERROR', } -- cgit