@@ -459,9 +459,10 @@ pub async fn get_decimals(
459
459
let conn = pool. get ( ) . await . map_err ( adapt_infra_error) ?;
460
460
461
461
let quote_currency = pair_id. split ( '/' ) . last ( ) . unwrap ( ) . to_uppercase ( ) ;
462
+ let base_currency = pair_id. split ( '/' ) . next ( ) . unwrap ( ) . to_uppercase ( ) ;
462
463
463
464
// Fetch currency in DB
464
- let decimals : BigDecimal = conn
465
+ let quote_decimals : BigDecimal = conn
465
466
. interact ( move |conn| {
466
467
currencies:: table
467
468
. filter ( currencies:: name. eq ( quote_currency) )
@@ -471,8 +472,24 @@ pub async fn get_decimals(
471
472
. await
472
473
. map_err ( adapt_infra_error) ?
473
474
. map_err ( adapt_infra_error) ?;
475
+ let base_decimals: BigDecimal = conn
476
+ . interact ( move |conn| {
477
+ currencies:: table
478
+ . filter ( currencies:: name. eq ( base_currency) )
479
+ . select ( currencies:: decimals)
480
+ . first :: < BigDecimal > ( conn)
481
+ } )
482
+ . await
483
+ . map_err ( adapt_infra_error) ?
484
+ . map_err ( adapt_infra_error) ?;
485
+
486
+ // Take the minimum of the two
487
+ let decimals = std:: cmp:: min (
488
+ quote_decimals. to_u32 ( ) . unwrap ( ) ,
489
+ base_decimals. to_u32 ( ) . unwrap ( ) ,
490
+ ) ;
474
491
475
- Ok ( decimals. to_u32 ( ) . unwrap ( ) )
492
+ Ok ( decimals)
476
493
}
477
494
478
495
#[ derive( Debug , Clone , Serialize , Deserialize , Queryable ) ]
0 commit comments