Update BN round up logic

This commit is contained in:
Adw8 2025-02-06 16:37:05 +05:30
parent 7aa0d44f61
commit 33350b263e

View File

@ -62,18 +62,17 @@ const Page: React.FC = (): React.ReactElement => {
}
}
const roundUpBN = (bnValue: BN) : BN => {
// Divide by 10^6
const decimalBN = bnValue.div(new BN (10 ** 6));
// Conver to Big decimal
const bigValue = new Big(decimalBN.toString())
// Ceil the result
const ceiledValue = bigValue.add(1);
// Convert back to BN
const ceiledBN = new BN(ceiledValue.toString());
// Multiple by 10^6
return ceiledBN.mul(new BN (10 ** 6))
}
const roundUpBigNumber = (bnValue: BN): BN => {
const bigNumber = new Big(bnValue.toString());
const bigNumberInUnits = bigNumber.div(new Big(10 ** 6));
const roundedUpValue = bigNumberInUnits.round(0, Big.roundUp);
// Multiply by 10^6 to revert back to original scale
const scaledValue = roundedUpValue.mul(new Big(10 ** 6));
return new BN(scaledValue.toString());
};
const handleFluxGeneration = (modelId: string, cost: BN) => {
return async (prompt: string): Promise<FluxGenerationResult> => {
@ -89,7 +88,7 @@ const Page: React.FC = (): React.ReactElement => {
// Convert cost in USDC to MTM tokens using the price ratio
const paymentResult = await processMTMPayment(
publicKey,
roundUpBN(cost),
roundUpBigNumber(cost),
type
)