Skip to content

Commit

Permalink
Merge pull request #134 from argentlabs/fix/connect-injected-wallet
Browse files Browse the repository at this point in the history
fix: add params to connect method and update starknetkit modal to use…
  • Loading branch information
bluecco authored Oct 2, 2024
2 parents 6610a8b + d578c9a commit 28c82c0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/connectors/connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ export interface ConnectorEvents {
disconnect(): void
}

export type ConnectOptions = {
silent_mode: boolean
}

export abstract class Connector extends EventEmitter<ConnectorEvents> {
/** Unique connector id. */
abstract get id(): string
Expand All @@ -41,7 +45,7 @@ export abstract class Connector extends EventEmitter<ConnectorEvents> {
/** Whether connector is already authorized */
abstract ready(): Promise<boolean>
/** Connect wallet. */
abstract connect(): Promise<ConnectorData>
abstract connect(params?: ConnectOptions): Promise<ConnectorData>
/** Disconnect wallet. */
abstract disconnect(): Promise<void>
/** Get current account silently. Return null if the account is not authorized */
Expand Down
16 changes: 12 additions & 4 deletions src/connectors/injected/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
} from "../../errors"
import { removeStarknetLastConnectedWallet } from "../../helpers/lastConnected"
import {
ConnectOptions,
Connector,
type ConnectorData,
type ConnectorIcons,
Expand Down Expand Up @@ -138,7 +139,7 @@ export class InjectedConnector extends Connector {
return new Account(provider, accounts[0], "")
}

async connect(): Promise<ConnectorData> {
async connect(params: ConnectOptions): Promise<ConnectorData> {
this.ensureWallet()

if (!this._wallet) {
Expand All @@ -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()
}
Expand Down
4 changes: 3 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 28c82c0

Please sign in to comment.