11import { Component , OnInit } from '@angular/core' ;
22import { ContractAgreementService } from "../../../shared/services/contractAgreement.service" ;
3- import { firstValueFrom , from , interval , Observable , of , timer } from "rxjs" ;
3+ import { firstValueFrom , from , interval , Observable , of , timer , Subscription } from "rxjs" ;
44import { ContractAgreement , IdResponse , TransferProcessInput } from "../../../shared/models/edc-connector-entities" ;
55import { catchError , filter , finalize , first , switchMap , takeUntil , tap } from "rxjs/operators" ;
66import { NotificationService } from "../../../shared/services/notification.service" ;
@@ -32,6 +32,7 @@ export class ContractViewerComponent implements OnInit {
3232 contracts : ContractAgreement [ ] = [ ] ;
3333 private runningTransfers : RunningTransferProcess [ ] = [ ] ;
3434 private pollingHandleTransfer ?: any ;
35+ private timeoutSubscription ?: Subscription ;
3536 PARTICIPANT_ID = `${ environment . runtime . participantId } ` ;
3637
3738 // Pagination
@@ -203,22 +204,23 @@ export class ContractViewerComponent implements OnInit {
203204 } )
204205 ) ;
205206
207+ this . timeoutSubscription = timeout$ . subscribe ( ) ;
208+
206209 this . runningTransfers . push ( {
207210 processId : transferProcessId . id ,
208211 state : TransferProcessStates . REQUESTED ,
209212 contractId : contractId
210213 } ) ;
211214
212215 if ( ! this . pollingHandleTransfer ) {
213- this . pollingHandleTransfer = this . pollRunningTransfers ( timeout$ )
216+ this . pollingHandleTransfer = this . pollRunningTransfers ( )
214217 . pipe ( finalize ( ( ) => this . cleanupPolling ( ) ) )
215218 . subscribe ( ) ;
216219 }
217220 }
218221
219- private pollRunningTransfers ( timeout$ : Observable < number > ) {
222+ private pollRunningTransfers ( ) {
220223 return interval ( 2000 ) . pipe (
221- takeUntil ( timeout$ ) ,
222224 switchMap ( ( ) => from ( [ ...this . runningTransfers ] ) ) ,
223225 switchMap ( runningTransferProcess =>
224226 this . catalogService . getTransferProcessesById ( runningTransferProcess . processId ) . pipe (
@@ -237,6 +239,7 @@ export class ContractViewerComponent implements OnInit {
237239 )
238240 ) ,
239241 tap ( transferProcess => {
242+ this . timeoutSubscription ?. unsubscribe ( ) ;
240243 this . removeTransferFromList ( transferProcess . id ) ;
241244 this . notificationService . showWarning (
242245 `Transfer [${ transferProcess . id } ] complete! Check if the process was successful` ,
@@ -259,7 +262,6 @@ export class ContractViewerComponent implements OnInit {
259262 private cleanupPolling ( ) {
260263 clearInterval ( this . pollingHandleTransfer ) ;
261264 this . pollingHandleTransfer = undefined ;
265+ this . timeoutSubscription ?. unsubscribe ( ) ;
262266 }
263-
264-
265267}
0 commit comments