From c3a5169872409bbe815ab93556b868654ac3552f Mon Sep 17 00:00:00 2001 From: bluecco Date: Fri, 19 Jan 2024 12:26:28 +0100 Subject: [PATCH 1/2] fix: use rpc public urls --- src/connectors/argentMobile/constants.ts | 6 ----- src/connectors/injected/index.ts | 2 +- src/connectors/webwallet/constants.ts | 6 ----- .../helpers/mapTargetUrlToNodeUrl.ts | 13 ++++++----- src/helpers/publicRcpNodes.ts | 22 +++++++++++++++++++ 5 files changed, 30 insertions(+), 19 deletions(-) create mode 100644 src/helpers/publicRcpNodes.ts diff --git a/src/connectors/argentMobile/constants.ts b/src/connectors/argentMobile/constants.ts index c5919b6..8d6fb77 100644 --- a/src/connectors/argentMobile/constants.ts +++ b/src/connectors/argentMobile/constants.ts @@ -13,9 +13,3 @@ export const DEFAULT_ARGENT_MOBILE_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/mainnet/rpc/v0.5" diff --git a/src/connectors/injected/index.ts b/src/connectors/injected/index.ts index d72008c..33af12a 100644 --- a/src/connectors/injected/index.ts +++ b/src/connectors/injected/index.ts @@ -6,6 +6,7 @@ import { UserNotConnectedError, UserRejectedRequestError, } from "../../errors" +import { removeStarknetLastConnectedWallet } from "../../helpers/lastConnected" import { Connector, type ConnectorData, @@ -15,7 +16,6 @@ import { WALLET_NOT_FOUND_ICON_DARK, WALLET_NOT_FOUND_ICON_LIGHT, } from "./constants" -import { removeStarknetLastConnectedWallet } from "../../helpers/lastConnected" /** Injected connector options. */ export interface InjectedConnectorOptions { /** The wallet id. */ diff --git a/src/connectors/webwallet/constants.ts b/src/connectors/webwallet/constants.ts index 4642193..d209e53 100644 --- a/src/connectors/webwallet/constants.ts +++ b/src/connectors/webwallet/constants.ts @@ -14,9 +14,3 @@ 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/mainnet/rpc/v0.5" diff --git a/src/connectors/webwallet/helpers/mapTargetUrlToNodeUrl.ts b/src/connectors/webwallet/helpers/mapTargetUrlToNodeUrl.ts index d3f83de..aff97a9 100644 --- a/src/connectors/webwallet/helpers/mapTargetUrlToNodeUrl.ts +++ b/src/connectors/webwallet/helpers/mapTargetUrlToNodeUrl.ts @@ -1,24 +1,25 @@ -import { RPC_NODE_URL_MAINNET, RPC_NODE_URL_TESTNET } from "../constants" +import { getRandomPublicRPCNode } from "../../../helpers/publicRcpNodes" export function mapTargetUrlToNodeUrl(target: string): string { + const publicRPCNode = getRandomPublicRPCNode() try { const { origin } = new URL(target) if (origin.includes("localhost") || origin.includes("127.0.0.1")) { - return RPC_NODE_URL_TESTNET + return publicRPCNode.testnet } if (origin.includes("hydrogen")) { - return RPC_NODE_URL_TESTNET + return publicRPCNode.testnet } if (origin.includes("staging")) { - return RPC_NODE_URL_MAINNET + return publicRPCNode.mainnet } if (origin.includes("argent.xyz")) { - return RPC_NODE_URL_MAINNET + return publicRPCNode.mainnet } } catch (e) { console.warn( "Could not determine rpc nodeUrl from target URL, defaulting to mainnet", ) } - return RPC_NODE_URL_MAINNET + return publicRPCNode.mainnet } diff --git a/src/helpers/publicRcpNodes.ts b/src/helpers/publicRcpNodes.ts new file mode 100644 index 0000000..72e81df --- /dev/null +++ b/src/helpers/publicRcpNodes.ts @@ -0,0 +1,22 @@ +export type PublicRpcNode = { + mainnet: string + testnet: string +} + +// Public RPC nodes +export const BLAST_RPC_NODE: PublicRpcNode = { + mainnet: "https://starknet-mainnet.public.blastapi.io", + testnet: "https://starknet-testnet.public.blastapi.io", +} as const + +export const LAVA_RPC_NODE: PublicRpcNode = { + mainnet: "https://rpc.starknet.lava.build", + testnet: "https://rpc.starknet-testnet.lava.build", +} as const + +export const PUBLIC_RPC_NODES = [BLAST_RPC_NODE, LAVA_RPC_NODE] as const + +export function getRandomPublicRPCNode() { + const randomIndex = Math.floor(Math.random() * PUBLIC_RPC_NODES.length) + return PUBLIC_RPC_NODES[randomIndex] +} From d0d150f9249e0ccde05153936165a2753221eb02 Mon Sep 17 00:00:00 2001 From: bluecco Date: Fri, 19 Jan 2024 12:28:06 +0100 Subject: [PATCH 2/2] fix: use rpc public urls for mobile connector --- src/connectors/argentMobile/index.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/connectors/argentMobile/index.ts b/src/connectors/argentMobile/index.ts index cd28c37..50fb6f7 100644 --- a/src/connectors/argentMobile/index.ts +++ b/src/connectors/argentMobile/index.ts @@ -19,7 +19,7 @@ import { } from "../connector" import type { StarknetAdapter } from "./modal/starknet/adapter" import { removeStarknetLastConnectedWallet } from "../../helpers/lastConnected" -import { RPC_NODE_URL_MAINNET, RPC_NODE_URL_TESTNET } from "./constants" +import { getRandomPublicRPCNode } from "../../helpers/publicRcpNodes" export interface ArgentMobileConnectorOptions { dappName?: string @@ -162,11 +162,12 @@ export class ArgentMobileConnector extends Connector { rpcUrl, } = this._options + const publicRPCNode = getRandomPublicRPCNode() const providerRpcUrl = rpcUrl ?? (!chainId || chainId === constants.NetworkName.SN_MAIN - ? RPC_NODE_URL_MAINNET - : RPC_NODE_URL_TESTNET) + ? publicRPCNode.mainnet + : publicRPCNode.testnet) const options = { chainId: chainId ?? constants.NetworkName.SN_MAIN,