{"version":3,"file":"StakingAPI.DzRVDXSU.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,EAAY,CAAC,IAAwB,EAAE,EAAe,CAAC,IAA2B,EAAE,EAAgB,CAAC,IAA4B,EAAE,EAAuB,CAAC,IAA8B,MAAc,CAC5O,EAAc,CAAC,cAAY,iBAAe,kBAAgB,yBAAuB,EACjF,IAAM,EAAS,gBAAgB,CAAC,EAAc,CAAC,cAAY,iBAAe,kBAAgB,yBAAuB,CAAG,EAAC,KAAK,UAAU,cAAc,EAAW,EAAC,EAAE,CAAG,CAOsN,SAAgB,EAAgB,EAAU,CAAC,MAAO,IAAO,CAAC,IAAqB,GAAK,CAAC,EAAM,CAAC,IAA0B,EAAY,MAA2E,OAAlE,EAAM,OAAO,OAAK,EAAY,GAAG,OAAO,EAAM,MAAM,QAAQ,GAAG,IAAuB,EAAK,EAAU,CAAC,GAAG,EAAM,KAAK,EAAY,CAAG,CAAE,UAAgB,EAAiB,EAAU,CAAC,MAAO,IAAO,CAAC,IAAqB,GAAK,CAAC,EAAM,CAAC,IAA2B,EAAY,MAA8D,OAArD,EAAM,UAAU,OAAK,EAAY,GAAG,EAAM,QAAQ,IAAuB,EAAK,EAAU,CAAC,GAAG,EAAM,KAAK,EAAY,CAAG,CAAE,UAAgB,EAAoB,EAAU,CAAC,MAAO,IAAO,CAAC,IAAqB,GA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