@@ -27,7 +27,7 @@ import { validateAddress, validateAll, validateETHAmount } from '@/lib/core/util
2727import { loadJson } from '@/lib/utils/load-json' ;
2828import { newSavableRecoverData , recoverDataFromJson } from '@/lib/utils/recover-data' ;
2929import { saveJson } from '@/lib/utils/save-json' ;
30- import { useEffect , useState } from 'react' ;
30+ import { Dispatch , SetStateAction , useEffect , useState } from 'react' ;
3131import { Client , formatEther , hexToBytes , parseEther , toHex } from 'viem' ;
3232import { waitForTransactionReceipt } from 'viem/actions' ;
3333import { useClient , usePublicClient , useSendTransaction } from 'wagmi' ;
@@ -50,7 +50,7 @@ export default function Wormhole() {
5050
5151 // state
5252 const [ wormholeState , setWormholeState ] = useState < WormholeState > ( 'Start' ) ;
53- const isLoadingState = wormholeState === 'Calculating ' || wormholeState == 'Sending' || wormholeState == 'Minting' ;
53+ const isLoadingState = ! ( wormholeState === 'Send ' || wormholeState === 'Start' ) ;
5454 const [ error , setError ] = useState < string | null > ( null ) ; // null means no error state
5555
5656 const [ burnAddress , setBurnAddress ] = useState < BurnAddressContent | null > ( null ) ;
@@ -124,11 +124,18 @@ export default function Wormhole() {
124124 } ;
125125
126126 const onSendClick = async ( ) => {
127- setWormholeState ( 'Sending' ) ;
128127 try {
128+ setWormholeState ( 'Sending to burn address' ) ;
129129 await transferETH ( mutateAsync , client ! , burnAddress ! . revealAmount , burnAddress ! . burnAddress ) ;
130- setWormholeState ( 'Minting' ) ;
131- await generateAndSubmit ( client ! , burnAddress ! , publicClient , burnAddress ! . revealAmount , network , proverAddress ! ) ;
130+ await generateAndSubmit (
131+ client ! ,
132+ burnAddress ! ,
133+ setWormholeState ,
134+ publicClient ,
135+ burnAddress ! . revealAmount ,
136+ network ,
137+ proverAddress !
138+ ) ;
132139 resetStates ( ) ;
133140 } catch ( e ) {
134141 console . error ( 'onSend' , e ) ;
@@ -180,11 +187,11 @@ export default function Wormhole() {
180187 burnAmount . update ( formatEther ( recoverData . burn . revealAmount ) ) ;
181188 receiverAddress . update ( recoverData . burn . receiverAddr ) ;
182189
183- setWormholeState ( 'Sending' ) ;
184190 try {
185191 await generateAndSubmit (
186192 client ! ,
187193 recoverData . burn ,
194+ setWormholeState ,
188195 publicClient ,
189196 recoverData . burn . revealAmount ,
190197 network ,
@@ -278,11 +285,13 @@ export default function Wormhole() {
278285const generateAndSubmit = async (
279286 client : Client ,
280287 burnAddress : BurnAddressContent ,
288+ setWormholeState : Dispatch < SetStateAction < WormholeState > > ,
281289 publicClient : any , // pass whatever usePublicClient() returns
282290 burnAmount : bigint ,
283291 network : WormNetwork ,
284292 proverAddress ?: `0x${string } `
285293) => {
294+ setWormholeState ( 'Generating proof' ) ;
286295 let blockNumber = ( await publicClient ! . getBlock ( ) ) . number ;
287296 let accountProof = await publicClient ?. getProof ( {
288297 address : burnAddress . burnAddress as `0x${string } `,
@@ -314,6 +323,7 @@ const generateAndSubmit = async (
314323 }
315324 console . log ( 'rapidsnarkProof:' , rapidsnarkProof ) ;
316325
326+ setWormholeState ( 'Submitting proof' ) ;
317327 const remainingCoin = calculateRemainingCoinHash (
318328 burnAddress . burnKey ,
319329 burnAddress . revealAmount ,
@@ -348,4 +358,11 @@ const generateAndSubmit = async (
348358 }
349359} ;
350360
351- type WormholeState = 'Start' | 'Calculating' | 'Send' | 'Sending' | 'Minting' ;
361+ /// primary button texts
362+ type WormholeState =
363+ | 'Start'
364+ | 'Calculating'
365+ | 'Send'
366+ | 'Sending to burn address'
367+ | 'Generating proof'
368+ | 'Submitting proof' ;
0 commit comments