From 5fae2982ed321c911ed502245ec7f601dcc7531e Mon Sep 17 00:00:00 2001 From: bluecco Date: Tue, 24 Sep 2024 16:09:19 +0200 Subject: [PATCH 1/7] fix: fix connectors account method to return an Account instead of WalletAccount --- src/connectors/argentMobile/index.ts | 24 ++++++++++++++---------- src/connectors/injected/index.ts | 19 ++++++++++++------- src/connectors/webwallet/index.ts | 12 ++++++++++-- 3 files changed, 36 insertions(+), 19 deletions(-) diff --git a/src/connectors/argentMobile/index.ts b/src/connectors/argentMobile/index.ts index 27904b8..54447c4 100644 --- a/src/connectors/argentMobile/index.ts +++ b/src/connectors/argentMobile/index.ts @@ -1,11 +1,4 @@ import { type AccountChangeEventHandler } from "@starknet-io/get-starknet-core" -import { - AccountInterface, - ProviderInterface, - ProviderOptions, - WalletAccount, - constants, -} from "starknet" import { Permission, RequestFnCall, @@ -13,6 +6,13 @@ import { RpcTypeToMessageMap, type StarknetWindowObject, } from "@starknet-io/types-js" +import { + Account, + AccountInterface, + ProviderInterface, + ProviderOptions, + constants, +} from "starknet" import { ConnectorNotConnectedError, ConnectorNotFoundError, @@ -27,10 +27,10 @@ import { type ConnectorData, type ConnectorIcons, } from "../connector" +import { InjectedConnector, InjectedConnectorOptions } from "../injected" import { DEFAULT_ARGENT_MOBILE_ICON, DEFAULT_PROJECT_ID } from "./constants" -import type { StarknetAdapter } from "./modal/starknet/adapter" import { isInArgentMobileAppBrowser } from "./helpers" -import { InjectedConnector, InjectedConnectorOptions } from "../injected" +import type { StarknetAdapter } from "./modal/starknet/adapter" export interface ArgentMobileConnectorOptions { dappName: string @@ -131,8 +131,12 @@ export class ArgentMobileBaseConnector extends Connector { if (!this._wallet) { throw new ConnectorNotConnectedError() } + const accounts = await this._wallet.request({ + type: "wallet_requestAccounts", + params: { silent_mode: true }, + }) - return new WalletAccount(provider, this._wallet) + return new Account(provider, accounts[0], "") } async chainId(): Promise { diff --git a/src/connectors/injected/index.ts b/src/connectors/injected/index.ts index 26d7143..968c152 100644 --- a/src/connectors/injected/index.ts +++ b/src/connectors/injected/index.ts @@ -1,9 +1,3 @@ -import { - AccountInterface, - ProviderInterface, - ProviderOptions, - WalletAccount, -} from "starknet" import { Permission, RequestFnCall, @@ -11,6 +5,12 @@ import { RpcTypeToMessageMap, type StarknetWindowObject, } from "@starknet-io/types-js" +import { + Account, + AccountInterface, + ProviderInterface, + ProviderOptions, +} from "starknet" import { ConnectorNotConnectedError, ConnectorNotFoundError, @@ -130,7 +130,12 @@ export class InjectedConnector extends Connector { throw new ConnectorNotConnectedError() } - return new WalletAccount(provider, this._wallet) + const accounts = await this.request({ + type: "wallet_requestAccounts", + params: { silent_mode: true }, + }) + + return new Account(provider, accounts[0], "") } async connect(): Promise { diff --git a/src/connectors/webwallet/index.ts b/src/connectors/webwallet/index.ts index 8678456..5da2957 100644 --- a/src/connectors/webwallet/index.ts +++ b/src/connectors/webwallet/index.ts @@ -7,10 +7,10 @@ import { type StarknetWindowObject, } from "@starknet-io/types-js" import { + Account, AccountInterface, ProviderInterface, ProviderOptions, - WalletAccount, } from "starknet" import { ConnectorNotConnectedError, @@ -30,6 +30,7 @@ import { setPopupOptions } from "./helpers/trpc" import type { WebWalletStarknetWindowObject } from "./starknetWindowObject/argentStarknetWindowObject" let _wallet: StarknetWindowObject | null = null +let _address: string | null = null interface WebWalletConnectorOptions { url?: string @@ -116,6 +117,8 @@ export class WebWalletConnector extends Connector { const hexChainId = getStarknetChainId(chainId) + _address = account[0] + return { account: account[0], chainId: BigInt(hexChainId), @@ -145,6 +148,7 @@ export class WebWalletConnector extends Connector { } _wallet = null + _address = null this._wallet = _wallet removeStarknetLastConnectedWallet() } @@ -158,7 +162,11 @@ export class WebWalletConnector extends Connector { throw new ConnectorNotConnectedError() } - return new WalletAccount(provider, this._wallet) + if (!_address) { + throw new ConnectorNotConnectedError() + } + + return new Account(provider, _address, "") } async chainId(): Promise { From 97012ea840315a670e6c3cb7ea095691e02ff3ac Mon Sep 17 00:00:00 2001 From: bluecco Date: Tue, 24 Sep 2024 16:09:48 +0200 Subject: [PATCH 2/7] fix: modal connect callback return connector if resultType is connector --- src/main.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main.ts b/src/main.ts index c3ff489..a941d35 100644 --- a/src/main.ts +++ b/src/main.ts @@ -139,9 +139,8 @@ export const connect = async ({ callback: async (connector: StarknetkitConnector | null) => { try { selectedConnector = connector - const connectorData = (await connector?.connect()) ?? null - if (resultType === "wallet") { + const connectorData = (await connector?.connect()) ?? null if (connector !== null) { setStarknetLastConnectedWallet(connector.id) } @@ -155,7 +154,7 @@ export const connect = async ({ resolve({ connector, wallet: null, - connectorData, + connectorData: null, }) } } catch (error) { From 2b44892c8b40f9624176ab5493d70f0a5fc5abd7 Mon Sep 17 00:00:00 2001 From: bluecco Date: Mon, 30 Sep 2024 09:50:32 +0200 Subject: [PATCH 3/7] chore: reset _address to default --- src/connectors/webwallet/index.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/connectors/webwallet/index.ts b/src/connectors/webwallet/index.ts index 5da2957..fe7964f 100644 --- a/src/connectors/webwallet/index.ts +++ b/src/connectors/webwallet/index.ts @@ -52,6 +52,7 @@ export class WebWalletConnector extends Connector { async ready(): Promise { if (!_wallet) { this._wallet = null + _address = null return false } @@ -200,6 +201,7 @@ export class WebWalletConnector extends Connector { this._wallet.off("accountsChanged", accountChangeCb) _wallet = null + _address = null this._wallet = null } From 2d43feb0d757d73c2b705b6c5acaa311c8841a0c Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Mon, 30 Sep 2024 10:13:47 +0000 Subject: [PATCH 4/7] chore(release): 2.3.1 [skip ci] ## [2.3.1](https://github.com/argentlabs/starknetkit/compare/v2.3.0...v2.3.1) (2024-09-30) ### Bug Fixes * fix connectors account method to return an Account instead of WalletAccount ([5fae298](https://github.com/argentlabs/starknetkit/commit/5fae2982ed321c911ed502245ec7f601dcc7531e)) * modal connect callback return connector if resultType is connector ([97012ea](https://github.com/argentlabs/starknetkit/commit/97012ea840315a670e6c3cb7ea095691e02ff3ac)) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7ff923d..e7f39ad 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "starknetkit", - "version": "2.3.0", + "version": "2.3.1", "repository": "github:argentlabs/starknetkit", "private": false, "browser": { From d578c9ae0fe8cea9bc946a6ec71153143ad719ce Mon Sep 17 00:00:00 2001 From: bluecco Date: Wed, 2 Oct 2024 11:43:18 +0200 Subject: [PATCH 5/7] 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 { From 9000289e0a2c6ed346a2a9317c6392c77aa6da2e Mon Sep 17 00:00:00 2001 From: cussone Date: Wed, 2 Oct 2024 14:00:13 +0200 Subject: [PATCH 6/7] chore: set `options` as optional in `useStarknetkitConnectModal` All properties under `ConnectOptionsWithConnectors` are already optional so, it makes no sense to require options --- src/hooks/useStarknetkitConnectModal.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hooks/useStarknetkitConnectModal.ts b/src/hooks/useStarknetkitConnectModal.ts index 0727ac3..68c1354 100644 --- a/src/hooks/useStarknetkitConnectModal.ts +++ b/src/hooks/useStarknetkitConnectModal.ts @@ -6,12 +6,12 @@ type UseStarknetkitConnectors = { } const useStarknetkitConnectModal = ( - options: ConnectOptionsWithConnectors, + options?: ConnectOptionsWithConnectors, ): UseStarknetkitConnectors => { const starknetkitConnectModal = async (): Promise => { return await connect({ ...options, - resultType: options.resultType ?? "connector", + resultType: options?.resultType ?? "connector", }) } From 9dfd3046c03072e873f5a3e928583f3aae43e7d1 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Wed, 2 Oct 2024 13:07:59 +0000 Subject: [PATCH 7/7] chore(release): 2.3.2 [skip ci] ## [2.3.2](https://github.com/argentlabs/starknetkit/compare/v2.3.1...v2.3.2) (2024-10-02) ### Bug Fixes * add params to connect method and update starknetkit modal to use silent_mode ([d578c9a](https://github.com/argentlabs/starknetkit/commit/d578c9ae0fe8cea9bc946a6ec71153143ad719ce)) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e7f39ad..a01af0f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "starknetkit", - "version": "2.3.1", + "version": "2.3.2", "repository": "github:argentlabs/starknetkit", "private": false, "browser": {