From 37121fbaa6b2128e9099e4660103c451edd063b6 Mon Sep 17 00:00:00 2001 From: bluecco Date: Tue, 9 Jan 2024 10:22:44 +0100 Subject: [PATCH] fix: default to mainnet for argent mobile --- src/connectors/argentMobile/constants.ts | 6 ++++ src/connectors/argentMobile/index.ts | 34 ++++++++++++------- src/connectors/argentMobile/modal/adapter.ts | 2 ++ src/connectors/argentMobile/modal/login.ts | 6 ++-- .../argentMobile/modal/starknet/adapter.ts | 6 ++-- 5 files changed, 36 insertions(+), 18 deletions(-) diff --git a/src/connectors/argentMobile/constants.ts b/src/connectors/argentMobile/constants.ts index 8d6fb77..c5919b6 100644 --- a/src/connectors/argentMobile/constants.ts +++ b/src/connectors/argentMobile/constants.ts @@ -13,3 +13,9 @@ 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/argentMobile/index.ts b/src/connectors/argentMobile/index.ts index a3e0524..65f5d0c 100644 --- a/src/connectors/argentMobile/index.ts +++ b/src/connectors/argentMobile/index.ts @@ -18,6 +18,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" export interface ArgentMobileConnectorOptions { dappName?: string @@ -27,6 +28,7 @@ export interface ArgentMobileConnectorOptions { url?: string icons?: string[] provider?: ProviderInterface + rpcUrl?: string } export class ArgentMobileConnector extends Connector { @@ -145,8 +147,23 @@ export class ArgentMobileConnector extends Connector { private async ensureWallet(): Promise { const { getStarknetWindowObject } = await import("./modal") - const { chainId, projectId, dappName, description, url, icons } = - this._options + const { + chainId, + projectId, + dappName, + description, + url, + icons, + provider, + rpcUrl, + } = this._options + + const providerRpcUrl = + rpcUrl ?? + (!chainId || chainId === constants.NetworkName.SN_MAIN + ? RPC_NODE_URL_MAINNET + : RPC_NODE_URL_TESTNET) + const options = { chainId: chainId ?? constants.NetworkName.SN_MAIN, name: dappName, @@ -154,10 +171,8 @@ export class ArgentMobileConnector extends Connector { description, url, icons, - rpcUrl: - chainId === constants.NetworkName.SN_MAIN - ? "https://cloud.argent-api.com/v1/starknet/mainnet/rpc/v0.5" - : "https://api.hydrogen.argent47.net/v1/starknet/goerli/rpc/v0.5", + provider, + rpcUrl: providerRpcUrl, } if (projectId === DEFAULT_PROJECT_ID) { @@ -177,13 +192,6 @@ export class ArgentMobileConnector extends Connector { const _wallet = await getStarknetWindowObject(options) - const { provider } = this._options - if (provider) { - Object.assign(_wallet, { - provider, - }) - } - this._wallet = _wallet // wallet connect rpc enable diff --git a/src/connectors/argentMobile/modal/adapter.ts b/src/connectors/argentMobile/modal/adapter.ts index c0be7c3..0ab6503 100644 --- a/src/connectors/argentMobile/modal/adapter.ts +++ b/src/connectors/argentMobile/modal/adapter.ts @@ -14,11 +14,13 @@ import { } from "@walletconnect/utils" import type { EthereumRpcConfig } from "./starknet/adapter" +import { ProviderInterface } from "starknet" export interface NamespaceAdapterOptions { client: SignClient chainId?: string | number rpcUrl?: string + provider: ProviderInterface } export abstract class NamespaceAdapter { diff --git a/src/connectors/argentMobile/modal/login.ts b/src/connectors/argentMobile/modal/login.ts index 6d63548..1aefd7c 100644 --- a/src/connectors/argentMobile/modal/login.ts +++ b/src/connectors/argentMobile/modal/login.ts @@ -1,7 +1,7 @@ import SignClient from "@walletconnect/sign-client" import type { SignClientTypes } from "@walletconnect/types" -import { constants } from "starknet" +import { ProviderInterface, constants } from "starknet" // Using NetworkName as a value. const Network: typeof constants.NetworkName = constants.NetworkName @@ -22,6 +22,7 @@ export interface IArgentLoginOptions { mobileUrl?: string modalType?: "overlay" | "window" walletConnect?: SignClientTypes.Options + provider?: ProviderInterface } export const login = async ( @@ -37,6 +38,7 @@ export const login = async ( url, icons, walletConnect, + provider, }: IArgentLoginOptions, Adapter: new (options: NamespaceAdapterOptions) => TAdapter, ): Promise => { @@ -63,7 +65,7 @@ export const login = async ( } const client = await SignClient.init(signClientOptions) - const adapter = new Adapter({ client, chainId, rpcUrl }) + const adapter = new Adapter({ client, chainId, rpcUrl, provider }) client.on("session_event", (_) => { // Handle session events, such as "chainChanged", "accountsChanged", etc. diff --git a/src/connectors/argentMobile/modal/starknet/adapter.ts b/src/connectors/argentMobile/modal/starknet/adapter.ts index eabd13d..d0fb6f1 100644 --- a/src/connectors/argentMobile/modal/starknet/adapter.ts +++ b/src/connectors/argentMobile/modal/starknet/adapter.ts @@ -63,10 +63,10 @@ export class StarknetAdapter private walletRpc: IStarknetRpc - constructor({ client, chainId, rpcUrl }: NamespaceAdapterOptions) { + constructor({ client, chainId, rpcUrl, provider }: NamespaceAdapterOptions) { super() - this.chainId = String(chainId || "SN_GOERLI") + this.chainId = String(chainId ?? constants.NetworkName.SN_MAIN) this.rpc = { chains: chainId ? [this.formatChainId(this.chainId)] : [], methods: this.methods, @@ -84,7 +84,7 @@ export class StarknetAdapter this.remoteSigner = new StarknetRemoteSigner(this.walletRpc) - this.provider = new RpcProvider({ nodeUrl: rpcUrl }) + this.provider = provider ? provider : new RpcProvider({ nodeUrl: rpcUrl }) this.account = new StarknetRemoteAccount( this.provider, "",