{"version":3,"file":"StakingAPI.DIRx6TET.mjs","names":[],"sources":["https:/framerusercontent.com/modules/IR9ubgy4gVQsRArdrPOG/q9hBhy3aiGhIkvvdA2Et/StakingAPI.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import{useEffect}from\"react\";import{createStore}from\"https://framer.com/m/framer/store.js@^1.0.0\";// --- DOT Price Store ---\nconst useDotPriceStore=createStore({price:null,change:null,lastUpdate:0});// --- Rewards Rate Store ---\nconst useRewardsRateStore=createStore({rate:null,lastUpdate:0});// --- Supply Staked Store ---\nconst useSupplyStakedStore=createStore({percent:null,lastUpdate:0});// --- Staking Participants Store (Validators & Nominators) ---\nconst useStakingParticipantsStore=createStore({totalValidators:null,totalNominators:null,lastUpdate:0});// --- Unified Fetch Function ---\nconst fetchAllStats=async({setDotPrice,setRewardsRate,setSupplyStaked,setStakingParticipants})=>{try{const response=await fetch(\"https://api.staking.polkadot.cloud/\",{method:\"POST\",headers:{\"Content-Type\":\"application/json\"},body:JSON.stringify({query:`\n                  query AllStats($chain: String!, $ticker: String!, $network: String!) {\n                    tokenPrice(ticker: $ticker) { price change }\n                    averageRewardRate(chain: $chain) { rate }\n                    supplyStaked(chain: $chain) { supplyStakedPercent }\n                    stakingParticipants(network: $network) { totalValidators totalNominators }\n                  }\n                `,variables:{chain:\"polkadot\",ticker:\"DOTUSDT\",network:\"polkadot\"}})});const data=await response.json();// --- Update DOT Price Store ---\nconst priceValue=data?.data?.tokenPrice?.price;const changeValue=data?.data?.tokenPrice?.change;setDotPrice({price:typeof priceValue===\"number\"?priceValue:null,change:typeof changeValue===\"number\"?changeValue:null,lastUpdate:Date.now()});// --- Update Rewards Rate Store ---\nconst rateValue=data?.data?.averageRewardRate?.rate;setRewardsRate({rate:typeof rateValue===\"number\"?rateValue:null,lastUpdate:Date.now()});// --- Update Supply Staked Store ---\nconst percentValue=data?.data?.supplyStaked?.supplyStakedPercent;setSupplyStaked({percent:percentValue?Number(percentValue).toFixed(2):null,lastUpdate:Date.now()});// --- Update Staking Participants Store ---\nconst counts=data?.data?.stakingParticipants;setStakingParticipants({totalValidators:counts?.totalValidators??null,totalNominators:counts?.totalNominators??null,lastUpdate:Date.now()});}catch(e){// Don't set state if there's an error - keep previous values\nconsole.log(\"Error fetching stats:\",e);}};// --- Shared Polling Hook ---\nfunction useAllStatsPolling(){const[,setDotPrice]=useDotPriceStore();const[,setRewardsRate]=useRewardsRateStore();const[,setSupplyStaked]=useSupplyStakedStore();const[,setStakingParticipants]=useStakingParticipantsStore();useEffect(()=>{// Fetch immediately on mount\nfetchAllStats({setDotPrice,setRewardsRate,setSupplyStaked,setStakingParticipants});// Poll every 30 seconds\nconst interval=setInterval(()=>{fetchAllStats({setDotPrice,setRewardsRate,setSupplyStaked,setStakingParticipants});},3e4);return()=>clearInterval(interval);},[]);}// --- HOCs for Framer Components ---\nexport function withDotPrice(Component){return props=>{useAllStatsPolling();const[store]=useDotPriceStore();let displayText=\"...\";if(store.price!==null)displayText=`$${Number(store.price).toFixed(2)}`;return /*#__PURE__*/_jsx(Component,{...props,text:displayText});};}export function withDotPriceChangePositive(Component){return props=>{useAllStatsPolling();const[store]=useDotPriceStore();// Hide during loading\nif(store.change===undefined||store.change===null){return /*#__PURE__*/_jsx(Component,{...props,text:\"\",style:{opacity:0,pointerEvents:\"none\"}});}const changeValue=parseFloat(store.change);// Show only if positive or zero\nif(changeValue>=0){const displayText=`+${changeValue.toFixed(2)}%`;return /*#__PURE__*/_jsx(Component,{...props,text:displayText,style:{opacity:1}});}else{// Hide if negative\nreturn /*#__PURE__*/_jsx(Component,{...props,text:\"\",style:{opacity:0,pointerEvents:\"none\"}});}};}export function withDotPriceChangeNegative(Component){return props=>{useAllStatsPolling();const[store]=useDotPriceStore();// Hide during loading\nif(store.change===undefined||store.change===null){return /*#__PURE__*/_jsx(Component,{...props,text:\"\",style:{opacity:0,pointerEvents:\"none\"}});}const changeValue=parseFloat(store.change);// Show only if negative\nif(changeValue<0){const displayText=`${changeValue.toFixed(2)}%`;return /*#__PURE__*/_jsx(Component,{...props,text:displayText,style:{opacity:1}});}else{// Hide if positive\nreturn /*#__PURE__*/_jsx(Component,{...props,text:\"\",style:{opacity:0,pointerEvents:\"none\"}});}};}export function withOneDotPrice(Component){return props=>{useAllStatsPolling();const[store]=useDotPriceStore();let displayText=\"...\";if(store.price!==null)displayText=`1 DOT / $${Number(store.price).toFixed(2)}`;return /*#__PURE__*/_jsx(Component,{...props,text:displayText});};}export function withRewardsRate(Component){return props=>{useAllStatsPolling();const[store]=useRewardsRateStore();let displayText=\"...\";if(store.rate!==null)displayText=`${Number(store.rate).toFixed(2)}%`;return /*#__PURE__*/_jsx(Component,{...props,text:displayText});};}export function withSupplyStaked(Component){return props=>{useAllStatsPolling();const[store]=useSupplyStakedStore();let displayText=\"...\";if(store.percent!==null)displayText=`${store.percent}%`;return /*#__PURE__*/_jsx(Component,{...props,text:displayText});};}export function withTotalNominators(Component){return props=>{useAllStatsPolling();const[store]=useStakingParticipantsStore();let displayText=\"...\";if(store.totalNominators!==null)displayText=`${Number(store.totalNominators).toLocaleString()}`;return /*#__PURE__*/_jsx(Component,{...props,text:displayText});};}export function withTotalValidators(Component){return props=>{useAllStatsPolling();const[store]=useStakingParticipantsStore();let displayText=\"...\";if(store.totalValidators!==null)displayText=`${Number(store.totalValidators).toLocaleString()}`;return /*#__PURE__*/_jsx(Component,{...props,text:displayText});};}\nexport const __FramerMetadata__ = {\"exports\":{\"withDotPriceChangeNegative\":{\"type\":\"reactHoc\",\"name\":\"withDotPriceChangeNegative\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withTotalValidators\":{\"type\":\"reactHoc\",\"name\":\"withTotalValidators\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withDotPriceChangePositive\":{\"type\":\"reactHoc\",\"name\":\"withDotPriceChangePositive\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withSupplyStaked\":{\"type\":\"reactHoc\",\"name\":\"withSupplyStaked\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withTotalNominators\":{\"type\":\"reactHoc\",\"name\":\"withTotalNominators\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withOneDotPrice\":{\"type\":\"reactHoc\",\"name\":\"withOneDotPrice\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withDotPrice\":{\"type\":\"reactHoc\",\"name\":\"withDotPrice\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withRewardsRate\":{\"type\":\"reactHoc\",\"name\":\"withRewardsRate\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./StakingAPI.map"],"mappings":"0OAkBA,SAAS,GAAoB,CAAC,GAAK,EAAE,GAAa,GAAkB,CAAM,EAAE,GAAgB,GAAqB,CAAM,EAAE,GAAiB,GAAsB,CAAM,EAAE,GAAwB,GAA6B,CAAC,MAAc,CAC5O,EAAc,CAAC,cAAY,iBAAe,kBAAgB,yBAAuB,CAAC,CAClF,IAAM,EAAS,gBAAgB,CAAC,EAAc,CAAC,cAAY,iBAAe,kBAAgB,yBAAuB,CAAC,EAAG,IAAI,CAAC,UAAU,cAAc,EAAS,EAAG,EAAE,CAAC,CAOwN,SAAgB,EAAgB,EAAU,CAAC,MAAO,IAAO,CAAC,GAAoB,CAAC,GAAK,CAAC,GAAO,GAAqB,CAAK,EAAY,MAA2E,OAAlE,EAAM,OAAO,OAAK,EAAY,GAAG,OAAO,EAAM,KAAK,CAAC,QAAQ,EAAE,CAAC,IAAuB,EAAK,EAAU,CAAC,GAAG,EAAM,KAAK,EAAY,CAAC,EAAI,SAAgB,EAAiB,EAAU,CAAC,MAAO,IAAO,CAAC,GAAoB,CAAC,GAAK,CAAC,GAAO,GAAsB,CAAK,EAAY,MAA8D,OAArD,EAAM,UAAU,OAAK,EAAY,GAAG,EAAM,QAAQ,IAAuB,EAAK,EAAU,CAAC,GAAG,EAAM,KAAK,EAAY,CAAC,EAAI,SAAgB,EAAoB,EAA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