11import {
2- calculateRatio ,
32 direction2Symbol ,
3+ previewConversion ,
44 reservedCKB ,
55 symbol2Direction ,
66 toText ,
77} from "./utils.ts" ;
8- import { CKB , max , min , type I8Header } from "@ickb/lumos-utils" ;
8+ import { CKB , max , min } from "@ickb/lumos-utils" ;
9+ import type { OrderRatio } from "@ickb/v1-core" ;
910import type { JSX } from "react" ;
1011
1112export default function Form ( {
1213 rawText,
1314 setRawText,
1415 amount,
15- tipHeader ,
16+ calculateRatio ,
1617 isFrozen,
1718 ckbNative,
1819 ickbNative,
@@ -24,7 +25,7 @@ export default function Form({
2425 rawText : string ;
2526 setRawText : ( s : string ) => void ;
2627 amount : bigint ;
27- tipHeader : I8Header ;
28+ calculateRatio : ( isCkb2Udt : boolean , amount : bigint ) => OrderRatio ;
2829 isFrozen : boolean ;
2930 ckbNative : bigint ;
3031 ickbNative : bigint ;
@@ -98,10 +99,10 @@ export default function Form({
9899 ⇌
99100 </ button >
100101 < span className = "text-center" >
101- { approxConversion ( isCkb2Udt , CKB , tipHeader ) + " " + b . name }
102+ { textConversionPreview ( isCkb2Udt , CKB , calculateRatio ) } { b . name }
102103 </ span >
103104 < span className = "col-span-3 text-center text-3xl text-amber-400" >
104- ⏳{ approxConversion ( isCkb2Udt , amount , tipHeader ) }
105+ ⏳{ textConversionPreview ( isCkb2Udt , amount , calculateRatio ) }
105106 </ span >
106107 < span className = "text-amber-400" > { display ( b . native , "✅" ) } </ span >
107108 < span className = "text-2xl text-amber-400" > { b . name } </ span >
@@ -127,17 +128,12 @@ function display(shannons: bigint, prefix: string): JSX.Element {
127128 ) ;
128129}
129130
130- function approxConversion (
131+ function textConversionPreview (
131132 isCkb2Udt : boolean ,
132133 amount : bigint ,
133- tipHeader : I8Header ,
134+ calculateRatio : ( isCkb2Udt : boolean , amount : bigint ) => OrderRatio ,
134135) : string {
135- //Worst case scenario is a 0.1% fee for bot
136- const { ckbMultiplier, udtMultiplier } = calculateRatio ( isCkb2Udt , tipHeader ) ;
137-
138- const convertedAmount = isCkb2Udt
139- ? ( amount * ckbMultiplier ) / udtMultiplier
140- : ( amount * udtMultiplier ) / ckbMultiplier ;
141-
142- return toText ( convertedAmount ) ;
136+ return toText (
137+ previewConversion ( isCkb2Udt , amount , calculateRatio ( isCkb2Udt , amount ) ) ,
138+ ) ;
143139}
0 commit comments