Skip to content

Commit 0f41d4a

Browse files
authored
Merge pull request #22 from anwen/fix/relogin-error
fix: show connect wallet and logined same time
2 parents 4b9fc06 + 8a29418 commit 0f41d4a

File tree

1 file changed

+57
-56
lines changed

1 file changed

+57
-56
lines changed

pages/_app.tsx

+57-56
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function App({ Component, pageProps }) {
2929
const isSupportCurrentNetwork = SUPPORT_NETWORKS.includes(chainId)
3030
const [backendVersion, setBackendVersion] = useState("err")
3131

32-
const [, actions] = useAsync(async() => {
32+
const [autoLoginState, actions] = useAsync(async() => {
3333
if (!sigInLocal || !accountInLocal) return
3434
const cachedProvider = await createProvider(undefined, (id) => dispatch({ type: "SET_CHAIN_ID", chainId: id }))
3535
if (!cachedProvider) return
@@ -117,6 +117,7 @@ function App({ Component, pageProps }) {
117117

118118

119119
const renderActionButton = () => {
120+
if (!['success', 'error'].includes(autoLoginState.status)) return null
120121
if (!sigInLocal || !accountInLocal) {
121122
return (
122123
<button
@@ -159,61 +160,61 @@ function App({ Component, pageProps }) {
159160
</div>
160161
</div>
161162

162-
<div
163-
style={{ display: account && isSupportCurrentNetwork ? "block" : "none" }}
164-
className="absolute top-8 right-8 text-right fixed "
165-
>
166-
<Menu as="div" className="relative inline-block text-left">
167-
<div>
168-
<Menu.Button
169-
className="inline-flex justify-center w-full px-2 py-2 font-medium text-white bg-black rounded-md bg-opacity-20 hover:bg-opacity-30 focus:outline-none focus-visible:ring-2 focus-visible:ring-white focus-visible:ring-opacity-75">
170-
<ChevronDownIcon
171-
className="w-5 h-5 text-violet-200 hover:text-violet-100"
172-
aria-hidden="true"
173-
/>
174-
</Menu.Button>
175-
</div>
176-
<Transition
177-
as={Fragment}
178-
enter="transition ease-out duration-100"
179-
enterFrom="transform opacity-0 scale-95"
180-
enterTo="transform opacity-100 scale-100"
181-
leave="transition ease-in duration-75"
182-
leaveFrom="transform opacity-100 scale-100"
183-
leaveTo="transform opacity-0 scale-95"
184-
>
185-
<Menu.Items
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-
<div className="px-1 py-1">
188-
<Menu.Item>
189-
{({ active }) => (
190-
<button
191-
className={`${
192-
active ? "bg-blue-500 text-gray-300" : "text-gray-900"
193-
} group flex rounded-md items-center w-full px-2 py-2 text-sm`}
194-
>
195-
id: {getBrief(account)}
196-
</button>
197-
)}
198-
</Menu.Item>
199-
200-
<Menu.Item>
201-
{({ active }) => (
202-
<button
203-
onClick={disconnectWallet}
204-
className={`${
205-
active ? "bg-blue-500 text-gray-300" : "text-gray-900"
206-
} group flex rounded-md items-center w-full px-2 py-2 text-sm`}
207-
>
208-
Logout
209-
</button>
210-
)}
211-
</Menu.Item>
212-
</div>
213-
</Menu.Items>
214-
</Transition>
215-
</Menu>
216-
</div>
163+
{
164+
sigInLocal && account && isSupportCurrentNetwork &&
165+
<div className="absolute top-8 right-8 text-right fixed">
166+
<Menu as="div" className="relative inline-block text-left">
167+
<div>
168+
<Menu.Button
169+
className="inline-flex justify-center w-full px-2 py-2 font-medium text-white bg-black rounded-md bg-opacity-20 hover:bg-opacity-30 focus:outline-none focus-visible:ring-2 focus-visible:ring-white focus-visible:ring-opacity-75">
170+
<ChevronDownIcon
171+
className="w-5 h-5 text-violet-200 hover:text-violet-100"
172+
aria-hidden="true"
173+
/>
174+
</Menu.Button>
175+
</div>
176+
<Transition
177+
as={Fragment}
178+
enter="transition ease-out duration-100"
179+
enterFrom="transform opacity-0 scale-95"
180+
enterTo="transform opacity-100 scale-100"
181+
leave="transition ease-in duration-75"
182+
leaveFrom="transform opacity-100 scale-100"
183+
leaveTo="transform opacity-0 scale-95"
184+
>
185+
<Menu.Items
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+
<div className="px-1 py-1">
188+
<Menu.Item>
189+
{({ active }) => (
190+
<button
191+
className={`${
192+
active ? "bg-blue-500 text-gray-300" : "text-gray-900"
193+
} group flex rounded-md items-center w-full px-2 py-2 text-sm`}
194+
>
195+
id: {getBrief(account)}
196+
</button>
197+
)}
198+
</Menu.Item>
199+
200+
<Menu.Item>
201+
{({ active }) => (
202+
<button
203+
onClick={disconnectWallet}
204+
className={`${
205+
active ? "bg-blue-500 text-gray-300" : "text-gray-900"
206+
} group flex rounded-md items-center w-full px-2 py-2 text-sm`}
207+
>
208+
Logout
209+
</button>
210+
)}
211+
</Menu.Item>
212+
</div>
213+
</Menu.Items>
214+
</Transition>
215+
</Menu>
216+
</div>
217+
}
217218
</nav>
218219
<Web3Context.Provider value={web3ContextValue}>
219220
<Component {...pageProps} />

0 commit comments

Comments
 (0)