diff --git a/README.md b/README.md index a5df495..8312eca 100644 --- a/README.md +++ b/README.md @@ -10,21 +10,5 @@ yarn add @aurora-is-near/staking ## Usage -Wrap your application in a `StakingProvider`, for example: - -```tsx - -

Hello, World!

-
-``` - -Then access the staking functionality via the `useStaking` hook: - -```tsx -const staking = useStaking(); - -console.log(staking.balance) // => 1337 -``` +Wrap your application in a `StakingProvider`, then access the staking +functionality via the `useStaking` hook. diff --git a/src/provider.tsx b/src/provider.tsx index 6409974..b1c6e97 100644 --- a/src/provider.tsx +++ b/src/provider.tsx @@ -11,7 +11,6 @@ import { getIsPaused, getPendingWithdrawals, getStreamedAmounts, - getStreamPrices, getStreamsProgress, getStreamsSchedule, getTotalShares, @@ -37,12 +36,17 @@ type StakingProviderProps = { isConnected: boolean; network: AuroraNetwork; children: ReactNode; + getStreamPrices: (streamNames: string[]) => Promise<{ + prices: number[]; + marketCaps: number[]; + }>; }; export const StakingProvider = ({ isConnected, network, children, + getStreamPrices, }: StakingProviderProps) => { const networkConfig = config[network]; const { tokenStreams } = networkConfig; diff --git a/src/utils.ts b/src/utils.ts index b7ce73e..1e7dd81 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,4 +1,3 @@ -import { differenceInMinutes } from 'date-fns'; import { BigNumber, ethers, providers } from 'ethers'; import { stakingAbi } from './abis/staking'; import { erc20abi } from './abis/erc20'; @@ -262,54 +261,6 @@ export const calculateStakedPctOfSupply = ( return pct; }; -export const getStreamPrices = async ( - names: string[], -): Promise<{ prices: number[]; marketCaps: number[] }> => { - // Token ids in coingecko: https://docs.google.com/spreadsheets/d/1wTTuxXt8n9q7C4NDXqQpI3wpKu1_5bGVmP9Xz0XGSyU/ - - let refetch = false; - let data: any = null; - - // Get cached data from localStorage - const localStorageData = localStorage.getItem('stream-prices'); - - data = localStorageData && JSON.parse(localStorageData); - - // If there's no data or it's over a minute old, refetch - if ( - !data || - (data?.timestamp && - differenceInMinutes(new Date(), new Date(data.timestamp)) > 0) - ) { - refetch = true; - } - - if (refetch) { - // Get fresh data and save to localStorage - const url = `/api/market/prices`; - const response = await fetch(url, { - method: 'GET', - headers: { - 'Content-Type': 'application/json', - }, - }); - - data = await response.json(); - - localStorage.setItem( - 'stream-prices', - JSON.stringify({ ...data, timestamp: Date.now() }), - ); - } - - return { - prices: names.map((name) => (name === 'vote' ? 0 : data[name].usd)), - marketCaps: names.map((name) => - name === 'vote' ? 0 : data[name].usd_market_cap, - ), - }; -}; - export const getIsPaused = async ( provider: providers.JsonRpcProvider, networkConfig: AuroraNetworkConfig, @@ -322,7 +273,7 @@ export const getIsPaused = async ( const pausedFlag = await staking.paused(); - return !!(pausedFlag.toNumber() & 1); + return pausedFlag.toNumber() === 1; }; export const approveStaking = async (