Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: add enableCustomRpc parameter #3418

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/adapters/ethers/src/tests/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ const mockAuthProvider = {
const mockNetworks = [mainnet]
const mockCaipNetworks = CaipNetworksUtil.extendCaipNetworks(mockNetworks, {
projectId: 'test-project-id',
customNetworkImageUrls: {}
customNetworkImageUrls: {},
enableCustomRpc: true
})

describe('EthersAdapter', () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/adapters/ethers5/src/tests/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ const mockAuthProvider = {
const mockNetworks = [mainnet]
const mockCaipNetworks = CaipNetworksUtil.extendCaipNetworks(mockNetworks, {
projectId: 'test-project-id',
customNetworkImageUrls: {}
customNetworkImageUrls: {},
enableCustomRpc: true
})

describe('Ethers5Adapter', () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/adapters/solana/src/tests/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ const mockAuthProvider = {
const mockNetworks = [solana]
const mockCaipNetworks = CaipNetworksUtil.extendCaipNetworks(mockNetworks, {
projectId: 'test-project-id',
customNetworkImageUrls: {}
customNetworkImageUrls: {},
enableCustomRpc: true
})

describe('SolanaAdapter', () => {
Expand Down
55 changes: 30 additions & 25 deletions packages/adapters/wagmi/src/client.ts
Original file line number Diff line number Diff line change
@@ -1,60 +1,60 @@
import type UniversalProvider from '@walletconnect/universal-provider'
import type { AppKitNetwork, BaseNetwork, CaipNetwork } from '@reown/appkit-common'
import { AdapterBlueprint } from '@reown/appkit/adapters'
import { CoreHelperUtil } from '@reown/appkit-core'
import { AdapterBlueprint } from '@reown/appkit/adapters'
import {
connect,
disconnect as wagmiDisconnect,
createConfig,
type Config,
type CreateConfigParameters,
type CreateConnectorFn,
getConnections,
switchChain,
injected,
type Connector,
watchAccount,
watchConnections,
getAccount,
getBalance,
getEnsName,
getConnections,
getEnsAvatar,
getEnsName,
injected,
prepareTransactionRequest,
reconnect,
signMessage,
switchChain,
disconnect as wagmiDisconnect,
estimateGas as wagmiEstimateGas,
sendTransaction as wagmiSendTransaction,
getEnsAddress as wagmiGetEnsAddress,
sendTransaction as wagmiSendTransaction,
writeContract as wagmiWriteContract,
waitForTransactionReceipt,
getAccount,
prepareTransactionRequest,
reconnect,
watchAccount,
watchConnections,
type Config,
type Connector,
type CreateConfigParameters,
type CreateConnectorFn,
watchPendingTransactions
} from '@wagmi/core'
import { type Chain } from '@wagmi/core/chains'
import type UniversalProvider from '@walletconnect/universal-provider'

import { AppKit, WcHelpersUtil, type AppKitOptions } from '@reown/appkit'
import {
ConstantsUtil as CommonConstantsUtil,
isReownName,
NetworkUtil
} from '@reown/appkit-common'
import { authConnector } from './connectors/AuthConnector.js'
import { AppKit, WcHelpersUtil, type AppKitOptions } from '@reown/appkit'
import { walletConnect } from './connectors/UniversalConnector.js'
import { coinbaseWallet } from '@wagmi/connectors'
import {
ConstantsUtil as CoreConstantsUtil,
type ConnectorType,
type Provider
} from '@reown/appkit-core'
import { CaipNetworksUtil, ConstantsUtil, PresetsUtil } from '@reown/appkit-utils'
import type { W3mFrameProvider } from '@reown/appkit-wallet'
import { coinbaseWallet } from '@wagmi/connectors'
import {
formatUnits,
parseUnits,
type GetEnsAddressReturnType,
type Hex,
type HttpTransport
} from 'viem'
import type { W3mFrameProvider } from '@reown/appkit-wallet'
import { normalize } from 'viem/ens'
import { authConnector } from './connectors/AuthConnector.js'
import { walletConnect } from './connectors/UniversalConnector.js'
import { parseWalletCapabilities } from './utils/helpers.js'

export class WagmiAdapter extends AdapterBlueprint {
Expand All @@ -66,21 +66,24 @@ export class WagmiAdapter extends AdapterBlueprint {
configParams: Partial<CreateConfigParameters> & {
networks: AppKitNetwork[]
projectId: string
enableCustomRpc?: boolean
}
) {
super({
projectId: configParams.projectId,
networks: CaipNetworksUtil.extendCaipNetworks(configParams.networks, {
projectId: configParams.projectId,
customNetworkImageUrls: {}
customNetworkImageUrls: {},
enableCustomRpc: configParams.enableCustomRpc
}) as [CaipNetwork, ...CaipNetwork[]]
})
this.namespace = CommonConstantsUtil.CHAIN.EVM
this.createConfig({
...configParams,
networks: CaipNetworksUtil.extendCaipNetworks(configParams.networks, {
projectId: configParams.projectId,
customNetworkImageUrls: {}
customNetworkImageUrls: {},
enableCustomRpc: configParams.enableCustomRpc
}) as [CaipNetwork, ...CaipNetwork[]],
projectId: configParams.projectId
})
Expand Down Expand Up @@ -119,11 +122,13 @@ export class WagmiAdapter extends AdapterBlueprint {
configParams: Partial<CreateConfigParameters> & {
networks: CaipNetwork[]
projectId: string
enableCustomRpc?: boolean
}
) {
this.caipNetworks = CaipNetworksUtil.extendCaipNetworks(configParams.networks, {
projectId: configParams.projectId,
customNetworkImageUrls: {}
customNetworkImageUrls: {},
enableCustomRpc: configParams.enableCustomRpc
}) as [CaipNetwork, ...CaipNetwork[]]

this.wagmiChains = this.caipNetworks.filter(
Expand Down
39 changes: 27 additions & 12 deletions packages/adapters/wagmi/src/tests/client.test.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import { describe, it, expect, beforeEach, vi } from 'vitest'
import { WagmiAdapter } from '../client'
import { CaipNetworksUtil } from '@reown/appkit-utils'
import type { Config } from '@wagmi/core'
import {
disconnect as wagmiDisconnect,
getConnections,
switchChain,
estimateGas,
getAccount,
getBalance,
getEnsName,
getConnections,
getEnsAvatar,
getEnsName,
signMessage,
estimateGas,
sendTransaction as wagmiSendTransaction,
switchChain,
disconnect as wagmiDisconnect,
getEnsAddress as wagmiGetEnsAddress,
sendTransaction as wagmiSendTransaction,
writeContract as wagmiWriteContract,
waitForTransactionReceipt,
getAccount,
watchPendingTransactions
} from '@wagmi/core'
import { mainnet } from '@wagmi/core/chains'
import { CaipNetworksUtil } from '@reown/appkit-utils'
import type UniversalProvider from '@walletconnect/universal-provider'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { WagmiAdapter } from '../client'

vi.mock('@wagmi/core', async () => {
const actual = await vi.importActual('@wagmi/core')
Expand Down Expand Up @@ -55,7 +55,8 @@ const mockProjectId = 'test-project-id'
const mockNetworks = [mainnet]
const mockCaipNetworks = CaipNetworksUtil.extendCaipNetworks(mockNetworks, {
projectId: mockProjectId,
customNetworkImageUrls: {}
customNetworkImageUrls: {},
enableCustomRpc: false
})

const mockWagmiConfig = {
Expand Down Expand Up @@ -95,7 +96,21 @@ describe('WagmiAdapter', () => {
expect(adapter.adapterType).toBe('wagmi')
expect(adapter.namespace).toBe('eip155')
})

it('should be set to reown RPC by default', () => {
expect(adapter.wagmiChains?.[0].rpcUrls.default.http[0]).toBe(
`https://rpc.walletconnect.org/v1/?chainId=eip155%3A1&projectId=${mockProjectId}`
)
})
it('should be set to customRPC rpc if enableCustomRpc is true', () => {
const adapterWithCustomRpc = new WagmiAdapter({
networks: mockNetworks,
projectId: mockProjectId,
enableCustomRpc: true
})
expect(adapterWithCustomRpc.wagmiChains?.[0].rpcUrls.default.http[0]).toBe(
`https://cloudflare-eth.com`
)
})
it('should not set info property for injected connector', () => {
const mockConnectors = [
{
Expand Down
102 changes: 51 additions & 51 deletions packages/appkit-new/src/client.ts
Original file line number Diff line number Diff line change
@@ -1,62 +1,56 @@
/* eslint-disable max-depth */
import {
type EventsControllerState,
type PublicStateControllerState,
type ThemeControllerState,
type ModalControllerState,
type ConnectedWalletInfo,
type RouterControllerState,
type ChainAdapter,
type SdkVersion,
type UseAppKitAccountReturn,
type UseAppKitNetworkReturn,
type NetworkControllerClient,
type ConnectionControllerClient,
ConstantsUtil as CoreConstantsUtil,
type ConnectorType,
type WriteContractArgs,
type Provider,
type SendTransactionArgs,
type EstimateGasTransactionArgs,
type AccountControllerState,
type AdapterNetworkState,
SIWXUtil
} from '@reown/appkit-core'
ConstantsUtil,
SafeLocalStorage,
SafeLocalStorageKeys,
type CaipAddress,
type CaipNetwork,
type CaipNetworkId,
type ChainNamespace
} from '@reown/appkit-common'
import {
AccountController,
AlertController,
ApiController,
AssetUtil,
BlockchainApiController,
ChainController,
ConnectionController,
ConnectorController,
ConstantsUtil as CoreConstantsUtil,
CoreHelperUtil,
EnsController,
EventsController,
ModalController,
ChainController,
OptionsController,
PublicStateController,
ThemeController,
SnackController,
RouterController,
EnsController,
OptionsController,
AssetUtil,
ApiController,
AlertController,
StorageUtil
SIWXUtil,
SnackController,
StorageUtil,
ThemeController,
type AccountControllerState,
type AdapterNetworkState,
type ChainAdapter,
type ConnectedWalletInfo,
type ConnectionControllerClient,
type ConnectorType,
type EstimateGasTransactionArgs,
type EventsControllerState,
type ModalControllerState,
type NetworkControllerClient,
type Provider,
type PublicStateControllerState,
type RouterControllerState,
type SdkVersion,
type SendTransactionArgs,
type ThemeControllerState,
type UseAppKitAccountReturn,
type UseAppKitNetworkReturn,
type WriteContractArgs
} from '@reown/appkit-core'
import type { AppKitNetwork } from '@reown/appkit-new/networks'
import { setColorTheme, setThemeVariables } from '@reown/appkit-ui-new'
import {
ConstantsUtil,
type CaipNetwork,
type ChainNamespace,
SafeLocalStorage,
SafeLocalStorageKeys,
type CaipAddress,
type CaipNetworkId
} from '@reown/appkit-common'
import type { AppKitOptions } from './utils/TypesUtil.js'
import {
UniversalAdapter,
UniversalAdapter as UniversalAdapterClient
} from './universal-adapter/client.js'
import {
CaipNetworksUtil,
ErrorUtil,
Expand All @@ -68,13 +62,17 @@ import {
type W3mFrameProvider,
type W3mFrameTypes
} from '@reown/appkit-wallet'
import { ProviderUtil } from './store/ProviderUtil.js'
import type { AppKitNetwork } from '@reown/appkit-new/networks'
import type { AdapterBlueprint } from './adapters/ChainAdapterBlueprint.js'
import UniversalProvider from '@walletconnect/universal-provider'
import type { SessionTypes } from '@walletconnect/types'
import type { UniversalProviderOpts } from '@walletconnect/universal-provider'
import UniversalProvider from '@walletconnect/universal-provider'
import type { AdapterBlueprint } from './adapters/ChainAdapterBlueprint.js'
import { W3mFrameProviderSingleton } from './auth-provider/W3MFrameProviderSingleton.js'
import { ProviderUtil } from './store/ProviderUtil.js'
import {
UniversalAdapter,
UniversalAdapter as UniversalAdapterClient
} from './universal-adapter/client.js'
import type { AppKitOptions } from './utils/TypesUtil.js'

declare global {
interface Window {
Expand Down Expand Up @@ -685,7 +683,8 @@ export class AppKit {
private extendCaipNetworks(options: AppKitOptions) {
const extendedNetworks = CaipNetworksUtil.extendCaipNetworks(options.networks, {
customNetworkImageUrls: options.chainImages,
projectId: options.projectId
projectId: options.projectId,
enableCustomRpc: options.enableCustomRpc
})

return extendedNetworks
Expand All @@ -696,7 +695,8 @@ export class AppKit {
const extendedNetwork = defaultNetwork
? CaipNetworksUtil.extendCaipNetwork(defaultNetwork, {
customNetworkImageUrls: options.chainImages,
projectId: options.projectId
projectId: options.projectId,
enableCustomRpc: options.enableCustomRpc
})
: undefined

Expand Down
2 changes: 2 additions & 0 deletions packages/appkit-new/src/utils/TypesUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ export type AppKitOptions = {
* @see https://cloud.walletconnect.com/
*/
metadata?: Metadata

enableCustomRpc?: boolean
} & OptionsControllerState

export type AppKitOptionsWithCaipNetworks = Omit<AppKitOptions, 'defaultNetwork' | 'networks'> & {
Expand Down
Loading
Loading