-
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
19 changed files
with
5,976 additions
and
252 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 @@ | ||
INFURA=XXXXXXXX |
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 |
---|---|---|
|
@@ -32,3 +32,6 @@ yarn-error.log* | |
|
||
# vercel | ||
.vercel | ||
|
||
# DotEnv | ||
.env |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import styled from 'styled-components' | ||
|
||
export const Column = styled.div` | ||
display: flex; | ||
flex-direction: column; | ||
width: ${({ w }) => w}; | ||
height: ${({ h }) => h}; | ||
padding: ${({ p }) => p}; | ||
margin: ${({ m }) => m}; | ||
align-items: ${({ ai }) => ai}; | ||
justify-content: ${({ jc }) => jc}; | ||
flex-grow: ${({ fg }) => fg}; | ||
` | ||
export const Row = styled.div` | ||
width: ${({ w }) => (w ? w : '100%')}; | ||
height: ${({ h }) => h}; | ||
display: flex; | ||
flex-direction: row; | ||
padding: ${({ p }) => p}; | ||
margin: ${({ m }) => m}; | ||
justify-content: ${({ jc }) => jc}; | ||
align-items: ${({ ai }) => ai}; | ||
flex-grow: ${({ fg }) => fg}; | ||
` |
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,95 @@ | ||
import React, { | ||
createContext, | ||
useState, | ||
useContext, | ||
useMemo, | ||
useEffect, | ||
useCallback, | ||
} from 'react' | ||
|
||
import { useWallet } from 'use-wallet' | ||
import { web3, registerProvider } from '../utils/ethers' | ||
|
||
import useLocalStorage from '../hooks/useLocalStorage' | ||
const atob = (a) => Buffer.from(a, 'base64').toString('binary') | ||
|
||
// Create Context | ||
export const UseWeb3Context = createContext() | ||
|
||
export const Web3Provider = (props) => { | ||
const { account, connect, status, ethereum, reset } = useWallet() | ||
|
||
// Remember provider preference | ||
const [provider, setProvider] = useLocalStorage('provider', false) | ||
|
||
// Connect/Disconnect Wallet | ||
const connectWallet = async (key) => { | ||
await connect(key) | ||
setProvider(key) | ||
registerProvider(ethereum) | ||
} | ||
const disconnectWallet = () => { | ||
reset() | ||
setProvider(false) | ||
} | ||
|
||
// Check to see if we've set a provider in local Storage and connect | ||
const initProvider = () => { | ||
if (provider) { | ||
console.log('Provider Found:', provider) | ||
connect(provider) | ||
registerProvider(ethereum) | ||
} | ||
} | ||
|
||
// Once we've connected a wallet, switch to wallet provider | ||
useEffect(() => { | ||
if (status === 'connected') { | ||
console.log('Connected!') | ||
registerProvider(ethereum) | ||
} | ||
}, [status]) | ||
|
||
// Once loaded, initalise the provider | ||
useEffect(() => { | ||
initProvider() | ||
}, [provider]) | ||
|
||
const tools = useMemo( | ||
() => ({ | ||
provider, | ||
setProvider, | ||
connectWallet, | ||
disconnectWallet, | ||
account, | ||
status, | ||
}), | ||
[provider, account, status] | ||
) | ||
|
||
// pass the value in provider and return | ||
return ( | ||
<UseWeb3Context.Provider | ||
value={{ | ||
tools, | ||
}} | ||
> | ||
{props.children} | ||
</UseWeb3Context.Provider> | ||
) | ||
} | ||
|
||
export function useWeb3() { | ||
const web3Context = useContext(UseWeb3Context) | ||
if (web3Context === null) { | ||
throw new Error( | ||
'useWeb3() can only be used inside of <UseToolsProvider />, ' + | ||
'please declare it at a higher level.' | ||
) | ||
} | ||
const { tools } = web3Context | ||
|
||
return useMemo(() => ({ web3, ...tools }), [tools]) | ||
} | ||
|
||
export default useWeb3 |
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,3 @@ | ||
import usdc from './usdc' | ||
|
||
export default { usdc } |
Oops, something went wrong.