From 340559b8052b1f34c2bee83b551db6c27b837b6a Mon Sep 17 00:00:00 2001 From: Whymarrh Whitby Date: Sun, 24 Nov 2019 01:19:51 -0330 Subject: [PATCH] Convert TokenList component to use JSX (#7541) --- ui/app/components/app/token-list.js | 97 +++++++++++++---------------- 1 file changed, 45 insertions(+), 52 deletions(-) diff --git a/ui/app/components/app/token-list.js b/ui/app/components/app/token-list.js index c15e86e1d..5bab96a45 100644 --- a/ui/app/components/app/token-list.js +++ b/ui/app/components/app/token-list.js @@ -1,6 +1,5 @@ -const Component = require('react').Component -const PropTypes = require('prop-types') -const h = require('react-hyperscript') +import PropTypes from 'prop-types' +import React, { Component } from 'react' const inherits = require('util').inherits const TokenTracker = require('eth-token-tracker') const TokenCell = require('./token-cell.js') @@ -44,53 +43,60 @@ function TokenList () { Component.call(this) } -TokenList.prototype.render = function () { +TokenList.prototype.render = function TokenList () { const { userAddress, assetImages } = this.props const state = this.state const { tokens, isLoading, error } = state if (isLoading) { - return this.message(this.context.t('loadingTokens')) + return ( +
+ {this.context.t('loadingTokens')} +
+ ) } if (error) { log.error(error) - return h('.hotFix', { - style: { + return ( +
{ - global.platform.openWindow({ - url: `https://ethplorer.io/address/${userAddress}`, - }) - }, - }, this.context.t('here')), - ]) + }}> + {this.context.t('troubleTokenBalances')} + { + global.platform.openWindow({ + url: `https://ethplorer.io/address/${userAddress}`, + }) + }} + > + {this.context.t('here')} + +
+ ) } - return h('div', tokens.map((tokenData) => { - tokenData.image = assetImages[tokenData.address] - return h(TokenCell, tokenData) - })) - -} - -TokenList.prototype.message = function (body) { - return h('div', { - style: { - display: 'flex', - height: '250px', - alignItems: 'center', - justifyContent: 'center', - padding: '30px', - }, - }, body) + return ( +
+ {tokens.map((tokenData, index) => { + tokenData.image = assetImages[tokenData.address] + return ( + + ) + })} +
+ ) } TokenList.prototype.componentDidMount = function () { @@ -179,16 +185,3 @@ TokenList.prototype.componentWillUnmount = function () { this.tracker.removeListener('update', this.balanceUpdater) this.tracker.removeListener('error', this.showError) } - -// function uniqueMergeTokens (tokensA, tokensB = []) { -// const uniqueAddresses = [] -// const result = [] -// tokensA.concat(tokensB).forEach((token) => { -// const normal = normalizeAddress(token.address) -// if (!uniqueAddresses.includes(normal)) { -// uniqueAddresses.push(normal) -// result.push(token) -// } -// }) -// return result -// }