Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
frontend
Commits
4dcfa6d9
Commit
4dcfa6d9
authored
Nov 06, 2024
by
tom
Committed by
tom goriunov
Nov 08, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
handle reconnecting state of web3wallet
parent
eb7e70be
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
38 additions
and
30 deletions
+38
-30
useWallet.ts
lib/web3/useWallet.ts
+7
-5
UserProfileContentWallet.tsx
ui/snippets/user/profile/UserProfileContentWallet.tsx
+14
-13
UserWalletDesktop.tsx
ui/snippets/user/wallet/UserWalletDesktop.tsx
+1
-0
UserWalletMenuContent.tsx
ui/snippets/user/wallet/UserWalletMenuContent.tsx
+15
-12
UserWalletMobile.tsx
ui/snippets/user/wallet/UserWalletMobile.tsx
+1
-0
No files found.
lib/web3/useWallet.ts
View file @
4dcfa6d9
import
{
useWeb3Modal
,
useWeb3ModalState
}
from
'
@web3modal/wagmi/react
'
;
import
React
from
'
react
'
;
import
{
use
Account
,
use
Disconnect
,
useAccountEffect
}
from
'
wagmi
'
;
import
{
useDisconnect
,
useAccountEffect
}
from
'
wagmi
'
;
import
*
as
mixpanel
from
'
lib/mixpanel/index
'
;
import
useAccount
from
'
lib/web3/useAccount
'
;
interface
Params
{
source
:
mixpanel
.
EventPayload
<
mixpanel
.
EventTypes
.
WALLET_CONNECT
>
[
'
Source
'
];
...
...
@@ -44,16 +45,17 @@ export default function useWeb3Wallet({ source }: Params) {
useAccountEffect
({
onConnect
:
handleAccountConnected
});
const
{
address
,
isDisconnected
}
=
useAccount
();
const
isConnected
=
isClientLoaded
&&
!
isDisconnected
&&
address
!==
undefined
;
const
account
=
useAccount
();
const
address
=
account
.
address
;
const
isConnected
=
isClientLoaded
&&
!
account
.
isDisconnected
&&
account
.
address
!==
undefined
;
return
React
.
useMemo
(()
=>
({
connect
:
handleConnect
,
disconnect
:
handleDisconnect
,
isOpen
:
isOpening
||
isOpen
,
isConnected
,
isReconnecting
:
account
.
isReconnecting
,
address
,
openModal
,
}),
[
handleConnect
,
handleDisconnect
,
isOpen
,
isOpening
,
isConnected
,
address
,
openModal
]);
}),
[
handleConnect
,
handleDisconnect
,
isOpen
ing
,
isOpen
,
isConnected
,
account
.
isReconnecting
,
address
,
openModal
]);
}
ui/snippets/user/profile/UserProfileContentWallet.tsx
View file @
4dcfa6d9
import
{
chakra
,
Box
,
Button
,
Flex
,
IconButton
,
useColorModeValue
}
from
'
@chakra-ui/react
'
;
import
{
chakra
,
Box
,
Button
,
Flex
,
IconButton
,
useColorModeValue
,
Spinner
}
from
'
@chakra-ui/react
'
;
import
React
from
'
react
'
;
import
delay
from
'
lib/delay
'
;
...
...
@@ -34,7 +34,7 @@ const UserProfileContentWallet = ({ onClose, className }: Props) => {
const
content
=
(()
=>
{
if
(
web3Wallet
.
isConnected
&&
web3AccountWithDomain
.
address
)
{
return
(
<
Flex
alignItems=
"center"
columnGap=
{
2
}
bgColor=
{
walletSnippetBgColor
}
px=
{
2
}
py=
"10px"
borderRadius=
"base"
>
<
Flex
alignItems=
"center"
columnGap=
{
2
}
bgColor=
{
walletSnippetBgColor
}
px=
{
2
}
py=
"10px"
borderRadius=
"base"
justifyContent=
"space-between"
>
<
AddressEntity
address=
{
{
hash
:
web3AccountWithDomain
.
address
,
ens_domain_name
:
web3AccountWithDomain
.
domain
}
}
isLoading=
{
web3AccountWithDomain
.
isLoading
}
...
...
@@ -44,17 +44,18 @@ const UserProfileContentWallet = ({ onClose, className }: Props) => {
fontWeight=
{
500
}
noAltHash
/>
<
IconButton
aria
-
label=
"Open wallet"
icon=
{
<
IconSvg
name=
"gear_slim"
boxSize=
{
5
}
/>
}
variant=
"simple"
color=
"icon_info"
boxSize=
{
5
}
onClick=
{
handleOpenWalletClick
}
isLoading=
{
web3Wallet
.
isOpen
}
flexShrink=
{
0
}
ml=
"auto"
/>
{
web3Wallet
.
isReconnecting
?
<
Spinner
size=
"sm"
m=
"2px"
flexShrink=
{
0
}
/>
:
(
<
IconButton
aria
-
label=
"Open wallet"
icon=
{
<
IconSvg
name=
"gear_slim"
boxSize=
{
5
}
/>
}
variant=
"simple"
color=
"icon_info"
boxSize=
{
5
}
onClick=
{
handleOpenWalletClick
}
isLoading=
{
web3Wallet
.
isOpen
}
flexShrink=
{
0
}
/>
)
}
</
Flex
>
);
}
...
...
ui/snippets/user/wallet/UserWalletDesktop.tsx
View file @
4dcfa6d9
...
...
@@ -55,6 +55,7 @@ const UserWalletDesktop = ({ buttonSize, buttonVariant = 'header' }: Props) => {
address=
{
web3AccountWithDomain
.
address
}
domain=
{
web3AccountWithDomain
.
domain
}
isAutoConnectDisabled=
{
isAutoConnectDisabled
}
isReconnecting=
{
web3Wallet
.
isReconnecting
}
onOpenWallet=
{
handleOpenWalletClick
}
onDisconnect=
{
handleDisconnectClick
}
/>
...
...
ui/snippets/user/wallet/UserWalletMenuContent.tsx
View file @
4dcfa6d9
import
{
Box
,
Button
,
Flex
,
IconButton
,
Text
}
from
'
@chakra-ui/react
'
;
import
{
Box
,
Button
,
Flex
,
IconButton
,
Spinner
,
Text
}
from
'
@chakra-ui/react
'
;
import
React
from
'
react
'
;
import
delay
from
'
lib/delay
'
;
...
...
@@ -11,11 +11,12 @@ interface Props {
address
:
string
;
domain
?:
string
;
isAutoConnectDisabled
?:
boolean
;
isReconnecting
?:
boolean
;
onDisconnect
:
()
=>
void
;
onOpenWallet
:
()
=>
void
;
}
const
UserWalletMenuContent
=
({
isAutoConnectDisabled
,
address
,
domain
,
onDisconnect
,
onOpenWallet
}:
Props
)
=>
{
const
UserWalletMenuContent
=
({
isAutoConnectDisabled
,
address
,
domain
,
isReconnecting
,
onDisconnect
,
onOpenWallet
}:
Props
)
=>
{
const
handleOpenWalletClick
=
React
.
useCallback
(
async
()
=>
{
await
delay
(
100
);
...
...
@@ -29,7 +30,7 @@ const UserWalletMenuContent = ({ isAutoConnectDisabled, address, domain, onDisco
<
Text
fontSize=
"sm"
mb=
{
5
}
fontWeight=
{
400
}
color=
"text_secondary"
>
Your wallet is used to interact with apps and contracts in the explorer.
</
Text
>
<
Flex
alignItems=
"center"
columnGap=
{
2
}
>
<
Flex
alignItems=
"center"
columnGap=
{
2
}
justifyContent=
"space-between"
>
<
AddressEntity
address=
{
{
hash
:
address
,
ens_domain_name
:
domain
}
}
isTooltipDisabled
...
...
@@ -37,15 +38,17 @@ const UserWalletMenuContent = ({ isAutoConnectDisabled, address, domain, onDisco
fontSize=
"sm"
fontWeight=
{
700
}
/>
<
IconButton
aria
-
label=
"Open wallet"
icon=
{
<
IconSvg
name=
"gear_slim"
boxSize=
{
5
}
/>
}
variant=
"simple"
color=
"icon_info"
boxSize=
{
5
}
onClick=
{
handleOpenWalletClick
}
flexShrink=
{
0
}
/>
{
isReconnecting
?
<
Spinner
size=
"sm"
m=
"2px"
flexShrink=
{
0
}
/>
:
(
<
IconButton
aria
-
label=
"Open wallet"
icon=
{
<
IconSvg
name=
"gear_slim"
boxSize=
{
5
}
/>
}
variant=
"simple"
color=
"icon_info"
boxSize=
{
5
}
onClick=
{
handleOpenWalletClick
}
flexShrink=
{
0
}
/>
)
}
</
Flex
>
<
Button
size=
"sm"
width=
"full"
variant=
"outline"
onClick=
{
onDisconnect
}
mt=
{
6
}
>
Disconnect
...
...
ui/snippets/user/wallet/UserWalletMobile.tsx
View file @
4dcfa6d9
...
...
@@ -52,6 +52,7 @@ const UserWalletMobile = () => {
address=
{
web3AccountWithDomain
.
address
}
domain=
{
web3AccountWithDomain
.
domain
}
isAutoConnectDisabled=
{
isAutoConnectDisabled
}
isReconnecting=
{
web3Wallet
.
isReconnecting
}
onOpenWallet=
{
handleOpenWalletClick
}
onDisconnect=
{
handleDisconnectClick
}
/>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment