Skip to content

Commit

Permalink
feat: switch widget api to eth api
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeday committed Jul 3, 2024
1 parent b424cda commit 262b8cc
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 21 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ yarn build:ipfs

## Adding a new route API

**Deprecated: do not add new endpoints to next api**

- create a new file in `pages/api/` folder
- use `wrapRequest` function from `@lidofinance/next-api-wrapper` package.
- use default wrappers from `utilsApi/nextApiWrappers.ts` if needed (e.g. `defaultErrorHandler` for handle errors)
Expand Down
12 changes: 4 additions & 8 deletions shared/hooks/useLidoStats.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { useMemo } from 'react';
import { useSDK, useLidoSWR } from '@lido-sdk/react';
import { useLidoSWR } from '@lido-sdk/react';

import { config } from 'config';
import { DATA_UNAVAILABLE } from 'consts/text';
import { STRATEGY_LAZY } from 'consts/swr-strategies';
import { prependBasePath } from 'utils';
import { standardFetcher } from 'utils/standardFetcher';

export type ResponseData = {
type ResponseData = {
uniqueAnytimeHolders: string;
uniqueHolders: string;
totalStaked: string;
Expand All @@ -22,12 +21,9 @@ export const useLidoStats = (): {
};
initialLoading: boolean;
} => {
const { chainId } = useSDK();
const apiShortLidoStatsPath = `api/short-lido-stats?chainId=${chainId}`;
const url = `${config.ethAPIBasePath}/v1/protocol/steth/stats`;
const lidoStats = useLidoSWR<ResponseData>(
config.ipfsMode
? `${config.widgetApiBasePathForIpfs}/${apiShortLidoStatsPath}`
: prependBasePath(apiShortLidoStatsPath),
url,
standardFetcher,
STRATEGY_LAZY,
);
Expand Down
9 changes: 2 additions & 7 deletions utils/get-one-inch-rate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { BigNumber } from 'ethers';
import { TOKENS } from '@lido-sdk/constants';
import { config } from 'config';
import { standardFetcher } from './standardFetcher';
import { prependBasePath } from './prependBasePath';

type GetOneInchRateParams = {
token: TOKENS.STETH | TOKENS.WSTETH | 'ETH';
Expand All @@ -15,15 +14,11 @@ export const getOneInchRate = async ({
}: GetOneInchRateParams) => {
const params = new URLSearchParams({ token });
if (amount) params.append('amount', amount.toString());
const apiOneInchRatePath = `api/oneinch-rate?${params.toString()}`;
const url = `${config.ethAPIBasePath}/v1/swap/one-inch?${params.toString()}`;
const data = await standardFetcher<{
rate: number;
toReceive: string;
}>(
config.ipfsMode
? `${config.widgetApiBasePathForIpfs}/${apiOneInchRatePath}`
: prependBasePath(apiOneInchRatePath),
);
}>(url);
return {
rate: data.rate,
toReceive: BigNumber.from(data.toReceive),
Expand Down
1 change: 0 additions & 1 deletion utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ export * from './appCookies';
export * from './formatBalance';
export * from './formatBalanceString';
export * from './logger';
export * from './prependBasePath';
export * from './weiToEth';
export * from './nprogress';
export * from './getErrorMessage';
Expand Down
5 changes: 0 additions & 5 deletions utils/prependBasePath.ts

This file was deleted.

0 comments on commit 262b8cc

Please sign in to comment.