From 83b66015e6fe4e92fd558e0fbbd5bfde6b4947f0 Mon Sep 17 00:00:00 2001 From: bluecco Date: Wed, 13 Dec 2023 14:59:01 +0100 Subject: [PATCH] fix: allow custom provider for webwallet connector --- src/connectors/webwallet/index.ts | 10 ++++++++-- .../starknetWindowObject/getWebWalletStarknetObject.ts | 5 +++-- 2 files changed, 11 insertions(+), 4 deletions(-) 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,