From f14ed329801ab65c31e84f8e9d8d93700ed56670 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 18 Jun 2018 15:33:50 -0700 Subject: [PATCH] Begin letting UI show suggested tokens --- app/scripts/controllers/preferences.js | 30 +++++++++++++++---- .../confirm-add-token.container.js | 8 +++-- ui/app/components/pages/home.js | 7 +++++ 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/app/scripts/controllers/preferences.js b/app/scripts/controllers/preferences.js index 8a8b9a335..b76141be4 100644 --- a/app/scripts/controllers/preferences.js +++ b/app/scripts/controllers/preferences.js @@ -25,7 +25,7 @@ class PreferencesController { frequentRpcList: [], currentAccountTab: 'history', tokens: [], - suggestedTokens: [], + suggestedTokens: {}, useBlockie: false, featureFlags: {}, currentLocale: opts.initLangCode, @@ -53,6 +53,13 @@ class PreferencesController { return this.store.getState().suggestedTokens } + addSuggestedToken (tokenOpts) { + // TODO: Validate params + const suggested = this.getSuggestedTokens() + suggested[tokenOpts.address] = suggested + this.store.updateState({ suggestedTokens: suggested }) + } + /** * RPC engine middleware for requesting new token added * @@ -63,13 +70,24 @@ class PreferencesController { */ requestAddToken(req, res, next, end) { if (req.method === 'eth_watchToken') { - // Validate params! - // this.suggestedTokens.push(req.params) + // TODO: Validate params! const [ rawAddress, symbol, decimals ] = req.params - this.addToken(rawAddress, symbol, decimals) - end(null, rawAddress) + + const tokenOpts = { + address: rawAddress, + decimals, + symbol, + } + + this.suggestWatchToken() + + return end(null, { + result: rawAddress, + "jsonrpc": "2.0", + id: req.id, + }) } else { - next() + return next() } } diff --git a/ui/app/components/pages/confirm-add-token/confirm-add-token.container.js b/ui/app/components/pages/confirm-add-token/confirm-add-token.container.js index 0190024d9..500b406bb 100644 --- a/ui/app/components/pages/confirm-add-token/confirm-add-token.container.js +++ b/ui/app/components/pages/confirm-add-token/confirm-add-token.container.js @@ -1,12 +1,16 @@ import { connect } from 'react-redux' import ConfirmAddToken from './confirm-add-token.component' +const extend = require('xtend') + const { addTokens, clearPendingTokens } = require('../../../actions') const mapStateToProps = ({ metamask }) => { - const { pendingTokens } = metamask + const { pendingTokens, suggestedTokens } = metamask + const params = extend(pendingTokens, suggestedTokens) + return { - pendingTokens, + pendingTokens: params, } } diff --git a/ui/app/components/pages/home.js b/ui/app/components/pages/home.js index c53413d3b..f37366396 100644 --- a/ui/app/components/pages/home.js +++ b/ui/app/components/pages/home.js @@ -25,6 +25,7 @@ const { RESTORE_VAULT_ROUTE, CONFIRM_TRANSACTION_ROUTE, NOTICE_ROUTE, + CONFIRM_ADD_TOKEN_ROUTE, } = require('../../routes') class Home extends Component { @@ -35,8 +36,14 @@ class Home extends Component { unapprovedMsgCount = 0, unapprovedPersonalMsgCount = 0, unapprovedTypedMessagesCount = 0, + suggestedTokens = {}, } = this.props + // suggested new tokens + if (suggestedTokens.length > 0) { + history.push(CONFIRM_ADD_TOKEN_ROUTE) + } + // unapprovedTxs and unapproved messages if (Object.keys(unapprovedTxs).length || unapprovedTypedMessagesCount + unapprovedMsgCount + unapprovedPersonalMsgCount > 0) {