11import { Component , OnDestroy , OnInit } from '@angular/core' ;
22import { ApiService } from '../services/api.service' ;
33import { WalletService } from '../services/wallet.service' ;
4- import { ContractDto , IpoBid , IpoBidOverview , Transaction } from '../services/api.model' ;
4+ import { ContractDto , IpoBid , IpoBidOverview } from '../services/api.model' ;
55import { Router } from '@angular/router' ;
66import { catchError , forkJoin , of , Subject } from 'rxjs' ;
77import { map , switchMap , takeUntil } from 'rxjs/operators' ;
88import { AddressNameService } from '../services/address-name.service' ;
99import { getDisplayName } from '../utils/address.utils' ;
1010import { ApiLiveService } from '../services/apis/live/api.live.service' ;
1111import { IpoBidsResponse } from '../services/apis/live/api.live.model' ;
12- import { QubicStaticService } from '../services/apis/static/qubic-static.service ' ;
13- import { StaticSmartContract } from '../services/apis/static/qubic-static.model ' ;
12+ import { CurrentIpoBidsContract } from '../services/apis/aggregation/api.aggregation.model ' ;
13+ import { ApiAggregationService } from '../services/apis/aggregation/api.aggregation.service ' ;
1414import { ExplorerUrlHelper } from '../services/explorer-url.helper' ;
1515
1616@Component ( {
@@ -27,15 +27,15 @@ export class IpoComponent implements OnInit, OnDestroy {
2727 public loadError : boolean = false ;
2828 public failedBidContracts = new Set < number > ( ) ;
2929 public retryingContracts = new Set < number > ( ) ;
30- public ipoBids : Transaction [ ] = [ ] ;
31- private contractAddressMap = new Map < number , string > ( ) ;
30+ public ipoBids : CurrentIpoBidsContract [ ] = [ ] ;
31+ public ipoBidsLoadError : boolean = false ;
3232 private destroy$ = new Subject < void > ( ) ;
3333
3434 constructor (
3535 private router : Router ,
3636 private api : ApiService ,
3737 private apiLiveService : ApiLiveService ,
38- private qubicStaticService : QubicStaticService ,
38+ private apiAggregationService : ApiAggregationService ,
3939 private walletService : WalletService ,
4040 private addressNameService : AddressNameService
4141 ) { }
@@ -56,17 +56,18 @@ export class IpoComponent implements OnInit, OnDestroy {
5656 init ( ) {
5757 this . refreshing = true ;
5858 this . loadError = false ;
59+ this . ipoBidsLoadError = false ;
5960 this . failedBidContracts . clear ( ) ;
6061 this . retryingContracts . clear ( ) ;
6162
6263 // Step 1: Get active IPOs, then fetch bids for each in parallel
6364 this . apiLiveService . getActiveIpos ( ) . pipe (
6465 switchMap ( activeIpos => {
6566 if ( activeIpos . length === 0 ) {
66- return of ( { activeIpos, bidResponses : [ ] as IpoBidsResponse [ ] , bids : [ ] as Transaction [ ] , staticContracts : [ ] as StaticSmartContract [ ] } ) ;
67+ return of ( { activeIpos, bidResponses : [ ] as IpoBidsResponse [ ] , bids : [ ] as CurrentIpoBidsContract [ ] } ) ;
6768 }
6869
69- // Fetch bids, user transactions, and contract addresses in parallel
70+ // Fetch bids and user bid transactions in parallel
7071 const bidRequests = activeIpos . map ( ipo =>
7172 this . apiLiveService . getIpoBids ( ipo . contractIndex ) . pipe (
7273 catchError ( ( ) => {
@@ -77,21 +78,19 @@ export class IpoComponent implements OnInit, OnDestroy {
7778 ) ;
7879 return forkJoin ( {
7980 bidResponses : forkJoin ( bidRequests ) ,
80- bids : this . api . getCurrentIpoBids ( this . getSeeds ( ) . map ( m => m . publicId ) ) ,
81- staticContracts : this . qubicStaticService . getSmartContracts ( )
81+ bids : this . apiAggregationService . getCurrentIpoBids ( this . getSeeds ( ) . map ( m => m . publicId ) ) . pipe (
82+ catchError ( ( ) => {
83+ this . ipoBidsLoadError = true ;
84+ return of ( [ ] as CurrentIpoBidsContract [ ] ) ;
85+ } )
86+ ) ,
8287 } ) . pipe (
8388 map ( result => ( { activeIpos, ...result } ) )
8489 ) ;
8590 } ) ,
8691 takeUntil ( this . destroy$ )
8792 ) . subscribe ( {
8893 next : ( result ) => {
89- // Build contract address map for matching bids to contracts
90- this . contractAddressMap . clear ( ) ;
91- for ( const sc of result . staticContracts ) {
92- this . contractAddressMap . set ( sc . contractIndex , sc . address ) ;
93- }
94-
9594 // Map live API responses to existing ContractDto format
9695 this . ipoContracts = result . activeIpos . map ( ( ipo , i ) => {
9796 const bidResponse = result . bidResponses [ i ] ;
@@ -155,14 +154,8 @@ export class IpoComponent implements OnInit, OnDestroy {
155154 }
156155
157156 getContractBids ( contractId : number ) {
158- const destination = this . contractAddressMap . get ( contractId ) ;
159- if ( ! destination ) {
160- return [ ] ;
161- }
162-
163- return this . ipoBids . filter (
164- ( tx : Transaction ) => tx . destId === destination
165- ) ;
157+ const contract = this . ipoBids . find ( c => c . contractIndex === contractId ) ;
158+ return contract ?. transactions || [ ] ;
166159 }
167160
168161 hasBidError ( contractIndex : number ) : boolean {
0 commit comments