Commit ebdab0c 1 parent 6e71bf5 commit ebdab0c Copy full SHA for ebdab0c
File tree 1 file changed +25
-7
lines changed
suite-common/wallet-core/src/fiat-rates
1 file changed +25
-7
lines changed Original file line number Diff line number Diff line change @@ -184,13 +184,31 @@ export const fetchFiatRatesThunk = createThunk(
184
184
// NOTE: do not await it here, leave it just to return
185
185
// updateFiatRatesThunk is handled in the reducer and we don't need to wait for
186
186
// all the token fiat rates to be loaded as it slows down start of the app massively
187
- dispatch (
188
- updateFiatRatesThunk ( {
189
- tickers,
190
- localCurrency,
191
- rateType,
192
- fetchAttemptTimestamp : Date . now ( ) as Timestamp ,
193
- } ) ,
187
+ // Because of that, let's chunk the number of fiat rates to be loaded
188
+ // and have then loaded by chunks to not overload the API
189
+ const FIAT_RATES_FETCH_CHUNK_SIZE = 4 ;
190
+ const tickerChunks = Array . from (
191
+ { length : Math . ceil ( tickers . length / FIAT_RATES_FETCH_CHUNK_SIZE ) } ,
192
+ ( _ , i ) =>
193
+ tickers . slice (
194
+ i * FIAT_RATES_FETCH_CHUNK_SIZE ,
195
+ ( i + 1 ) * FIAT_RATES_FETCH_CHUNK_SIZE ,
196
+ ) ,
197
+ ) ;
198
+
199
+ tickerChunks . reduce < Promise < any > > (
200
+ ( chain , chunk ) =>
201
+ chain . then ( ( ) =>
202
+ dispatch (
203
+ updateFiatRatesThunk ( {
204
+ tickers : chunk ,
205
+ localCurrency,
206
+ rateType,
207
+ fetchAttemptTimestamp : Date . now ( ) as Timestamp ,
208
+ } ) ,
209
+ ) ,
210
+ ) ,
211
+ Promise . resolve ( ) ,
194
212
) ;
195
213
196
214
return ;
You can’t perform that action at this time.
0 commit comments