Skip to content

Commit

Permalink
:fix Add option for allowUnsupportedChain (#1982)
Browse files Browse the repository at this point in the history
Co-authored-by: Glitch <[email protected]>
Co-authored-by: tomiir <[email protected]>
  • Loading branch information
3 people authored Feb 29, 2024
1 parent b7ad4fc commit d612339
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/core/src/controllers/NetworkController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface NetworkControllerState {
caipNetwork?: CaipNetwork
requestedCaipNetworks?: CaipNetwork[]
approvedCaipNetworkIds?: CaipNetworkId[]
allowUnsupportedChain?: boolean
}

type StateKey = keyof NetworkControllerState
Expand Down Expand Up @@ -56,7 +57,9 @@ export const NetworkController = {
setCaipNetwork(caipNetwork: NetworkControllerState['caipNetwork']) {
state.caipNetwork = caipNetwork
PublicStateController.set({ selectedNetworkId: caipNetwork?.id })
this.checkIfSupportedNetwork()
if (!this.state.allowUnsupportedChain) {
this.checkIfSupportedNetwork()
}
},

setDefaultCaipNetwork(caipNetwork: NetworkControllerState['caipNetwork']) {
Expand All @@ -69,6 +72,10 @@ export const NetworkController = {
state.requestedCaipNetworks = requestedNetworks
},

setAllowUnsupportedChain(allowUnsupportedChain: NetworkControllerState['allowUnsupportedChain']) {
state.allowUnsupportedChain = allowUnsupportedChain
},

getRequestedCaipNetworks() {
const { approvedCaipNetworkIds, requestedCaipNetworks } = state

Expand Down
5 changes: 5 additions & 0 deletions packages/scaffold/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export interface LibraryOptions {
enableAnalytics?: OptionsControllerState['enableAnalytics']
metadata?: OptionsControllerState['metadata']
enableOnramp?: OptionsControllerState['enableOnramp']
allowUnsupportedChain?: NetworkControllerState['allowUnsupportedChain']
_sdkVersion: OptionsControllerState['sdkVersion']
}

Expand Down Expand Up @@ -236,6 +237,10 @@ export class Web3ModalScaffold {
if (options.enableOnramp) {
OptionsController.setOnrampEnabled(Boolean(options.enableOnramp))
}

if (options.allowUnsupportedChain) {
NetworkController.setAllowUnsupportedChain(options.allowUnsupportedChain)
}
}

private async initOrContinue() {
Expand Down

0 comments on commit d612339

Please sign in to comment.