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
1 parent
1da22b2
commit a90b0b1
Showing
7 changed files
with
89 additions
and
97 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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
import { Modal } from 'antd'; | ||
import React from 'react'; | ||
|
||
|
||
import './styles.css'; | ||
|
||
export interface ModalProps { | ||
|
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
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,7 +1,6 @@ | ||
import { useContext } from "react"; | ||
import { MASA_CONTEXT } from "./masa-context"; | ||
import { useContext } from 'react'; | ||
import { MASA_CONTEXT } from './masa-context'; | ||
|
||
export const useMasa = () => { | ||
return useContext(MASA_CONTEXT); | ||
}; | ||
|
||
return useContext(MASA_CONTEXT); | ||
}; |
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,66 +1,66 @@ | ||
import { ethers } from "ethers"; | ||
import { useCallback, useEffect } from "react"; | ||
import { useMasa } from "./use-masa"; | ||
import { ethers } from 'ethers'; | ||
import { useCallback, useEffect } from 'react'; | ||
import { useMasa } from './use-masa'; | ||
|
||
//@ts-ignore | ||
const provider = new ethers.providers.Web3Provider(window?.ethereum); | ||
|
||
export const useMetamask = () => { | ||
const { setProvider, masa } = useMasa(); | ||
|
||
useEffect(() => { | ||
const connectWalletOnPageLoad = async () => { | ||
if (localStorage?.getItem('isWalletConnected') === 'true') { | ||
try { | ||
connect(); | ||
} catch (ex) { | ||
console.log(ex); | ||
} | ||
const { setProvider, masa } = useMasa(); | ||
|
||
useEffect(() => { | ||
const connectWalletOnPageLoad = async () => { | ||
if (localStorage?.getItem('isWalletConnected') === 'true') { | ||
try { | ||
connect(); | ||
} catch (ex) { | ||
console.log(ex); | ||
} | ||
}; | ||
connectWalletOnPageLoad(); | ||
}, []); | ||
|
||
const onConnect = () => { | ||
localStorage.setItem('isWalletConnected', 'true'); | ||
} | ||
}; | ||
|
||
const handleLogout = useCallback(async () => { | ||
await masa?.session.logout(); | ||
}, [masa]); | ||
|
||
const disconnect = useCallback(async () => { | ||
await handleLogout(); | ||
localStorage.setItem('isWalletConnected', 'false'); | ||
setProvider?.(null); | ||
}, [masa]); | ||
|
||
useEffect(() => { | ||
//@ts-ignore | ||
window?.ethereum?.on('accountsChanged', async function (accounts) { | ||
if (accounts.length === 0) { | ||
await handleLogout(); | ||
disconnect(); | ||
connectWalletOnPageLoad(); | ||
}, []); | ||
|
||
const onConnect = () => { | ||
localStorage.setItem('isWalletConnected', 'true'); | ||
}; | ||
|
||
const handleLogout = useCallback(async () => { | ||
await masa?.session.logout(); | ||
}, [masa]); | ||
|
||
const disconnect = useCallback(async () => { | ||
await handleLogout(); | ||
localStorage.setItem('isWalletConnected', 'false'); | ||
setProvider?.(null); | ||
}, [masa]); | ||
|
||
useEffect(() => { | ||
//@ts-ignore | ||
window?.ethereum?.on('accountsChanged', async function (accounts) { | ||
if (accounts.length === 0) { | ||
await handleLogout(); | ||
disconnect(); | ||
} | ||
}); | ||
}, []); | ||
|
||
const connect = () => { | ||
//@ts-ignore | ||
if (window.ethereum) { | ||
provider.send('eth_requestAccounts', []).then(async () => { | ||
console.log('ETH ACCOUNT'); | ||
await accountChangedHandler(provider.getSigner(0)); | ||
if (provider && setProvider) { | ||
setProvider(provider.getSigner(0)); | ||
onConnect(); | ||
} | ||
}); | ||
}, []); | ||
|
||
const connect = () => { | ||
//@ts-ignore | ||
if (window.ethereum) { | ||
provider.send('eth_requestAccounts', []).then(async () => { | ||
console.log('ETH ACCOUNT'); | ||
await accountChangedHandler(provider.getSigner(0)); | ||
if (provider && setProvider) { | ||
setProvider(provider.getSigner(0)); | ||
onConnect(); | ||
} | ||
}); | ||
} | ||
}; | ||
const accountChangedHandler = async (newAccount) => { | ||
if (setProvider) setProvider(newAccount); | ||
}; | ||
|
||
return { connect }; | ||
}; | ||
} | ||
}; | ||
const accountChangedHandler = async (newAccount) => { | ||
if (setProvider) setProvider(newAccount); | ||
}; | ||
|
||
return { connect }; | ||
}; |
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,27 +1,27 @@ | ||
module.exports = { | ||
white: '#FFF', | ||
black: '#000', | ||
skeleton: '#DEDEDE', | ||
gray: '#8692A6', | ||
gray2: '#F5F5F5', | ||
gray3: '#BDBDBD', | ||
gray4: '#696F79', | ||
gray5: '#EFEFEF', | ||
gray6: '#C7C7C7', | ||
gray7: '#918e8e', | ||
gray8: '#292929', | ||
linkYellow: '#FFC01F', | ||
blue: 'rgba(50, 130, 246, 0.8)', | ||
// intent colors | ||
default: '#8692A6', | ||
primary: '#3282f6', | ||
success: '#44C73B', | ||
warning: '#C79C3B', | ||
danger: '#BC2D00', | ||
// charts | ||
chartGreen: '#219653', | ||
chartViolet: '#9B51E0', | ||
white: '#FFF', | ||
black: '#000', | ||
skeleton: '#DEDEDE', | ||
gray: '#8692A6', | ||
gray2: '#F5F5F5', | ||
gray3: '#BDBDBD', | ||
gray4: '#696F79', | ||
gray5: '#EFEFEF', | ||
gray6: '#C7C7C7', | ||
gray7: '#918e8e', | ||
gray8: '#292929', | ||
linkYellow: '#FFC01F', | ||
blue: 'rgba(50, 130, 246, 0.8)', | ||
// intent colors | ||
default: '#8692A6', | ||
primary: '#3282f6', | ||
success: '#44C73B', | ||
warning: '#C79C3B', | ||
danger: '#BC2D00', | ||
// charts | ||
chartGreen: '#219653', | ||
chartViolet: '#9B51E0', | ||
|
||
// overlay | ||
whiteOverlay: 'rgba(255,255,255,0.1)', | ||
} | ||
// overlay | ||
whiteOverlay: 'rgba(255,255,255,0.1)', | ||
}; |
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