Skip to content

Commit

Permalink
Merge pull request #60 from argentlabs/fix/rpc-public-urls
Browse files Browse the repository at this point in the history
Fix/rpc public urls
  • Loading branch information
bluecco authored Jan 19, 2024
2 parents 79c7a1f + d0d150f commit e09b41b
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 22 deletions.
6 changes: 0 additions & 6 deletions src/connectors/argentMobile/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,3 @@ export const DEFAULT_ARGENT_MOBILE_ICON = `<svg
fill="white"
/>
</svg>`

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"
7 changes: 4 additions & 3 deletions src/connectors/argentMobile/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/connectors/injected/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
UserNotConnectedError,
UserRejectedRequestError,
} from "../../errors"
import { removeStarknetLastConnectedWallet } from "../../helpers/lastConnected"
import {
Connector,
type ConnectorData,
Expand All @@ -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. */
Expand Down
6 changes: 0 additions & 6 deletions src/connectors/webwallet/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,3 @@ export const DEFAULT_WEBWALLET_ICON = `<svg
fill="currentColor"
/>
</svg>`

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"
13 changes: 7 additions & 6 deletions src/connectors/webwallet/helpers/mapTargetUrlToNodeUrl.ts
Original file line number Diff line number Diff line change
@@ -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
}
22 changes: 22 additions & 0 deletions src/helpers/publicRcpNodes.ts
Original file line number Diff line number Diff line change
@@ -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]
}

0 comments on commit e09b41b

Please sign in to comment.