1- import React , { useEffect , useMemo , useState } from 'react' ;
2- import { Button , StyleSheet , Text , View } from 'react-native' ;
3- import { Address , Chain , createWalletClient , custom , formatEther } from 'viem' ;
4- import { mainnet , sepolia } from 'viem/chains' ;
5- import { useWalletConnectModal } from '@walletconnect/modal-react-native' ;
6- import { publicClient } from '../clients/public' ;
1+ import React , { useEffect , useMemo , useState } from 'react' ;
2+ import { Button , StyleSheet , Text , View } from 'react-native' ;
3+ import { Address , Chain , createWalletClient , custom , formatEther } from 'viem' ;
4+ import { mainnet , sepolia } from 'viem/chains' ;
5+ import {
6+ useWalletConnectModal ,
7+ IProvider ,
8+ } from '@walletconnect/modal-react-native' ;
9+ import { publicClient } from '../clients/public' ;
710
811export const CHAINS = [ mainnet , sepolia ] ;
912
10- type ConnectEventInfo = {
11- session : {
12- namespaces : {
13- eip155 : {
14- chains : `eip155:${number } `[ ] ;
15- } ;
16- } ;
17- } ;
18- } ;
19-
2013export default function HomePage ( ) {
2114 const {
2215 open,
@@ -31,8 +24,8 @@ export default function HomePage() {
3124 createWalletClient ( {
3225 chain : mainnet ,
3326 transport : custom ( {
34- async request ( { method, params} ) {
35- return await provider ?. request ( { method, params} ) ;
27+ async request ( { method, params } ) {
28+ return await provider ?. request ( { method, params } ) ;
3629 } ,
3730 } ) ,
3831 } ) ,
@@ -77,13 +70,19 @@ export default function HomePage() {
7770 setChain ( chain ) ;
7871 } ;
7972
80- const onConnectEvent = async ( info : ConnectEventInfo ) => {
81- const chainId = info . session . namespaces . eip155 . chains [ 0 ] . replace (
73+ const onConnectEvent = async ( {
74+ session,
75+ } : {
76+ session : IProvider [ 'session' ] ;
77+ } ) => {
78+ const chainId = session ?. namespaces . eip155 . chains ?. [ 0 ] . replace (
8279 'eip155:' ,
8380 '' ,
8481 ) ;
8582
86- onChainChangedEvent ( chainId ) ;
83+ if ( chainId ) {
84+ onChainChangedEvent ( chainId ) ;
85+ }
8786
8887 if ( address ) {
8988 const balance = await publicClient . getBalance ( {
0 commit comments