Skip to content

Commit

Permalink
Merge pull request #155 from argentlabs/fix/connector-interface
Browse files Browse the repository at this point in the history
fix: update connector interface for starknet-react compatibility
  • Loading branch information
bluecco authored Nov 14, 2024
2 parents 67906c4 + 0a24fbc commit 292b478
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/connectors/argentMobile/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -93,7 +94,7 @@ export class ArgentMobileBaseConnector extends Connector {
return this._wallet
}

async connect(): Promise<ConnectorData> {
async connect(_args: ConnectArgs = {}): Promise<ConnectorData> {
await this.ensureWallet()

if (!this._wallet) {
Expand All @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion src/connectors/braavosMobile/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from "@starknet-io/types-js"
import { AccountInterface, ProviderInterface, ProviderOptions } from "starknet"
import {
ConnectArgs,
Connector,
type ConnectorData,
type ConnectorIcons,
Expand Down Expand Up @@ -51,7 +52,7 @@ export class BraavosMobileBaseConnector extends Connector {
throw new Error("not implemented")
}

async connect(): Promise<ConnectorData> {
async connect(_args: ConnectArgs = {}): Promise<ConnectorData> {
await this.ensureWallet()

// will return empty data, connect will only open braavos mobile app
Expand Down
6 changes: 3 additions & 3 deletions src/connectors/connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ConnectorEvents> {
Expand All @@ -45,7 +45,7 @@ export abstract class Connector extends EventEmitter<ConnectorEvents> {
/** Whether connector is already authorized */
abstract ready(): Promise<boolean>
/** Connect wallet. */
abstract connect(params?: ConnectOptions): Promise<ConnectorData>
abstract connect(params?: ConnectArgs): Promise<ConnectorData>
/** Disconnect wallet. */
abstract disconnect(): Promise<void>
/** Get current account silently. Return null if the account is not authorized */
Expand Down
17 changes: 5 additions & 12 deletions src/connectors/injected/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
} from "../../errors"
import { removeStarknetLastConnectedWallet } from "../../helpers/lastConnected"
import {
ConnectOptions,
ConnectArgs,
Connector,
type ConnectorData,
type ConnectorIcons,
Expand Down Expand Up @@ -132,7 +132,7 @@ export class InjectedConnector extends Connector {
return new Account(provider, accounts[0], "")
}

async connect(params: ConnectOptions): Promise<ConnectorData> {
async connect(_args: ConnectArgs = {}): Promise<ConnectorData> {
this.ensureWallet()

if (!this._wallet) {
Expand All @@ -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()
}
Expand Down
3 changes: 2 additions & 1 deletion src/connectors/webwallet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
import { getStarknetChainId } from "../../helpers/getStarknetChainId"
import { removeStarknetLastConnectedWallet } from "../../helpers/lastConnected"
import {
ConnectArgs,
Connector,
type ConnectorData,
type ConnectorIcons,
Expand Down Expand Up @@ -100,7 +101,7 @@ export class WebWalletConnector extends Connector {
return "Powered by Argent"
}

async connect(): Promise<ConnectorData> {
async connect(_args: ConnectArgs = {}): Promise<ConnectorData> {
await this.ensureWallet()

if (!this._wallet) {
Expand Down
5 changes: 1 addition & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import type {

let selectedConnector: StarknetkitConnector | null = null


/**
*
* @param [modalMode="canAsk"] - Choose connection behavior:
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 292b478

Please sign in to comment.