aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts
diff options
context:
space:
mode:
authorFrankie <frankie.diamond@gmail.com>2019-01-30 02:13:51 +0800
committerGitHub <noreply@github.com>2019-01-30 02:13:51 +0800
commitdf3169d1c7250d13bb8bc123dc91f7913ad75a81 (patch)
tree266721dc67ae2079543f9ba78e7c546e24f1d068 /app/scripts
parent98d5b4d63217094db9dfc535d0baaed7f8ab0520 (diff)
downloadtangerine-wallet-browser-df3169d1c7250d13bb8bc123dc91f7913ad75a81.tar
tangerine-wallet-browser-df3169d1c7250d13bb8bc123dc91f7913ad75a81.tar.gz
tangerine-wallet-browser-df3169d1c7250d13bb8bc123dc91f7913ad75a81.tar.bz2
tangerine-wallet-browser-df3169d1c7250d13bb8bc123dc91f7913ad75a81.tar.lz
tangerine-wallet-browser-df3169d1c7250d13bb8bc123dc91f7913ad75a81.tar.xz
tangerine-wallet-browser-df3169d1c7250d13bb8bc123dc91f7913ad75a81.tar.zst
tangerine-wallet-browser-df3169d1c7250d13bb8bc123dc91f7913ad75a81.zip
I#5956 fix2 dont overwrite existing rpc settings (#6044)
* mm-controller - dont overwrite existing rpc settings * ui-networkDropdown - dont pass old network as chainId * add methods preferencesController.updateRpc and metamaskController.updateAndSetCustomRpc * use updateAndSetCustomRpc in settings to allow rpcs to be updated * use new rpc as nickname if no nick name has been supplied * fix update rpc method
Diffstat (limited to 'app/scripts')
-rw-r--r--app/scripts/controllers/preferences.js26
-rw-r--r--app/scripts/metamask-controller.js27
2 files changed, 51 insertions, 2 deletions
diff --git a/app/scripts/controllers/preferences.js b/app/scripts/controllers/preferences.js
index e82a69da2..d2ef987f2 100644
--- a/app/scripts/controllers/preferences.js
+++ b/app/scripts/controllers/preferences.js
@@ -407,6 +407,32 @@ class PreferencesController {
}
/**
+ * updates custom RPC details
+ *
+ * @param {string} url The RPC url to add to frequentRpcList.
+ * @param {number} chainId Optional chainId of the selected network.
+ * @param {string} ticker Optional ticker symbol of the selected network.
+ * @param {string} nickname Optional nickname of the selected network.
+ * @returns {Promise<array>} Promise resolving to updated frequentRpcList.
+ *
+ */
+
+
+ updateRpc (newRpcDetails) {
+ const rpcList = this.getFrequentRpcListDetail()
+ const index = rpcList.findIndex((element) => { return element.rpcUrl === newRpcDetails.rpcUrl })
+ if (index > -1) {
+ const rpcDetail = rpcList[index]
+ const updatedRpc = extend(rpcDetail, newRpcDetails)
+ rpcList[index] = updatedRpc
+ this.store.updateState({ frequentRpcListDetail: rpcList })
+ } else {
+ const { rpcUrl, chainId, ticker, nickname } = newRpcDetails
+ return this.addToFrequentRpcList(rpcUrl, chainId, ticker, nickname)
+ }
+ return Promise.resolve(rpcList)
+ }
+ /**
* Adds custom RPC url to state.
*
* @param {string} url The RPC url to add to frequentRpcList.
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js
index 4189bdd10..942c6a62e 100644
--- a/app/scripts/metamask-controller.js
+++ b/app/scripts/metamask-controller.js
@@ -414,6 +414,7 @@ module.exports = class MetamaskController extends EventEmitter {
// network management
setProviderType: nodeify(networkController.setProviderType, networkController),
setCustomRpc: nodeify(this.setCustomRpc, this),
+ updateAndSetCustomRpc: nodeify(this.updateAndSetCustomRpc, this),
delCustomRpc: nodeify(this.delCustomRpc, this),
// PreferencesController
@@ -1503,6 +1504,21 @@ module.exports = class MetamaskController extends EventEmitter {
}
// network
+ /**
+ * A method for selecting a custom URL for an ethereum RPC provider and updating it
+ * @param {string} rpcUrl - A URL for a valid Ethereum RPC API.
+ * @param {number} chainId - The chainId of the selected network.
+ * @param {string} ticker - The ticker symbol of the selected network.
+ * @param {string} nickname - Optional nickname of the selected network.
+ * @returns {Promise<String>} - The RPC Target URL confirmed.
+ */
+
+ async updateAndSetCustomRpc (rpcUrl, chainId, ticker = 'ETH', nickname) {
+ await this.preferencesController.updateRpc({ rpcUrl, chainId, ticker, nickname })
+ this.networkController.setRpcTarget(rpcUrl, chainId, ticker, nickname)
+ return rpcUrl
+ }
+
/**
* A method for selecting a custom URL for an ethereum RPC provider.
@@ -1513,8 +1529,15 @@ module.exports = class MetamaskController extends EventEmitter {
* @returns {Promise<String>} - The RPC Target URL confirmed.
*/
async setCustomRpc (rpcTarget, chainId, ticker = 'ETH', nickname = '') {
- this.networkController.setRpcTarget(rpcTarget, chainId, ticker, nickname)
- await this.preferencesController.addToFrequentRpcList(rpcTarget, chainId, ticker, nickname)
+ const frequentRpcListDetail = this.preferencesController.getFrequentRpcListDetail()
+ const rpcSettings = frequentRpcListDetail.find((rpc) => rpcTarget === rpc.rpcUrl)
+
+ if (rpcSettings) {
+ this.networkController.setRpcTarget(rpcSettings.rpcUrl, rpcSettings.chainId, rpcSettings.ticker, rpcSettings.nickname)
+ } else {
+ this.networkController.setRpcTarget(rpcTarget, chainId, ticker, nickname)
+ await this.preferencesController.addToFrequentRpcList(rpcTarget, chainId, ticker, nickname)
+ }
return rpcTarget
}