aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan <danjm.com@gmail.com>2017-10-04 01:25:52 +0800
committerChi Kei Chan <chikeichan@gmail.com>2017-10-04 06:46:01 +0800
commitac4868170f4c61d13291389d01bf1002fe240ed4 (patch)
treed4000928e6b890d99d28b8109ad82cde7bf82fce
parent45dbd017e65e5698db4580c77d723bface0e9b63 (diff)
downloadtangerine-wallet-browser-ac4868170f4c61d13291389d01bf1002fe240ed4.tar
tangerine-wallet-browser-ac4868170f4c61d13291389d01bf1002fe240ed4.tar.gz
tangerine-wallet-browser-ac4868170f4c61d13291389d01bf1002fe240ed4.tar.bz2
tangerine-wallet-browser-ac4868170f4c61d13291389d01bf1002fe240ed4.tar.lz
tangerine-wallet-browser-ac4868170f4c61d13291389d01bf1002fe240ed4.tar.xz
tangerine-wallet-browser-ac4868170f4c61d13291389d01bf1002fe240ed4.tar.zst
tangerine-wallet-browser-ac4868170f4c61d13291389d01bf1002fe240ed4.zip
Enables remove token and ensures add/remove update the list without need for refresh.
-rw-r--r--app/scripts/controllers/preferences.js13
-rw-r--r--app/scripts/metamask-controller.js1
-rw-r--r--ui/app/actions.js35
-rw-r--r--ui/app/components/dropdowns/token-menu-dropdown.js1
-rw-r--r--ui/app/components/modals/hide-token-confirmation-modal.js16
-rw-r--r--ui/app/components/token-list.js14
-rw-r--r--ui/app/reducers/metamask.js6
7 files changed, 72 insertions, 14 deletions
diff --git a/app/scripts/controllers/preferences.js b/app/scripts/controllers/preferences.js
index bc4848421..ecac40481 100644
--- a/app/scripts/controllers/preferences.js
+++ b/app/scripts/controllers/preferences.js
@@ -42,7 +42,18 @@ class PreferencesController {
}
this.store.updateState({ tokens })
- return Promise.resolve()
+ return Promise.resolve(tokens)
+ }
+
+ removeToken (rawAddress) {
+ const address = normalizeAddress(rawAddress)
+
+ const tokens = this.store.getState().tokens
+
+ const updatedTokens = tokens.filter(token => token.address !== rawAddress)
+
+ this.store.updateState({ tokens: updatedTokens })
+ return Promise.resolve(updatedTokens)
}
getTokens () {
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js
index 5b3161bc6..b5c81c348 100644
--- a/app/scripts/metamask-controller.js
+++ b/app/scripts/metamask-controller.js
@@ -327,6 +327,7 @@ module.exports = class MetamaskController extends EventEmitter {
// PreferencesController
setSelectedAddress: nodeify(preferencesController.setSelectedAddress, preferencesController),
addToken: nodeify(preferencesController.addToken, preferencesController),
+ removeToken: nodeify(preferencesController.removeToken, preferencesController),
setCurrentAccountTab: nodeify(preferencesController.setCurrentAccountTab, preferencesController),
setDefaultRpc: nodeify(this.setDefaultRpc, this),
setCustomRpc: nodeify(this.setCustomRpc, this),
diff --git a/ui/app/actions.js b/ui/app/actions.js
index 1f3726f46..630b6390c 100644
--- a/ui/app/actions.js
+++ b/ui/app/actions.js
@@ -152,6 +152,9 @@ var actions = {
showAddTokenPage,
addToken,
addTokens,
+ removeToken,
+ updateTokens,
+ UPDATE_TOKENS: 'UPDATE_TOKENS',
setRpcTarget: setRpcTarget,
setDefaultRpcTarget: setDefaultRpcTarget,
setProviderType: setProviderType,
@@ -753,16 +756,31 @@ function addToken (address, symbol, decimals) {
return (dispatch) => {
dispatch(actions.showLoadingIndication())
return new Promise((resolve, reject) => {
- background.addToken(address, symbol, decimals, (err) => {
+ background.addToken(address, symbol, decimals, (err, tokens) => {
dispatch(actions.hideLoadingIndication())
if (err) {
dispatch(actions.displayWarning(err.message))
reject(err)
}
- resolve()
- // setTimeout(() => {
- // dispatch(actions.goHome())
- // }, 250)
+ dispatch(actions.updateTokens(tokens))
+ resolve(tokens)
+ })
+ })
+ }
+}
+
+function removeToken (address) {
+ return (dispatch) => {
+ dispatch(actions.showLoadingIndication())
+ return new Promise((resolve, reject) => {
+ background.removeToken(address, (err, tokens) => {
+ dispatch(actions.hideLoadingIndication())
+ if (err) {
+ dispatch(actions.displayWarning(err.message))
+ reject(err)
+ }
+ dispatch(actions.updateTokens(tokens))
+ resolve(tokens)
})
})
}
@@ -786,6 +804,13 @@ function addTokens (tokens) {
}
}
+function updateTokens(newTokens) {
+ return {
+ type: actions.UPDATE_TOKENS,
+ newTokens
+ }
+}
+
function goBackToInitView () {
return {
type: actions.BACK_TO_INIT_MENU,
diff --git a/ui/app/components/dropdowns/token-menu-dropdown.js b/ui/app/components/dropdowns/token-menu-dropdown.js
index 0f4bc2b87..7234a9b21 100644
--- a/ui/app/components/dropdowns/token-menu-dropdown.js
+++ b/ui/app/components/dropdowns/token-menu-dropdown.js
@@ -41,6 +41,7 @@ TokenMenuDropdown.prototype.render = function () {
onClick: (e) => {
e.stopPropagation()
showHideTokenConfirmationModal(this.props.token)
+ this.props.onClose()
},
}, 'Hide Token')
diff --git a/ui/app/components/modals/hide-token-confirmation-modal.js b/ui/app/components/modals/hide-token-confirmation-modal.js
index d3f06b483..fa3ad0b1e 100644
--- a/ui/app/components/modals/hide-token-confirmation-modal.js
+++ b/ui/app/components/modals/hide-token-confirmation-modal.js
@@ -13,7 +13,15 @@ function mapStateToProps (state) {
}
function mapDispatchToProps (dispatch) {
- return {}
+ return {
+ hideModal: () => dispatch(actions.hideModal()),
+ hideToken: address => {
+ dispatch(actions.removeToken(address))
+ .then(() => {
+ dispatch(actions.hideModal())
+ })
+ },
+ }
}
inherits(HideTokenConfirmationModal, Component)
@@ -26,7 +34,7 @@ function HideTokenConfirmationModal () {
module.exports = connect(mapStateToProps, mapDispatchToProps)(HideTokenConfirmationModal)
HideTokenConfirmationModal.prototype.render = function () {
- const { token, network } = this.props
+ const { token, network, hideToken, hideModal } = this.props
const { symbol, address } = token
return h('div.hide-token-confirmation', {}, [
@@ -51,12 +59,12 @@ HideTokenConfirmationModal.prototype.render = function () {
h('div.hide-token-confirmation__buttons', {}, [
h('button.btn-clear', {
- onClick: () => {},
+ onClick: () => hideModal(),
}, [
'CANCEL',
]),
h('button.btn-clear', {
- onClick: () => {},
+ onClick: () => hideToken(address),
}, [
'HIDE',
]),
diff --git a/ui/app/components/token-list.js b/ui/app/components/token-list.js
index 0efa89c63..fb11be826 100644
--- a/ui/app/components/token-list.js
+++ b/ui/app/components/token-list.js
@@ -27,7 +27,6 @@ for (const address in contracts) {
module.exports = connect(mapStateToProps)(TokenList)
-
inherits(TokenList, Component)
function TokenList () {
this.state = {
@@ -129,15 +128,22 @@ TokenList.prototype.componentDidUpdate = function (nextProps) {
const {
network: oldNet,
userAddress: oldAddress,
+ tokens,
} = this.props
const {
network: newNet,
userAddress: newAddress,
+ tokens: newTokens,
} = nextProps
- if (newNet === 'loading') return
- if (!oldNet || !newNet || !oldAddress || !newAddress) return
- if (oldAddress === newAddress && oldNet === newNet) return
+ const isLoading = newNet === 'loading'
+ const missingInfo = !oldNet || !newNet || !oldAddress || !newAddress
+ const sameUserAndNetwork = oldAddress === newAddress && oldNet === newNet
+ const shouldUpdateTokens = isLoading || missingInfo || sameUserAndNetwork
+
+ const tokensLengthUnchanged = tokens.length === newTokens.length
+
+ if (tokensLengthUnchanged && shouldUpdateTokens) return
this.setState({ isLoading: true })
this.createFreshTokenTracker()
diff --git a/ui/app/reducers/metamask.js b/ui/app/reducers/metamask.js
index cdc98d05e..a0884b834 100644
--- a/ui/app/reducers/metamask.js
+++ b/ui/app/reducers/metamask.js
@@ -19,6 +19,7 @@ function reduceMetamask (state, action) {
addressBook: [],
selectedTokenAddress: null,
tokenExchangeRates: {},
+ tokens: [],
}, state.metamask)
switch (action.type) {
@@ -146,6 +147,11 @@ function reduceMetamask (state, action) {
},
})
+ case actions.UPDATE_TOKENS:
+ return extend(metamaskState, {
+ tokens: action.newTokens,
+ })
+
default:
return metamaskState