//@ts-ignore import React, { useState, useEffect, useContext } from 'react'; import { CONNECT_MAP, TomoProvider, useTomo } from '../dist'; import './v2.css'; import { EthereumProvider } from '../dist'; import { SupportedProvidersContext } from '.'; import BigNumber from 'bignumber.js'; import { useThemeParams } from '@vkruglikov/react-telegram-web-app'; import { BASE_URL_DEV } from './baseUrlDev'; import { url } from 'inspector'; function stringToHex(str: string) { let hex = ''; for (let i = 0; i < str.length; i++) { hex += str.charCodeAt(i).toString(16); } return '0x' + hex; } function Index({ setChains }: { setChains: any }) { const [supportedChains, setSupportedChains] = useState('1,56,324'); const [chainIdInvalid, setChainIdInvalid] = useState(false); const [addr, setAddr] = useState(''); const [requestAccountsRs, setRequestAccountsRs] = useState(''); const [ethAccountsRs, setEthAccountsRs] = useState(''); const [chainIdInput, setChainIdInput] = useState('1'); const [ethChainId, setEthChainId] = useState(''); const [switchChainRs, setSwitchChainRs] = useState(''); const [personalSignInput, setPersonalSignInput] = useState(''); const [personalSignResult, setPersonalSignResult] = useState(''); const [toAddr, setToAddr] = useState(''); const [sendValue, setSendValue] = useState(''); const [sendChainId, setSendChainId] = useState(''); const [sendTxResult, setSendTxResult] = useState(''); const { openConnectModal, providers } = useTomo(); // on chain ids change useEffect(() => { try { const ids = supportedChains .split(',') .map(i => i.trim()) .filter(i => !!i); const valid = ids.every(id => !isNaN(+id)); if (valid) { setChainIdInvalid(false); setChains(ids); } else setChainIdInvalid(true); } catch (e) { setChainIdInvalid(true); } }, [supportedChains]); const walletAddressReq = async (eth: EthereumProvider) => { const [address] = await eth.request({ method: 'eth_accounts', }); console.log('Multi Chain Tomo Wallet accounts:', address); setAddr(address || ''); }; useEffect(() => { const ethereum = providers.ethereum; console.log('ethereum', ethereum, ethereum?.isConnected); if (ethereum?.isConnected) { walletAddressReq(ethereum); } else { setAddr(''); } }, [providers.ethereum]); // clear after disconnect useEffect(() => { if (!providers.ethereum) { setAddr(''); setRequestAccountsRs(''); setEthChainId(''); setSwitchChainRs(''); } }, [providers.ethereum]); const connectWallet = async () => { openConnectModal(); }; const disconnect = async () => { await providers.ethereum?.disconnect?.(); console.log('disconnect', providers.ethereum?.isConnected); setAddr(''); return; }; // const { setProviderTypes } = useContext(SupportedProvidersContext); // useEffect(() => { // setProviderTypes(['EVM']); // console.log(`setProviderTypes(['EVM'])`); // }, []); return (

Demo For TG SDK Connect

{addr ? ( <>

My Tomo Wallet Address

{addr ?? ''}
Disconnect
openConnectModal()}> Open Modal While connected
) : ( <>

Connect To Tomo Wallet

please enter supported chainIds, separate by comma

{ setSupportedChains(e.target.value); }} />
Connect
)}
{requestAccountsRs}
{ethAccountsRs}
{ethChainId}

ChainId

{ setChainIdInput(e.target.value); }} /> {switchChainRs}

personal_sign