@@ -191,10 +191,14 @@ export const revolutRampPlugin: RampPluginFactory = (
191191 }  =  request 
192192 const  currencyPluginId  =  request . wallet . currencyInfo . pluginId 
193193
194-  const  isMaxAmount  = 
195-  'max'  in  request . exchangeAmount  &&  request . exchangeAmount . max 
194+  const  isMaxAmount  =  'max'  in  request . exchangeAmount 
196195 const  exchangeAmount  = 
197196 'amount'  in  request . exchangeAmount  ? request . exchangeAmount . amount  : '' 
197+  const  maxAmountLimit  = 
198+  'max'  in  request . exchangeAmount  && 
199+  typeof  request . exchangeAmount . max  ===  'string' 
200+  ? request . exchangeAmount . max 
201+  : undefined 
198202
199203 // Constraints per request 
200204 const  constraintOk  =  validateRampQuoteRequest ( 
@@ -287,7 +291,7 @@ export const revolutRampPlugin: RampPluginFactory = (
287291 } 
288292
289293 // Fetch quote from Revolut (API only needs country code) 
290-  const  quoteData  =  await  fetchRevolutQuote ( 
294+  let  quoteData  =  await  fetchRevolutQuote ( 
291295 { 
292296 fiat : revolutFiat . currency , 
293297 amount, 
@@ -298,8 +302,42 @@ export const revolutRampPlugin: RampPluginFactory = (
298302 {  apiKey,  baseUrl : apiUrl  } 
299303 ) 
300304
305+  if  ( isMaxAmount  &&  maxAmountLimit  !=  null )  { 
306+  const  capValue  =  parseFloat ( maxAmountLimit ) 
307+  const  quotedCrypto  =  parseFloat ( quoteData . crypto . amount . toString ( ) ) 
308+  const  currentFiat  =  parseFloat ( amount ) 
309+  if  ( 
310+  ! Number . isNaN ( capValue )  && 
311+  ! Number . isNaN ( quotedCrypto )  && 
312+  ! Number . isNaN ( currentFiat )  && 
313+  quotedCrypto  >  0  && 
314+  capValue  <  quotedCrypto 
315+  )  { 
316+  const  scaledFiat  =  ( currentFiat  *  capValue )  /  quotedCrypto 
317+  if  ( scaledFiat  <  revolutFiat . min_limit )  { 
318+  throw  new  FiatProviderError ( { 
319+  providerId : pluginId , 
320+  errorType : 'underLimit' , 
321+  errorAmount : revolutFiat . min_limit , 
322+  displayCurrencyCode : revolutFiat . currency 
323+  } ) 
324+  } 
325+  amount  =  scaledFiat . toString ( ) 
326+  quoteData  =  await  fetchRevolutQuote ( 
327+  { 
328+  fiat : revolutFiat . currency , 
329+  amount, 
330+  crypto : revolutCrypto . id , 
331+  payment : 'revolut' , 
332+  region : regionCode . countryCode 
333+  } , 
334+  {  apiKey,  baseUrl : apiUrl  } 
335+  ) 
336+  } 
337+  } 
338+ 301339 const  cryptoAmount  =  quoteData . crypto . amount . toString ( ) 
302-  const  fiatAmount  =  exchangeAmount 
340+  const  fiatAmount  =  amount 
303341
304342 // Assume 1 minute expiration 
305343 const  expirationDate  =  new  Date ( Date . now ( )  +  1000  *  60 ) 
0 commit comments