eth_watchToken working

feature/default_network_editable
Esteban MIno 6 years ago
parent 12dd7a7232
commit 9ac9f53a73
  1. 7
      app/scripts/controllers/preferences.js
  2. 1
      app/scripts/metamask-controller.js
  3. 24
      ui/app/actions.js
  4. 9
      ui/app/components/pages/confirm-add-token/confirm-add-token.component.js
  5. 3
      ui/app/components/pages/confirm-add-token/confirm-add-token.container.js
  6. 1
      ui/app/reducers/metamask.js

@ -211,6 +211,13 @@ class PreferencesController {
return selected return selected
} }
removeSuggestedTokens () {
return new Promise((resolve, reject) => {
this.store.updateState({ suggestedTokens: {} })
resolve()
})
}
/** /**
* Setter for the `selectedAddress` property * Setter for the `selectedAddress` property
* *

@ -392,6 +392,7 @@ module.exports = class MetamaskController extends EventEmitter {
setSelectedAddress: nodeify(preferencesController.setSelectedAddress, preferencesController), setSelectedAddress: nodeify(preferencesController.setSelectedAddress, preferencesController),
addToken: nodeify(preferencesController.addToken, preferencesController), addToken: nodeify(preferencesController.addToken, preferencesController),
removeToken: nodeify(preferencesController.removeToken, preferencesController), removeToken: nodeify(preferencesController.removeToken, preferencesController),
removeSuggestedTokens: nodeify(preferencesController.removeSuggestedTokens, preferencesController),
setCurrentAccountTab: nodeify(preferencesController.setCurrentAccountTab, preferencesController), setCurrentAccountTab: nodeify(preferencesController.setCurrentAccountTab, preferencesController),
setAccountLabel: nodeify(preferencesController.setAccountLabel, preferencesController), setAccountLabel: nodeify(preferencesController.setAccountLabel, preferencesController),
setFeatureFlag: nodeify(preferencesController.setFeatureFlag, preferencesController), setFeatureFlag: nodeify(preferencesController.setFeatureFlag, preferencesController),

@ -226,6 +226,7 @@ var actions = {
addTokens, addTokens,
removeToken, removeToken,
updateTokens, updateTokens,
removeSuggestedTokens,
UPDATE_TOKENS: 'UPDATE_TOKENS', UPDATE_TOKENS: 'UPDATE_TOKENS',
setRpcTarget: setRpcTarget, setRpcTarget: setRpcTarget,
setProviderType: setProviderType, setProviderType: setProviderType,
@ -1612,6 +1613,29 @@ function addTokens (tokens) {
} }
} }
function removeSuggestedTokens () {
return (dispatch) => {
dispatch(actions.showLoadingIndication())
return new Promise((resolve, reject) => {
background.removeSuggestedTokens((err) => {
dispatch(actions.hideLoadingIndication())
if (err) {
dispatch(actions.displayWarning(err.message))
reject(err)
}
dispatch(actions.clearPendingTokens())
resolve()
})
})
}
}
function clearPendingTokens () {
return {
type: actions.CLEAR_PENDING_TOKENS,
}
}
function updateTokens (newTokens) { function updateTokens (newTokens) {
return { return {
type: actions.UPDATE_TOKENS, type: actions.UPDATE_TOKENS,

@ -15,6 +15,7 @@ export default class ConfirmAddToken extends Component {
clearPendingTokens: PropTypes.func, clearPendingTokens: PropTypes.func,
addTokens: PropTypes.func, addTokens: PropTypes.func,
pendingTokens: PropTypes.object, pendingTokens: PropTypes.object,
removeSuggestedTokens: PropTypes.func,
} }
componentDidMount () { componentDidMount () {
@ -32,7 +33,7 @@ export default class ConfirmAddToken extends Component {
} }
render () { render () {
const { history, addTokens, clearPendingTokens, pendingTokens } = this.props const { history, addTokens, clearPendingTokens, pendingTokens, removeSuggestedTokens } = this.props
return ( return (
<div className="page-container"> <div className="page-container">
@ -90,7 +91,11 @@ export default class ConfirmAddToken extends Component {
type="default" type="default"
large large
className="page-container__footer-button" className="page-container__footer-button"
onClick={() => history.push(ADD_TOKEN_ROUTE)} onClick={() => {
// TODO find the right pace to removeSuggestedTokens
removeSuggestedTokens()
history.push(ADD_TOKEN_ROUTE)
}}
> >
{ this.context.t('back') } { this.context.t('back') }
</Button> </Button>

@ -3,7 +3,7 @@ import ConfirmAddToken from './confirm-add-token.component'
const extend = require('xtend') const extend = require('xtend')
const { addTokens, clearPendingTokens } = require('../../../actions') const { addTokens, clearPendingTokens, removeSuggestedTokens } = require('../../../actions')
const mapStateToProps = ({ metamask }) => { const mapStateToProps = ({ metamask }) => {
const { pendingTokens, suggestedTokens } = metamask const { pendingTokens, suggestedTokens } = metamask
@ -18,6 +18,7 @@ const mapDispatchToProps = dispatch => {
return { return {
addTokens: tokens => dispatch(addTokens(tokens)), addTokens: tokens => dispatch(addTokens(tokens)),
clearPendingTokens: () => dispatch(clearPendingTokens()), clearPendingTokens: () => dispatch(clearPendingTokens()),
removeSuggestedTokens: () => dispatch(removeSuggestedTokens()),
} }
} }

@ -29,6 +29,7 @@ function reduceMetamask (state, action) {
tokenExchangeRates: {}, tokenExchangeRates: {},
tokens: [], tokens: [],
pendingTokens: {}, pendingTokens: {},
suggestedTokens: {},
send: { send: {
gasLimit: null, gasLimit: null,
gasPrice: null, gasPrice: null,

Loading…
Cancel
Save