@@ -73,6 +73,7 @@ const addressTypeMap: StringMap = {
7373}
7474
7575const swapType = 'fixed' as const
76+ const ccyAmountLimitRegex = / c c y A m o u n t m u s t b e ( [ > < ] ) \s * ( [ \d . ] + ) /
7677
7778export function makeXgramPlugin ( opts : EdgeCorePluginOptions ) : EdgeSwapPlugin {
7879 const { io } = opts
@@ -189,6 +190,24 @@ export function makeXgramPlugin(opts: EdgeCorePluginOptions): EdgeSwapPlugin {
189190 throw new Error ( 'Xgram create order error' )
190191 }
191192
193+ if ( 'error' in quoteReply ) {
194+ const match = ccyAmountLimitRegex . exec ( quoteReply . error )
195+ if ( match != null ) {
196+ const [ , direction , limitStr ] = match
197+ const nativeLimit = denominationToNative (
198+ isSelling ? request . fromWallet : request . toWallet ,
199+ limitStr ,
200+ isSelling ? request . fromTokenId : request . toTokenId
201+ )
202+ if ( direction === '>' ) {
203+ throw new SwapBelowLimitError ( swapInfo , nativeLimit , quoteFor )
204+ }
205+ throw new SwapAboveLimitError ( swapInfo , nativeLimit , quoteFor )
206+ }
207+
208+ throw new Error ( `Xgram: ${ quoteReply . error } ` )
209+ }
210+
192211 return {
193212 id : quoteReply . id ,
194213 validUntil : quoteReply . expiresAt ,
@@ -349,6 +368,9 @@ const asXgramError = asObject({
349368 asEither ( asXgramLimitError , asXgramRegionError , asXgramCurrencyError )
350369 )
351370} )
371+ const asXgramStringError = asObject ( {
372+ error : asString
373+ } )
352374const asXgramQuote = asObject ( {
353375 ccyAmountToExpected : asEither ( asNumber , asString ) ,
354376 depositAddress : asString ,
@@ -358,4 +380,8 @@ const asXgramQuote = asObject({
358380 expiresAt : asOptional ( asDate ) ,
359381 ccyAmountFrom : asString
360382} )
361- const asXgramQuoteReply = asEither ( asXgramQuote , asXgramError )
383+ const asXgramQuoteReply = asEither (
384+ asXgramQuote ,
385+ asXgramError ,
386+ asXgramStringError
387+ )
0 commit comments