@@ -50,7 +50,7 @@ import type * as MessageTypes from '@trezor/blockchain-link-types/src/messages';
50
50
import { CustomError } from '@trezor/blockchain-link-types/src/constants/errors' ;
51
51
import { MESSAGES , RESPONSES } from '@trezor/blockchain-link-types/src/constants' ;
52
52
import { solanaUtils } from '@trezor/blockchain-link-utils' ;
53
- import { BigNumber , createLazy } from '@trezor/utils' ;
53
+ import { BigNumber , createDeferred , createLazy } from '@trezor/utils' ;
54
54
import {
55
55
transformTokenInfo ,
56
56
tokenProgramsInfo ,
@@ -298,6 +298,23 @@ const getAccountInfo = async (
298
298
)
299
299
. send ( ) ;
300
300
301
+ const getEpoch = async ( ) : Promise < number > => {
302
+ const cachedEpoch = await request . state . cache . get ( 'epoch' ) ;
303
+
304
+ if ( cachedEpoch ) {
305
+ return cachedEpoch ;
306
+ }
307
+
308
+ // for parallel requests we store the promise in the cache immediately
309
+ const deferred = createDeferred < number > ( ) ;
310
+ request . state . cache . set ( 'epoch' , deferred . promise , 3_600_000 ) ;
311
+
312
+ const { epoch } = await api . rpc . getEpochInfo ( ) . send ( ) ;
313
+ deferred . resolve ( Number ( epoch ) ) ;
314
+
315
+ return deferred . promise ;
316
+ } ;
317
+
301
318
const tokenAccounts = (
302
319
await Promise . all (
303
320
Object . values ( tokenProgramsInfo ) . map ( programInfo =>
@@ -355,7 +372,7 @@ const getAccountInfo = async (
355
372
owner : accountInfo ?. owner ,
356
373
rent : Number ( rent ) ,
357
374
solStakingAccounts : stakingData ?. stakingAccounts ,
358
- solEpoch : stakingData ?. epoch ,
375
+ solEpoch : await getEpoch ( ) ,
359
376
} ;
360
377
}
361
378
}
0 commit comments