Skip to content

Commit

Permalink
sui delayed detection
Browse files Browse the repository at this point in the history
  • Loading branch information
LukassF committed Apr 5, 2024
1 parent b54fd53 commit fe8568e
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions sdk/packages/selector-sui/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ export class NightlyConnectSuiAdapter extends EventEmitter<SuiAdapterEvents> {

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
}
Expand Down Expand Up @@ -161,6 +165,8 @@ export class NightlyConnectSuiAdapter extends EventEmitter<SuiAdapterEvents> {
getRecentWalletForNetwork(SUI_NETWORK)?.walletName ?? undefined
)

adapter.checkForArrivingWallets(metadataWallets)

// Add event listener for userConnected
app.on('userConnected', async (e) => {
try {
Expand Down Expand Up @@ -240,6 +246,8 @@ export class NightlyConnectSuiAdapter extends EventEmitter<SuiAdapterEvents> {
getRecentWalletForNetwork(SUI_NETWORK)?.walletName ?? undefined
)

adapter.checkForArrivingWallets(metadataWallets)

app.on('userConnected', async (e) => {
try {
persistRecentWalletForNetwork(SUI_NETWORK, {
Expand Down Expand Up @@ -337,6 +345,8 @@ export class NightlyConnectSuiAdapter extends EventEmitter<SuiAdapterEvents> {
getRecentWalletForNetwork(SUI_NETWORK)?.walletName ?? undefined
)

this.checkForArrivingWallets(metadataWallets)

// Add event listener for userConnected
app.on('userConnected', async (e) => {
try {
Expand Down Expand Up @@ -778,6 +788,22 @@ export class NightlyConnectSuiAdapter extends EventEmitter<SuiAdapterEvents> {
)
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
)
}, 1000)
}
}

export const createSuiWalletAccountFromString = (publicKey: string): WalletAccount => {
Expand Down

0 comments on commit fe8568e

Please sign in to comment.