File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ import {
1919 bigIntMax ,
2020 convert ,
2121 convertWithExchangeRate ,
22- getExchangeRatesMemoized ,
22+ getExchangeRates ,
2323 getNextSendableAmount ,
2424} from '@/background/utils' ;
2525import type {
@@ -129,7 +129,7 @@ export class PaymentSession {
129129
130130 if ( isCrossCurrency ) {
131131 try {
132- const exchangeRates = await getExchangeRatesMemoized ( ) ;
132+ const exchangeRates = await getExchangeRates ( ) ;
133133 amountToSend = convertWithExchangeRate (
134134 amountToSend ,
135135 this . receiver ,
Original file line number Diff line number Diff line change @@ -75,25 +75,23 @@ interface ExchangeRates {
7575 rates : Record < string , number > ;
7676}
7777
78- export const getExchangeRates = async ( ) : Promise < ExchangeRates > => {
79- const response = await fetch ( EXCHANGE_RATES_URL ) ;
80- if ( ! response . ok ) {
81- throw new Error (
82- `Could not fetch exchange rates. [Status code: ${ response . status } ]` ,
83- ) ;
84- }
85- const rates = await response . json ( ) ;
86- if ( ! rates . base || ! rates . rates ) {
87- throw new Error ( 'Invalid rates format' ) ;
88- }
89-
90- return rates ;
91- } ;
92-
93- export const getExchangeRatesMemoized = memoize ( getExchangeRates , {
94- maxAge : 15 * 60 * 1000 ,
95- mechanism : 'stale-while-revalidate' ,
96- } ) ;
78+ export const getExchangeRates = memoize (
79+ async ( ) : Promise < ExchangeRates > => {
80+ const response = await fetch ( EXCHANGE_RATES_URL ) ;
81+ if ( ! response . ok ) {
82+ throw new Error (
83+ `Could not fetch exchange rates. [Status code: ${ response . status } ]` ,
84+ ) ;
85+ }
86+ const rates = await response . json ( ) ;
87+ if ( ! rates . base || ! rates . rates ) {
88+ throw new Error ( 'Invalid rates format' ) ;
89+ }
90+
91+ return rates ;
92+ } ,
93+ { maxAge : 15 * 60 * 1000 , mechanism : 'stale-while-revalidate' } ,
94+ ) ;
9795
9896export const getExchangeRate = (
9997 rates : ExchangeRates ,
You can’t perform that action at this time.
0 commit comments