mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
support editable customRPC (#5267)
* support editable customRPC #5246 * remove rpcList size restriction
This commit is contained in:
parent
49a3d52dd6
commit
13a1d46720
@ -375,11 +375,12 @@ class PreferencesController {
|
|||||||
* Gets an updated rpc list from this.addToFrequentRpcList() and sets the `frequentRpcList` to this update list.
|
* Gets an updated rpc list from this.addToFrequentRpcList() and sets the `frequentRpcList` to this update list.
|
||||||
*
|
*
|
||||||
* @param {string} _url The the new rpc url to add to the updated list
|
* @param {string} _url The the new rpc url to add to the updated list
|
||||||
|
* @param {bool} remove Remove selected url
|
||||||
* @returns {Promise<void>} Promise resolves with undefined
|
* @returns {Promise<void>} Promise resolves with undefined
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
updateFrequentRpcList (_url) {
|
updateFrequentRpcList (_url, remove = false) {
|
||||||
return this.addToFrequentRpcList(_url)
|
return this.addToFrequentRpcList(_url, remove)
|
||||||
.then((rpcList) => {
|
.then((rpcList) => {
|
||||||
this.store.updateState({ frequentRpcList: rpcList })
|
this.store.updateState({ frequentRpcList: rpcList })
|
||||||
return Promise.resolve()
|
return Promise.resolve()
|
||||||
@ -406,21 +407,19 @@ class PreferencesController {
|
|||||||
* end of the list. The current list is modified and returned as a promise.
|
* end of the list. The current list is modified and returned as a promise.
|
||||||
*
|
*
|
||||||
* @param {string} _url The rpc url to add to the frequentRpcList.
|
* @param {string} _url The rpc url to add to the frequentRpcList.
|
||||||
|
* @param {bool} remove Remove selected url
|
||||||
* @returns {Promise<array>} The updated frequentRpcList.
|
* @returns {Promise<array>} The updated frequentRpcList.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
addToFrequentRpcList (_url) {
|
addToFrequentRpcList (_url, remove = false) {
|
||||||
const rpcList = this.getFrequentRpcList()
|
const rpcList = this.getFrequentRpcList()
|
||||||
const index = rpcList.findIndex((element) => { return element === _url })
|
const index = rpcList.findIndex((element) => { return element === _url })
|
||||||
if (index !== -1) {
|
if (index !== -1) {
|
||||||
rpcList.splice(index, 1)
|
rpcList.splice(index, 1)
|
||||||
}
|
}
|
||||||
if (_url !== 'http://localhost:8545') {
|
if (!remove && _url !== 'http://localhost:8545') {
|
||||||
rpcList.push(_url)
|
rpcList.push(_url)
|
||||||
}
|
}
|
||||||
if (rpcList.length > 3) {
|
|
||||||
rpcList.shift()
|
|
||||||
}
|
|
||||||
return Promise.resolve(rpcList)
|
return Promise.resolve(rpcList)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -376,6 +376,7 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||||||
// network management
|
// network management
|
||||||
setProviderType: nodeify(networkController.setProviderType, networkController),
|
setProviderType: nodeify(networkController.setProviderType, networkController),
|
||||||
setCustomRpc: nodeify(this.setCustomRpc, this),
|
setCustomRpc: nodeify(this.setCustomRpc, this),
|
||||||
|
delCustomRpc: nodeify(this.delCustomRpc, this),
|
||||||
|
|
||||||
// PreferencesController
|
// PreferencesController
|
||||||
setSelectedAddress: nodeify(preferencesController.setSelectedAddress, preferencesController),
|
setSelectedAddress: nodeify(preferencesController.setSelectedAddress, preferencesController),
|
||||||
@ -1439,6 +1440,14 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||||||
return rpcTarget
|
return rpcTarget
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A method for deleting a selected custom URL.
|
||||||
|
* @param {string} rpcTarget - A RPC URL to delete.
|
||||||
|
*/
|
||||||
|
async delCustomRpc (rpcTarget) {
|
||||||
|
await this.preferencesController.updateFrequentRpcList(rpcTarget, true)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets whether or not to use the blockie identicon format.
|
* Sets whether or not to use the blockie identicon format.
|
||||||
* @param {boolean} val - True for bockie, false for jazzicon.
|
* @param {boolean} val - True for bockie, false for jazzicon.
|
||||||
|
@ -237,6 +237,7 @@ var actions = {
|
|||||||
removeSuggestedTokens,
|
removeSuggestedTokens,
|
||||||
UPDATE_TOKENS: 'UPDATE_TOKENS',
|
UPDATE_TOKENS: 'UPDATE_TOKENS',
|
||||||
setRpcTarget: setRpcTarget,
|
setRpcTarget: setRpcTarget,
|
||||||
|
delRpcTarget: delRpcTarget,
|
||||||
setProviderType: setProviderType,
|
setProviderType: setProviderType,
|
||||||
SET_HARDWARE_WALLET_DEFAULT_HD_PATH: 'SET_HARDWARE_WALLET_DEFAULT_HD_PATH',
|
SET_HARDWARE_WALLET_DEFAULT_HD_PATH: 'SET_HARDWARE_WALLET_DEFAULT_HD_PATH',
|
||||||
setHardwareWalletDefaultHdPath,
|
setHardwareWalletDefaultHdPath,
|
||||||
@ -1836,6 +1837,19 @@ function setRpcTarget (newRpc) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function delRpcTarget (oldRpc) {
|
||||||
|
return (dispatch) => {
|
||||||
|
log.debug(`background.delRpcTarget: ${oldRpc}`)
|
||||||
|
background.delCustomRpc(oldRpc, (err, result) => {
|
||||||
|
if (err) {
|
||||||
|
log.error(err)
|
||||||
|
return dispatch(self.displayWarning('Had a problem removing network!'))
|
||||||
|
}
|
||||||
|
dispatch(actions.setSelectedToken())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Calls the addressBookController to add a new address.
|
// Calls the addressBookController to add a new address.
|
||||||
function addToAddressBook (recipient, nickname = '') {
|
function addToAddressBook (recipient, nickname = '') {
|
||||||
log.debug(`background.addToAddressBook`)
|
log.debug(`background.addToAddressBook`)
|
||||||
|
@ -43,6 +43,9 @@ function mapDispatchToProps (dispatch) {
|
|||||||
setRpcTarget: (target) => {
|
setRpcTarget: (target) => {
|
||||||
dispatch(actions.setRpcTarget(target))
|
dispatch(actions.setRpcTarget(target))
|
||||||
},
|
},
|
||||||
|
delRpcTarget: (target) => {
|
||||||
|
dispatch(actions.delRpcTarget(target))
|
||||||
|
},
|
||||||
showNetworkDropdown: () => dispatch(actions.showNetworkDropdown()),
|
showNetworkDropdown: () => dispatch(actions.showNetworkDropdown()),
|
||||||
hideNetworkDropdown: () => dispatch(actions.hideNetworkDropdown()),
|
hideNetworkDropdown: () => dispatch(actions.hideNetworkDropdown()),
|
||||||
}
|
}
|
||||||
@ -300,6 +303,13 @@ NetworkDropdown.prototype.renderCommonRpc = function (rpcList, provider) {
|
|||||||
color: currentRpcTarget ? '#ffffff' : '#9b9b9b',
|
color: currentRpcTarget ? '#ffffff' : '#9b9b9b',
|
||||||
},
|
},
|
||||||
}, rpc),
|
}, rpc),
|
||||||
|
h('i.fa.fa-times.delete',
|
||||||
|
{
|
||||||
|
onClick: (e) => {
|
||||||
|
e.stopPropagation()
|
||||||
|
props.delRpcTarget(rpc)
|
||||||
|
},
|
||||||
|
}),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,7 @@ export default class SettingsTab extends PureComponent {
|
|||||||
setHexDataFeatureFlag: PropTypes.func,
|
setHexDataFeatureFlag: PropTypes.func,
|
||||||
setCurrentCurrency: PropTypes.func,
|
setCurrentCurrency: PropTypes.func,
|
||||||
setRpcTarget: PropTypes.func,
|
setRpcTarget: PropTypes.func,
|
||||||
|
delRpcTarget: PropTypes.func,
|
||||||
displayWarning: PropTypes.func,
|
displayWarning: PropTypes.func,
|
||||||
revealSeedConfirmation: PropTypes.func,
|
revealSeedConfirmation: PropTypes.func,
|
||||||
setFeatureFlagToBeta: PropTypes.func,
|
setFeatureFlagToBeta: PropTypes.func,
|
||||||
|
@ -59,6 +59,15 @@
|
|||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.dropdown-menu-item .fa.delete {
|
||||||
|
margin-right: 10px;
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropdown-menu-item:hover .fa.delete {
|
||||||
|
display: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
.network-droppo {
|
.network-droppo {
|
||||||
right: 2px;
|
right: 2px;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user