diff --git a/src/controllers/PreferencesController.js b/src/controllers/PreferencesController.js index f0d7d8c8b..335dd40a2 100644 --- a/src/controllers/PreferencesController.js +++ b/src/controllers/PreferencesController.js @@ -839,7 +839,7 @@ class PreferencesController extends SafeEventEmitter { const req = this.getAddChainRequest(id) switch (data.status) { case 'approved': - return resolve() + return resolve('null') // https://docs.metamask.io/wallet/reference/wallet_addethereumchain/ case 'rejected': return reject(ethErrors.provider.userRejectedRequest(`Torus add chain: ${req.errorMsg || 'User denied add chain request.'}`)) default: @@ -920,7 +920,7 @@ class PreferencesController extends SafeEventEmitter { blockExplorer: block_explorer_url || undefined, } - await this.addCustomNetwork(RPC, customNetwork) + this.addCustomNetwork(RPC, customNetwork) this._setAddChainReqStatus(addChainReqId, 'approved') } catch (error) { log.error('error while approving add chain', error) diff --git a/src/controllers/network/NetworkController.js b/src/controllers/network/NetworkController.js index 9b26151ab..20131e83c 100644 --- a/src/controllers/network/NetworkController.js +++ b/src/controllers/network/NetworkController.js @@ -131,7 +131,7 @@ export default class NetworkController extends EventEmitter { const req = this.getSwitchChainRequest(id) switch (data.status) { case 'approved': - return resolve() + return resolve('null') case 'rejected': return reject(ethErrors.provider.userRejectedRequest(`Torus switch chain method: ${req.errorMsg || 'User denied switch chain request.'}`)) default: diff --git a/src/controllers/network/createMetamaskMiddleware.js b/src/controllers/network/createMetamaskMiddleware.js index 1b3665edb..a86cee00e 100644 --- a/src/controllers/network/createMetamaskMiddleware.js +++ b/src/controllers/network/createMetamaskMiddleware.js @@ -68,7 +68,12 @@ export function createAddChainMiddleware({ processAddChain }) { } */ - const { chainId, rpcUrls, nativeCurrency } = request.params || {} + let finalObj = {} + + if (Array.isArray(request.params)) finalObj = request.params[0] + else finalObj = request.params + + const { chainId, rpcUrls, nativeCurrency } = finalObj || {} if (!chainId) throw new Error('createAddChainMiddleware - params.chainId not provided') if (!rpcUrls || rpcUrls.length === 0) throw new Error('createAddChainMiddleware - params.rpcUrls not provided') if (!nativeCurrency) throw new Error('createAddChainMiddleware - params.nativeCurrency not provided') @@ -78,7 +83,7 @@ export function createAddChainMiddleware({ processAddChain }) { if (!symbol) throw new Error('createAddChainMiddleware - params.nativeCurrency.symbol not provided') if (decimals === undefined) throw new Error('createAddChainMiddleware - params.nativeCurrency.decimals not provided') - response.result = await processAddChain(request.params, request) + response.result = await processAddChain(finalObj, request) return undefined }) } @@ -95,10 +100,15 @@ export function createSwitchChainMiddleware({ processSwitchChain }) { } */ - const { chainId } = request.params || {} + let finalObj = {} + + if (Array.isArray(request.params)) finalObj = request.params[0] + else finalObj = request.params + + const { chainId } = finalObj || {} if (!chainId) throw new Error('createSwitchChainMiddleware - params.chainId not provided') - response.result = await processSwitchChain(request.params, request) + response.result = await processSwitchChain(finalObj, request) return undefined }) }