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
Show 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
{
useWeb3Modal
,
useWeb3ModalState
}
from
'
@web3modal/wagmi/react
'
;
import
React
from
'
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
*
as
mixpanel
from
'
lib/mixpanel/index
'
;
import
useAccount
from
'
lib/web3/useAccount
'
;
interface
Params
{
interface
Params
{
source
:
mixpanel
.
EventPayload
<
mixpanel
.
EventTypes
.
WALLET_CONNECT
>
[
'
Source
'
];
source
:
mixpanel
.
EventPayload
<
mixpanel
.
EventTypes
.
WALLET_CONNECT
>
[
'
Source
'
];
...
@@ -44,16 +45,17 @@ export default function useWeb3Wallet({ source }: Params) {
...
@@ -44,16 +45,17 @@ export default function useWeb3Wallet({ source }: Params) {
useAccountEffect
({
onConnect
:
handleAccountConnected
});
useAccountEffect
({
onConnect
:
handleAccountConnected
});
const
{
address
,
isDisconnected
}
=
useAccount
();
const
account
=
useAccount
();
const
address
=
account
.
address
;
const
isConnected
=
isClientLoaded
&&
!
isDisconnected
&&
address
!==
undefined
;
const
isConnected
=
isClientLoaded
&&
!
account
.
isDisconnected
&&
account
.
address
!==
undefined
;
return
React
.
useMemo
(()
=>
({
return
React
.
useMemo
(()
=>
({
connect
:
handleConnect
,
connect
:
handleConnect
,
disconnect
:
handleDisconnect
,
disconnect
:
handleDisconnect
,
isOpen
:
isOpening
||
isOpen
,
isOpen
:
isOpening
||
isOpen
,
isConnected
,
isConnected
,
isReconnecting
:
account
.
isReconnecting
,
address
,
address
,
openModal
,
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
React
from
'
react
'
;
import
delay
from
'
lib/delay
'
;
import
delay
from
'
lib/delay
'
;
...
@@ -34,7 +34,7 @@ const UserProfileContentWallet = ({ onClose, className }: Props) => {
...
@@ -34,7 +34,7 @@ const UserProfileContentWallet = ({ onClose, className }: Props) => {
const
content
=
(()
=>
{
const
content
=
(()
=>
{
if
(
web3Wallet
.
isConnected
&&
web3AccountWithDomain
.
address
)
{
if
(
web3Wallet
.
isConnected
&&
web3AccountWithDomain
.
address
)
{
return
(
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
<
AddressEntity
address=
{
{
hash
:
web3AccountWithDomain
.
address
,
ens_domain_name
:
web3AccountWithDomain
.
domain
}
}
address=
{
{
hash
:
web3AccountWithDomain
.
address
,
ens_domain_name
:
web3AccountWithDomain
.
domain
}
}
isLoading=
{
web3AccountWithDomain
.
isLoading
}
isLoading=
{
web3AccountWithDomain
.
isLoading
}
...
@@ -44,6 +44,7 @@ const UserProfileContentWallet = ({ onClose, className }: Props) => {
...
@@ -44,6 +44,7 @@ const UserProfileContentWallet = ({ onClose, className }: Props) => {
fontWeight=
{
500
}
fontWeight=
{
500
}
noAltHash
noAltHash
/>
/>
{
web3Wallet
.
isReconnecting
?
<
Spinner
size=
"sm"
m=
"2px"
flexShrink=
{
0
}
/>
:
(
<
IconButton
<
IconButton
aria
-
label=
"Open wallet"
aria
-
label=
"Open wallet"
icon=
{
<
IconSvg
name=
"gear_slim"
boxSize=
{
5
}
/>
}
icon=
{
<
IconSvg
name=
"gear_slim"
boxSize=
{
5
}
/>
}
...
@@ -53,8 +54,8 @@ const UserProfileContentWallet = ({ onClose, className }: Props) => {
...
@@ -53,8 +54,8 @@ const UserProfileContentWallet = ({ onClose, className }: Props) => {
onClick=
{
handleOpenWalletClick
}
onClick=
{
handleOpenWalletClick
}
isLoading=
{
web3Wallet
.
isOpen
}
isLoading=
{
web3Wallet
.
isOpen
}
flexShrink=
{
0
}
flexShrink=
{
0
}
ml=
"auto"
/>
/>
)
}
</
Flex
>
</
Flex
>
);
);
}
}
...
...
ui/snippets/user/wallet/UserWalletDesktop.tsx
View file @
4dcfa6d9
...
@@ -55,6 +55,7 @@ const UserWalletDesktop = ({ buttonSize, buttonVariant = 'header' }: Props) => {
...
@@ -55,6 +55,7 @@ const UserWalletDesktop = ({ buttonSize, buttonVariant = 'header' }: Props) => {
address=
{
web3AccountWithDomain
.
address
}
address=
{
web3AccountWithDomain
.
address
}
domain=
{
web3AccountWithDomain
.
domain
}
domain=
{
web3AccountWithDomain
.
domain
}
isAutoConnectDisabled=
{
isAutoConnectDisabled
}
isAutoConnectDisabled=
{
isAutoConnectDisabled
}
isReconnecting=
{
web3Wallet
.
isReconnecting
}
onOpenWallet=
{
handleOpenWalletClick
}
onOpenWallet=
{
handleOpenWalletClick
}
onDisconnect=
{
handleDisconnectClick
}
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
React
from
'
react
'
;
import
delay
from
'
lib/delay
'
;
import
delay
from
'
lib/delay
'
;
...
@@ -11,11 +11,12 @@ interface Props {
...
@@ -11,11 +11,12 @@ interface Props {
address
:
string
;
address
:
string
;
domain
?:
string
;
domain
?:
string
;
isAutoConnectDisabled
?:
boolean
;
isAutoConnectDisabled
?:
boolean
;
isReconnecting
?:
boolean
;
onDisconnect
:
()
=>
void
;
onDisconnect
:
()
=>
void
;
onOpenWallet
:
()
=>
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
()
=>
{
const
handleOpenWalletClick
=
React
.
useCallback
(
async
()
=>
{
await
delay
(
100
);
await
delay
(
100
);
...
@@ -29,7 +30,7 @@ const UserWalletMenuContent = ({ isAutoConnectDisabled, address, domain, onDisco
...
@@ -29,7 +30,7 @@ const UserWalletMenuContent = ({ isAutoConnectDisabled, address, domain, onDisco
<
Text
fontSize=
"sm"
mb=
{
5
}
fontWeight=
{
400
}
color=
"text_secondary"
>
<
Text
fontSize=
"sm"
mb=
{
5
}
fontWeight=
{
400
}
color=
"text_secondary"
>
Your wallet is used to interact with apps and contracts in the explorer.
Your wallet is used to interact with apps and contracts in the explorer.
</
Text
>
</
Text
>
<
Flex
alignItems=
"center"
columnGap=
{
2
}
>
<
Flex
alignItems=
"center"
columnGap=
{
2
}
justifyContent=
"space-between"
>
<
AddressEntity
<
AddressEntity
address=
{
{
hash
:
address
,
ens_domain_name
:
domain
}
}
address=
{
{
hash
:
address
,
ens_domain_name
:
domain
}
}
isTooltipDisabled
isTooltipDisabled
...
@@ -37,6 +38,7 @@ const UserWalletMenuContent = ({ isAutoConnectDisabled, address, domain, onDisco
...
@@ -37,6 +38,7 @@ const UserWalletMenuContent = ({ isAutoConnectDisabled, address, domain, onDisco
fontSize=
"sm"
fontSize=
"sm"
fontWeight=
{
700
}
fontWeight=
{
700
}
/>
/>
{
isReconnecting
?
<
Spinner
size=
"sm"
m=
"2px"
flexShrink=
{
0
}
/>
:
(
<
IconButton
<
IconButton
aria
-
label=
"Open wallet"
aria
-
label=
"Open wallet"
icon=
{
<
IconSvg
name=
"gear_slim"
boxSize=
{
5
}
/>
}
icon=
{
<
IconSvg
name=
"gear_slim"
boxSize=
{
5
}
/>
}
...
@@ -46,6 +48,7 @@ const UserWalletMenuContent = ({ isAutoConnectDisabled, address, domain, onDisco
...
@@ -46,6 +48,7 @@ const UserWalletMenuContent = ({ isAutoConnectDisabled, address, domain, onDisco
onClick=
{
handleOpenWalletClick
}
onClick=
{
handleOpenWalletClick
}
flexShrink=
{
0
}
flexShrink=
{
0
}
/>
/>
)
}
</
Flex
>
</
Flex
>
<
Button
size=
"sm"
width=
"full"
variant=
"outline"
onClick=
{
onDisconnect
}
mt=
{
6
}
>
<
Button
size=
"sm"
width=
"full"
variant=
"outline"
onClick=
{
onDisconnect
}
mt=
{
6
}
>
Disconnect
Disconnect
...
...
ui/snippets/user/wallet/UserWalletMobile.tsx
View file @
4dcfa6d9
...
@@ -52,6 +52,7 @@ const UserWalletMobile = () => {
...
@@ -52,6 +52,7 @@ const UserWalletMobile = () => {
address=
{
web3AccountWithDomain
.
address
}
address=
{
web3AccountWithDomain
.
address
}
domain=
{
web3AccountWithDomain
.
domain
}
domain=
{
web3AccountWithDomain
.
domain
}
isAutoConnectDisabled=
{
isAutoConnectDisabled
}
isAutoConnectDisabled=
{
isAutoConnectDisabled
}
isReconnecting=
{
web3Wallet
.
isReconnecting
}
onOpenWallet=
{
handleOpenWalletClick
}
onOpenWallet=
{
handleOpenWalletClick
}
onDisconnect=
{
handleDisconnectClick
}
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