Skip to content

Commit

Permalink
Merge pull request #162 from nightly-labs/aptos-detection
Browse files Browse the repository at this point in the history
add aptos delayed wallets detection
  • Loading branch information
LukassF authored Apr 15, 2024
2 parents 0ce1219 + 00ef682 commit e753efd
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
2 changes: 1 addition & 1 deletion sdk/apps/modal-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@nightlylabs/nightly-connect-polkadot": "0.0.15",
"@nightlylabs/nightly-connect-solana": "0.0.29",
"@nightlylabs/nightly-connect-sui": "0.0.29",
"@nightlylabs/wallet-selector-aptos": "0.0.1",
"@nightlylabs/wallet-selector-aptos": "0.1.1",
"@nightlylabs/wallet-selector-base": "^0.4.0",
"@nightlylabs/wallet-selector-polkadot": "0.2.3",
"@nightlylabs/wallet-selector-solana": "0.3.0",
Expand Down
4 changes: 2 additions & 2 deletions sdk/packages/selector-aptos/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nightlylabs/wallet-selector-aptos",
"version": "0.1.0",
"version": "0.1.1",
"description": "",
"type": "module",
"exports": {
Expand Down Expand Up @@ -41,4 +41,4 @@
"tslib": "^2.5.3",
"typescript": "^5.1.3"
}
}
}
26 changes: 26 additions & 0 deletions sdk/packages/selector-aptos/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ export class NightlyConnectAptosAdapter extends EventEmitter<AptosAdapterEvents>
private _networkInfo: NetworkInfo | undefined
private _accountInfo: AccountInfo | undefined

// 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 @@ -160,6 +164,8 @@ export class NightlyConnectAptosAdapter extends EventEmitter<AptosAdapterEvents>
getRecentWalletForNetwork(APTOS_NETWORK)?.walletName ?? undefined
)

adapter.checkForArrivingWallets(metadataWallets)

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

adapter.checkForArrivingWallets(metadataWallets)

app.on('userConnected', async (accountInfo, networkInfo) => {
try {
persistRecentWalletForNetwork(APTOS_NETWORK, {
Expand Down Expand Up @@ -381,6 +389,8 @@ export class NightlyConnectAptosAdapter extends EventEmitter<AptosAdapterEvents>
getRecentWalletForNetwork(APTOS_NETWORK)?.walletName ?? undefined
)

this.checkForArrivingWallets(metadataWallets)

// Add event listener for userConnected
app.on('userConnected', async (accountInfo, networkInfo) => {
try {
Expand Down Expand Up @@ -830,4 +840,20 @@ export class NightlyConnectAptosAdapter extends EventEmitter<AptosAdapterEvents>
)
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 = getAptosWalletsList(
metadataWallets,
getRecentWalletForNetwork(APTOS_NETWORK)?.walletName ?? undefined
)
}, 500)
}
}

0 comments on commit e753efd

Please sign in to comment.