Skip to content

Commit

Permalink
fix: allow custom provider for webwallet connector
Browse files Browse the repository at this point in the history
  • Loading branch information
bluecco committed Dec 13, 2023
1 parent acdbf1c commit 83b6601
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/connectors/webwallet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -23,6 +23,7 @@ let _wallet: StarknetWindowObject | null = null

interface WebWalletConnectorOptions {
url?: string
provider?: ProviderInterface
}

export class WebWalletConnector extends Connector {
Expand Down Expand Up @@ -163,11 +164,16 @@ export class WebWalletConnector extends Connector {

private async ensureWallet(): Promise<void> {
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
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -9,14 +9,15 @@ import { getArgentStarknetWindowObject } from "./argentStarknetWindowObject"
export const getWebWalletStarknetObject = async (
target: string,
proxyLink: CreateTRPCProxyClient<AppRouter>,
provider?: ProviderInterface,
): Promise<WebWalletStarknetWindowObject> => {
const globalWindow = typeof window !== "undefined" ? window : undefined
if (!globalWindow) {
throw new Error("window is not defined")
}

const nodeUrl = mapTargetUrlToNodeUrl(target)
const defaultProvider = new RpcProvider({ nodeUrl })
const defaultProvider = provider ?? new RpcProvider({ nodeUrl })
const starknetWindowObject = getArgentStarknetWindowObject(
{
host: globalWindow.location.origin,
Expand Down

0 comments on commit 83b6601

Please sign in to comment.