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..fe7964f 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 @@ -51,6 +52,7 @@ export class WebWalletConnector extends Connector { async ready(): Promise { if (!_wallet) { this._wallet = null + _address = null return false } @@ -116,6 +118,8 @@ export class WebWalletConnector extends Connector { const hexChainId = getStarknetChainId(chainId) + _address = account[0] + return { account: account[0], chainId: BigInt(hexChainId), @@ -145,6 +149,7 @@ export class WebWalletConnector extends Connector { } _wallet = null + _address = null this._wallet = _wallet removeStarknetLastConnectedWallet() } @@ -158,7 +163,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 { @@ -192,6 +201,7 @@ export class WebWalletConnector extends Connector { this._wallet.off("accountsChanged", accountChangeCb) _wallet = null + _address = null this._wallet = null } 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) {