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

fix: remove ensure wallet in argent mobile and argent webwallet #126

Merged
merged 1 commit into from
Aug 20, 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
17 changes: 8 additions & 9 deletions src/connectors/argentMobile/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,19 @@ export class ArgentMobileBaseConnector extends Connector {
}

async ready(): Promise<boolean> {
// check if session is valid and retrieve the wallet
// if no sessions, it will show the login modal
await this.ensureWallet()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this code the _wallet property will not be initialized unless connect is called - will this be good enough? I wonder if the ensureWallet method shouldn't still initialize the _wallet property but not try to call enable

Copy link
Contributor Author

@bluecco bluecco Aug 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this code the _wallet property will not be initialized unless connect is called - will this be good enough?

yes, it follows the same behaviour as webwallet

  • if the wallet is not initialized, the dapp would display a connect button
  • if the dapp has an autoconnect function, it will be initialized

if the dapp perform the request while not connected, it will receive the exception that will be managed on dapp side (like showing the connect modal)

managing ensureWallet without enable could be a little tricky at the moment, but can be a good point to improve in a future release

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me - just wanted to make sure it won't break our normal flows 👍

if (!this._wallet) {
return false
}

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

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

get id(): string {
Expand Down Expand Up @@ -150,8 +151,6 @@ export class ArgentMobileBaseConnector extends Connector {
async request<T extends RpcMessage["type"]>(
call: RequestFnCall<T>,
): Promise<RpcTypeToMessageMap[T]["result"]> {
this.ensureWallet()

if (!this._wallet) {
throw new ConnectorNotConnectedError()
}
Expand Down
12 changes: 8 additions & 4 deletions src/connectors/webwallet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,15 @@ export class WebWalletConnector extends Connector {
}

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

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

get id(): string {
Expand Down