Skip to content

Commit

Permalink
fix: solana default chain logic (#2849)
Browse files Browse the repository at this point in the history
  • Loading branch information
zoruka authored Sep 13, 2024
1 parent 7e37c01 commit 90ba7c3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
1 change: 0 additions & 1 deletion apps/laboratory/src/pages/library/solana.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const modal = createWeb3Modal({
solanaConfig,
projectId: ConstantsUtil.ProjectId,
metadata: ConstantsUtil.Metadata,
defaultChain: solana,
chains,
enableAnalytics: false,
termsConditionsUrl: 'https://walletconnect.com/terms',
Expand Down
27 changes: 12 additions & 15 deletions packages/base/adapters/solana/web3js/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ export class SolanaWeb3JsClient implements ChainAdapter<SolStoreUtilState, CaipN

private provider: Provider | undefined

public defaultChain: CaipNetwork | undefined = undefined

public defaultSolanaChain: Chain | undefined = undefined
public defaultChain: CaipNetwork

public constructor(options: Web3ModalClientOptions) {
const { solanaConfig, chains, defaultChain, connectionSettings = 'confirmed' } = options
Expand All @@ -104,13 +102,12 @@ export class SolanaWeb3JsClient implements ChainAdapter<SolStoreUtilState, CaipN

this.connectionSettings = connectionSettings

this.defaultChain = defaultChain
? SolHelpersUtil.getChainFromCaip(
this.chains,
SafeLocalStorage.getItem(SolConstantsUtil.CAIP_CHAIN_ID) || defaultChain.chainId
)
: undefined
this.defaultSolanaChain = this.chains.find(c => c.chainId === defaultChain?.chainId)
this.defaultChain = SolHelpersUtil.getChainFromCaip(
this.chains,
SafeLocalStorage.getItem(SolConstantsUtil.CAIP_CHAIN_ID) ||
withSolanaNamespace(defaultChain?.chainId) ||
withSolanaNamespace(chains[0]?.chainId)
)

this.networkControllerClient = {
switchCaipNetwork: async caipNetwork => {
Expand Down Expand Up @@ -291,13 +288,13 @@ export class SolanaWeb3JsClient implements ChainAdapter<SolStoreUtilState, CaipN
...clientOptions.solanaConfig.auth
})

if (this.defaultSolanaChain) {
SolStoreUtil.setCurrentChain(this.defaultSolanaChain)
SolStoreUtil.setCaipChainId(`solana:${this.defaultSolanaChain.chainId}`)
}

if (this.defaultChain) {
this.appKit?.setCaipNetwork(this.defaultChain)
SolStoreUtil.setCaipChainId(this.defaultChain.id)
const chain = this.chains.find(c => withSolanaNamespace(c.chainId) === this.defaultChain.id)
if (chain) {
SolStoreUtil.setCurrentChain(chain)
}
}

this.syncNetwork()
Expand Down

0 comments on commit 90ba7c3

Please sign in to comment.