1
1
import "../styles/globals.css"
2
2
import "../styles/markdown.css"
3
3
import Head from "next/head"
4
- import { ethers , providers } from "ethers"
5
- import { Menu , Transition } from "@headlessui/react"
6
- import { Fragment , useCallback , useMemo , useReducer , useState } from "react"
7
- import { ChevronDownIcon } from "@heroicons/react/solid"
8
- import { Navigation } from "../components/Navigation" ;
4
+ import { ethers , providers } from "ethers"
5
+ import { Menu , Transition } from "@headlessui/react"
6
+ import { Fragment , useCallback , useMemo , useReducer , useState } from "react"
7
+ import { ChevronDownIcon } from "@heroicons/react/solid"
8
+ import { Navigation } from "../components/Navigation"
9
9
import {
10
10
DOMAIN ,
11
11
signInfo ,
12
12
STORAGE_KEY_ACCOUNT ,
13
13
STORAGE_KEY_ACCOUNT_SIG ,
14
14
SUPPORT_NETWORKS
15
- } from "../constants" ;
16
- import { useAsync , useLocalStorageValue , useMountEffect } from "@react-hookz/web" ;
17
- import { initialWeb3State , Web3Context , web3Reducer } from "../context/web3Context" ;
18
- import { createProvider , switchNetwork } from "../web3" ;
19
- import { getBrief } from "../web3/utils" ;
15
+ } from "../constants"
16
+ import { useAsync , useLocalStorageValue , useMountEffect } from "@react-hookz/web"
17
+ import { initialWeb3State , Web3Context , web3Reducer } from "../context/web3Context"
18
+ import { createProvider , switchNetwork } from "../web3"
19
+ import { getBrief } from "../web3/utils"
20
20
import axios from "axios"
21
21
import { FrontendVersion } from "../version.js"
22
22
23
23
24
- function App ( { Component, pageProps} ) {
24
+ function App ( { Component, pageProps } ) {
25
25
const [ accountInLocal , setLocalAccount , removeLocalAccount ] = useLocalStorageValue < string > ( STORAGE_KEY_ACCOUNT )
26
26
const [ sigInLocal , setLocalSig , removeLocalSig ] = useLocalStorageValue ( STORAGE_KEY_ACCOUNT_SIG )
27
- const [ state , dispatch ] = useReducer ( web3Reducer , { ...initialWeb3State , account : accountInLocal } ) ;
28
- const { account, provider, chainId} = state
27
+ const [ state , dispatch ] = useReducer ( web3Reducer , { ...initialWeb3State , account : accountInLocal } )
28
+ const { account, provider, chainId } = state
29
29
const isSupportCurrentNetwork = SUPPORT_NETWORKS . includes ( chainId )
30
30
const [ backendVersion , setBackendVersion ] = useState ( "err" )
31
31
32
- const [ , actions ] = useAsync ( async ( ) => {
32
+ const [ , actions ] = useAsync ( async ( ) => {
33
33
if ( ! sigInLocal || ! accountInLocal ) return
34
- const cachedProvider = await createProvider ( undefined , ( id ) => dispatch ( { type : "SET_CHAIN_ID" , chainId : id } ) )
34
+ const cachedProvider = await createProvider ( undefined , ( id ) => dispatch ( { type : "SET_CHAIN_ID" , chainId : id } ) )
35
35
if ( ! cachedProvider ) return
36
- dispatch ( { type : 'SET_WEB3_PROVIDER' , provider : cachedProvider } )
36
+ dispatch ( { type : 'SET_WEB3_PROVIDER' , provider : cachedProvider } )
37
37
const web3Provider = new providers . Web3Provider ( cachedProvider )
38
38
const signer = web3Provider . getSigner ( )
39
39
const address = await signer . getAddress ( )
@@ -64,16 +64,16 @@ function App({Component, pageProps}) {
64
64
}
65
65
66
66
const web3ContextValue = useMemo ( ( ) => {
67
- return { state, dispatch} ;
68
- } , [ state , dispatch ] ) ;
67
+ return { state, dispatch }
68
+ } , [ state , dispatch ] )
69
69
70
- const connectWallet = useCallback ( async function ( ) {
71
- const provider = await createProvider ( undefined , ( id ) => dispatch ( { type : "SET_CHAIN_ID" , chainId : id } ) )
70
+ const connectWallet = useCallback ( async function ( ) {
71
+ const provider = await createProvider ( undefined , ( id ) => dispatch ( { type : "SET_CHAIN_ID" , chainId : id } ) )
72
72
if ( provider . chainId !== '0x13881' ) {
73
73
await switchNetwork ( provider )
74
74
}
75
75
if ( ! provider ) return
76
- dispatch ( { type : 'SET_WEB3_PROVIDER' , provider} )
76
+ dispatch ( { type : 'SET_WEB3_PROVIDER' , provider } )
77
77
78
78
const web3Provider = new providers . Web3Provider ( provider )
79
79
const signer = web3Provider . getSigner ( )
@@ -103,7 +103,7 @@ function App({Component, pageProps}) {
103
103
} )
104
104
} , [ ] )
105
105
106
- const disconnectWallet = async ( ) => {
106
+ const disconnectWallet = async ( ) => {
107
107
dispatch ( {
108
108
type : 'SET_WEB3_PROVIDER' ,
109
109
provider : undefined ,
@@ -160,7 +160,7 @@ function App({Component, pageProps}) {
160
160
</ div >
161
161
162
162
< div
163
- style = { { display : account && isSupportCurrentNetwork ? "block" : "none" } }
163
+ style = { { display : account && isSupportCurrentNetwork ? "block" : "none" } }
164
164
className = "absolute top-8 right-8 text-right fixed "
165
165
>
166
166
< Menu as = "div" className = "relative inline-block text-left" >
@@ -186,7 +186,7 @@ function App({Component, pageProps}) {
186
186
className = "absolute right-0 w-56 mt-2 origin-top-right bg-white divide-y divide-gray-100 rounded-md shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none" >
187
187
< div className = "px-1 py-1" >
188
188
< Menu . Item >
189
- { ( { active} ) => (
189
+ { ( { active } ) => (
190
190
< button
191
191
className = { `${
192
192
active ? "bg-blue-500 text-gray-300" : "text-gray-900"
@@ -198,7 +198,7 @@ function App({Component, pageProps}) {
198
198
</ Menu . Item >
199
199
200
200
< Menu . Item >
201
- { ( { active} ) => (
201
+ { ( { active } ) => (
202
202
< button
203
203
onClick = { disconnectWallet }
204
204
className = { `${
0 commit comments