mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
delete according image when token added with watchToken deleted
This commit is contained in:
parent
bb868f5834
commit
dbab9a007f
@ -15,7 +15,7 @@ class PreferencesController {
|
|||||||
* @property {string} store.currentAccountTab Indicates the selected tab in the ui
|
* @property {string} store.currentAccountTab Indicates the selected tab in the ui
|
||||||
* @property {array} store.tokens The tokens the user wants display in their token lists
|
* @property {array} store.tokens The tokens the user wants display in their token lists
|
||||||
* @property {object} store.accountTokens The tokens stored per account and then per network type
|
* @property {object} store.accountTokens The tokens stored per account and then per network type
|
||||||
* @property {object} store.objects Contains assets objects related to assets added
|
* @property {object} store.imageObjects Contains assets objects related to assets added
|
||||||
* @property {boolean} store.useBlockie The users preference for blockie identicons within the UI
|
* @property {boolean} store.useBlockie The users preference for blockie identicons within the UI
|
||||||
* @property {object} store.featureFlags A key-boolean map, where keys refer to features and booleans to whether the
|
* @property {object} store.featureFlags A key-boolean map, where keys refer to features and booleans to whether the
|
||||||
* user wishes to see that feature
|
* user wishes to see that feature
|
||||||
@ -28,8 +28,8 @@ class PreferencesController {
|
|||||||
frequentRpcList: [],
|
frequentRpcList: [],
|
||||||
currentAccountTab: 'history',
|
currentAccountTab: 'history',
|
||||||
accountTokens: {},
|
accountTokens: {},
|
||||||
|
imageObjects: {},
|
||||||
tokens: [],
|
tokens: [],
|
||||||
objects: {},
|
|
||||||
suggestedTokens: {},
|
suggestedTokens: {},
|
||||||
useBlockie: false,
|
useBlockie: false,
|
||||||
featureFlags: {},
|
featureFlags: {},
|
||||||
@ -60,8 +60,8 @@ class PreferencesController {
|
|||||||
return this.store.getState().suggestedTokens
|
return this.store.getState().suggestedTokens
|
||||||
}
|
}
|
||||||
|
|
||||||
getObjects () {
|
getImageObjects () {
|
||||||
return this.store.getState().objects
|
return this.store.getState().imageObjects
|
||||||
}
|
}
|
||||||
|
|
||||||
addSuggestedToken (tokenOpts) {
|
addSuggestedToken (tokenOpts) {
|
||||||
@ -89,11 +89,12 @@ class PreferencesController {
|
|||||||
case 'ERC20':
|
case 'ERC20':
|
||||||
this._handleWatchAssetERC20(options, res)
|
this._handleWatchAssetERC20(options, res)
|
||||||
res.result = options.address
|
res.result = options.address
|
||||||
|
end()
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
// TODO return promise for not handled assets
|
// TODO return promise for not handled assets
|
||||||
|
end(new Error(`Asset of type ${type} not supported`))
|
||||||
}
|
}
|
||||||
end()
|
|
||||||
} else {
|
} else {
|
||||||
next()
|
next()
|
||||||
}
|
}
|
||||||
@ -291,7 +292,7 @@ class PreferencesController {
|
|||||||
const address = normalizeAddress(rawAddress)
|
const address = normalizeAddress(rawAddress)
|
||||||
const newEntry = { address, symbol, decimals }
|
const newEntry = { address, symbol, decimals }
|
||||||
const tokens = this.store.getState().tokens
|
const tokens = this.store.getState().tokens
|
||||||
const objects = this.getObjects()
|
const imageObjects = this.getImageObjects()
|
||||||
const previousEntry = tokens.find((token, index) => {
|
const previousEntry = tokens.find((token, index) => {
|
||||||
return token.address === address
|
return token.address === address
|
||||||
})
|
})
|
||||||
@ -302,8 +303,8 @@ class PreferencesController {
|
|||||||
} else {
|
} else {
|
||||||
tokens.push(newEntry)
|
tokens.push(newEntry)
|
||||||
}
|
}
|
||||||
objects[address] = imageUrl
|
imageObjects[address] = imageUrl
|
||||||
this._updateAccountTokens(tokens, objects)
|
this._updateAccountTokens(tokens, imageObjects)
|
||||||
return Promise.resolve(tokens)
|
return Promise.resolve(tokens)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -316,10 +317,10 @@ class PreferencesController {
|
|||||||
*/
|
*/
|
||||||
removeToken (rawAddress) {
|
removeToken (rawAddress) {
|
||||||
const tokens = this.store.getState().tokens
|
const tokens = this.store.getState().tokens
|
||||||
const objects = this.getObjects()
|
const imageObjects = this.getImageObjects()
|
||||||
const updatedTokens = tokens.filter(token => token.address !== rawAddress)
|
const updatedTokens = tokens.filter(token => token.address !== rawAddress)
|
||||||
const updatedObjects = Object.keys(objects).filter(key => key !== rawAddress)
|
delete imageObjects[rawAddress]
|
||||||
this._updateAccountTokens(updatedTokens, updatedObjects)
|
this._updateAccountTokens(updatedTokens, imageObjects)
|
||||||
return Promise.resolve(updatedTokens)
|
return Promise.resolve(updatedTokens)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -483,10 +484,10 @@ class PreferencesController {
|
|||||||
* @param {array} tokens Array of tokens to be updated.
|
* @param {array} tokens Array of tokens to be updated.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
_updateAccountTokens (tokens, objects) {
|
_updateAccountTokens (tokens, imageObjects) {
|
||||||
const { accountTokens, providerType, selectedAddress } = this._getTokenRelatedStates()
|
const { accountTokens, providerType, selectedAddress } = this._getTokenRelatedStates()
|
||||||
accountTokens[selectedAddress][providerType] = tokens
|
accountTokens[selectedAddress][providerType] = tokens
|
||||||
this.store.updateState({ accountTokens, tokens, objects })
|
this.store.updateState({ accountTokens, tokens, imageObjects })
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -22,7 +22,7 @@ function mapStateToProps (state) {
|
|||||||
network,
|
network,
|
||||||
conversionRate: state.metamask.conversionRate,
|
conversionRate: state.metamask.conversionRate,
|
||||||
currentCurrency: state.metamask.currentCurrency,
|
currentCurrency: state.metamask.currentCurrency,
|
||||||
objects: state.metamask.objects,
|
imageObjects: state.metamask.imageObjects,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,9 +33,9 @@ function BalanceComponent () {
|
|||||||
|
|
||||||
BalanceComponent.prototype.render = function () {
|
BalanceComponent.prototype.render = function () {
|
||||||
const props = this.props
|
const props = this.props
|
||||||
const { token, network, objects } = props
|
const { token, network, imageObjects } = props
|
||||||
let imageUrl
|
let imageUrl
|
||||||
if (token) imageUrl = objects[token.address]
|
if (token) imageUrl = imageObjects[token.address]
|
||||||
|
|
||||||
return h('div.balance-container', {}, [
|
return h('div.balance-container', {}, [
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ function mapStateToProps (state) {
|
|||||||
return {
|
return {
|
||||||
network: state.metamask.network,
|
network: state.metamask.network,
|
||||||
token: state.appState.modal.modalState.props.token,
|
token: state.appState.modal.modalState.props.token,
|
||||||
tokenImagesHashes: state.metamask.objects,
|
imageObjects: state.metamask.imageObjects,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,9 +41,9 @@ module.exports = connect(mapStateToProps, mapDispatchToProps)(HideTokenConfirmat
|
|||||||
|
|
||||||
|
|
||||||
HideTokenConfirmationModal.prototype.render = function () {
|
HideTokenConfirmationModal.prototype.render = function () {
|
||||||
const { token, network, hideToken, hideModal, tokenImagesHashes } = this.props
|
const { token, network, hideToken, hideModal, imageObjects } = this.props
|
||||||
const { symbol, address } = token
|
const { symbol, address } = token
|
||||||
const imageUrl = tokenImagesHashes[address]
|
const imageUrl = imageObjects[address]
|
||||||
|
|
||||||
return h('div.hide-token-confirmation', {}, [
|
return h('div.hide-token-confirmation', {}, [
|
||||||
h('div.hide-token-confirmation__container', {
|
h('div.hide-token-confirmation__container', {
|
||||||
|
@ -15,7 +15,7 @@ function mapStateToProps (state) {
|
|||||||
network: state.metamask.network,
|
network: state.metamask.network,
|
||||||
tokens: state.metamask.tokens,
|
tokens: state.metamask.tokens,
|
||||||
userAddress: selectors.getSelectedAddress(state),
|
userAddress: selectors.getSelectedAddress(state),
|
||||||
tokenImagesHashes: state.metamask.objects,
|
imageObjects: state.metamask.imageObjects,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ function TokenList () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TokenList.prototype.render = function () {
|
TokenList.prototype.render = function () {
|
||||||
const { userAddress, tokenImagesHashes } = this.props
|
const { userAddress, imageObjects } = this.props
|
||||||
const state = this.state
|
const state = this.state
|
||||||
const { tokens, isLoading, error } = state
|
const { tokens, isLoading, error } = state
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
@ -77,7 +77,7 @@ TokenList.prototype.render = function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return h('div', tokens.map((tokenData) => {
|
return h('div', tokens.map((tokenData) => {
|
||||||
tokenData.imageUrl = tokenImagesHashes[tokenData.address]
|
tokenData.imageUrl = imageObjects[tokenData.address]
|
||||||
return h(TokenCell, tokenData)
|
return h(TokenCell, tokenData)
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user