Skip to content

Commit

Permalink
Merge pull request #56 from argentlabs/fix/argent-mobile-chainId
Browse files Browse the repository at this point in the history
fix: default to mainnet for argent mobile
  • Loading branch information
bluecco authored Jan 9, 2024
2 parents 43ea9a3 + 37121fb commit 36ff10f
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 18 deletions.
6 changes: 6 additions & 0 deletions src/connectors/argentMobile/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@ 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"
34 changes: 21 additions & 13 deletions src/connectors/argentMobile/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,6 +28,7 @@ export interface ArgentMobileConnectorOptions {
url?: string
icons?: string[]
provider?: ProviderInterface
rpcUrl?: string
}

export class ArgentMobileConnector extends Connector {
Expand Down Expand Up @@ -145,19 +147,32 @@ export class ArgentMobileConnector extends Connector {

private async ensureWallet(): Promise<void> {
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,
projectId: projectId ?? DEFAULT_PROJECT_ID,
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) {
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/connectors/argentMobile/modal/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 4 additions & 2 deletions src/connectors/argentMobile/modal/login.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -22,6 +22,7 @@ export interface IArgentLoginOptions {
mobileUrl?: string
modalType?: "overlay" | "window"
walletConnect?: SignClientTypes.Options
provider?: ProviderInterface
}

export const login = async <TAdapter extends NamespaceAdapter>(
Expand All @@ -37,6 +38,7 @@ export const login = async <TAdapter extends NamespaceAdapter>(
url,
icons,
walletConnect,
provider,
}: IArgentLoginOptions,
Adapter: new (options: NamespaceAdapterOptions) => TAdapter,
): Promise<TAdapter | null> => {
Expand All @@ -63,7 +65,7 @@ export const login = async <TAdapter extends NamespaceAdapter>(
}

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.
Expand Down
6 changes: 3 additions & 3 deletions src/connectors/argentMobile/modal/starknet/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
"",
Expand Down

0 comments on commit 36ff10f

Please sign in to comment.