Skip to content

Commit

Permalink
fix: use rpc provider instead of sequencer for webwallet
Browse files Browse the repository at this point in the history
  • Loading branch information
bluecco committed Dec 7, 2023
1 parent 7e0d7ed commit ec29d60
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/connectors/webwallet/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@ 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/goerli/rpc/v0.5"
24 changes: 24 additions & 0 deletions src/connectors/webwallet/helpers/mapTargetUrlToNodeUrl.ts
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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,
Expand Down

0 comments on commit ec29d60

Please sign in to comment.