File tree Expand file tree Collapse file tree 4 files changed +23
-21
lines changed
Expand file tree Collapse file tree 4 files changed +23
-21
lines changed Original file line number Diff line number Diff line change 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
44window . 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
Original file line number Diff line number Diff line change 1- import { weiToTokens , formatPrice } from './PriceProvider' ;
2-
31export 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 = {
Original file line number Diff line number Diff line change 1- import { weiToTokens , formatPrice } from './PriceProvider' ;
2-
31export 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' } } >
Original file line number Diff line number Diff line change 11import { 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-
173export const PriceProvider = ( { children, component : Component } ) => {
184 // Constants - defined inside component for Mintlify compatibility
195 const NAGA_PROD_PRICE_FEED_ADDRESS = '0x88F5535Fa6dA5C225a3C06489fE4e3405b87608C' ;
You can’t perform that action at this time.
0 commit comments