From 5fae2982ed321c911ed502245ec7f601dcc7531e Mon Sep 17 00:00:00 2001 From: bluecco Date: Tue, 24 Sep 2024 16:09:19 +0200 Subject: [PATCH 1/3] 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/3] 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/3] 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 }