Skip to content

Commit 3fe29d3

Browse files
author
sam
committed
feat(release): v1.0.0
0 parents  commit 3fe29d3

File tree

19 files changed

+7986
-0
lines changed

19 files changed

+7986
-0
lines changed

.env-example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
INFURA=XXXXXXXX

.github/workflows/nodejs.yml

Whitespace-only changes.

.gitignore

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# next.js
12+
/.next/
13+
/out/
14+
15+
# production
16+
/build
17+
18+
# misc
19+
.DS_Store
20+
*.pem
21+
22+
# debug
23+
npm-debug.log*
24+
yarn-debug.log*
25+
yarn-error.log*
26+
27+
# local env files
28+
.env.local
29+
.env.development.local
30+
.env.test.local
31+
.env.production.local
32+
33+
# vercel
34+
.vercel
35+
36+
# DotEnv
37+
.env

README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Web3 Starter
2+
3+
Simple web3 starter
4+
5+
## Get started:
6+
7+
First, run the development server:
8+
9+
```bash
10+
npm run dev
11+
# or
12+
yarn dev
13+
```
14+
15+
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
16+
17+
You can start editing the page by modifying `pages/index.js`. The page auto-updates as you edit the file.
18+
19+
[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.js`.
20+
21+
The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages.
22+
23+
## Layout:
24+
25+
- `components` - UI components
26+
- `contexts` - App wide data contexts, comes with wallet management
27+
- `contracts` - Contract presets for use in the
28+
- `hooks` -
29+
- `pages` - Routing and base pages
30+
- `public` - static objects available at `/`
31+
- `utils` - Small functions that help out
32+
33+
## Learn More
34+
35+
To learn more about the underlying framework: Next.js, take a look at the following resources:
36+
37+
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
38+
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
39+
40+
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
41+
42+
## Deploy on Vercel
43+
44+
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
45+
46+
Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.

components/helpers.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import styled from 'styled-components'
2+
3+
export const Column = styled.div`
4+
display: flex;
5+
flex-direction: column;
6+
width: ${({ w }) => w};
7+
height: ${({ h }) => h};
8+
padding: ${({ p }) => p};
9+
margin: ${({ m }) => m};
10+
align-items: ${({ ai }) => ai};
11+
justify-content: ${({ jc }) => jc};
12+
flex-grow: ${({ fg }) => fg};
13+
`
14+
export const Row = styled.div`
15+
width: ${({ w }) => (w ? w : '100%')};
16+
height: ${({ h }) => h};
17+
display: flex;
18+
flex-direction: row;
19+
padding: ${({ p }) => p};
20+
margin: ${({ m }) => m};
21+
justify-content: ${({ jc }) => jc};
22+
align-items: ${({ ai }) => ai};
23+
flex-grow: ${({ fg }) => fg};
24+
`

contexts/useWeb3.js

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import React, {
2+
createContext,
3+
useState,
4+
useContext,
5+
useMemo,
6+
useEffect,
7+
useCallback,
8+
} from 'react'
9+
10+
import { useWallet } from 'use-wallet'
11+
import { web3, registerProvider } from '../utils/ethers'
12+
13+
import useLocalStorage from '../hooks/useLocalStorage'
14+
const atob = (a) => Buffer.from(a, 'base64').toString('binary')
15+
16+
// Create Context
17+
export const UseWeb3Context = createContext()
18+
19+
export const Web3Provider = (props) => {
20+
const { account, connect, status, ethereum, reset } = useWallet()
21+
22+
// Remember provider preference
23+
const [provider, setProvider] = useLocalStorage('provider', false)
24+
25+
// Connect/Disconnect Wallet
26+
const connectWallet = async (key) => {
27+
await connect(key)
28+
setProvider(key)
29+
registerProvider(ethereum)
30+
}
31+
const disconnectWallet = () => {
32+
reset()
33+
setProvider(false)
34+
}
35+
36+
// Check to see if we've set a provider in local Storage and connect
37+
const initProvider = () => {
38+
if (provider) {
39+
console.log('Provider Found:', provider)
40+
connect(provider)
41+
registerProvider(ethereum)
42+
}
43+
}
44+
45+
// Once we've connected a wallet, switch to wallet provider
46+
useEffect(() => {
47+
if (status === 'connected') {
48+
console.log('Connected!')
49+
registerProvider(ethereum)
50+
}
51+
}, [status])
52+
53+
// Once loaded, initalise the provider
54+
useEffect(() => {
55+
initProvider()
56+
}, [provider])
57+
58+
const tools = useMemo(
59+
() => ({
60+
provider,
61+
setProvider,
62+
connectWallet,
63+
disconnectWallet,
64+
account,
65+
status,
66+
}),
67+
[provider, account, status]
68+
)
69+
70+
// pass the value in provider and return
71+
return (
72+
<UseWeb3Context.Provider
73+
value={{
74+
tools,
75+
}}
76+
>
77+
{props.children}
78+
</UseWeb3Context.Provider>
79+
)
80+
}
81+
82+
export function useWeb3() {
83+
const web3Context = useContext(UseWeb3Context)
84+
if (web3Context === null) {
85+
throw new Error(
86+
'useWeb3() can only be used inside of <UseToolsProvider />, ' +
87+
'please declare it at a higher level.'
88+
)
89+
}
90+
const { tools } = web3Context
91+
92+
return useMemo(() => ({ web3, ...tools }), [tools])
93+
}
94+
95+
export default useWeb3

contracts/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import usdc from './usdc'
2+
3+
export default { usdc }

0 commit comments

Comments
 (0)