@@ -13,7 +13,6 @@ import { trackTransaction } from "../../analytics/track/transaction.js";
1313import type { Chain } from "../../chains/types.js" ;
1414import {
1515 getCachedChain ,
16- getChainMetadata ,
1716 getRpcUrlForChain ,
1817} from "../../chains/utils.js" ;
1918import type { ThirdwebClient } from "../../client/client.js" ;
@@ -40,7 +39,6 @@ import type {
4039 Wallet ,
4140} from "../interfaces/wallet.js" ;
4241import type { DisconnectFn , SwitchChainFn } from "../types.js" ;
43- import { getValidPublicRPCUrl } from "../utils/chains.js" ;
4442import { getDefaultAppMetadata } from "../utils/defaultDappMetadata.js" ;
4543import { normalizeChainId } from "../utils/normalizeChainId.js" ;
4644import type { WalletEmitter } from "../wallet-emitter.js" ;
@@ -56,8 +54,6 @@ type SavedConnectParams = {
5654 pairingTopic ?: string ;
5755} ;
5856
59- const ADD_ETH_CHAIN_METHOD = "wallet_addEthereumChain" ;
60-
6157const storageKeys = {
6258 lastUsedChainId : "tw.wc.lastUsedChainId" ,
6359 requestedChains : "tw.wc.requestedChains" ,
@@ -275,13 +271,6 @@ async function initProvider(
275271 }
276272 }
277273
278- // For UniversalProvider, chain configuration is handled during session establishment
279- // const { requiredChain, optionalChains: chainsToRequest } = getChainsToRequest({
280- // chain: chainToRequest,
281- // client: options.client,
282- // optionalChains: optionalChains,
283- // });
284-
285274 const provider = await UniversalProvider . init ( {
286275 metadata : {
287276 description :
@@ -480,74 +469,17 @@ function onConnect(
480469 account ,
481470 chain ,
482471 disconnect ,
483- ( newChain ) => switchChainWC ( provider , newChain , storage ) ,
472+ ( newChain ) => switchChainWC ( provider , newChain ) ,
484473 ] ;
485474}
486475
487- // Storage utils -----------------------------------------------------------------------------------------------
488-
489- function getNamespaceMethods ( provider : WCProvider ) {
490- return provider . session ?. namespaces [ NAMESPACE ] ?. methods || [ ] ;
491- }
492-
493- function getNamespaceChainsIds ( provider : WCProvider ) : number [ ] {
494- const chainIds = provider . session ?. namespaces [ NAMESPACE ] ?. chains ?. map (
495- ( chain : string ) => Number . parseInt ( chain . split ( ":" ) [ 1 ] || "" ) ,
496- ) ;
497-
498- return chainIds ?? [ ] ;
499- }
500-
501476async function switchChainWC (
502477 provider : WCProvider ,
503478 chain : Chain ,
504- storage : AsyncStorage ,
505479) {
506480 const chainId = chain . id ;
507481 try {
508- const namespaceChains = getNamespaceChainsIds ( provider ) ;
509- const namespaceMethods = getNamespaceMethods ( provider ) ;
510- const isChainApproved = namespaceChains . includes ( chainId ) ;
511-
512482 provider . setDefaultChain ( `eip155:${ chainId } ` ) ;
513-
514- if ( ! isChainApproved && namespaceMethods . includes ( ADD_ETH_CHAIN_METHOD ) ) {
515- const apiChain = await getChainMetadata ( chain ) ;
516-
517- const blockExplorerUrls = [
518- ...new Set ( [
519- ...( chain . blockExplorers ?. map ( ( x ) => x . url ) || [ ] ) ,
520- ...( apiChain . explorers ?. map ( ( x ) => x . url ) || [ ] ) ,
521- ] ) ,
522- ] ;
523-
524- await provider . request (
525- {
526- method : ADD_ETH_CHAIN_METHOD ,
527- params : [
528- {
529- blockExplorerUrls :
530- blockExplorerUrls . length > 0 ? blockExplorerUrls : undefined ,
531- chainId : numberToHex ( apiChain . chainId ) ,
532- chainName : apiChain . name ,
533- nativeCurrency : apiChain . nativeCurrency , // no clientId on purpose
534- rpcUrls : getValidPublicRPCUrl ( apiChain ) ,
535- } ,
536- ] ,
537- } ,
538- `eip155:${ chainId } ` ,
539- ) ;
540- const requestedChains = await getRequestedChainsIds ( storage ) ;
541- requestedChains . push ( chainId ) ;
542- setRequestedChainsIds ( requestedChains , storage ) ;
543- }
544- await provider . request (
545- {
546- method : "wallet_switchEthereumChain" ,
547- params : [ { chainId : numberToHex ( chainId ) } ] ,
548- } ,
549- `eip155:${ 8453 } ` ,
550- ) ;
551483 } catch ( error ) {
552484 const message =
553485 typeof error === "string" ? error : ( error as ProviderRpcError ) ?. message ;
@@ -570,15 +502,6 @@ function setRequestedChainsIds(
570502 storage ?. setItem ( storageKeys . requestedChains , stringify ( chains ) ) ;
571503}
572504
573- /**
574- * Get the last requested chains from the storage.
575- * @internal
576- */
577- async function getRequestedChainsIds ( storage : AsyncStorage ) : Promise < number [ ] > {
578- const data = await storage . getItem ( storageKeys . requestedChains ) ;
579- return data ? JSON . parse ( data ) : [ ] ;
580- }
581-
582505function getChainsToRequest ( options : {
583506 chain ?: Chain ;
584507 optionalChains ?: Chain [ ] ;
0 commit comments