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: add params to connect method and update starknetkit modal to use… #134

Merged
merged 1 commit into from
Oct 2, 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
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