Skip to content

Commit b688821

Browse files
authored
Refactor home page (#3)
1 parent c13a178 commit b688821

File tree

2 files changed

+79
-14
lines changed

2 files changed

+79
-14
lines changed

templates/default/pages/index.js

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
import { useConnect, useAccount } from 'wagmi';
22

33
const Home = () => {
4-
const [{ data, error }, connect] = useConnect();
4+
const [{ data: connectData, error: connectError }, connect] = useConnect();
5+
const { connected } = connectData;
56
const [{ data: accountData }, disconnect] = useAccount({
67
fetchEns: true,
78
});
8-
const { connected } = data;
99

1010
if (connected) {
1111
return (
1212
<div className='py-24 text-center'>
1313
<p className='text-2xl font-bold'>
1414
Welcome {accountData?.ens?.name || accountData?.address}
1515
</p>
16-
<button className='mx-auto mt-10 rounded bg-slate-200 p-2' onClick={disconnect}>
16+
<button
17+
className='mx-auto mt-10 rounded bg-slate-200 p-2'
18+
onClick={disconnect}
19+
>
1720
Disconnect
1821
</button>
22+
<InfoSection />
1923
</div>
2024
);
2125
}
@@ -25,7 +29,8 @@ const Home = () => {
2529
<h1 className='text-2xl font-bold'>Welcome to create-web3-frontend</h1>
2630
<p className='mt-10'>Connect your wallet:</p>
2731
<div className='mt-5 flex justify-center gap-6'>
28-
{data.connectors.map((x) => (
32+
{/* connectData.connectors contains the list of available 'connectors' like Metamask, WalletConnect, etc */}
33+
{connectData.connectors.map((x) => (
2934
<button
3035
className='rounded bg-slate-200 p-2'
3136
key={x.id}
@@ -37,9 +42,38 @@ const Home = () => {
3742
))}
3843
</div>
3944

40-
{error && (
41-
<p className='text-red-500'>{error?.message ?? 'Failed to connect'}</p>
45+
{connectError && (
46+
<p className='text-red-500'>
47+
{connectError?.message ?? 'Failed to connect'}
48+
</p>
4249
)}
50+
51+
<InfoSection />
52+
</div>
53+
);
54+
};
55+
56+
const InfoSection = () => {
57+
return (
58+
<div className='mt-10'>
59+
<hr className='my-4' />
60+
<h2 className='text-xl font-bold'>If you need help</h2>
61+
<div className='flex flex-col gap-2 mt-2'>
62+
<a
63+
href='https://wagmi.sh'
64+
target='_blank'
65+
className='underline text-gray-600'
66+
>
67+
Link to wagmi docs
68+
</a>
69+
<a
70+
href='https://github.com/dhaiwat10/create-web3-frontend'
71+
target='_blank'
72+
className='underline text-gray-600'
73+
>
74+
Open an issue on Github
75+
</a>
76+
</div>
4377
</div>
4478
);
4579
};

templates/typescript/pages/index.tsx

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import type { NextPage } from 'next';
2-
import { useCallback } from 'react';
3-
import { useAccount, useConnect, useNetwork, useSignMessage } from 'wagmi';
1+
import { NextPage } from 'next';
2+
import { FC } from 'react';
3+
import { useConnect, useAccount } from 'wagmi';
44

55
const Home: NextPage = () => {
6-
const [{ data, error }, connect] = useConnect();
6+
const [{ data: connectData, error: connectError }, connect] = useConnect();
7+
const { connected } = connectData;
78
const [{ data: accountData }, disconnect] = useAccount({
89
fetchEns: true,
910
});
10-
const { connected } = data;
1111

1212
if (connected) {
1313
return (
@@ -21,6 +21,7 @@ const Home: NextPage = () => {
2121
>
2222
Disconnect
2323
</button>
24+
<InfoSection />
2425
</div>
2526
);
2627
}
@@ -30,7 +31,8 @@ const Home: NextPage = () => {
3031
<h1 className='text-2xl font-bold'>Welcome to create-web3-frontend</h1>
3132
<p className='mt-10'>Connect your wallet:</p>
3233
<div className='mt-5 flex justify-center gap-6'>
33-
{data.connectors.map((x) => (
34+
{/* connectData.connectors contains the list of available 'connectors' like Metamask, WalletConnect, etc */}
35+
{connectData.connectors.map((x) => (
3436
<button
3537
className='rounded bg-slate-200 p-2'
3638
key={x.id}
@@ -42,9 +44,38 @@ const Home: NextPage = () => {
4244
))}
4345
</div>
4446

45-
{error && (
46-
<p className='text-red-500'>{error?.message ?? 'Failed to connect'}</p>
47+
{connectError && (
48+
<p className='text-red-500'>
49+
{connectError?.message ?? 'Failed to connect'}
50+
</p>
4751
)}
52+
53+
<InfoSection />
54+
</div>
55+
);
56+
};
57+
58+
const InfoSection: FC = () => {
59+
return (
60+
<div className='mt-10'>
61+
<hr className='my-4' />
62+
<h2 className='text-xl font-bold'>If you need help</h2>
63+
<div className='flex flex-col gap-2 mt-2'>
64+
<a
65+
href='https://wagmi.sh'
66+
target='_blank'
67+
className='underline text-gray-600'
68+
>
69+
Link to wagmi docs
70+
</a>
71+
<a
72+
href='https://github.com/dhaiwat10/create-web3-frontend'
73+
target='_blank'
74+
className='underline text-gray-600'
75+
>
76+
Open an issue on Github
77+
</a>
78+
</div>
4879
</div>
4980
);
5081
};

0 commit comments

Comments
 (0)