diff --git a/sdk/apps/modal-example/package.json b/sdk/apps/modal-example/package.json index 77c6a2c2..f52dfda6 100644 --- a/sdk/apps/modal-example/package.json +++ b/sdk/apps/modal-example/package.json @@ -26,7 +26,7 @@ "@nightlylabs/wallet-selector-base": "^0.4.0", "@nightlylabs/wallet-selector-polkadot": "0.2.3", "@nightlylabs/wallet-selector-solana": "0.3.0", - "@nightlylabs/wallet-selector-sui": "0.3.0", + "@nightlylabs/wallet-selector-sui": "0.3.1", "@polkadot/api": "^10.10.1", "@polkadot/extension-inject": "^0.46.5", "@solana/web3.js": "^1.77.2", @@ -42,4 +42,4 @@ "engines": { "node": ">=16.8" } -} \ No newline at end of file +} diff --git a/sdk/packages/selector-sui/package.json b/sdk/packages/selector-sui/package.json index 522b70a1..7c23ca93 100644 --- a/sdk/packages/selector-sui/package.json +++ b/sdk/packages/selector-sui/package.json @@ -1,6 +1,6 @@ { "name": "@nightlylabs/wallet-selector-sui", - "version": "0.3.0", + "version": "0.3.1", "description": "", "type": "module", "exports": { diff --git a/sdk/packages/selector-sui/src/adapter.ts b/sdk/packages/selector-sui/src/adapter.ts index 304e2a1a..ecd96adf 100644 --- a/sdk/packages/selector-sui/src/adapter.ts +++ b/sdk/packages/selector-sui/src/adapter.ts @@ -65,6 +65,10 @@ export class NightlyConnectSuiAdapter extends EventEmitter { private _connectionOptions: ConnectionOptions = defaultConnectionOptions + // interval used for checking for wallets with delayed detection + private _detectionIntervalId: NodeJS.Timeout | undefined + private _maxNumberOfChecks = 10 + get walletsList() { return this._walletsList } @@ -161,6 +165,8 @@ export class NightlyConnectSuiAdapter extends EventEmitter { getRecentWalletForNetwork(SUI_NETWORK)?.walletName ?? undefined ) + adapter.checkForArrivingWallets(metadataWallets) + // Add event listener for userConnected app.on('userConnected', async (e) => { try { @@ -240,6 +246,8 @@ export class NightlyConnectSuiAdapter extends EventEmitter { getRecentWalletForNetwork(SUI_NETWORK)?.walletName ?? undefined ) + adapter.checkForArrivingWallets(metadataWallets) + app.on('userConnected', async (e) => { try { persistRecentWalletForNetwork(SUI_NETWORK, { @@ -337,6 +345,8 @@ export class NightlyConnectSuiAdapter extends EventEmitter { getRecentWalletForNetwork(SUI_NETWORK)?.walletName ?? undefined ) + this.checkForArrivingWallets(metadataWallets) + // Add event listener for userConnected app.on('userConnected', async (e) => { try { @@ -778,6 +788,22 @@ export class NightlyConnectSuiAdapter extends EventEmitter { ) 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 = getSuiWalletsList( + metadataWallets, + getRecentWalletForNetwork(SUI_NETWORK)?.walletName ?? undefined + ) + }, 500) + } } export const createSuiWalletAccountFromString = (publicKey: string): WalletAccount => {