Skip to content

Commit

Permalink
fix: mipd subscribe
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm committed Nov 13, 2023
1 parent 8c71b42 commit 9e1400b
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions packages/core/src/createConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export function createConfig<
: []),
].map(setup),
)
function setup(connectorFn: CreateConnectorFn) {
function setup(connectorFn: CreateConnectorFn): Connector {
// Set up emitter with uid and add to connector so they are "linked" together.
const emitter = createEmitter<ConnectorEventMap>(uid())
const connector = {
Expand Down Expand Up @@ -218,10 +218,19 @@ export function createConfig<

// EIP-6963 subscribe for new wallet providers
mipd?.subscribe((providerDetails) => {
const currentConnectorIds = new Map()
for (const connector of connectors.getState()) {
currentConnectorIds.set(connector.id, true)
}

const newConnectors: Connector[] = []
for (const providerDetail of providerDetails) {
const connector = setup(providerDetailToConnector(providerDetail))
connectors.setState((x) => [...x, connector])
if (currentConnectorIds.has(connector.id)) continue
newConnectors.push(connector)
}

connectors.setState((x) => [...x, ...newConnectors], true)
})

/////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 9e1400b

Please sign in to comment.