diff --git a/sdk/apps/modal-example/src/routes/externalModal.tsx b/sdk/apps/modal-example/src/routes/externalModal.tsx index f7ed664c..977910b2 100644 --- a/sdk/apps/modal-example/src/routes/externalModal.tsx +++ b/sdk/apps/modal-example/src/routes/externalModal.tsx @@ -63,6 +63,12 @@ export default function SolanaExternalModal() { setAdapter(adapter) }) + createEffect(() => { + if (modal() && adapter()) { + modal()!.walletsList = adapter()!.walletsList + } + }) + createEffect(() => { if (eager()) { adapter() diff --git a/sdk/packages/selector-solana/src/adapter.ts b/sdk/packages/selector-solana/src/adapter.ts index 8781de7e..2f92bf39 100644 --- a/sdk/packages/selector-solana/src/adapter.ts +++ b/sdk/packages/selector-solana/src/adapter.ts @@ -70,6 +70,10 @@ export class NightlyConnectAdapter extends BaseMessageSignerWalletAdapter { private _loading: boolean + // interval used for checking for wallets with delayed detection + private _detectionIntervalId: NodeJS.Timeout | undefined + private _maxNumberOfChecks = 10 + private _connectionOptions: ConnectionOptions = defaultConnectionOptions // eslint-disable-next-line @typescript-eslint/no-explicit-any private _eventHandlers: Map void> = new Map() @@ -220,6 +224,8 @@ export class NightlyConnectAdapter extends BaseMessageSignerWalletAdapter { getRecentWalletForNetwork(SOLANA_NETWORK)?.walletName ?? undefined ) + adapter.checkForArrivingWallets(metadataWallets) + // Add event listener for userConnected app.on('userConnected', async () => { try { @@ -304,6 +310,8 @@ export class NightlyConnectAdapter extends BaseMessageSignerWalletAdapter { getRecentWalletForNetwork(SOLANA_NETWORK)?.walletName ?? undefined ) + adapter.checkForArrivingWallets(metadataWallets) + // Add event listener for userConnected app.on('userConnected', async () => { try { @@ -560,10 +568,14 @@ export class NightlyConnectAdapter extends BaseMessageSignerWalletAdapter { .then(([app, metadataWallets]) => { this._app = app this._metadataWallets = metadataWallets + this.walletsList = getSolanaWalletsList( metadataWallets, getRecentWalletForNetwork(SOLANA_NETWORK)?.walletName ?? undefined ) + + this.checkForArrivingWallets(metadataWallets) + // Add event listener for userConnected app.on('userConnected', async () => { try { @@ -686,6 +698,22 @@ export class NightlyConnectAdapter extends BaseMessageSignerWalletAdapter { return this.walletsList } + checkForArrivingWallets = (metadataWallets: WalletMetadata[]) => { + clearInterval(this._detectionIntervalId) + let checks = 0 + + this._detectionIntervalId = setInterval(() => { + if (checks >= this._maxNumberOfChecks || this.connected) { + clearInterval(this._detectionIntervalId) + } + checks++ + this.walletsList = getSolanaWalletsList( + metadataWallets, + getRecentWalletForNetwork(SOLANA_NETWORK)?.walletName ?? undefined + ) + }, 1000) + } + disconnect = async () => { if (this.connected) { if (this._appSessionActive) { @@ -734,6 +762,8 @@ export class NightlyConnectAdapter extends BaseMessageSignerWalletAdapter { this._connected = false this.emit('disconnect') + + clearInterval(this._detectionIntervalId) } }