@@ -18,9 +18,10 @@ interface IAtlasProvider {
18
18
19
19
const Context = createContext < IAtlasProvider | undefined > ( undefined ) ;
20
20
21
- // eslint-disable-next-line
22
- // @ts -ignore
23
- const atlasUri = import . meta. env . REACT_APP_ATLAS_URI ?? "" ;
21
+ const atlasUri : string = import . meta. env . REACT_APP_ATLAS_URI ?? "" ;
22
+ if ( ! atlasUri ) {
23
+ console . warn ( "REACT_APP_ATLAS_URI is not defined. Please check your environment variables." ) ;
24
+ }
24
25
25
26
const AtlasProvider : React . FC < { children ?: React . ReactNode } > = ( { children } ) => {
26
27
const { address } = useAccount ( ) ;
@@ -75,27 +76,24 @@ const AtlasProvider: React.FC<{ children?: React.ReactNode }> = ({ children }) =
75
76
/**
76
77
* @description authorise user and enable authorised calls
77
78
*/
78
- const authoriseUser = useCallback ( ( ) => {
79
- if ( ! address ) return ;
80
- setIsSigningIn ( true ) ;
81
- getNonce ( atlasGqlClient , address )
82
- . then ( ( nonce ) => {
83
- const message = createMessage ( address , chainId , nonce ) ;
84
- signMessageAsync ( { message } ) . then ( ( signature ) => {
85
- if ( ! isUndefined ( signature ) ) {
86
- loginUser ( atlasGqlClient , { signature, message } )
87
- . then ( ( token ) => {
88
- setAuthToken ( token ) ;
89
- } )
90
- . finally ( ( ) => setIsSigningIn ( false ) ) ;
91
- }
92
- } ) ;
93
- } )
94
- . catch ( ( err ) => {
95
- // eslint-disable-next-line no-console
96
- console . log ( `authorise user error : ${ err ?. message } ` ) ;
97
- setIsSigningIn ( false ) ;
98
- } ) ;
79
+ const authoriseUser = useCallback ( async ( ) => {
80
+ try {
81
+ if ( ! address || ! chainId ) return ;
82
+ setIsSigningIn ( true ) ;
83
+ const nonce = await getNonce ( atlasGqlClient , address ) ;
84
+ const message = createMessage ( address , nonce , chainId ) ;
85
+ const signature = await signMessageAsync ( { message } ) ;
86
+
87
+ if ( ! signature ) return ;
88
+ const token = await loginUser ( atlasGqlClient , { message, signature } ) ;
89
+
90
+ setAuthToken ( token ) ;
91
+ } catch ( err : any ) {
92
+ // eslint-disable-next-line
93
+ console . log ( "Authorize User Error : " , err ?. message ) ;
94
+ } finally {
95
+ setIsSigningIn ( false ) ;
96
+ }
99
97
} , [ address , chainId , setAuthToken , signMessageAsync , atlasGqlClient ] ) ;
100
98
101
99
return (
0 commit comments