subOraclePrices
Parameters
Returns
Description
Example Usage
export function useTokenPrice(network: string) {
const [tokenPrice, setTokenPrice] = useState<{ [key: string]: number }>({});
const [isLoading, setIsLoading] = useState<boolean>(false);
const [error, setError] = useState<string | null>(null);
useEffect(() => {
if (isLoading) return;
setIsLoading(true);
const oracleAPI = new OracleAPI(network);
Promise.all([
oracleAPI.subOraclePrices(
Array.from(
new Set([...Object.keys(oracleAPI.consts.pythFeeder.feeder)]),
),
priceInfo => {
setTokenPrice(prevPrice => ({
...prevPrice,
[priceInfo.id]: priceInfo
.getPriceUnchecked()
.getPriceAsNumberUnchecked(),
}));
},
),
])
.then(() => {
setIsLoading(false);
})
.catch(err => {
console.error(err);
setError(err.message);
setIsLoading(false);
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [network]);
return {
tokenPrice,
isLoading,
error,
};
}Last updated