forked from mito-systems/sol-mem-gen
Update BN round up logic
This commit is contained in:
parent
7aa0d44f61
commit
33350b263e
@ -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
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user