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

small fixes for aleph adapter #66

Merged
merged 3 commits into from
Sep 29, 2023
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
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-sui": "0.0.26",
"@nightlylabs/wallet-selector-sui": "0.2.3",
"@nightlylabs/nightly-connect-polkadot": "0.0.6",
"@nightlylabs/wallet-selector-polkadot": "0.1.3",
"@nightlylabs/wallet-selector-polkadot": "0.1.4",
"@polkadot/extension-inject": "^0.46.5",
"@polkadot/api": "^10.9.1",
"@solana/web3.js": "^1.77.2",
Expand Down
4 changes: 2 additions & 2 deletions sdk/packages/selector-polkadot/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nightlylabs/wallet-selector-polkadot",
"version": "0.1.3",
"version": "0.1.4",
"description": "",
"type": "module",
"exports": {
Expand Down Expand Up @@ -40,4 +40,4 @@
"tslib": "^2.5.3",
"typescript": "^5.1.3"
}
}
}
87 changes: 44 additions & 43 deletions sdk/packages/selector-polkadot/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,16 +225,21 @@ export class NightlyConnectAdapter implements Injected {

adapter._loading = true

NightlyConnectAdapter.initApp(appInitData).then(([app, metadataWallets]) => {
adapter._app = app
adapter._metadataWallets = metadataWallets
adapter.walletsList = getPolkadotWalletsList(
metadataWallets,
getRecentStandardWalletForNetwork(adapter.network) ?? undefined
)

adapter._loading = false
})
NightlyConnectAdapter.initApp(appInitData)
.then(([app, metadataWallets]) => {
adapter._app = app
adapter._metadataWallets = metadataWallets
adapter.walletsList = getPolkadotWalletsList(
metadataWallets,
getRecentStandardWalletForNetwork(adapter.network) ?? undefined
)

adapter._loading = false
})
.catch(() => {
adapter._loading = false
throw new Error('Failed to initialize adapter')
})

return adapter
}
Expand Down Expand Up @@ -399,7 +404,10 @@ export class NightlyConnectAdapter implements Injected {
try {
// @ts-expect-error we want to pass network to enable
const inject = await adapter!.enable!('Nightly Connect', this.network) // TODO should we also use connect?

// Assert that there is at least one account
if ((await inject.accounts.get()).length <= 0) {
throw new Error('No accounts found')
}
persistRecentStandardWalletForNetwork(walletName, this.network)
persistStandardConnectForNetwork(this.network)
this._innerStandardAdapter = {
Expand All @@ -421,6 +429,8 @@ export class NightlyConnectAdapter implements Injected {
this._modal?.closeModal()
onSuccess()
} catch {
// clear recent wallet
persistStandardDisconnectForNetwork(this.network)
if (this._modal) {
this._modal.setStandardWalletConnectProgress(false)
}
Expand Down Expand Up @@ -453,10 +463,11 @@ export class NightlyConnectAdapter implements Injected {
getRecentStandardWalletForNetwork(this.network) ?? undefined
)
} catch (e) {
this._connecting = false
if (!this._app) {
this._connecting = false
throw new Error('Wallet not ready')
}
throw e
}
}
} else {
Expand Down Expand Up @@ -511,6 +522,11 @@ export class NightlyConnectAdapter implements Injected {
} else {
clearRecentStandardWalletForNetwork(this.network)
}
if (!this._app || this._app.accounts.activeAccounts.length <= 0) {
this._connecting = false
// If user does not pass any accounts, we should disconnect
this.disconnect()
}
this._connected = true
this._connecting = false
this._appSessionActive = true
Expand Down Expand Up @@ -551,37 +567,22 @@ export class NightlyConnectAdapter implements Injected {
})

disconnect = async () => {
if (this.connected) {
if (this._appSessionActive) {
clearSessionIdForNetwork(this.network)
this._appSessionActive = false
this._loading = true
AppPolkadot.build(this._appInitData)
.then(
(app) => {
this._app = app
},
(err) => {
console.log(err)
}
)
.finally(() => {
this._loading = false
})
}
if (this._innerStandardAdapter) {
this._innerStandardAdapter = undefined
persistStandardDisconnectForNetwork(this.network)
}
// Update recent wallet
this.walletsList = getPolkadotWalletsList(
this._metadataWallets,
getRecentStandardWalletForNetwork(this.network) ?? undefined
)
if (this._modal) {
this._modal.walletsList = this.walletsList
}
this._connected = false
// Some apps might use disconnect to reset state / recreate session
clearSessionIdForNetwork(this.network)
this._appSessionActive = false
this._app = await AppPolkadot.build(this._appInitData)
if (this._innerStandardAdapter) {
this._innerStandardAdapter = undefined
persistStandardDisconnectForNetwork(this.network)
}
// Update recent wallet
this.walletsList = getPolkadotWalletsList(
this._metadataWallets,
getRecentStandardWalletForNetwork(this.network) ?? undefined
)
if (this._modal) {
this._modal.walletsList = this.walletsList
}
this._connected = false
}
}
45 changes: 23 additions & 22 deletions sdk/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading