From d578c9ae0fe8cea9bc946a6ec71153143ad719ce Mon Sep 17 00:00:00 2001 From: bluecco Date: Wed, 2 Oct 2024 11:43:18 +0200 Subject: [PATCH] fix: add params to connect method and update starknetkit modal to use silent_mode --- src/connectors/connector.ts | 6 +++++- src/connectors/injected/index.ts | 16 ++++++++++++---- src/main.ts | 4 +++- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/connectors/connector.ts b/src/connectors/connector.ts index 36198d8..a4e2593 100644 --- a/src/connectors/connector.ts +++ b/src/connectors/connector.ts @@ -28,6 +28,10 @@ export interface ConnectorEvents { disconnect(): void } +export type ConnectOptions = { + silent_mode: boolean +} + export abstract class Connector extends EventEmitter { /** Unique connector id. */ abstract get id(): string @@ -41,7 +45,7 @@ export abstract class Connector extends EventEmitter { /** Whether connector is already authorized */ abstract ready(): Promise /** Connect wallet. */ - abstract connect(): Promise + abstract connect(params?: ConnectOptions): Promise /** Disconnect wallet. */ abstract disconnect(): Promise /** Get current account silently. Return null if the account is not authorized */ diff --git a/src/connectors/injected/index.ts b/src/connectors/injected/index.ts index 968c152..6ab2653 100644 --- a/src/connectors/injected/index.ts +++ b/src/connectors/injected/index.ts @@ -18,6 +18,7 @@ import { } from "../../errors" import { removeStarknetLastConnectedWallet } from "../../helpers/lastConnected" import { + ConnectOptions, Connector, type ConnectorData, type ConnectorIcons, @@ -138,7 +139,7 @@ export class InjectedConnector extends Connector { return new Account(provider, accounts[0], "") } - async connect(): Promise { + async connect(params: ConnectOptions): Promise { this.ensureWallet() if (!this._wallet) { @@ -147,9 +148,16 @@ export class InjectedConnector extends Connector { let accounts: string[] try { - accounts = await this.request({ - type: "wallet_requestAccounts", - }) + accounts = await this.request( + params + ? { + type: "wallet_requestAccounts", + params, + } + : { + type: "wallet_requestAccounts", + }, + ) } catch { throw new UserRejectedRequestError() } diff --git a/src/main.ts b/src/main.ts index a941d35..a99cbe3 100644 --- a/src/main.ts +++ b/src/main.ts @@ -52,7 +52,9 @@ export const connect = async ({ let connectorData: ConnectorData | null = null if (connector && resultType === "wallet") { - connectorData = await connector.connect() + connectorData = await connector.connect({ + silent_mode: true, + }) } return {