@@ -268,7 +268,7 @@ Update `src/App.tsx` with the following code:
268268
269269``` ts title="App.tsx"
270270import " ./App.css"
271- import { DiscoverWalletProviders } from " ./components/DiscoverWalletProviders "
271+ import { DiscoverWalletProviders } from " ./components/WalletProviders "
272272
273273function App() {
274274 return (
@@ -279,18 +279,17 @@ function App() {
279279export default App
280280```
281281
282- This code renders the ` DiscoverWalletProviders ` component that you'll create in the next step, which
282+ This code renders the ` WalletProviders ` component that you'll create in the next step, which
283283contains the logic for detecting and connecting to wallet providers.
284284
285285#### 4. Detect and connect to wallets
286286
287- In the ` src/components ` directory, create a component ` DiscoverWalletProviders.tsx ` with the
288- following code:
287+ Create a ` src/components ` directory and add a file ` WalletProviders.tsx ` with the following code:
289288
290- ``` ts title="DiscoverWalletProviders .tsx"
289+ ``` ts title="WalletProviders .tsx"
291290import { useState } from " react"
292291import { useSyncProviders } from " ../hooks/useSyncProviders"
293- import { formatAddress } from " ~ /utils"
292+ import { formatAddress } from " .. /utils"
294293
295294export const DiscoverWalletProviders = () => {
296295 const [selectedWallet, setSelectedWallet] = useState <EIP6963ProviderDetail >()
@@ -299,15 +298,16 @@ export const DiscoverWalletProviders = () => {
299298
300299 // Connect to the selected provider using eth_requestAccounts.
301300 const handleConnect = async (providerWithInfo : EIP6963ProviderDetail ) => {
302- try {
303- const accounts = await providerWithInfo .provider .request ({
304- method: " eth_requestAccounts"
305- })
306-
301+ const accounts: string [] | undefined =
302+ await (
303+ providerWithInfo .provider
304+ .request ({ method: " eth_requestAccounts" })
305+ .catch (console .error )
306+ ) as string [] | undefined ;
307+
308+ if (accounts ?.[0 ]) {
307309 setSelectedWallet (providerWithInfo )
308310 setUserAccount (accounts ?.[0 ])
309- } catch (error ) {
310- console .error (error )
311311 }
312312 }
313313
@@ -363,7 +363,7 @@ address are displayed.
363363
364364#### 5. Add React hooks
365365
366- Create a ` src/hooks ` directory and add a ` store.ts ` file with the following code:
366+ Create a ` src/hooks ` directory and add a file ` store.ts ` with the following code:
367367
368368``` ts title="hooks/store.ts"
369369declare global {
0 commit comments