mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Begin letting UI show suggested tokens
This commit is contained in:
parent
5d7c2810a7
commit
f14ed32980
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user