Skip to content

Commit

Permalink
refactor: refactor ready, ensure wallet before checking readiness
Browse files Browse the repository at this point in the history
  • Loading branch information
Cussone committed Feb 3, 2025
1 parent c594273 commit 8046d2e
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions src/connectors/webwallet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ import {
import { DEFAULT_WEBWALLET_ICON, DEFAULT_WEBWALLET_URL } from "./constants"
import { openWebwallet } from "./helpers/openWebwallet"
import { setPopupOptions } from "./helpers/trpc"
import type {
Theme,
WebWalletStarknetWindowObject,
import {
type Theme,
type WebWalletStarknetWindowObject,
} from "./starknetWindowObject/argentStarknetWindowObject"

let _wallet: StarknetWindowObject | null = null
Expand All @@ -57,21 +57,25 @@ export class WebWalletConnector extends Connector {
}

async ready(): Promise<boolean> {
if (!_wallet) {
this._wallet = null
_address = null
return false
if (!this._wallet) {
await this.ensureWallet()
}

this._wallet = _wallet
try {
const permissions = await this._wallet.request({
type: "wallet_getPermissions",
})
if (!this._wallet) {
this._wallet = null
_address = null

return (permissions as Permission[]).includes(Permission.ACCOUNTS)
} catch {
return false
} else {
try {
const permissions = await this._wallet.request({
type: "wallet_getPermissions",
})

return (permissions as Permission[]).includes(Permission.ACCOUNTS)
} catch {
return false
}
}
}

Expand Down

0 comments on commit 8046d2e

Please sign in to comment.