From acdbf1c7d77d68286df81fb3ee74ee93424c47d4 Mon Sep 17 00:00:00 2001 From: bluecco Date: Wed, 13 Dec 2023 14:29:25 +0100 Subject: [PATCH 1/5] fix: allow custom provider for injected connectors --- src/connectors/injected/index.ts | 11 ++++++++++- src/helpers/defaultConnectors.ts | 7 +++++-- src/main.ts | 2 ++ src/types/modal.ts | 2 ++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/connectors/injected/index.ts b/src/connectors/injected/index.ts index fb29653..e90ee8b 100644 --- a/src/connectors/injected/index.ts +++ b/src/connectors/injected/index.ts @@ -1,5 +1,5 @@ import type { StarknetWindowObject } from "get-starknet-core" -import { AccountInterface, constants } from "starknet" +import { AccountInterface, ProviderInterface, constants } from "starknet" import { ConnectorNotConnectedError, ConnectorNotFoundError, @@ -23,6 +23,8 @@ export interface InjectedConnectorOptions { name?: string /** Wallet icons. */ icon?: ConnectorIcons + /** Provider */ + provider?: ProviderInterface } export class InjectedConnector extends Connector { @@ -211,6 +213,13 @@ export class InjectedConnector extends Connector { const installed = getAvailableWallets(globalThis) const wallet = installed.filter((w) => w.id === this._options.id)[0] if (wallet) { + const { provider } = this._options + if (provider) { + Object.assign(wallet, { + provider, + }) + } + this._wallet = wallet } } diff --git a/src/helpers/defaultConnectors.ts b/src/helpers/defaultConnectors.ts index 5a36195..acda731 100644 --- a/src/helpers/defaultConnectors.ts +++ b/src/helpers/defaultConnectors.ts @@ -1,3 +1,4 @@ +import { ProviderInterface } from "starknet" import { type Connector } from "../connectors" import { ArgentMobileConnector, @@ -9,9 +10,11 @@ import { WebWalletConnector } from "../connectors/webwallet" export const defaultConnectors = ({ argentMobileOptions, webWalletUrl, + provider, }: { argentMobileOptions?: ArgentMobileConnectorOptions webWalletUrl?: string + provider?: ProviderInterface }): Connector[] => { const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent) @@ -19,10 +22,10 @@ export const defaultConnectors = ({ if (!isSafari) { defaultConnectors.push( - new InjectedConnector({ options: { id: "argentX" } }), + new InjectedConnector({ options: { id: "argentX", provider } }), ) defaultConnectors.push( - new InjectedConnector({ options: { id: "braavos" } }), + new InjectedConnector({ options: { id: "braavos", provider } }), ) } diff --git a/src/main.ts b/src/main.ts index 6d3d51e..cc2be13 100644 --- a/src/main.ts +++ b/src/main.ts @@ -31,6 +31,7 @@ export const connect = async ({ webWalletUrl = DEFAULT_WEBWALLET_URL, argentMobileOptions, connectors = [], + provider, ...restOptions }: ConnectOptions = {}): Promise => { // force null in case it was disconnected from mobile app @@ -40,6 +41,7 @@ export const connect = async ({ ? defaultConnectors({ argentMobileOptions, webWalletUrl, + provider, }) : connectors diff --git a/src/types/modal.ts b/src/types/modal.ts index 91608dd..4325fb6 100644 --- a/src/types/modal.ts +++ b/src/types/modal.ts @@ -1,6 +1,7 @@ import type { GetWalletOptions } from "get-starknet-core" import type { Connector, ConnectorIcons } from "../connectors/connector" import type { ArgentMobileConnectorOptions } from "../connectors/argentMobile" +import { ProviderInterface } from "starknet" export type StoreVersion = "chrome" | "firefox" | "edge" @@ -12,6 +13,7 @@ export interface ConnectOptions extends GetWalletOptions { modalTheme?: "light" | "dark" | "system" storeVersion?: StoreVersion | null webWalletUrl?: string + provider?: ProviderInterface } export type ModalWallet = { From 83b66015e6fe4e92fd558e0fbbd5bfde6b4947f0 Mon Sep 17 00:00:00 2001 From: bluecco Date: Wed, 13 Dec 2023 14:59:01 +0100 Subject: [PATCH 2/5] fix: allow custom provider for webwallet connector --- src/connectors/webwallet/index.ts | 10 ++++++++-- .../starknetWindowObject/getWebWalletStarknetObject.ts | 5 +++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/connectors/webwallet/index.ts b/src/connectors/webwallet/index.ts index 18ddfb8..7e53c8f 100644 --- a/src/connectors/webwallet/index.ts +++ b/src/connectors/webwallet/index.ts @@ -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, @@ -23,6 +23,7 @@ let _wallet: StarknetWindowObject | null = null interface WebWalletConnectorOptions { url?: string + provider?: ProviderInterface } export class WebWalletConnector extends Connector { @@ -163,11 +164,16 @@ export class WebWalletConnector extends Connector { private async ensureWallet(): Promise { 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 diff --git a/src/connectors/webwallet/starknetWindowObject/getWebWalletStarknetObject.ts b/src/connectors/webwallet/starknetWindowObject/getWebWalletStarknetObject.ts index a7ae80e..90dd22e 100644 --- a/src/connectors/webwallet/starknetWindowObject/getWebWalletStarknetObject.ts +++ b/src/connectors/webwallet/starknetWindowObject/getWebWalletStarknetObject.ts @@ -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" @@ -9,6 +9,7 @@ import { getArgentStarknetWindowObject } from "./argentStarknetWindowObject" export const getWebWalletStarknetObject = async ( target: string, proxyLink: CreateTRPCProxyClient, + provider?: ProviderInterface, ): Promise => { const globalWindow = typeof window !== "undefined" ? window : undefined if (!globalWindow) { @@ -16,7 +17,7 @@ export const getWebWalletStarknetObject = async ( } const nodeUrl = mapTargetUrlToNodeUrl(target) - const defaultProvider = new RpcProvider({ nodeUrl }) + const defaultProvider = provider ?? new RpcProvider({ nodeUrl }) const starknetWindowObject = getArgentStarknetWindowObject( { host: globalWindow.location.origin, From 8e99cbb793882474015603185eb60515e4159b0a Mon Sep 17 00:00:00 2001 From: bluecco Date: Wed, 13 Dec 2023 14:59:23 +0100 Subject: [PATCH 3/5] fix: allow custom provider for argent mobile connector --- src/connectors/argentMobile/index.ts | 15 ++++++++++++++- .../argentMobile/modal/starknet/adapter.ts | 9 ++------- src/helpers/defaultConnectors.ts | 8 ++++++-- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/connectors/argentMobile/index.ts b/src/connectors/argentMobile/index.ts index bc9512b..05641f9 100644 --- a/src/connectors/argentMobile/index.ts +++ b/src/connectors/argentMobile/index.ts @@ -2,7 +2,7 @@ import type { AccountChangeEventHandler, StarknetWindowObject, } from "get-starknet-core" -import type { AccountInterface } from "starknet" +import type { AccountInterface, ProviderInterface } from "starknet" import { constants } from "starknet" import { DEFAULT_ARGENT_MOBILE_ICON, DEFAULT_PROJECT_ID } from "./constants" import { @@ -26,6 +26,7 @@ export interface ArgentMobileConnectorOptions { description?: string url?: string icons?: string[] + provider?: ProviderInterface } export class ArgentMobileConnector extends Connector { @@ -153,6 +154,10 @@ export class ArgentMobileConnector extends Connector { description, url, icons, + rpcUrl: + chainId === constants.NetworkName.SN_MAIN + ? "https://cloud.argent-api.com/v1/starknet/goerli/rpc/v0.5" + : "https://api.hydrogen.argent47.net/v1/starknet/goerli/rpc/v0.5", } if (projectId === DEFAULT_PROJECT_ID) { @@ -171,6 +176,14 @@ export class ArgentMobileConnector extends Connector { } const _wallet = await getStarknetWindowObject(options) + + const { provider } = this._options + if (provider) { + Object.assign(_wallet, { + provider, + }) + } + console.log(_wallet.provider) this._wallet = _wallet // wallet connect rpc enable diff --git a/src/connectors/argentMobile/modal/starknet/adapter.ts b/src/connectors/argentMobile/modal/starknet/adapter.ts index 8c4152a..eabd13d 100644 --- a/src/connectors/argentMobile/modal/starknet/adapter.ts +++ b/src/connectors/argentMobile/modal/starknet/adapter.ts @@ -11,7 +11,7 @@ import type { ProviderInterface, SignerInterface, } from "starknet" -import { Provider, constants } from "starknet" +import { RpcProvider, constants } from "starknet" import type { NamespaceAdapterOptions } from "../adapter" import { NamespaceAdapter } from "../adapter" @@ -84,12 +84,7 @@ export class StarknetAdapter this.remoteSigner = new StarknetRemoteSigner(this.walletRpc) - if (rpcUrl) { - this.provider = new Provider({ rpc: { nodeUrl: rpcUrl } }) - } else { - const network = this.getNetworkName(this.chainId) - this.provider = new Provider({ sequencer: { network } }) - } + this.provider = new RpcProvider({ nodeUrl: rpcUrl }) this.account = new StarknetRemoteAccount( this.provider, "", diff --git a/src/helpers/defaultConnectors.ts b/src/helpers/defaultConnectors.ts index acda731..14b6659 100644 --- a/src/helpers/defaultConnectors.ts +++ b/src/helpers/defaultConnectors.ts @@ -29,8 +29,12 @@ export const defaultConnectors = ({ ) } - defaultConnectors.push(new ArgentMobileConnector(argentMobileOptions)) - defaultConnectors.push(new WebWalletConnector({ url: webWalletUrl })) + defaultConnectors.push( + new ArgentMobileConnector({ ...argentMobileOptions, provider }), + ) + defaultConnectors.push( + new WebWalletConnector({ url: webWalletUrl, provider }), + ) return defaultConnectors } From 041751b5f61eb02c6d5774be2c4860168beee906 Mon Sep 17 00:00:00 2001 From: bluecco Date: Wed, 13 Dec 2023 15:09:57 +0100 Subject: [PATCH 4/5] chore: removed console log --- src/connectors/argentMobile/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/connectors/argentMobile/index.ts b/src/connectors/argentMobile/index.ts index 05641f9..13dc819 100644 --- a/src/connectors/argentMobile/index.ts +++ b/src/connectors/argentMobile/index.ts @@ -183,7 +183,7 @@ export class ArgentMobileConnector extends Connector { provider, }) } - console.log(_wallet.provider) + this._wallet = _wallet // wallet connect rpc enable From e951459a74020a22273467ba8a227e3cb5bd648f Mon Sep 17 00:00:00 2001 From: bluecco Date: Wed, 13 Dec 2023 15:14:16 +0100 Subject: [PATCH 5/5] fix: rpc urls for mainnet --- src/connectors/argentMobile/index.ts | 2 +- src/connectors/webwallet/constants.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/connectors/argentMobile/index.ts b/src/connectors/argentMobile/index.ts index 13dc819..a3e0524 100644 --- a/src/connectors/argentMobile/index.ts +++ b/src/connectors/argentMobile/index.ts @@ -156,7 +156,7 @@ export class ArgentMobileConnector extends Connector { icons, rpcUrl: chainId === constants.NetworkName.SN_MAIN - ? "https://cloud.argent-api.com/v1/starknet/goerli/rpc/v0.5" + ? "https://cloud.argent-api.com/v1/starknet/mainnet/rpc/v0.5" : "https://api.hydrogen.argent47.net/v1/starknet/goerli/rpc/v0.5", } diff --git a/src/connectors/webwallet/constants.ts b/src/connectors/webwallet/constants.ts index f1a69bd..4642193 100644 --- a/src/connectors/webwallet/constants.ts +++ b/src/connectors/webwallet/constants.ts @@ -19,4 +19,4 @@ 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" + "https://cloud.argent-api.com/v1/starknet/mainnet/rpc/v0.5"