@@ -961,24 +961,46 @@ class AleoNetworkClient {
961
961
* @param {string } solution The string representation of the solution desired to be submitted to the network.
962
962
*/
963
963
async waitForTransactionConfirmation (
964
- transactionId : string ,
965
- checkInterval : number = 2000 , // Poll every 2 seconds
966
- timeout : number = 45000 // Timeout after 45 seconds
967
- ) : Promise < Transaction > {
964
+ transactionId : string ,
965
+ checkInterval : number = 2000 ,
966
+ timeout : number = 45000
967
+ ) : Promise < "accepted" | "rejected" > {
968
968
const startTime = Date . now ( ) ;
969
-
970
- return new Promise < Transaction > ( ( resolve , reject ) => {
969
+
970
+ return new Promise ( ( resolve , reject ) => {
971
971
const interval = setInterval ( async ( ) => {
972
+ const elapsed = Date . now ( ) - startTime ;
973
+
974
+ if ( elapsed > timeout ) {
975
+ clearInterval ( interval ) ;
976
+ return reject ( new Error ( "Transaction confirmation timed out" ) ) ;
977
+ }
978
+
972
979
try {
973
- // Replace with actual Aleo transaction lookup API
974
- const transaction = < Transaction > await this . getTransactionObject ( transactionId ) ;
975
- resolve ( transaction ) ;
976
- if ( Date . now ( ) - startTime > timeout ) {
980
+ const res = await fetch ( `https://api.explorer.provable.com/v1/mainnet/transaction/confirmed/${ transactionId } ` ) ;
981
+
982
+ if ( ! res . ok ) {
983
+ const text = await res . text ( ) ;
984
+ console . error ( "Non-OK response:" , res . status , text ) ;
985
+ clearInterval ( interval ) ;
986
+ return reject ( new Error ( `HTTP ${ res . status } : ${ text } ` ) ) ;
987
+ }
988
+
989
+ const data = await res . json ( ) ;
990
+
991
+ if ( data ?. status === "accepted" ) {
992
+ clearInterval ( interval ) ;
993
+ return resolve ( "accepted" ) ;
994
+ }
995
+
996
+ if ( data ?. status === "rejected" ) {
977
997
clearInterval ( interval ) ;
978
- reject ( new Error ( "Transaction confirmation timed out" ) ) ;
998
+ return resolve ( "rejected" ) ;
979
999
}
980
- } catch ( error ) {
981
- console . error ( "Error checking transaction:" , error ) ;
1000
+
1001
+ // no status? keep polling
1002
+ } catch ( err ) {
1003
+ console . error ( "Polling error:" , err ) ;
982
1004
}
983
1005
} , checkInterval ) ;
984
1006
} ) ;
0 commit comments