Skip to content

Commit

Permalink
feat: Added logo to fetch token function (#657)
Browse files Browse the repository at this point in the history
  • Loading branch information
WingsDevelopment authored Jan 9, 2025
1 parent fc29099 commit c78bd95
Show file tree
Hide file tree
Showing 39 changed files with 1,098 additions and 327 deletions.
839 changes: 813 additions & 26 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"dotenv": "^16.3.1",
"ethereum-blockies-base64": "^1.0.2",
"graphql": "^16.10.0",
"moralis": "^2.27.2",
"path": "^0.12.7",
"react": "^18.2.0",
"react-apexcharts": "^1.4.1",
Expand Down Expand Up @@ -92,4 +93,4 @@
"vitest": "^1.2.2",
"wait-on": "^7.2.0"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ export const useFetchSimulateDeposit = (account: Address, amount: string, subStr
enabled
? rest
: {
...rest,
// todo: solve this differently, review displayvalue component, and render loading state in different way.
isFetched: true,
},
...rest,
// todo: solve this differently, review displayvalue component, and render loading state in different way.
isFetched: true,
},
]),
data: {
bigIntValue: data?.sharesToReceive,
Expand Down
25 changes: 6 additions & 19 deletions src/app/statev3/common/meta-data-queries/useFullTokenData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,17 @@ import { useReadContract } from "wagmi";
import { strategyConfig } from "../../settings/config";
import { AssetBaseConfig } from "../../settings/configTypes";
import { assetsConfig } from "../../settings/landingMarketConfig";
import { useToken } from "@shared";

export interface FullAssetData extends Omit<AssetBaseConfig, "address"> {
decimals?: number;
}

// todo rename hook
export const useFullTokenData = (asset?: Address | undefined): FetchData<FullAssetData> => {
const config = asset
? assetsConfig[asset] || strategyConfig[asset]
: undefined;
const config = asset ? assetsConfig[asset] || strategyConfig[asset] : undefined;

const { data: decimals, ...decimalRest } = useReadContract({
address: asset,
abi: erc20Abi,
functionName: "decimals",
query: { ...metadataQueryConfig, enabled: !!asset },
});

const { data: symbol, ...symbolRest } = useReadContract({
address: asset,
abi: erc20Abi,
functionName: "symbol",
query: { ...metadataQueryConfig, enabled: !!asset },
});
const { data, ...dataRest } = useToken(asset);

const { data: name, ...nameRest } = useReadContract({
address: asset,
Expand All @@ -39,12 +26,12 @@ export const useFullTokenData = (asset?: Address | undefined): FetchData<FullAss
});

return {
...mergeQueryStates([decimalRest, symbolRest, nameRest]),
...mergeQueryStates([dataRest, nameRest]),
data: {
symbol,
name,
decimals,
...data,
...config,
logo: config?.logo || data?.logo,
},
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import { Address } from "viem";
import { rewardsControllerAddress, rewardsControllerAbi } from "@generated";
import { getConfig, queryContract } from "../../../utils/queryContractUtils";
import { cTotalRewards } from "./UserRewardsByStrategy.math";
import { fetchTokenData } from "../../metadata/TokenData.fetch";
import { fetchAssetPriceInBlock } from "../../queries/AssetPrice.hook";
import { FetchBigInt, FetchBigIntStrict, formatFetchBigInt, formatUsdValue } from "@shared";
import { FetchBigInt, FetchBigIntStrict, fetchToken, formatFetchBigInt, formatUsdValue } from "@shared";
import { cValueInUsd } from "../../math/utils";
import { heavyDataQueryConfig } from "../../settings/queryConfig";
import { readContractQueryOptions } from "wagmi/query";
Expand Down Expand Up @@ -41,7 +40,7 @@ export async function fetchAllUserRewardsByStrategy({
const rewardsInfo: FetchRewardsByStrategyInfo[] = await Promise.all(
rewardsAddresses.map(async (address, index) => {
const [{ decimals, symbol }, tokenPrice] = await Promise.all([
fetchTokenData(address),
fetchToken(address),
fetchAssetPriceInBlock(address),
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { Address, parseAbiItem } from "viem";
import { getPublicClient } from "wagmi/actions";
import { getExtensiveOperationsConfig } from "../../../utils/queryContractUtils";
import { TransfersWithStrategyPrice, cUserStrategyProfit } from "./UserStrategyProfit.math";
import { fetchTokenData } from "../../metadata/TokenData.fetch";
import { FetchBigIntStrict, formatFetchBigInt, formatUsdValue } from "../../../../shared";
import { FetchBigIntStrict, fetchToken, formatFetchBigInt, formatUsdValue } from "../../../../shared";
import { fetchAssetPriceInBlock } from "../../queries/AssetPrice.hook";
import { getQueryClient } from "../../../contexts/CustomQueryClientProvider";
import { heavyDataQueryConfig } from "../../settings/queryConfig";
Expand Down Expand Up @@ -142,7 +141,7 @@ export async function fetchUserStrategyProfit(

const [logs, { decimals: strategyDecimals, symbol: strategySymbol }] = await Promise.all([
getStrategyEventLogsForUser({ strategy, user }),
fetchTokenData(strategy),
fetchToken(strategy),
]);

const [transferWithStrategyPrice, currStrategyPrice] = await Promise.all([
Expand Down
13 changes: 6 additions & 7 deletions src/app/statev3/metadata/FullStrategyData.all.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Address } from "viem";
import { fetchTokenData } from "./TokenData.fetch";
import { fetchStrategyAssets } from "./StrategyAssets.fetch";
import { useQuery } from "@tanstack/react-query";
import { disableCacheQueryConfig } from "../settings/queryConfig";
import { addressIconMap, strategyConfig } from "../settings/config";
import { strategyConfig } from "../settings/config";
import { TagType } from "../common/types/StateTypes";
import { Displayable } from "../../../shared";
import { Displayable, fetchToken } from "@shared";
import { addressIconMap } from "@meta";

export interface FullStrategyData {
underlying?: Address;
Expand All @@ -16,22 +16,21 @@ export interface FullStrategyData {
address?: Address;
diagram?: string;

icon: string;
logo?: string;
symbol?: string;
decimals?: number;
name: string;
}

export async function fetchFullStrategyData(strategy: Address): Promise<FullStrategyData> {
const [tokenData, assets] = await Promise.all([fetchTokenData(strategy), fetchStrategyAssets(strategy)]);
const [tokenData, assets] = await Promise.all([fetchToken(strategy), fetchStrategyAssets(strategy)]);

const config = strategy ? strategyConfig[strategy] : undefined;
if (!config) throw new Error(`No config found for ${strategy}`);

return {
...tokenData,
...assets,
icon: strategy ? addressIconMap.get(strategy) || "" : "",
address: strategy,
...config,
};
Expand All @@ -53,7 +52,7 @@ export const useFetchFullStrategyData = (strategy?: Address): Displayable<FullSt
data: {
...data,
address: strategy,
icon: addressIconMap.get(strategy || "") || "",
logo: addressIconMap.get(strategy || "") || "",
...config,
},
};
Expand Down
66 changes: 0 additions & 66 deletions src/app/statev3/metadata/TokenData.fetch.ts

This file was deleted.

5 changes: 2 additions & 3 deletions src/app/statev3/queries/AssetBalance.hook.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Address, erc20Abi } from "viem";
import { FetchBigIntStrict } from "../../../shared";
import { fetchTokenData } from "../metadata/TokenData.fetch";
import { FetchBigIntStrict, fetchToken } from "@shared";
import { getConfig, queryContract } from "../../utils/queryContractUtils";
import { walletDataQueryConfig } from "../settings/queryConfig";
import { readContractQueryOptions } from "wagmi/query";
Expand All @@ -21,7 +20,7 @@ export async function fetchAssetBalance({ account, asset }: FetchAssetBalanceInp
}),
...walletDataQueryConfig,
}),
fetchTokenData(asset),
fetchToken(asset),
]);

return {
Expand Down
5 changes: 2 additions & 3 deletions src/app/statev3/queries/AssetTotalSupply.hook.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Address, erc20Abi } from "viem";
import { FetchBigIntStrict } from "../../../shared";
import { FetchBigIntStrict, fetchToken } from "../../../shared";
import { getConfig, queryContract } from "../../utils/queryContractUtils";
import { fetchTokenData } from "../metadata/TokenData.fetch";
import { infiniteCacheQueryConfig, platformDataQueryConfig } from "../settings/queryConfig";
import { readContractQueryOptions } from "wagmi/query";

Expand All @@ -26,7 +25,7 @@ export async function fetchAssetTotalSupplyInBlock({
}),
...cacheConfig,
}),
fetchTokenData(asset),
fetchToken(asset),
]);

return {
Expand Down
5 changes: 3 additions & 2 deletions src/app/statev3/queries/AvailableStrategyCap.hook.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Address, zeroAddress } from "viem";
import { fetchTokenData } from "../metadata/TokenData.fetch";
import { loopStrategyAbi } from "../../generated";
import {
Displayable,
FetchTokenAmountWithUsdValueStrict,
ViewBigIntWithUsdValue,
fetchToken,
formatFetchBigInt,
formatFetchBigIntToViewBigInt,
formatUsdValue,
Expand All @@ -29,6 +29,7 @@ export async function fetchMaxDeposit(strategy: Address): Promise<bigint> {
...infiniteCacheQueryConfig,
}).catch((error) => {
if (error.cause.reason === OVERFLOW_UNDERFLOW_REASON_MESSAGE) {
// eslint-disable-next-line no-console
console.info(`Failed to fetch available strategy cap for strategy ${strategy}`, error);
return 0n;
}
Expand All @@ -49,7 +50,7 @@ export async function fetchAvailableStrategyCap(strategy: Address): Promise<Fetc
] = await Promise.all([
fetchMaxDeposit(strategy),
fetchAssetPriceInBlock(underlyingAsset),
fetchTokenData(underlyingAsset),
fetchToken(underlyingAsset),
]);

return {
Expand Down
5 changes: 2 additions & 3 deletions src/app/statev3/queries/Collateral.fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { getConfig, queryContract } from "../../utils/queryContractUtils";
import { loopStrategyAbi } from "../../generated";
import { fetchStrategyAssets } from "../metadata/StrategyAssets.fetch";
import { fetchAssetPriceInBlock } from "./AssetPrice.hook";
import { fetchTokenData } from "../metadata/TokenData.fetch";
import { FetchTokenAmountWithUsdValueStrict, formatFetchBigInt, formatUsdValue } from "../../../shared";
import { fetchToken, FetchTokenAmountWithUsdValueStrict, formatFetchBigInt, formatUsdValue } from "@shared";
import { cValueFromUsd } from "../math/utils";
import { platformDataQueryConfig } from "../settings/queryConfig";
import { readContractQueryOptions } from "wagmi/query";
Expand All @@ -23,7 +22,7 @@ export async function fetchCollateral(strategy: Address): Promise<FetchTokenAmou
...platformDataQueryConfig,
}),
fetchAssetPriceInBlock(underlyingAsset),
fetchTokenData(underlyingAsset),
fetchToken(underlyingAsset),
]);

return {
Expand Down
10 changes: 3 additions & 7 deletions src/app/statev3/queries/Equity.hook.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
import { Address } from "viem";
import { fetchTokenData } from "../metadata/TokenData.fetch";
import { loopStrategyAbi } from "../../generated";
import {
Displayable,
FetchTokenAmountWithUsdValueStrict,
ViewBigIntWithUsdValue,
fetchToken,
formatFetchBigInt,
formatFetchBigIntToViewBigInt,
formatUsdValue,
} from "../../../shared";
import { getConfig, queryContract } from "../../utils/queryContractUtils";
import { useQuery } from "@tanstack/react-query";
import {
disableCacheQueryConfig,
infiniteCacheQueryConfig,
platformDataQueryConfig,
} from "../settings/queryConfig";
import { disableCacheQueryConfig, infiniteCacheQueryConfig, platformDataQueryConfig } from "../settings/queryConfig";
import { readContractQueryOptions } from "wagmi/query";

export interface FetchEquityInBlockInput {
Expand All @@ -29,7 +25,7 @@ export async function fetchEquityInBlock({
}: FetchEquityInBlockInput): Promise<FetchTokenAmountWithUsdValueStrict> {
const cacheConfig = blockNumber ? infiniteCacheQueryConfig : platformDataQueryConfig;

const { symbol, decimals } = await fetchTokenData(strategy);
const { symbol, decimals } = await fetchToken(strategy);

const [equity, equityUsd] = await Promise.all([
queryContract({
Expand Down
6 changes: 3 additions & 3 deletions src/app/statev3/queries/MetadataLoader.hook.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { fetchStrategies } from "./Strategies.hook";
import { fetchTokenData, TokenData } from "../metadata/TokenData.fetch";
import { useQuery } from "@tanstack/react-query";
import { disableCacheQueryConfig } from "../settings/queryConfig";
import { fetchToken, Token } from "@shared";

export async function fetchAllStrategyTokenData(): Promise<TokenData[]> {
export async function fetchAllStrategyTokenData(): Promise<Token[]> {
const strategies = await fetchStrategies();

const allStrategyData = await Promise.all(strategies.map((strategy) => fetchTokenData(strategy)));
const allStrategyData = await Promise.all(strategies.map((strategy) => fetchToken(strategy)));

return allStrategyData;
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/statev3/queries/StrategyCap.hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import {
Displayable,
FetchTokenAmountWithUsdValueStrict,
ViewBigIntWithUsdValue,
fetchToken,
formatFetchBigInt,
formatFetchBigIntToViewBigInt,
formatUsdValue,
} from "@shared";
import { fetchStrategyAssets } from "../metadata/StrategyAssets.fetch";
import { getConfig, queryContract } from "../../utils/queryContractUtils";
import { fetchAssetPriceInBlock } from "./AssetPrice.hook";
import { fetchTokenData } from "../metadata/TokenData.fetch";
import { loopStrategyAbi } from "../../generated";
import { cValueInUsd } from "../math/utils";
import { useQuery } from "@tanstack/react-query";
Expand All @@ -31,7 +31,7 @@ export async function fetchStrategyCap(strategy: Address): Promise<FetchTokenAmo
...infiniteCacheQueryConfig,
}),
fetchAssetPriceInBlock(underlying),
fetchTokenData(underlying),
fetchToken(underlying),
]);

return {
Expand Down
Loading

0 comments on commit c78bd95

Please sign in to comment.