@@ -16,8 +16,11 @@ import {
16
16
lightTheme ,
17
17
RainbowKitProvider ,
18
18
} from "@rainbow-me/rainbowkit" ;
19
- import { useConnect , useAddresses } from "iso-filecoin-react"
19
+ import { useConnect as FilUseConnect , useAddresses } from "iso-filecoin-react"
20
20
import { ConfigProvider , FloatButton , theme } from 'antd' ;
21
+ import {
22
+ useAccount as FilAccount
23
+ } from 'iso-filecoin-react'
21
24
import dayjs from 'dayjs' ;
22
25
import 'dayjs/locale/zh-cn' ;
23
26
import enUS from 'antd/locale/en_US' ;
@@ -26,7 +29,7 @@ import { useTranslation } from 'react-i18next';
26
29
import { useEffect , useRef } from "react" ;
27
30
import { useLocation , useRoutes } from "react-router-dom" ;
28
31
import "tailwindcss/tailwind.css" ;
29
- import { useAccount } from "wagmi" ;
32
+ import { useAccount , useConnect } from "wagmi" ;
30
33
import timezones from './json/timezons.json' ;
31
34
import { calibrationChainId , getFipListApi } from "./common/consts"
32
35
import { useVoterInfoSet } from "./common/hooks"
@@ -45,19 +48,31 @@ dayjs.locale(lang === 'en' ? lang : "zh-cn")
45
48
const App : React . FC = ( ) => {
46
49
// Destructure values from custom hooks
47
50
const { chain, address, isConnected } = useAccount ( ) ;
51
+ const { adapter, state} = FilAccount ( ) ;
52
+ const { connect, connectors } = useConnect ( )
48
53
const { address0x} = useAddresses ( { address : address as string } ) ;
49
-
50
- const { adapters, mutate : connect } = useConnect ( ) ;
54
+ const { mutate : FilConnect , adapters } = FilUseConnect ( ) ;
51
55
const chainId = chain ?. id || calibrationChainId ;
52
56
const prevAddressRef = useRef ( address ) ;
53
57
const setFipList = useFipList ( ( state : any ) => state . setFipList )
54
58
const { i18n } = useTranslation ( ) ;
55
59
60
+ useEffect ( ( ) => {
61
+ if ( state == "connected" ) {
62
+ connect ( { connector :connectors [ 0 ] } )
63
+ }
64
+ } , [ state ] )
65
+
56
66
useEffect ( ( ) => {
57
- if ( isConnected && address ! . indexOf ( "0x" ) < 0 ) {
58
- connect ( { adapter : adapters [ 0 ] } ) ;
67
+ const adapterId = window . localStorage . getItem ( 'adapter' ) ;
68
+ if ( isConnected ) {
69
+ if ( adapter ) {
70
+ FilConnect ( { adapter : adapter } ) ;
71
+ } else {
72
+ FilConnect ( { adapter : adapters . find ( item => item . id === adapterId ) || adapters [ 0 ] } ) ;
73
+ }
59
74
}
60
- } , [ isConnected , address ] )
75
+ } , [ isConnected , adapter ] )
61
76
62
77
// Render routes based on URL
63
78
const element = useRoutes ( routes ) ;
@@ -140,34 +155,34 @@ const App: React.FC = () => {
140
155
const lang = localStorage . getItem ( "lang" ) || "en" ;
141
156
142
157
return (
143
- < RainbowKitProvider
144
- locale = { lang === "en" ? "en-US" : "zh-CN" }
145
- theme = { lightTheme ( {
146
- accentColor : "#7b3fe4" ,
147
- accentColorForeground : "white" ,
148
- } ) }
149
- modalSize = "compact"
150
- >
151
- < ConfigProvider theme = { {
152
- algorithm : theme . defaultAlgorithm ,
153
- components : {
154
- Radio : {
155
- buttonSolidCheckedBg : ''
156
- }
157
- }
158
- } } locale = { lang === "en" ? enUS : zhCN } >
159
- < div className = "layout font-body" >
160
- { ! isLanding && < Header changeLang = { handleChange } /> }
161
- < div className = 'content w-[1000px] mx-auto pt-10 pb-10' >
162
- {
163
- element
158
+ < RainbowKitProvider
159
+ locale = { lang === "en" ? "en-US" : "zh-CN" }
160
+ theme = { lightTheme ( {
161
+ accentColor : "#7b3fe4" ,
162
+ accentColorForeground : "white" ,
163
+ } ) }
164
+ modalSize = "compact"
165
+ >
166
+ < ConfigProvider theme = { {
167
+ algorithm : theme . defaultAlgorithm ,
168
+ components : {
169
+ Radio : {
170
+ buttonSolidCheckedBg : ''
164
171
}
172
+ }
173
+ } } locale = { lang === "en" ? enUS : zhCN } >
174
+ < div className = "layout font-body" >
175
+ { ! isLanding && < Header changeLang = { handleChange } /> }
176
+ < div className = 'content w-[1000px] mx-auto pt-10 pb-10' >
177
+ {
178
+ element
179
+ }
180
+ </ div >
181
+ < Footer />
182
+ < FloatButton . BackTop style = { { bottom : 100 } } />
165
183
</ div >
166
- < Footer />
167
- < FloatButton . BackTop style = { { bottom : 100 } } />
168
- </ div >
169
- </ ConfigProvider >
170
- </ RainbowKitProvider >
184
+ </ ConfigProvider >
185
+ </ RainbowKitProvider >
171
186
)
172
187
}
173
188
0 commit comments