Skip to content

Commit 6c253a1

Browse files
committed
move utils
1 parent a7b0dc8 commit 6c253a1

File tree

4 files changed

+23
-21
lines changed

4 files changed

+23
-21
lines changed

docs/lit-pricing-constants.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Shared constants for Lit Protocol pricing components
1+
// Shared constants and helper functions for Lit Protocol pricing components
22
// This file is automatically included on every page by Mintlify
33

44
window.LitPricingConstants = {
@@ -23,5 +23,21 @@ window.LitPricingConstants = {
2323
perMegabyte: 1,
2424
perCount: 2,
2525
},
26+
27+
// Helper function to convert wei to tokens
28+
weiToTokens: (wei, ethers) => {
29+
if (!ethers || !ethers.utils) {
30+
return 0;
31+
}
32+
return parseFloat(ethers.utils.formatUnits(wei, 18));
33+
},
34+
35+
// Helper function to format price display
36+
formatPrice: (priceInTokens, priceInUSD) => {
37+
if (priceInUSD === null) {
38+
return `${priceInTokens.toFixed(6)} LITKEY`;
39+
}
40+
return `${priceInTokens.toFixed(6)} LITKEY ($${priceInUSD.toFixed(6)})`;
41+
},
2642
};
2743

docs/snippets/CurrentPricesTable.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { weiToTokens, formatPrice } from './PriceProvider';
2-
31
export const CurrentPricesTable = ({ priceData }) => {
4-
// Get constants from window (populated by lit-pricing-constants.js)
2+
// Get constants and helper functions from window (populated by lit-pricing-constants.js)
53
const LitActionPriceComponent = window.LitPricingConstants?.LitActionPriceComponent || {};
64
const NodePriceMeasurement = window.LitPricingConstants?.NodePriceMeasurement || {};
5+
const weiToTokens = window.LitPricingConstants?.weiToTokens || (() => 0);
6+
const formatPrice = window.LitPricingConstants?.formatPrice || ((price) => String(price));
77

88
// Product IDs
99
const ProductId = {

docs/snippets/ExampleLitActionCosts.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { weiToTokens, formatPrice } from './PriceProvider';
2-
31
export const ExampleLitActionCosts = ({ priceData }) => {
4-
// Get constants from window (populated by lit-pricing-constants.js)
2+
// Get constants and helper functions from window (populated by lit-pricing-constants.js)
53
const LitActionPriceComponent = window.LitPricingConstants?.LitActionPriceComponent || {};
64
const NodePriceMeasurement = window.LitPricingConstants?.NodePriceMeasurement || {};
5+
const weiToTokens = window.LitPricingConstants?.weiToTokens || (() => 0);
6+
const formatPrice = window.LitPricingConstants?.formatPrice || ((price) => String(price));
77
if (!priceData) {
88
return (
99
<div style={{ padding: '20px', textAlign: 'center' }}>

docs/snippets/PriceProvider.jsx

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,5 @@
11
import { useEffect, useState } from 'react';
22

3-
export const weiToTokens = (wei, ethers) => {
4-
if (!ethers || !ethers.utils) {
5-
return 0;
6-
}
7-
return parseFloat(ethers.utils.formatUnits(wei, 18));
8-
};
9-
10-
export const formatPrice = (priceInTokens, priceInUSD) => {
11-
if (priceInUSD === null) {
12-
return `${priceInTokens.toFixed(6)} LITKEY`;
13-
}
14-
return `${priceInTokens.toFixed(6)} LITKEY ($${priceInUSD.toFixed(6)})`;
15-
};
16-
173
export const PriceProvider = ({ children, component: Component }) => {
184
// Constants - defined inside component for Mintlify compatibility
195
const NAGA_PROD_PRICE_FEED_ADDRESS = '0x88F5535Fa6dA5C225a3C06489fE4e3405b87608C';

0 commit comments

Comments
 (0)