From 0a24fbcf7ac33e4cf1ec0272c010c4f14479b88d Mon Sep 17 00:00:00 2001 From: bluecco Date: Thu, 14 Nov 2024 10:00:49 +0100 Subject: [PATCH] fix: update connector interface for starknet-react compatibility --- src/connectors/argentMobile/index.ts | 4 ++-- src/connectors/braavosMobile/index.ts | 3 ++- src/connectors/connector.ts | 6 +++--- src/connectors/injected/index.ts | 17 +++++------------ src/connectors/webwallet/index.ts | 3 ++- src/main.ts | 5 +---- 6 files changed, 15 insertions(+), 23 deletions(-) diff --git a/src/connectors/argentMobile/index.ts b/src/connectors/argentMobile/index.ts index 54447c4..7361722 100644 --- a/src/connectors/argentMobile/index.ts +++ b/src/connectors/argentMobile/index.ts @@ -23,6 +23,7 @@ import { removeStarknetLastConnectedWallet } from "../../helpers/lastConnected" import { getRandomPublicRPCNode } from "../../helpers/publicRcpNodes" import { resetWalletConnect } from "../../helpers/resetWalletConnect" import { + ConnectArgs, Connector, type ConnectorData, type ConnectorIcons, @@ -93,7 +94,7 @@ export class ArgentMobileBaseConnector extends Connector { return this._wallet } - async connect(): Promise { + async connect(_args: ConnectArgs = {}): Promise { await this.ensureWallet() if (!this._wallet) { @@ -102,7 +103,6 @@ export class ArgentMobileBaseConnector extends Connector { const accounts = await this._wallet.request({ type: "wallet_requestAccounts", - params: { silent_mode: false }, // explicit to show the modal }) const chainId = await this.chainId() diff --git a/src/connectors/braavosMobile/index.ts b/src/connectors/braavosMobile/index.ts index 0a24a16..414c714 100644 --- a/src/connectors/braavosMobile/index.ts +++ b/src/connectors/braavosMobile/index.ts @@ -7,6 +7,7 @@ import { } from "@starknet-io/types-js" import { AccountInterface, ProviderInterface, ProviderOptions } from "starknet" import { + ConnectArgs, Connector, type ConnectorData, type ConnectorIcons, @@ -51,7 +52,7 @@ export class BraavosMobileBaseConnector extends Connector { throw new Error("not implemented") } - async connect(): Promise { + async connect(_args: ConnectArgs = {}): Promise { await this.ensureWallet() // will return empty data, connect will only open braavos mobile app diff --git a/src/connectors/connector.ts b/src/connectors/connector.ts index a4e2593..ba26227 100644 --- a/src/connectors/connector.ts +++ b/src/connectors/connector.ts @@ -28,8 +28,8 @@ export interface ConnectorEvents { disconnect(): void } -export type ConnectOptions = { - silent_mode: boolean +export type ConnectArgs = { + chainIdHint?: bigint } export abstract class Connector extends EventEmitter { @@ -45,7 +45,7 @@ export abstract class Connector extends EventEmitter { /** Whether connector is already authorized */ abstract ready(): Promise /** Connect wallet. */ - abstract connect(params?: ConnectOptions): Promise + abstract connect(params?: ConnectArgs): 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 5b21069..4427bfe 100644 --- a/src/connectors/injected/index.ts +++ b/src/connectors/injected/index.ts @@ -18,7 +18,7 @@ import { } from "../../errors" import { removeStarknetLastConnectedWallet } from "../../helpers/lastConnected" import { - ConnectOptions, + ConnectArgs, Connector, type ConnectorData, type ConnectorIcons, @@ -132,7 +132,7 @@ export class InjectedConnector extends Connector { return new Account(provider, accounts[0], "") } - async connect(params: ConnectOptions): Promise { + async connect(_args: ConnectArgs = {}): Promise { this.ensureWallet() if (!this._wallet) { @@ -141,16 +141,9 @@ export class InjectedConnector extends Connector { let accounts: string[] try { - accounts = await this.request( - params - ? { - type: "wallet_requestAccounts", - params, - } - : { - type: "wallet_requestAccounts", - }, - ) + accounts = await this.request({ + type: "wallet_requestAccounts", + }) } catch { throw new UserRejectedRequestError() } diff --git a/src/connectors/webwallet/index.ts b/src/connectors/webwallet/index.ts index fe7964f..e0b966c 100644 --- a/src/connectors/webwallet/index.ts +++ b/src/connectors/webwallet/index.ts @@ -20,6 +20,7 @@ import { import { getStarknetChainId } from "../../helpers/getStarknetChainId" import { removeStarknetLastConnectedWallet } from "../../helpers/lastConnected" import { + ConnectArgs, Connector, type ConnectorData, type ConnectorIcons, @@ -100,7 +101,7 @@ export class WebWalletConnector extends Connector { return "Powered by Argent" } - async connect(): Promise { + async connect(_args: ConnectArgs = {}): Promise { await this.ensureWallet() if (!this._wallet) { diff --git a/src/main.ts b/src/main.ts index 57e0fa8..f17df42 100644 --- a/src/main.ts +++ b/src/main.ts @@ -21,7 +21,6 @@ import type { let selectedConnector: StarknetkitConnector | null = null - /** * * @param [modalMode="canAsk"] - Choose connection behavior: @@ -80,9 +79,7 @@ export const connect = async ({ let connectorData: ConnectorData | null = null if (connector && resultType === "wallet") { - connectorData = await connector.connect({ - silent_mode: true, - }) + connectorData = await connector.connect() } return {