1- use std:: str:: FromStr ;
2-
31use primitives:: currency:: Currency ;
42use primitives:: { AssetId , Chain , FiatProviderName , FiatQuoteType , FiatTransaction , FiatTransactionStatus , PaymentType } ;
53use streamer:: FiatWebhook ;
64
75use crate :: model:: FiatProviderAsset ;
8- use crate :: providers:: paybis:: models:: { PaybisData , PaymentMethodWithLimits } ;
96use primitives:: fiat_assets:: FiatAssetLimits ;
107
118use super :: {
129 client:: PaybisClient ,
13- models:: { Currency as PaybisCurrency , PaybisWebhookData } ,
10+ models:: { Currency as PaybisCurrency , PaybisData , PaybisWebhookData } ,
1411} ;
1512
1613pub fn map_asset_id ( currency : PaybisCurrency ) -> Option < AssetId > {
@@ -137,7 +134,16 @@ pub fn map_webhook_data(webhook_data: PaybisWebhookData) -> FiatWebhook {
137134 } )
138135}
139136
140- fn map_asset ( currency : PaybisCurrency , buy_limits : Vec < FiatAssetLimits > , sell_limits : Vec < FiatAssetLimits > ) -> Option < FiatProviderAsset > {
137+ fn default_buy_limits ( ) -> Vec < FiatAssetLimits > {
138+ vec ! [ FiatAssetLimits {
139+ currency: Currency :: USD ,
140+ payment_type: PaymentType :: Card ,
141+ min_amount: None ,
142+ max_amount: None ,
143+ } ]
144+ }
145+
146+ fn map_asset ( currency : PaybisCurrency ) -> Option < FiatProviderAsset > {
141147 if !currency. is_crypto ( ) {
142148 return None ;
143149 }
@@ -151,52 +157,13 @@ fn map_asset(currency: PaybisCurrency, buy_limits: Vec<FiatAssetLimits>, sell_li
151157 network : currency. blockchain_name . clone ( ) ,
152158 enabled : true ,
153159 unsupported_countries : Some ( currency. unsupported_countries ( ) ) ,
154- buy_limits,
155- sell_limits,
160+ buy_limits : default_buy_limits ( ) ,
161+ sell_limits : vec ! [ ] ,
156162 } )
157163}
158164
159165pub fn map_assets ( currencies : Vec < PaybisCurrency > ) -> Vec < FiatProviderAsset > {
160- currencies. into_iter ( ) . flat_map ( |currency| map_asset ( currency, vec ! [ ] , vec ! [ ] ) ) . collect ( )
161- }
162-
163- fn map_payment_type ( payment_method_name : & str ) -> Option < PaymentType > {
164- match payment_method_name {
165- "gem-wallet-credit-card" => Some ( PaymentType :: Card ) ,
166- "gem-wallet-google-pay-credit-card" => Some ( PaymentType :: GooglePay ) ,
167- "gem-wallet-apple-pay-credit-card" => Some ( PaymentType :: ApplePay ) ,
168- _ => None ,
169- }
170- }
171-
172- pub fn map_assets_with_limits ( currencies : Vec < PaybisCurrency > , limits : & PaybisData < Vec < PaymentMethodWithLimits > > ) -> Vec < FiatProviderAsset > {
173- currencies
174- . into_iter ( )
175- . filter_map ( |currency| {
176- let asset_buy_limits = limits
177- . data
178- . iter ( )
179- . filter_map ( |payment_method| map_payment_type ( & payment_method. name ) . map ( |payment_type| ( payment_method, payment_type) ) )
180- . flat_map ( |( payment_method, payment_type) | {
181- payment_method. pairs . iter ( ) . filter_map ( {
182- let value = currency. code . clone ( ) ;
183- move |currency_pair| {
184- currency_pair. to . iter ( ) . find ( |c| c. currency_code == value) . and_then ( |currency_limit| {
185- Currency :: from_str ( currency_pair. from . as_str ( ) ) . ok ( ) . map ( |fiat_currency| FiatAssetLimits {
186- currency : fiat_currency,
187- payment_type : payment_type. clone ( ) ,
188- min_amount : Some ( currency_limit. min_amount ) ,
189- max_amount : Some ( currency_limit. max_amount ) ,
190- } )
191- } )
192- }
193- } )
194- } )
195- . collect ( ) ;
196-
197- map_asset ( currency, asset_buy_limits, vec ! [ ] )
198- } )
199- . collect ( )
166+ currencies. into_iter ( ) . flat_map ( map_asset) . collect ( )
200167}
201168
202169#[ cfg( test) ]
@@ -350,40 +317,13 @@ mod tests {
350317 }
351318
352319 #[ test]
353- fn test_paybis_limits_parsing ( ) -> Result < ( ) , Box < dyn std:: error:: Error + Send + Sync > > {
354- let limits: PaybisData < Vec < PaymentMethodWithLimits > > = serde_json:: from_str ( include_str ! ( "../../../testdata/paybis/assets_with_limits.json" ) ) ?;
355-
356- let test_currencies = vec ! [
357- PaybisCurrency {
358- code: "USDT-TRC20" . to_string( ) ,
359- blockchain_name: Some ( "tron" . to_string( ) ) ,
360- } ,
361- PaybisCurrency {
362- code: "TRX" . to_string( ) ,
363- blockchain_name: Some ( "tron" . to_string( ) ) ,
364- } ,
365- PaybisCurrency {
366- code: "XRP" . to_string( ) ,
367- blockchain_name: Some ( "xrp" . to_string( ) ) ,
368- } ,
369- ] ;
370-
371- let mapped_assets = map_assets_with_limits ( test_currencies, & limits) ;
372-
373- // Test that assets with limits have expected min/max amounts
374- let usdt_trc20 = mapped_assets. iter ( ) . find ( |a| a. symbol == "USDT-TRC20" ) . expect ( "USDT-TRC20 should exist" ) ;
375- assert ! ( !usdt_trc20. buy_limits. is_empty( ) , "USDT-TRC20 should have buy limits" ) ;
376-
377- // Find USD limit
378- let usd_limit = usdt_trc20. buy_limits . iter ( ) . find ( |limit| limit. currency == Currency :: USD ) ;
379- assert ! ( usd_limit. is_some( ) , "Should have USD limit" ) ;
380-
381- if let Some ( limit) = usd_limit {
382- assert_eq ! ( limit. min_amount, Some ( 5.0 ) ) ;
383- assert_eq ! ( limit. max_amount, Some ( 20000.0 ) ) ;
384- assert_eq ! ( limit. payment_type, PaymentType :: Card ) ;
385- }
386-
387- Ok ( ( ) )
320+ fn test_default_buy_limits ( ) {
321+ let limits = default_buy_limits ( ) ;
322+
323+ assert_eq ! ( limits. len( ) , 1 ) ;
324+ assert_eq ! ( limits[ 0 ] . currency, Currency :: USD ) ;
325+ assert_eq ! ( limits[ 0 ] . payment_type, PaymentType :: Card ) ;
326+ assert_eq ! ( limits[ 0 ] . min_amount, None ) ;
327+ assert_eq ! ( limits[ 0 ] . max_amount, None ) ;
388328 }
389329}
0 commit comments