Skip to content

Commit

Permalink
Merge pull request #163 from nightly-labs/sui-detection
Browse files Browse the repository at this point in the history
sui delayed detection
  • Loading branch information
LukassF authored Apr 8, 2024
2 parents b54fd53 + afff685 commit fd5817a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
4 changes: 2 additions & 2 deletions sdk/apps/modal-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -42,4 +42,4 @@
"engines": {
"node": ">=16.8"
}
}
}
2 changes: 1 addition & 1 deletion sdk/packages/selector-sui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nightlylabs/wallet-selector-sui",
"version": "0.3.0",
"version": "0.3.1",
"description": "",
"type": "module",
"exports": {
Expand Down
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
)
}, 500)
}
}

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

0 comments on commit fd5817a

Please sign in to comment.