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 => {
|
const roundUpBigNumber = (bnValue: BN): BN => {
|
||||||
// Divide by 10^6
|
const bigNumber = new Big(bnValue.toString());
|
||||||
const decimalBN = bnValue.div(new BN (10 ** 6));
|
const bigNumberInUnits = bigNumber.div(new Big(10 ** 6));
|
||||||
// Conver to Big decimal
|
|
||||||
const bigValue = new Big(decimalBN.toString())
|
const roundedUpValue = bigNumberInUnits.round(0, Big.roundUp);
|
||||||
// Ceil the result
|
|
||||||
const ceiledValue = bigValue.add(1);
|
// Multiply by 10^6 to revert back to original scale
|
||||||
// Convert back to BN
|
const scaledValue = roundedUpValue.mul(new Big(10 ** 6));
|
||||||
const ceiledBN = new BN(ceiledValue.toString());
|
|
||||||
// Multiple by 10^6
|
return new BN(scaledValue.toString());
|
||||||
return ceiledBN.mul(new BN (10 ** 6))
|
};
|
||||||
}
|
|
||||||
|
|
||||||
const handleFluxGeneration = (modelId: string, cost: BN) => {
|
const handleFluxGeneration = (modelId: string, cost: BN) => {
|
||||||
return async (prompt: string): Promise<FluxGenerationResult> => {
|
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
|
// Convert cost in USDC to MTM tokens using the price ratio
|
||||||
const paymentResult = await processMTMPayment(
|
const paymentResult = await processMTMPayment(
|
||||||
publicKey,
|
publicKey,
|
||||||
roundUpBN(cost),
|
roundUpBigNumber(cost),
|
||||||
type
|
type
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user