-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
1,359 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import React from 'react' | ||
|
||
const CancelButton = ({ | ||
fill = '#000A28', | ||
width = '16px', | ||
height = '16px', | ||
margin = {}, | ||
handleClick, | ||
}) => ( | ||
<button | ||
onClick={handleClick} | ||
style={{ | ||
border: 'none', | ||
outline: 'none', | ||
...(Object.keys(margin).length && { ...margin }), | ||
}} | ||
className="reset" | ||
> | ||
<svg | ||
style={{ | ||
cursor: 'pointerEvent', | ||
pointerEvents: 'none', | ||
}} | ||
width={width} | ||
height={height} | ||
viewBox="0 0 32 32" | ||
xmlns="http://www.w3.org/2000/svg" | ||
xmlnsXlink="http://www.w3.org/1999/xlink" | ||
> | ||
<path | ||
d="M28.5 9.62L26.38 7.5 18 15.88 9.62 7.5 7.5 9.62 15.88 18 7.5 26.38l2.12 2.12L18 20.12l8.38 8.38 2.12-2.12L20.12 18z" | ||
fill={fill} | ||
/> | ||
</svg> | ||
</button> | ||
) | ||
|
||
export default CancelButton |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { Box, Flex, HStack, Link, Text } from '@chakra-ui/layout' | ||
import React from 'react' | ||
|
||
const links = [ | ||
{ | ||
label: 'Code', | ||
href: '#', | ||
isExternal: true, | ||
}, | ||
{ | ||
label: 'Discord', | ||
href: '#', | ||
isExternal: true, | ||
}, | ||
{ | ||
label: 'FAQ', | ||
href: '#', | ||
isExternal: true, | ||
}, | ||
{ | ||
label: 'Governance', | ||
href: '#', | ||
isExternal: true, | ||
}, | ||
] | ||
|
||
const Footer = () => { | ||
return ( | ||
<Box as="footer"> | ||
<Flex | ||
py={8} | ||
flexDirection={['column', 'column', 'row']} | ||
justifyContent="space-between" | ||
alignItems="center" | ||
as="footer" | ||
> | ||
<Box textAlign={['center', 'center', 'initial']}> | ||
<Text fontWeight="bold" fontSize="md"> | ||
kitchen.sink | ||
</Text> | ||
<Text fontSize="sm" color="gray.500"> | ||
A NextJS Web3 Starter Repo | ||
</Text> | ||
</Box> | ||
<Box> | ||
<HStack spacing={4}> | ||
{links.map(({ href, isExternal, label }) => ( | ||
<Link | ||
py={1} | ||
key={label} | ||
href={href} | ||
fontSize="sm" | ||
isExternal={isExternal} | ||
rel="noopener noreferrer" | ||
_hover={{ | ||
color: 'green.300', | ||
borderBottomColor: 'green.300', | ||
borderBottomWidth: 1, | ||
}} | ||
> | ||
{label} | ||
</Link> | ||
))} | ||
</HStack> | ||
</Box> | ||
</Flex> | ||
</Box> | ||
) | ||
} | ||
|
||
export default Footer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import React from 'react' | ||
import { Image } from '@chakra-ui/image' | ||
import { IconButton } from '@chakra-ui/button' | ||
import { FiSun, FiMoon } from 'react-icons/fi' | ||
import { useColorMode, useColorModeValue } from '@chakra-ui/color-mode' | ||
import { Box, Flex, LinkBox, LinkOverlay } from '@chakra-ui/layout' | ||
|
||
import { useWeb3 } from '../../contexts/useWeb3' | ||
|
||
import UserAddress from './wallet' | ||
|
||
const Header = () => { | ||
const { account, balance } = useWeb3() | ||
const { colorMode, toggleColorMode } = useColorMode() | ||
|
||
const isDarkMode = colorMode === 'dark' | ||
const buttonHoverBgColor = useColorModeValue('gray.100', 'gray.700') | ||
|
||
return ( | ||
<> | ||
<Flex justifyContent="space-between" alignItems="center" py={4}> | ||
{/* Hardcoded 283 for now to center user wallet component */} | ||
<LinkBox width={['auto', 'auto', 283]}> | ||
<LinkOverlay href="/">🏔</LinkOverlay> | ||
</LinkBox> | ||
<Box display={['none', 'none', 'none', 'block']}> | ||
{/* {account && <UserWallet />} */} | ||
</Box> | ||
<Box> | ||
<IconButton | ||
mr={2} | ||
borderRadius="lg" | ||
variant="ghost" | ||
onClick={toggleColorMode} | ||
icon={isDarkMode ? <FiMoon /> : <FiSun />} | ||
aria-label={isDarkMode ? 'Toggle light mode' : 'Toggle dark mode'} | ||
_hover={{ background: buttonHoverBgColor }} | ||
/> | ||
<UserAddress /> | ||
</Box> | ||
</Flex> | ||
</> | ||
) | ||
} | ||
|
||
export default Header |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Box, Flex } from '@chakra-ui/layout' | ||
import Footer from './footer' | ||
import Header from './header' | ||
import React from 'react' | ||
import { useColorModeValue } from '@chakra-ui/color-mode' | ||
|
||
const Layout = ({ children }) => { | ||
const bgColor = useColorModeValue('gray.50', 'gray.800') | ||
|
||
return ( | ||
<Flex | ||
minHeight="100vh" | ||
flexDirection="column" | ||
backgroundColor={bgColor} | ||
px={[4, 4, 12]} | ||
> | ||
<Header /> | ||
<Box flexGrow={1}>{children}</Box> | ||
<Footer /> | ||
</Flex> | ||
) | ||
} | ||
export default Layout |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import React, { useContext } from 'react' | ||
import { Text, Button, Box, useColorModeValue } from '@chakra-ui/react' | ||
import CancelButton from './cancel' | ||
import { useWeb3 } from '../../contexts/useWeb3' | ||
|
||
export default function UserAddress() { | ||
const { | ||
web3, | ||
account, | ||
balance, | ||
status, | ||
disconnectWallet, | ||
connectWallet, | ||
} = useWeb3() | ||
|
||
const buttonBgColor = useColorModeValue('white', 'gray.700') | ||
|
||
return ( | ||
<> | ||
<Button | ||
onClick={() => connectWallet()} | ||
background={buttonBgColor} | ||
variant="muted" | ||
boxShadow="md" | ||
borderRadius="lg" | ||
> | ||
<Text fontSize="sm" color="gray.500" mr={2}> | ||
{account ? `${balance.toFixed(2)} ETH` : 'Connect Wallet'} | ||
</Text> | ||
{account && ( | ||
<> | ||
<Text fontSize="sm" mr={4}> | ||
{account.substring(0, 6) + | ||
'...' + | ||
account.substring(account.length - 4)} | ||
</Text> | ||
</> | ||
)} | ||
<Box | ||
background={account ? 'green.400' : 'gray.400'} | ||
borderRadius="100%" | ||
width={3} | ||
height={3} | ||
/> | ||
{account && ( | ||
<CancelButton | ||
margin={{ marginLeft: '8px' }} | ||
width="14px" | ||
height="14px" | ||
handleClick={() => disconnectWallet()} | ||
/> | ||
)} | ||
</Button> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import usdc from './usdc' | ||
import usdcInfo from './usdc' | ||
|
||
export default { usdc } | ||
export const usdc = usdcInfo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,59 @@ | ||
import { ethers } from 'ethers' | ||
import { web3 } from '../utils/ethers' | ||
import React, { useState, useEffect } from 'react' | ||
import { useWeb3 } from '../contexts/useWeb3' | ||
|
||
const currentBlock = () => { | ||
const currentBalance = (contract, digits) => { | ||
const { account } = useWeb3() | ||
let [block, setBlock] = useState(0) | ||
let [balance, setBalance] = useState(0) | ||
|
||
const erc20 = new ethers.Contract( | ||
contract, | ||
[ | ||
{ | ||
constant: true, | ||
inputs: [ | ||
{ | ||
name: '_owner', | ||
type: 'address', | ||
}, | ||
], | ||
name: 'balanceOf', | ||
outputs: [ | ||
{ | ||
name: 'balance', | ||
type: 'uint256', | ||
}, | ||
], | ||
payable: false, | ||
stateMutability: 'view', | ||
type: 'function', | ||
}, | ||
], | ||
web3 | ||
) | ||
|
||
const fetchBalance = async () => { | ||
const rawNum = await erc20.balanceOf(account) | ||
const normalised = ethers.utils.formatUnits(rawNum, digits || 18) | ||
setBalance(normalised) | ||
} | ||
|
||
useEffect(() => { | ||
if (account) fetchBalance() | ||
}, [account]) | ||
|
||
useEffect(() => { | ||
web3.on('block', (newBlock) => { | ||
if (newBlock > block && newBlock !== block) setBlock(newBlock) | ||
web3.on('block', async (newBlock) => { | ||
if (newBlock > block && newBlock !== block && account) { | ||
fetchBalance() | ||
setBlock(newBlock) | ||
} | ||
}) | ||
}, []) | ||
|
||
return block | ||
return balance | ||
} | ||
|
||
export default currentBlock | ||
export default currentBalance |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.