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
a67f0714
Commit
a67f0714
authored
Oct 18, 2024
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pass api error to the toast while signing in with wallet
parent
d2682889
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
17 deletions
+15
-17
useWallet.ts
lib/web3/useWallet.ts
+2
-2
useSignInWithWallet.ts
ui/snippets/auth/useSignInWithWallet.ts
+13
-15
No files found.
lib/web3/useWallet.ts
View file @
a67f0714
...
...
@@ -48,12 +48,12 @@ export default function useWeb3Wallet({ source }: Params) {
const
isConnected
=
isClientLoaded
&&
!
isDisconnected
&&
address
!==
undefined
;
return
{
return
React
.
useMemo
(()
=>
(
{
connect
:
handleConnect
,
disconnect
:
handleDisconnect
,
isOpen
:
isOpening
||
isOpen
,
isConnected
,
address
,
openModal
,
};
}
),
[
handleConnect
,
handleDisconnect
,
isOpen
,
isOpening
,
isConnected
,
address
,
openModal
])
;
}
ui/snippets/auth/useSignInWithWallet.ts
View file @
a67f0714
import
{
useWeb3Modal
}
from
'
@web3modal/wagmi/react
'
;
import
React
from
'
react
'
;
import
{
useSignMessage
}
from
'
wagmi
'
;
...
...
@@ -8,9 +7,10 @@ import config from 'configs/app';
import
useApiFetch
from
'
lib/api/useApiFetch
'
;
import
getErrorMessage
from
'
lib/errors/getErrorMessage
'
;
import
getErrorObj
from
'
lib/errors/getErrorObj
'
;
import
getErrorObjPayload
from
'
lib/errors/getErrorObjPayload
'
;
import
useToast
from
'
lib/hooks/useToast
'
;
import
*
as
mixpanel
from
'
lib/mixpanel
'
;
import
use
Account
from
'
lib/web3/useAccoun
t
'
;
import
type
*
as
mixpanel
from
'
lib/mixpanel
'
;
import
use
Web3Wallet
from
'
lib/web3/useWalle
t
'
;
interface
Props
{
onSuccess
?:
({
address
,
profile
}:
{
address
:
string
;
profile
:
UserInfo
})
=>
void
;
...
...
@@ -25,8 +25,7 @@ function useSignInWithWallet({ onSuccess, onError, source = 'Login', isAuth }: P
const
apiFetch
=
useApiFetch
();
const
toast
=
useToast
();
const
web3Modal
=
useWeb3Modal
();
const
{
isConnected
,
address
}
=
useAccount
();
const
web3Wallet
=
useWeb3Wallet
({
source
});
const
{
signMessageAsync
}
=
useSignMessage
();
const
proceedToAuth
=
React
.
useCallback
(
async
(
address
:
string
)
=>
{
...
...
@@ -46,12 +45,13 @@ function useSignInWithWallet({ onSuccess, onError, source = 'Login', isAuth }: P
onSuccess
?.({
address
,
profile
:
response
});
}
catch
(
error
)
{
const
errorObj
=
getErrorObj
(
error
);
const
apiErrorMessage
=
getErrorObjPayload
<
{
message
:
string
}
>
(
error
)?.
message
;
const
shortMessage
=
errorObj
&&
'
shortMessage
'
in
errorObj
&&
typeof
errorObj
.
shortMessage
===
'
string
'
?
errorObj
.
shortMessage
:
undefined
;
onError
?.();
toast
({
status
:
'
error
'
,
title
:
'
Error
'
,
description
:
shortMessage
||
getErrorMessage
(
error
)
||
'
Something went wrong
'
,
description
:
apiErrorMessage
||
shortMessage
||
getErrorMessage
(
error
)
||
'
Something went wrong
'
,
});
}
finally
{
setIsPending
(
false
);
...
...
@@ -60,22 +60,20 @@ function useSignInWithWallet({ onSuccess, onError, source = 'Login', isAuth }: P
const
start
=
React
.
useCallback
(()
=>
{
setIsPending
(
true
);
if
(
address
)
{
proceedToAuth
(
address
);
if
(
web3Wallet
.
address
)
{
proceedToAuth
(
web3Wallet
.
address
);
}
else
{
isConnectingWalletRef
.
current
=
true
;
web3Modal
.
open
();
mixpanel
.
logEvent
(
mixpanel
.
EventTypes
.
WALLET_CONNECT
,
{
Source
:
source
,
Status
:
'
Started
'
});
web3Wallet
.
openModal
();
}
},
[
address
,
proceedToAuth
,
source
,
web3Modal
]);
},
[
proceedToAuth
,
web3Wallet
]);
React
.
useEffect
(()
=>
{
if
(
address
&&
isConnectingWalletRef
.
current
)
{
if
(
web3Wallet
.
address
&&
isConnectingWalletRef
.
current
)
{
isConnectingWalletRef
.
current
=
false
;
proceedToAuth
(
address
);
mixpanel
.
logEvent
(
mixpanel
.
EventTypes
.
WALLET_CONNECT
,
{
Source
:
source
,
Status
:
'
Connected
'
});
proceedToAuth
(
web3Wallet
.
address
);
}
},
[
address
,
isConnected
,
proceedToAuth
,
source
]);
},
[
proceedToAuth
,
web3Wallet
.
address
]);
return
React
.
useMemo
(()
=>
({
start
,
isPending
}),
[
start
,
isPending
]);
}
...
...
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