diff --git a/src/connectors/webwallet/constants.ts b/src/connectors/webwallet/constants.ts index d209e53..f1a69bd 100644 --- a/src/connectors/webwallet/constants.ts +++ b/src/connectors/webwallet/constants.ts @@ -14,3 +14,9 @@ export const DEFAULT_WEBWALLET_ICON = ` ` + +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" diff --git a/src/connectors/webwallet/helpers/mapTargetUrlToNodeUrl.ts b/src/connectors/webwallet/helpers/mapTargetUrlToNodeUrl.ts new file mode 100644 index 0000000..d3f83de --- /dev/null +++ b/src/connectors/webwallet/helpers/mapTargetUrlToNodeUrl.ts @@ -0,0 +1,24 @@ +import { RPC_NODE_URL_MAINNET, RPC_NODE_URL_TESTNET } from "../constants" + +export function mapTargetUrlToNodeUrl(target: string): string { + try { + const { origin } = new URL(target) + if (origin.includes("localhost") || origin.includes("127.0.0.1")) { + return RPC_NODE_URL_TESTNET + } + if (origin.includes("hydrogen")) { + return RPC_NODE_URL_TESTNET + } + if (origin.includes("staging")) { + return RPC_NODE_URL_MAINNET + } + if (origin.includes("argent.xyz")) { + return RPC_NODE_URL_MAINNET + } + } catch (e) { + console.warn( + "Could not determine rpc nodeUrl from target URL, defaulting to mainnet", + ) + } + return RPC_NODE_URL_MAINNET +} diff --git a/src/connectors/webwallet/starknetWindowObject/getWebWalletStarknetObject.ts b/src/connectors/webwallet/starknetWindowObject/getWebWalletStarknetObject.ts index ffca03d..a7ae80e 100644 --- a/src/connectors/webwallet/starknetWindowObject/getWebWalletStarknetObject.ts +++ b/src/connectors/webwallet/starknetWindowObject/getWebWalletStarknetObject.ts @@ -1,7 +1,7 @@ import type { CreateTRPCProxyClient } from "@trpc/client" -import { SequencerProvider } from "starknet" +import { RpcProvider } from "starknet" -import { mapTargetUrlToNetworkId } from "../../../helpers/mapTargetUrlToNetworkId" +import { mapTargetUrlToNodeUrl } from "../helpers/mapTargetUrlToNodeUrl" import type { AppRouter } from "../helpers/trpc" import type { WebWalletStarknetWindowObject } from "./argentStarknetWindowObject" import { getArgentStarknetWindowObject } from "./argentStarknetWindowObject" @@ -15,8 +15,8 @@ export const getWebWalletStarknetObject = async ( throw new Error("window is not defined") } - const network = mapTargetUrlToNetworkId(target) - const defaultProvider = new SequencerProvider({ network }) + const nodeUrl = mapTargetUrlToNodeUrl(target) + const defaultProvider = new RpcProvider({ nodeUrl }) const starknetWindowObject = getArgentStarknetWindowObject( { host: globalWindow.location.origin,