Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v4.1.2 #2383

Merged
merged 5 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading