@@ -19,9 +19,10 @@ import type {
1919 VolatilityMetrics ,
2020 PropertyType ,
2121 OracleSource ,
22- TxResult ,
2322 ContractEvent ,
2423 ClientOptions ,
24+ TxProgressCallback ,
25+ TxProgressStatus ,
2526} from '../types' ;
2627import { decodeContractError , TransactionError , GasEstimationError } from '../utils/errors' ;
2728import { decodeTransactionEvents } from '../utils/events' ;
@@ -131,8 +132,9 @@ export class OracleClient {
131132 async requestValuation (
132133 signer : Signer ,
133134 propertyId : number ,
135+ onProgress ?: TxProgressCallback ,
134136 ) : Promise < { requestId : number } & TxResult > {
135- const txResult = await this . submitTx ( signer , 'request_valuation' , [ propertyId ] ) ;
137+ const txResult = await this . submitTx ( signer , 'request_valuation' , [ propertyId ] , onProgress ) ;
136138 return { requestId : 0 , ...txResult } ;
137139 }
138140
@@ -145,8 +147,9 @@ export class OracleClient {
145147 async batchRequestValuations (
146148 signer : Signer ,
147149 propertyIds : number [ ] ,
150+ onProgress ?: TxProgressCallback ,
148151 ) : Promise < TxResult > {
149- return this . submitTx ( signer , 'batch_request_valuations' , [ propertyIds ] ) ;
152+ return this . submitTx ( signer , 'batch_request_valuations' , [ propertyIds ] , onProgress ) ;
150153 }
151154
152155 // ==========================================================================
@@ -156,15 +159,15 @@ export class OracleClient {
156159 /**
157160 * Adds an oracle source (admin only).
158161 */
159- async addSource ( signer : Signer , source : OracleSource ) : Promise < TxResult > {
160- return this . submitTx ( signer , 'add_source' , [ source ] ) ;
162+ async addSource ( signer : Signer , source : OracleSource , onProgress ?: TxProgressCallback ) : Promise < TxResult > {
163+ return this . submitTx ( signer , 'add_source' , [ source ] , onProgress ) ;
161164 }
162165
163166 /**
164167 * Removes an oracle source (admin only).
165168 */
166- async removeSource ( signer : Signer , sourceId : string ) : Promise < TxResult > {
167- return this . submitTx ( signer , 'remove_source' , [ sourceId ] ) ;
169+ async removeSource ( signer : Signer , sourceId : string , onProgress ?: TxProgressCallback ) : Promise < TxResult > {
170+ return this . submitTx ( signer , 'remove_source' , [ sourceId ] , onProgress ) ;
168171 }
169172
170173 /**
@@ -211,6 +214,7 @@ export class OracleClient {
211214 signer : Signer ,
212215 method : string ,
213216 args : unknown [ ] ,
217+ onProgress ?: TxProgressCallback ,
214218 ) : Promise < TxResult > {
215219 const signerAddress = typeof signer === 'string' ? signer : signer . address ;
216220
@@ -246,7 +250,26 @@ export class OracleClient {
246250 signer as KeyringPair ,
247251 { } ,
248252 ( { status, events : rawEvents , dispatchError } ) => {
253+ if ( status . isReady && onProgress ) {
254+ onProgress ( { status : TxProgressStatus . Ready , txHash : tx . hash . toString ( ) } ) ;
255+ } else if ( status . isBroadcast && onProgress ) {
256+ onProgress ( { status : TxProgressStatus . Broadcast , txHash : tx . hash . toString ( ) } ) ;
257+ } else if ( status . isInBlock && onProgress ) {
258+ onProgress ( {
259+ status : TxProgressStatus . InBlock ,
260+ txHash : tx . hash . toString ( ) ,
261+ blockHash : status . asInBlock . toString ( )
262+ } ) ;
263+ }
264+
249265 if ( dispatchError ) {
266+ if ( onProgress ) {
267+ onProgress ( {
268+ status : TxProgressStatus . Error ,
269+ txHash : tx . hash . toString ( ) ,
270+ message : dispatchError . toString ( )
271+ } ) ;
272+ }
250273 reject (
251274 new TransactionError (
252275 `Transaction failed: ${ dispatchError . toString ( ) } ` ,
@@ -259,6 +282,14 @@ export class OracleClient {
259282
260283 if ( status . isFinalized ) {
261284 const blockHash = status . asFinalized . toString ( ) ;
285+ if ( onProgress ) {
286+ onProgress ( {
287+ status : TxProgressStatus . Finalized ,
288+ txHash : tx . hash . toString ( ) ,
289+ blockHash
290+ } ) ;
291+ }
292+
262293 const decodedEvents : ContractEvent [ ] = decodeTransactionEvents (
263294 this . abi ,
264295 rawEvents as unknown as Array < {
0 commit comments