@@ -12,6 +12,7 @@ import { GameConfig } from "./utils/game/configLib";
1212import { sum } from "./utils/bigintMinHeap" ;
1313import { SignedIn , SignedOut , SignInButton , useAuth , UserButton } from "@clerk/clerk-react" ;
1414import { isAddress } from "viem" ;
15+ import { useState } from "react" ;
1516
1617export function GameUI ( {
1718 liveState,
@@ -25,44 +26,56 @@ export function GameUI({
2526
2627 const { getToken } = useAuth ( ) ;
2728
29+ const [ generatingAccessSignature , setGeneratingAccessSignature ] = useState ( false ) ;
30+
2831 const generateAccessSignature = async ( ) => {
29- const address = prompt (
30- `🔗 Enter the Odyssey address you want to link your X account to.
32+ setGeneratingAccessSignature ( true ) ;
33+
34+ await new Promise ( ( resolve ) => setTimeout ( resolve , 50 ) ) ; // Wait a sec so the loader can show.
35+
36+ try {
37+ const address = prompt (
38+ `🔗 Enter the Odyssey address you want to link your X account to.
39+
40+ 📋 See the 'how to get started' section for more information.
3141
3242🚨 You cannot relink your account to a different address after linking.` ,
33- "0x..."
34- ) ;
43+ "0x..."
44+ ) ;
3545
36- if ( ! address || ! isAddress ( address ) ) {
37- alert ( "Invalid address. Try again." ) ;
38- return ;
39- }
46+ if ( ! address || ! isAddress ( address ) ) {
47+ alert ( "Invalid address. Try again." ) ;
48+ return ;
49+ }
4050
41- try {
42- const { accessSignature } = await fetch (
43- "https://rethmatch-auth.paradigm.xyz/generateAccessSignature" ,
44- {
51+ try {
52+ const res = await fetch ( "https://rethmatch-auth.paradigm.xyz/generateAccessSignature" , {
4553 method : "POST" ,
4654 body : JSON . stringify ( { address } ) ,
4755 headers : {
4856 "Content-Type" : "application/json" ,
4957 Authorization : `Bearer ${ await getToken ( ) } ` ,
5058 } ,
51- }
52- ) . then ( ( res ) => res . json ( ) ) ;
59+ } ) . then ( ( res ) => res . json ( ) ) ;
5360
54- if ( ! accessSignature ) throw new Error ( "Undefined access signature." ) ;
61+ console . log ( res ) ;
5562
56- prompt (
57- `🔏 Copy the access signature linking ${ address . slice ( 0 , 4 ) } ... ${ address . slice ( - 4 ) } to your X account below.
63+ if ( ! res . accessSignature )
64+ throw new Error ( "Undefined access signature. Got response: " + JSON . stringify ( res ) ) ;
5865
59- 📋 See the guide on bots for more information on how to use this.
66+ prompt (
67+ `🔏 Copy the access signature linking ${ address . slice ( 0 , 4 ) } ...${ address . slice ( - 4 ) } to your X account below.
68+
69+ 📋 See the 'how to get started' section for more information on how to use this.
6070` ,
61- accessSignature
62- ) ;
63- } catch ( error ) {
64- alert ( "Failed to generate access signature: " + error ) ;
65- return ;
71+ res . accessSignature
72+ ) ;
73+ } catch ( error ) {
74+ alert ( "Failed to generate access signature: " + error ) ;
75+ return ;
76+ }
77+ } finally {
78+ setGeneratingAccessSignature ( false ) ;
6679 }
6780 } ;
6881
@@ -115,6 +128,7 @@ export function GameUI({
115128 _hover = { { opacity : 0.8 } }
116129 _active = { { opacity : 0.35 } }
117130 onClick = { generateAccessSignature }
131+ isLoading = { generatingAccessSignature }
118132 >
119133 < UserButton /> < Text ml = { 2 } > GENERATE ACCESS SIGNATURE</ Text >
120134 </ Button >
0 commit comments