Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor changes #196

Merged
merged 2 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sdk/apps/modal-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@nightlylabs/wallet-selector-aptos": "0.1.6",
"@nightlylabs/wallet-selector-base": "^0.4.1",
"@nightlylabs/wallet-selector-polkadot": "0.2.7",
"@nightlylabs/wallet-selector-solana": "0.3.5",
"@nightlylabs/wallet-selector-solana": "0.3.6",
"@nightlylabs/wallet-selector-sui": "0.4.0",
"@polkadot/api": "^10.10.1",
"@polkadot/extension-inject": "^0.46.5",
Expand All @@ -43,4 +43,4 @@
"engines": {
"node": ">=16.8"
}
}
}
4 changes: 2 additions & 2 deletions sdk/packages/selector-solana/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nightlylabs/wallet-selector-solana",
"version": "0.3.5",
"version": "0.3.6",
"description": "",
"type": "module",
"exports": {
Expand Down Expand Up @@ -41,4 +41,4 @@
"tslib": "^2.5.3",
"typescript": "^5.1.3"
}
}
}
29 changes: 14 additions & 15 deletions sdk/packages/selector-solana/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class NightlyConnectAdapter extends BaseMessageSignerWalletAdapter {
// Remote app instance
private _app: AppSolana | undefined
// Remote app might be loading
private _loading: boolean
private _appLoading: boolean
// What type of connection is used
private _connectionType: ConnectionType | undefined
// Inner standard adapter
Expand All @@ -75,6 +75,7 @@ export class NightlyConnectAdapter extends BaseMessageSignerWalletAdapter {

// interval used for checking for wallets with delayed detection
private _detectionIntervalId: NodeJS.Timeout | undefined
// max number of tries to get delayed wallets
private _maxNumberOfChecks = 10
// Selected wallet
private _selectedWallet: ISelectedWallet | undefined = undefined
Expand All @@ -90,7 +91,7 @@ export class NightlyConnectAdapter extends BaseMessageSignerWalletAdapter {
this._appInitData = appInitData
if (appInitData.persistent !== false) this._appInitData.persistent = true

this._loading = false
this._appLoading = false
this._connectionOptions = { ...this._connectionOptions, ...connectionOptions }
// If not persistent, clear session id
if (!this._appInitData.persistent) {
Expand Down Expand Up @@ -310,13 +311,13 @@ export class NightlyConnectAdapter extends BaseMessageSignerWalletAdapter {

// If init on connect is not enabled, we should initialize app
if (!adapter._connectionOptions.initOnConnect) {
adapter._loading = true
adapter._appLoading = true

NightlyConnectAdapter.initApp(appInitData)
.then(([app, metadataWallets]) => {
adapter._app = app
adapter._metadataWallets = metadataWallets
adapter._loading = false
adapter._appLoading = false
adapter.walletsList = getSolanaWalletsList(
metadataWallets,
getRecentWalletForNetwork(SOLANA_NETWORK)?.walletName ?? undefined
Expand Down Expand Up @@ -380,16 +381,16 @@ export class NightlyConnectAdapter extends BaseMessageSignerWalletAdapter {
return false
}
// Wait for app to be restored
if (this._loading) {
if (this._appLoading) {
for (let i = 0; i < 200; i++) {
await sleep(10)
if (!this._loading) {
if (!this._appLoading) {
break
}
}
}

if (this._loading) {
if (this._appLoading) {
return false
}

Expand Down Expand Up @@ -582,11 +583,11 @@ export class NightlyConnectAdapter extends BaseMessageSignerWalletAdapter {
}

if (this._connectionOptions.initOnConnect) {
this._loading = true
this._appLoading = true
NightlyConnectAdapter.initApp(this._appInitData)
.then(([app, metadataWallets]) => {
this._app = app
this._loading = false
this._appLoading = false
this._metadataWallets = metadataWallets

this.walletsList = getSolanaWalletsList(
Expand Down Expand Up @@ -619,10 +620,9 @@ export class NightlyConnectAdapter extends BaseMessageSignerWalletAdapter {
this.disconnect()
}
})
this._loading = false
})
.catch(() => {
this._loading = false
this._appLoading = false
throw new Error('Failed to initialize adapter')
})
}
Expand Down Expand Up @@ -670,6 +670,7 @@ export class NightlyConnectAdapter extends BaseMessageSignerWalletAdapter {
this._app.on('userConnected', async () => {
try {
if (!this._app || this._app.connectedPublicKeys.length <= 0) {
this._connected = false
reject(new Error('No accounts found'))
}
this._connected = true
Expand All @@ -691,8 +692,6 @@ export class NightlyConnectAdapter extends BaseMessageSignerWalletAdapter {
}
}, 10)
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error: any) {
this._connecting = false

Expand Down Expand Up @@ -740,7 +739,7 @@ export class NightlyConnectAdapter extends BaseMessageSignerWalletAdapter {
// Disconnect remote app and clear session
if (this._connectionType === ConnectionType.Nightly) {
clearSessionIdForNetwork(SOLANA_NETWORK)
this._loading = true
this._appLoading = true
try {
this._app = await AppSolana.build(this._appInitData)
// Add event listener for userConnected
Expand Down Expand Up @@ -769,7 +768,7 @@ export class NightlyConnectAdapter extends BaseMessageSignerWalletAdapter {
} catch (err) {
console.log(err)
} finally {
this._loading = false
this._appLoading = false
}
}
// Disconnect standard wallet
Expand Down
Loading
Loading