Skip to content

Commit

Permalink
Merge pull request #2383 from torusresearch/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
chaitanyapotti authored Jan 8, 2024
2 parents 71e5f0f + 10061f0 commit d255d12
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/controllers/PreferencesController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/network/NetworkController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
18 changes: 14 additions & 4 deletions src/controllers/network/createMetamaskMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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
})
}
Expand All @@ -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
})
}
Expand Down

0 comments on commit d255d12

Please sign in to comment.