diff --git a/src/connectors/argentMobile/index.ts b/src/connectors/argentMobile/index.ts index bc9512b..a3e0524 100644 --- a/src/connectors/argentMobile/index.ts +++ b/src/connectors/argentMobile/index.ts @@ -2,7 +2,7 @@ import type { AccountChangeEventHandler, StarknetWindowObject, } from "get-starknet-core" -import type { AccountInterface } from "starknet" +import type { AccountInterface, ProviderInterface } from "starknet" import { constants } from "starknet" import { DEFAULT_ARGENT_MOBILE_ICON, DEFAULT_PROJECT_ID } from "./constants" import { @@ -26,6 +26,7 @@ export interface ArgentMobileConnectorOptions { description?: string url?: string icons?: string[] + provider?: ProviderInterface } export class ArgentMobileConnector extends Connector { @@ -153,6 +154,10 @@ export class ArgentMobileConnector extends Connector { description, url, icons, + rpcUrl: + chainId === constants.NetworkName.SN_MAIN + ? "https://cloud.argent-api.com/v1/starknet/mainnet/rpc/v0.5" + : "https://api.hydrogen.argent47.net/v1/starknet/goerli/rpc/v0.5", } if (projectId === DEFAULT_PROJECT_ID) { @@ -171,6 +176,14 @@ export class ArgentMobileConnector extends Connector { } const _wallet = await getStarknetWindowObject(options) + + const { provider } = this._options + if (provider) { + Object.assign(_wallet, { + provider, + }) + } + this._wallet = _wallet // wallet connect rpc enable diff --git a/src/connectors/argentMobile/modal/starknet/adapter.ts b/src/connectors/argentMobile/modal/starknet/adapter.ts index 8c4152a..eabd13d 100644 --- a/src/connectors/argentMobile/modal/starknet/adapter.ts +++ b/src/connectors/argentMobile/modal/starknet/adapter.ts @@ -11,7 +11,7 @@ import type { ProviderInterface, SignerInterface, } from "starknet" -import { Provider, constants } from "starknet" +import { RpcProvider, constants } from "starknet" import type { NamespaceAdapterOptions } from "../adapter" import { NamespaceAdapter } from "../adapter" @@ -84,12 +84,7 @@ export class StarknetAdapter this.remoteSigner = new StarknetRemoteSigner(this.walletRpc) - if (rpcUrl) { - this.provider = new Provider({ rpc: { nodeUrl: rpcUrl } }) - } else { - const network = this.getNetworkName(this.chainId) - this.provider = new Provider({ sequencer: { network } }) - } + this.provider = new RpcProvider({ nodeUrl: rpcUrl }) this.account = new StarknetRemoteAccount( this.provider, "", diff --git a/src/connectors/injected/index.ts b/src/connectors/injected/index.ts index fb29653..e90ee8b 100644 --- a/src/connectors/injected/index.ts +++ b/src/connectors/injected/index.ts @@ -1,5 +1,5 @@ import type { StarknetWindowObject } from "get-starknet-core" -import { AccountInterface, constants } from "starknet" +import { AccountInterface, ProviderInterface, constants } from "starknet" import { ConnectorNotConnectedError, ConnectorNotFoundError, @@ -23,6 +23,8 @@ export interface InjectedConnectorOptions { name?: string /** Wallet icons. */ icon?: ConnectorIcons + /** Provider */ + provider?: ProviderInterface } export class InjectedConnector extends Connector { @@ -211,6 +213,13 @@ export class InjectedConnector extends Connector { const installed = getAvailableWallets(globalThis) const wallet = installed.filter((w) => w.id === this._options.id)[0] if (wallet) { + const { provider } = this._options + if (provider) { + Object.assign(wallet, { + provider, + }) + } + this._wallet = wallet } } diff --git a/src/connectors/webwallet/constants.ts b/src/connectors/webwallet/constants.ts index f1a69bd..4642193 100644 --- a/src/connectors/webwallet/constants.ts +++ b/src/connectors/webwallet/constants.ts @@ -19,4 +19,4 @@ export const RPC_NODE_URL_TESTNET = "https://api.hydrogen.argent47.net/v1/starknet/goerli/rpc/v0.5" export const RPC_NODE_URL_MAINNET = - "https://cloud.argent-api.com/v1/starknet/goerli/rpc/v0.5" + "https://cloud.argent-api.com/v1/starknet/mainnet/rpc/v0.5" diff --git a/src/connectors/webwallet/index.ts b/src/connectors/webwallet/index.ts index 18ddfb8..7e53c8f 100644 --- a/src/connectors/webwallet/index.ts +++ b/src/connectors/webwallet/index.ts @@ -2,7 +2,7 @@ import type { AccountChangeEventHandler, StarknetWindowObject, } from "get-starknet-core" -import type { AccountInterface } from "starknet" +import type { AccountInterface, ProviderInterface } from "starknet" import { Connector, type ConnectorData, @@ -23,6 +23,7 @@ let _wallet: StarknetWindowObject | null = null interface WebWalletConnectorOptions { url?: string + provider?: ProviderInterface } export class WebWalletConnector extends Connector { @@ -163,11 +164,16 @@ export class WebWalletConnector extends Connector { private async ensureWallet(): Promise { const origin = this._options.url || DEFAULT_WEBWALLET_URL + const provider = this._options.provider setPopupOptions({ origin, location: "/interstitialLogin", }) - const wallet = await getWebWalletStarknetObject(origin, trpcProxyClient({})) + const wallet = await getWebWalletStarknetObject( + origin, + trpcProxyClient({}), + provider, + ) _wallet = wallet ?? null this._wallet = _wallet diff --git a/src/connectors/webwallet/starknetWindowObject/getWebWalletStarknetObject.ts b/src/connectors/webwallet/starknetWindowObject/getWebWalletStarknetObject.ts index a7ae80e..90dd22e 100644 --- a/src/connectors/webwallet/starknetWindowObject/getWebWalletStarknetObject.ts +++ b/src/connectors/webwallet/starknetWindowObject/getWebWalletStarknetObject.ts @@ -1,5 +1,5 @@ import type { CreateTRPCProxyClient } from "@trpc/client" -import { RpcProvider } from "starknet" +import { ProviderInterface, RpcProvider } from "starknet" import { mapTargetUrlToNodeUrl } from "../helpers/mapTargetUrlToNodeUrl" import type { AppRouter } from "../helpers/trpc" @@ -9,6 +9,7 @@ import { getArgentStarknetWindowObject } from "./argentStarknetWindowObject" export const getWebWalletStarknetObject = async ( target: string, proxyLink: CreateTRPCProxyClient, + provider?: ProviderInterface, ): Promise => { const globalWindow = typeof window !== "undefined" ? window : undefined if (!globalWindow) { @@ -16,7 +17,7 @@ export const getWebWalletStarknetObject = async ( } const nodeUrl = mapTargetUrlToNodeUrl(target) - const defaultProvider = new RpcProvider({ nodeUrl }) + const defaultProvider = provider ?? new RpcProvider({ nodeUrl }) const starknetWindowObject = getArgentStarknetWindowObject( { host: globalWindow.location.origin, diff --git a/src/helpers/defaultConnectors.ts b/src/helpers/defaultConnectors.ts index 5a36195..14b6659 100644 --- a/src/helpers/defaultConnectors.ts +++ b/src/helpers/defaultConnectors.ts @@ -1,3 +1,4 @@ +import { ProviderInterface } from "starknet" import { type Connector } from "../connectors" import { ArgentMobileConnector, @@ -9,9 +10,11 @@ import { WebWalletConnector } from "../connectors/webwallet" export const defaultConnectors = ({ argentMobileOptions, webWalletUrl, + provider, }: { argentMobileOptions?: ArgentMobileConnectorOptions webWalletUrl?: string + provider?: ProviderInterface }): Connector[] => { const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent) @@ -19,15 +22,19 @@ export const defaultConnectors = ({ if (!isSafari) { defaultConnectors.push( - new InjectedConnector({ options: { id: "argentX" } }), + new InjectedConnector({ options: { id: "argentX", provider } }), ) defaultConnectors.push( - new InjectedConnector({ options: { id: "braavos" } }), + new InjectedConnector({ options: { id: "braavos", provider } }), ) } - defaultConnectors.push(new ArgentMobileConnector(argentMobileOptions)) - defaultConnectors.push(new WebWalletConnector({ url: webWalletUrl })) + defaultConnectors.push( + new ArgentMobileConnector({ ...argentMobileOptions, provider }), + ) + defaultConnectors.push( + new WebWalletConnector({ url: webWalletUrl, provider }), + ) return defaultConnectors } diff --git a/src/main.ts b/src/main.ts index 6d3d51e..cc2be13 100644 --- a/src/main.ts +++ b/src/main.ts @@ -31,6 +31,7 @@ export const connect = async ({ webWalletUrl = DEFAULT_WEBWALLET_URL, argentMobileOptions, connectors = [], + provider, ...restOptions }: ConnectOptions = {}): Promise => { // force null in case it was disconnected from mobile app @@ -40,6 +41,7 @@ export const connect = async ({ ? defaultConnectors({ argentMobileOptions, webWalletUrl, + provider, }) : connectors diff --git a/src/types/modal.ts b/src/types/modal.ts index 91608dd..4325fb6 100644 --- a/src/types/modal.ts +++ b/src/types/modal.ts @@ -1,6 +1,7 @@ import type { GetWalletOptions } from "get-starknet-core" import type { Connector, ConnectorIcons } from "../connectors/connector" import type { ArgentMobileConnectorOptions } from "../connectors/argentMobile" +import { ProviderInterface } from "starknet" export type StoreVersion = "chrome" | "firefox" | "edge" @@ -12,6 +13,7 @@ export interface ConnectOptions extends GetWalletOptions { modalTheme?: "light" | "dark" | "system" storeVersion?: StoreVersion | null webWalletUrl?: string + provider?: ProviderInterface } export type ModalWallet = {