Skip to content

Commit

Permalink
fix: connectors not appearing on solana (#2990)
Browse files Browse the repository at this point in the history
  • Loading branch information
zoruka authored Oct 2, 2024
1 parent d40f978 commit c2e391d
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 11 deletions.
38 changes: 38 additions & 0 deletions .changeset/green-kiwis-play.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
'@reown/appkit-adapter-solana': patch
'@reown/appkit-core': patch
'@apps/demo': patch
'@apps/gallery': patch
'@apps/laboratory': patch
'@examples/html-ethers': patch
'@examples/html-ethers5': patch
'@examples/html-wagmi': patch
'@examples/next-ethers': patch
'@examples/next-wagmi': patch
'@examples/react-ethers': patch
'@examples/react-ethers5': patch
'@examples/react-solana': patch
'@examples/react-wagmi': patch
'@examples/vue-ethers5': patch
'@examples/vue-solana': patch
'@examples/vue-wagmi': patch
'@reown/appkit-adapter-ethers': patch
'@reown/appkit-adapter-ethers5': patch
'@reown/appkit-adapter-polkadot': patch
'@reown/appkit-adapter-wagmi': patch
'@reown/appkit': patch
'@reown/appkit-utils': patch
'@reown/appkit-cdn': patch
'@reown/appkit-common': patch
'@reown/appkit-ethers': patch
'@reown/appkit-ethers5': patch
'@reown/appkit-polyfills': patch
'@reown/appkit-scaffold-ui': patch
'@reown/appkit-siwe': patch
'@reown/appkit-solana': patch
'@reown/appkit-ui': patch
'@reown/appkit-wagmi': patch
'@reown/appkit-wallet': patch
---

Fixes external connectors not appearing when using Solana adapter
6 changes: 5 additions & 1 deletion packages/adapters/solana/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,11 @@ export class SolanaAdapter implements ChainAdapter {
type: provider.type,
imageUrl: provider.icon,
name: provider.name,
provider,
/**
* When the provider is different from 'AUTH', we don't need to pass it to the connector.
* This avoids issues with the valtio proxy and non-serializable state and follows same logic from other clients.
*/
provider: provider.type === 'AUTH' ? provider : undefined,
chain: CommonConstantsUtil.CHAIN.SOLANA
}))

Expand Down
35 changes: 25 additions & 10 deletions packages/core/src/controllers/ConnectorController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,31 @@ export const ConnectorController = {
},

setConnectors(connectors: ConnectorControllerState['connectors']) {
const newConnectors = connectors.filter(
newConnector =>
!state.allConnectors.some(
existingConnector =>
existingConnector.id === newConnector.id &&
this.getConnectorName(existingConnector.name) ===
this.getConnectorName(newConnector.name) &&
existingConnector.chain === newConnector.chain
)
)
const newConnectors = connectors.filter(newConnector => {
try {
/**
* This is a fix for non-serializable objects that may prevent all the connectors in the list from being displayed
* Check more about this issue on https://valtio.dev/docs/api/basic/proxy#Gotchas
*/
proxy(newConnector)
} catch (error) {
// eslint-disable-next-line no-console
console.error('ConnectorController.setConnectors: Not possible to add connector', {
newConnector,
error
})

return false
}

return !state.allConnectors.some(
existingConnector =>
existingConnector.id === newConnector.id &&
this.getConnectorName(existingConnector.name) ===
this.getConnectorName(newConnector.name) &&
existingConnector.chain === newConnector.chain
)
})

state.allConnectors = [...state.connectors, ...newConnectors]
state.connectors = this.mergeMultiChainConnectors(state.allConnectors)
Expand Down

0 comments on commit c2e391d

Please sign in to comment.