forked from mito-systems/sol-mem-gen
Update method to convert base units to decimal
This commit is contained in:
parent
2806fd344a
commit
41470fc895
@ -24,7 +24,7 @@ class QuotesService {
|
||||
|
||||
const quoteResponse = await response.json();
|
||||
|
||||
// Handle price with Big.js, then convert to BN
|
||||
// Handle price with big.js, then convert to bn.js instance
|
||||
const priceMTMFor1USDC = new Big(quoteResponse['data'][USDC_MINT]['price']).toFixed(6);
|
||||
const priceMTMFor1USDCInBaseUnits = new BN(new Big(priceMTMFor1USDC).times(new Big(10).pow(6)).toString());
|
||||
|
||||
|
@ -53,8 +53,8 @@ export async function POST(req: NextRequest): Promise<NextResponse> {
|
||||
const scale = new BN(100);
|
||||
const scaledModelCost = new BN(model.cost).mul(scale);
|
||||
|
||||
const lowestTokenAmount = scaledModelCost.mul(new BN(lowestAmountOfMTM)).div(scale);
|
||||
const isPaymentVerified = await verifyPayment(transactionSignature, lowestTokenAmount);
|
||||
const lowestTokenAmountForModel = scaledModelCost.mul(new BN(lowestAmountOfMTM)).div(scale);
|
||||
const isPaymentVerified = await verifyPayment(transactionSignature, lowestTokenAmountForModel);
|
||||
|
||||
if (!isPaymentVerified) {
|
||||
return NextResponse.json(
|
||||
|
@ -121,8 +121,8 @@ const Page: React.FC = (): React.ReactElement => {
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-6">
|
||||
{FLUX_MODELS.map((model) => {
|
||||
// Convert cost from number to BN
|
||||
const costBN = new BN(model.cost * 100);
|
||||
const priceMTM = costBN.mul(priceMTMFor1USDC).div(new BN(100));
|
||||
const scaledModelCost = new BN(model.cost * 100);
|
||||
const priceMTM = scaledModelCost.mul(priceMTMFor1USDC).div(new BN(100));
|
||||
|
||||
return (
|
||||
<AIServiceCard
|
||||
|
@ -19,7 +19,7 @@ interface GenerationState {
|
||||
error: string | null
|
||||
}
|
||||
|
||||
const formatBNWithDecimals = (value: BN, decimals: number): string => {
|
||||
const baseUnitToDecimalFormat = (value: BN, decimals: number): string => {
|
||||
const bigValue = new Big(value.toString());
|
||||
const factor = new Big(10).pow(decimals);
|
||||
|
||||
@ -95,7 +95,7 @@ const AIServiceCard: React.FC<AIServiceCardProps> = ({
|
||||
</h2>
|
||||
<p className="text-gray-400 mt-2">{description}</p>
|
||||
<div className="mt-2 inline-block px-3 py-1 bg-green-500/20 rounded-full text-green-300 text-sm">
|
||||
Cost: {priceMTM ? formatBNWithDecimals(priceMTM, 6) : '...'} MTM
|
||||
Cost: {priceMTM ? baseUnitToDecimalFormat(priceMTM, 6) : '...'} MTM
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -119,7 +119,7 @@ const AIServiceCard: React.FC<AIServiceCardProps> = ({
|
||||
transition-all duration-200 shadow-lg hover:shadow-green-500/25
|
||||
disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:shadow-none"
|
||||
>
|
||||
{generationState.loading ? 'Processing...' : `Pay ${priceMTM ? formatBNWithDecimals(priceMTM, 6) : '...'} MTM & Generate`}
|
||||
{generationState.loading ? 'Processing...' : `Pay ${priceMTM ? baseUnitToDecimalFormat(priceMTM, 6) : '...'} MTM & Generate`}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user