diff --git a/.env.development b/.env.development index 3937deeae..bedc6e1fc 100644 --- a/.env.development +++ b/.env.development @@ -1,7 +1,7 @@ VITE_PROVIDER_URL=wss://rpc.nice.hydration.cloud VITE_DOMAIN_URL=https://testnet-mining-app.hydradx.io VITE_INDEXER_URL=https://archive.nice.hydration.cloud/graphql -VITE_SQUID_URL=https://data-squid.nice.hydration.cloud/graphql +VITE_SQUID_URL=https://galacticcouncil.squids.live/hydration-pools:prod/api/graphql VITE_GRAFANA_URL=https://grafana-api.play.hydration.cloud/api/ds/query VITE_GRAFANA_DSN=11 VITE_ENV=development diff --git a/.env.production b/.env.production index 088c6772a..33a14b79c 100644 --- a/.env.production +++ b/.env.production @@ -1,7 +1,7 @@ VITE_PROVIDER_URL=wss://rpc.hydradx.cloud VITE_DOMAIN_URL=https://app.hydration.net VITE_INDEXER_URL=https://explorer.hydradx.cloud/graphql -VITE_SQUID_URL=https://hydra-data-squid.play.hydration.cloud/graphql +VITE_SQUID_URL=https://galacticcouncil.squids.live/hydration-pools:prod/api/graphql VITE_GRAFANA_URL=https://grafana.hydradx.cloud/api/ds/query VITE_GRAFANA_DSN=10 VITE_ENV=production diff --git a/.env.rococo b/.env.rococo index 61182085d..f3b60811a 100644 --- a/.env.rococo +++ b/.env.rococo @@ -1,7 +1,7 @@ -VITE_PROVIDER_URL=wss://rpc.nice.hydration.cloud -VITE_DOMAIN_URL=https://rococo-app.hydradx.io -VITE_INDEXER_URL=https://hydradx-rococo-explorer.play.hydration.cloud/graphql -VITE_SQUID_URL=https://squid.subsquid.io/hydradx-rococo-data-squid/v/v1/graphql +VITE_PROVIDER_URL=wss://paseo-rpc.play.hydration.cloud +VITE_DOMAIN_URL=https://paseo-app.hydration.net +VITE_INDEXER_URL=https://explorer.hydradx.cloud/graphql +VITE_SQUID_URL=https://galacticcouncil.squids.live/hydration-paseo-pools:prod/api/graphql VITE_GRAFANA_URL=https://grafana-api.play.hydration.cloud/api/ds/query VITE_GRAFANA_DSN=11 VITE_ENV=rococo diff --git a/package.json b/package.json index f329ee0de..d9cac6336 100644 --- a/package.json +++ b/package.json @@ -45,9 +45,9 @@ "@galacticcouncil/math-stableswap": "^1.0.0", "@galacticcouncil/math-staking": "^1.0.0", "@galacticcouncil/math-xyk": "^1.0.0", - "@galacticcouncil/sdk": "^5.0.1", + "@galacticcouncil/sdk": "^5.1.0", "@galacticcouncil/ui": "^5.2.3", - "@galacticcouncil/xcm-cfg": "^5.6.0", + "@galacticcouncil/xcm-cfg": "^5.7.1", "@galacticcouncil/xcm-core": "^5.4.0", "@galacticcouncil/xcm-sdk": "^7.0.0", "@hookform/resolvers": "^3.3.4", diff --git a/src/api/bonds.ts b/src/api/bonds.ts index 3e82d64e4..877b6b7a4 100644 --- a/src/api/bonds.ts +++ b/src/api/bonds.ts @@ -18,7 +18,7 @@ export type Bond = { } export const useLbpPool = (params?: { id?: string }) => { - const { api } = useRpcProvider() + const { api, isLoaded } = useRpcProvider() const { id } = params ?? {} @@ -49,7 +49,7 @@ export const useLbpPool = (params?: { id?: string }) => { return data }, { - enabled: !(params && !id), + enabled: !(params && !id) && isLoaded, select: (pools) => { if (id) { const pool = pools.find((pool) => @@ -355,31 +355,38 @@ export const useHistoricalPoolBalance = (pool?: string, block?: number) => { } type THistoricalPoolBalance = { - id: string + poolId: string assetBId: number assetAId: number - historicalBalances: Array<{ - assetABalance: string - assetBBalance: string - }> + paraChainBlockHeight: number + assetBBalance: string + assetABalance: string } const getHistoricalPoolBalance = (url: string, pool: string, block: number) => async () => { return { ...(await request<{ - pools: Array + lbpPoolHistoricalData: { nodes: Array } }>( url, gql` query PoolHistoricalBalance($pool: String, $block: Int) { - pools(where: { id_eq: $pool }) { - id - assetBId - assetAId - historicalBalances(where: { paraChainBlockHeight_eq: $block }) { - assetABalance + lbpPoolHistoricalData( + filter: { + poolId: { equalTo: $pool } + paraChainBlockHeight: { lessThanOrEqualTo: $block } + } + orderBy: PARA_CHAIN_BLOCK_HEIGHT_DESC + first: 1 + ) { + nodes { assetBBalance + assetABalance + assetAId + assetBId + paraChainBlockHeight + poolId } } } @@ -391,13 +398,23 @@ const getHistoricalPoolBalance = export const useLBPAveragePrice = (poolAddress?: string) => { const { getAssets } = useAssets() + const url = useSquidUrl() + return useQuery( QUERY_KEYS.lbpAveragePrice(poolAddress), poolAddress ? async () => { - const { historicalVolumes } = await getLBPAveragePrice(poolAddress)() - const { assetAId, assetBId, averagePrice, id } = - historicalVolumes?.[0] ?? [] + const { lbpPoolHistoricalVolumes } = await getLBPAveragePrice( + url, + poolAddress, + )() + + const { + assetAId, + assetBId, + averagePrice, + poolId: id, + } = lbpPoolHistoricalVolumes?.edges?.[0].node ?? {} const [assetAMeta, assetBMeta] = getAssets([ assetAId?.toString(), assetBId?.toString(), @@ -414,34 +431,43 @@ export const useLBPAveragePrice = (poolAddress?: string) => { ) } -const getLBPAveragePrice = (poolAddress: string) => async () => { - return { - ...(await request<{ - historicalVolumes: Array<{ - averagePrice: number - assetAId: number - assetBId: number - id: string - }> - }>( - "https://squid.subsquid.io/hydradx-lbp-squid/graphql", - gql` - query LBPAveragePrice($poolAddress: String) { - historicalVolumes( - orderBy: id_DESC - limit: 1 - where: { id_contains: $poolAddress } - ) { - averagePrice - assetAId - assetBId - id - } +const getLBPAveragePrice = + (indexerUrl: string, poolAddress: string) => async () => { + return { + ...(await request<{ + lbpPoolHistoricalVolumes: { + edges: Array<{ + node: { + averagePrice: string + assetAId: string + assetBId: string + poolId: string + } + }> } - `, - { - poolAddress, - }, - )), + }>( + indexerUrl, + gql` + query LBPAveragePrice($poolAddress: String) { + lbpPoolHistoricalVolumes( + filter: { poolId: { equalTo: $poolAddress } } + orderBy: ID_DESC + last: 1 + ) { + edges { + node { + averagePrice + assetAId + assetBId + poolId + } + } + } + } + `, + { + poolAddress, + }, + )), + } } -} diff --git a/src/api/external/index.ts b/src/api/external/index.ts index 0d75d27de..fdfc2621b 100644 --- a/src/api/external/index.ts +++ b/src/api/external/index.ts @@ -14,13 +14,14 @@ import { TRegisteredAsset, useUserExternalTokenStore, } from "sections/wallet/addToken/AddToken.utils" -import { BN_0, HYDRATION_PARACHAIN_ID } from "utils/constants" +import { HYDRATION_PARACHAIN_ID } from "utils/constants" import { isAnyParachain, isNotNil } from "utils/helpers" import { QUERY_KEYS } from "utils/queryKeys" import { assethub, useAssetHubAssetRegistry } from "./assethub" import { pendulum, usePendulumAssetRegistry } from "./pendulum" import { usePolkadotRegistry } from "./polkadot" import { useAssets } from "providers/assets" +import BigNumber from "bignumber.js" export { assethub, pendulum } @@ -180,11 +181,11 @@ export const useExternalTokensRugCheck = (ids?: string[]) => { const totalSupplyExternal = !shouldIgnoreRugCheck && externalToken.supply - ? BN(externalToken.supply) + ? externalToken.supply : null const totalSupplyInternal = - !shouldIgnoreRugCheck && issuance ? BN(issuance) : null + !shouldIgnoreRugCheck && issuance ? issuance.toString() : null const warnings = createRugWarningList({ totalSupplyExternal, @@ -241,8 +242,8 @@ const createRugWarningList = ({ storedToken, externalToken, }: { - totalSupplyExternal: BN | null - totalSupplyInternal: BN | null + totalSupplyExternal: string | null + totalSupplyInternal: string | null externalToken: TExternalAsset storedToken?: TRegisteredAsset }) => { @@ -251,12 +252,12 @@ const createRugWarningList = ({ if ( totalSupplyExternal && totalSupplyInternal && - totalSupplyExternal.lt(totalSupplyInternal) + BigNumber(totalSupplyExternal).lt(totalSupplyInternal) ) { warnings.push({ type: "supply", severity: "high", - diff: [totalSupplyInternal ?? BN_0, totalSupplyExternal ?? BN_0], + diff: [totalSupplyInternal ?? "0", totalSupplyExternal ?? "0"], }) } diff --git a/src/api/farms.ts b/src/api/farms.ts index 063b1887f..061e264cb 100644 --- a/src/api/farms.ts +++ b/src/api/farms.ts @@ -59,6 +59,7 @@ export type TClaimableFarmValue = { shares: string loyaltyFactor: string isClaimable: boolean + isActiveFarm: boolean } export type TFarmAprData = { @@ -114,51 +115,51 @@ const getActiveFarms = return await Promise.all(activeFarmIds) } +const getStoppedFarms = (deposits: TDeposit[], activeFarms: TFarmIds[]) => + deposits.reduce((result, deposit) => { + const missingEntries = deposit.data.yieldFarmEntries.filter((entry) => { + const isActive = activeFarms.some( + (activeFarm) => + activeFarm.poolId === deposit.data.ammPoolId && + activeFarm.yieldFarmId === entry.yieldFarmId && + activeFarm.globalFarmId === entry.globalFarmId, + ) + return !isActive + }) + + missingEntries.forEach((entry) => { + const isAlreadyInResult = result.some( + (item) => + item.yieldFarmId === entry.yieldFarmId && + item.poolId === deposit.data.ammPoolId && + item.globalFarmId === entry.globalFarmId, + ) + + if (!isAlreadyInResult) { + result.push({ + yieldFarmId: entry.yieldFarmId, + poolId: deposit.data.ammPoolId, + globalFarmId: entry.globalFarmId, + isActive: false, + }) + } + }) + + return result + }, []) + const getFarmsData = ( api: ApiPromise, balanceClient: BalanceClient, activeFarms: TFarmIds[], getAsset: (id: string) => TAsset, - deposits: TDeposit[], isXyk: boolean = false, ) => async () => { const accountResolver = getAccountResolver(api.registry) - const stoppedFarms = deposits.reduce((result, deposit) => { - const missingEntries = deposit.data.yieldFarmEntries.filter((entry) => { - const isActive = activeFarms.some( - (activeFarm) => - activeFarm.poolId === deposit.data.ammPoolId && - activeFarm.yieldFarmId === entry.yieldFarmId && - activeFarm.globalFarmId === entry.globalFarmId, - ) - return !isActive - }) - - missingEntries.forEach((entry) => { - const isAlreadyInResult = result.some( - (item) => - item.yieldFarmId === entry.yieldFarmId && - item.poolId === deposit.data.ammPoolId && - item.globalFarmId === entry.globalFarmId, - ) - - if (!isAlreadyInResult) { - result.push({ - yieldFarmId: entry.yieldFarmId, - poolId: deposit.data.ammPoolId, - globalFarmId: entry.globalFarmId, - isActive: false, - }) - } - }) - - return result - }, []) - - const farmsData = [...activeFarms, ...stoppedFarms].map(async (farm) => { + const farmsData = activeFarms.map(async (farm) => { const { isActive, globalFarmId, yieldFarmId, poolId } = farm const yieldFarmRaw = isXyk ? await api.query.xykWarehouseLM.yieldFarm( @@ -266,9 +267,9 @@ export const useOmnipoolFarms = (ids: string[]) => { const { account } = useAccount() const { api, balanceClient, isLoaded } = useRpcProvider() const { getAssetWithFallback } = useAssets() - const { data, isSuccess: isAccountAssets } = useAccountAssets() + const { data } = useAccountAssets() - const { omnipoolDeposits } = data ?? {} + const { omnipoolDeposits = [] } = data ?? {} const { data: activeFarms, isSuccess: isActiveFarms } = useQuery( QUERY_KEYS.omnipoolActiveFarms, @@ -276,32 +277,45 @@ export const useOmnipoolFarms = (ids: string[]) => { { enabled: !!ids.length && isLoaded, staleTime: millisecondsInHour }, ) - return useQuery( - QUERY_KEYS.omnipoolFarms(account?.address), - activeFarms && omnipoolDeposits - ? getFarmsData( - api, - balanceClient, - activeFarms, - getAssetWithFallback, - omnipoolDeposits, - ) + const stoppedFarms = useMemo( + () => getStoppedFarms(omnipoolDeposits, activeFarms ?? []), + [activeFarms, omnipoolDeposits], + ) + + const { data: stoppedFarmsData = [] } = useQuery( + QUERY_KEYS.stoppedOmnipoolFarms(account?.address), + getFarmsData(api, balanceClient, stoppedFarms, getAssetWithFallback), + { + enabled: + isActiveFarms && + isLoaded && + !!account?.address && + !!stoppedFarms.length, + staleTime: millisecondsInHour, + }, + ) + + const { data: activeFarmsData = [], isLoading } = useQuery( + QUERY_KEYS.omnipoolFarms, + activeFarms + ? getFarmsData(api, balanceClient, activeFarms, getAssetWithFallback) : undefinedNoop, { - enabled: isActiveFarms && isLoaded && isAccountAssets, - select, + enabled: isActiveFarms && isLoaded, staleTime: millisecondsInHour, }, ) + + return { data: select([...activeFarmsData, ...stoppedFarmsData]), isLoading } } export const useXYKFarms = (ids: string[]) => { const { account } = useAccount() const { api, balanceClient, isLoaded } = useRpcProvider() const { getAssetWithFallback } = useAssets() - const { data, isSuccess: isAccountAssets } = useAccountAssets() + const { data } = useAccountAssets() - const { xykDeposits } = data ?? {} + const { xykDeposits = [] } = data ?? {} const { data: activeFarms, isSuccess: isActiveFarms } = useQuery( QUERY_KEYS.xykActiveFarms, @@ -309,24 +323,42 @@ export const useXYKFarms = (ids: string[]) => { { enabled: !!ids.length && isLoaded, staleTime: millisecondsInHour }, ) - return useQuery( - QUERY_KEYS.xykFarms(account?.address), - activeFarms && xykDeposits + const stoppedFarms = useMemo( + () => getStoppedFarms(xykDeposits, activeFarms ?? []), + [activeFarms, xykDeposits], + ) + + const { data: stoppedFarmsData = [] } = useQuery( + QUERY_KEYS.stoppedXykFarms(account?.address), + getFarmsData(api, balanceClient, stoppedFarms, getAssetWithFallback, true), + { + enabled: + isActiveFarms && + isLoaded && + !!account?.address && + !!stoppedFarms.length, + staleTime: millisecondsInHour, + }, + ) + + const { data: activeFarmsData = [], isLoading } = useQuery( + QUERY_KEYS.xykFarms, + activeFarms ? getFarmsData( api, balanceClient, activeFarms, getAssetWithFallback, - xykDeposits, true, ) : undefinedNoop, { - enabled: isActiveFarms && isAccountAssets && isLoaded, - select, + enabled: isActiveFarms && isLoaded, staleTime: millisecondsInHour, }, ) + + return { data: select([...activeFarmsData, ...stoppedFarmsData]), isLoading } } export const useFarmCurrentPeriod = () => { @@ -730,6 +762,8 @@ export const useAccountClaimableFarmValues = () => { const isClaimable = BN(loyaltyFactor).gt(range) + const isActiveFarm = yieldFarm.state.isActive + return { poolId, rewardCurrency: reward.assetId, @@ -746,6 +780,7 @@ export const useAccountClaimableFarmValues = () => { shares: deposit.data.shares.toString(), loyaltyFactor, isClaimable, + isActiveFarm, } } diff --git a/src/api/provider.ts b/src/api/provider.ts index 1d6891450..1ae245a20 100644 --- a/src/api/provider.ts +++ b/src/api/provider.ts @@ -37,12 +37,15 @@ export type TFeatureFlags = { dispatchPermit: boolean } +export const PASEO_WS_URL = "paseo-rpc.play.hydration.cloud" + export const PROVIDERS: ProviderProps[] = [ { name: "GalacticCouncil", url: "wss://rpc.hydradx.cloud", indexerUrl: "https://explorer.hydradx.cloud/graphql", - squidUrl: "https://hydra-data-squid.play.hydration.cloud/graphql", + squidUrl: + "https://galacticcouncil.squids.live/hydration-pools:prod/api/graphql", env: "production", dataEnv: "mainnet", }, @@ -50,7 +53,8 @@ export const PROVIDERS: ProviderProps[] = [ name: "Dwellir", url: "wss://hydradx-rpc.dwellir.com", indexerUrl: "https://explorer.hydradx.cloud/graphql", - squidUrl: "https://hydra-data-squid.play.hydration.cloud/graphql", + squidUrl: + "https://galacticcouncil.squids.live/hydration-pools:prod/api/graphql", env: "production", dataEnv: "mainnet", }, @@ -58,7 +62,8 @@ export const PROVIDERS: ProviderProps[] = [ name: "Helikon", url: "wss://rpc.helikon.io/hydradx", indexerUrl: "https://explorer.hydradx.cloud/graphql", - squidUrl: "https://hydra-data-squid.play.hydration.cloud/graphql", + squidUrl: + "https://galacticcouncil.squids.live/hydration-pools:prod/api/graphql", env: "production", dataEnv: "mainnet", }, @@ -66,7 +71,8 @@ export const PROVIDERS: ProviderProps[] = [ name: "Dotters", url: "wss://hydration.dotters.network", indexerUrl: "https://explorer.hydradx.cloud/graphql", - squidUrl: "https://hydra-data-squid.play.hydration.cloud/graphql", + squidUrl: + "https://galacticcouncil.squids.live/hydration-pools:prod/api/graphql", env: "production", dataEnv: "mainnet", }, @@ -74,10 +80,20 @@ export const PROVIDERS: ProviderProps[] = [ name: "Testnet", url: "wss://rpc.nice.hydration.cloud", indexerUrl: "https://archive.nice.hydration.cloud/graphql", - squidUrl: "https://data-squid.nice.hydration.cloud/graphql", + squidUrl: + "https://galacticcouncil.squids.live/hydration-pools:prod/api/graphql", env: ["development"], dataEnv: "testnet", }, + { + name: "Paseo", + url: `wss://${PASEO_WS_URL}`, + indexerUrl: "https://explorer.hydradx.cloud/graphql", + squidUrl: + "https://galacticcouncil.squids.live/hydration-paseo-pools:prod/api/graphql", + env: ["rococo", "development"], + dataEnv: "testnet", + }, ] export const PROVIDER_LIST = PROVIDERS.filter((provider) => diff --git a/src/components/HydrationLogo/HydrationLogo.tsx b/src/components/HydrationLogo/HydrationLogo.tsx index bff6d0e1a..d93479a04 100644 --- a/src/components/HydrationLogo/HydrationLogo.tsx +++ b/src/components/HydrationLogo/HydrationLogo.tsx @@ -12,47 +12,68 @@ import { theme } from "theme" import ApeIcon from "assets/icons/ApeIcon.svg?react" import { useTranslation } from "react-i18next" -const hostname = window.location.hostname -const DEPLOY_PREVIEW_NAME = - hostname.includes("deploy-preview") && hostname.match(/--([^-\s]+)-/)?.[1] +const getBadgeLabel = () => { + const hostname = window.location.hostname + + if (hostname === "localhost") { + return "localhost" + } else if (hostname.includes("testnet-app")) { + return "testnet" + } else if (hostname.includes("paseo-app")) { + return "paseo" + } else if (hostname.includes("edge-app")) { + return "edge" + } else if (hostname.includes("deploy-preview")) { + return hostname.match(/--([^-\s]+)-/)?.[1] + } else { + return undefined + } +} const HydrationLogoMobile: React.FC<{ degenMode: boolean }> = ({ degenMode, -}) => ( - <> - - - { + const badgeLabel = getBadgeLabel() + + return ( + <> + + + + + + {badgeLabel && ( +
+ + {badgeLabel} + +
+ )} + {degenMode && ( + - -
- {DEPLOY_PREVIEW_NAME && ( -
- - {DEPLOY_PREVIEW_NAME} - -
- )} - {degenMode && ( - - )} - -) + )} + + ) +} const HyderationLogoDesktop: React.FC<{ degenMode: boolean }> = ({ degenMode, }) => { const { t } = useTranslation() + + const badgeLabel = getBadgeLabel() + return ( <> @@ -128,9 +149,9 @@ const HyderationLogoDesktop: React.FC<{ degenMode: boolean }> = ({ > {t("header.settings.degenMode.title")} - {DEPLOY_PREVIEW_NAME && ( + {badgeLabel && ( - {DEPLOY_PREVIEW_NAME} + {badgeLabel} )} diff --git a/src/components/Layout/Page/Page.tsx b/src/components/Layout/Page/Page.tsx index cab8073e6..8ecf27166 100644 --- a/src/components/Layout/Page/Page.tsx +++ b/src/components/Layout/Page/Page.tsx @@ -23,7 +23,6 @@ import { } from "./Page.styled" import { useControlScroll } from "./Page.utils" import { usePreviousUrl } from "hooks/usePreviousUrl" -import { useRpcProvider } from "providers/rpcProvider" type Props = { className?: string @@ -51,7 +50,6 @@ const useSubheaderComponent = () => { const matchRoute = useMatchRoute() const search = useSearch() const isDesktop = useMedia(theme.viewport.gte.sm) - const { featureFlags } = useRpcProvider() const prevUrl = usePreviousUrl() diff --git a/src/components/Toast/sidebar/referendums/ToastSidebarReferendums.tsx b/src/components/Toast/sidebar/referendums/ToastSidebarReferendums.tsx index dd94a2e63..6f8d9e818 100644 --- a/src/components/Toast/sidebar/referendums/ToastSidebarReferendums.tsx +++ b/src/components/Toast/sidebar/referendums/ToastSidebarReferendums.tsx @@ -2,17 +2,14 @@ import { useReferendums } from "api/democracy" import { ReferendumCard } from "components/ReferendumCard/ReferendumCard" import { useTranslation } from "react-i18next" import { ToastSidebarGroup } from "components/Toast/sidebar/group/ToastSidebarGroup" -import { useProviderRpcUrlStore } from "api/provider" +import { PASEO_WS_URL, useProviderRpcUrlStore } from "api/provider" import { ReferendumCardRococo } from "components/ReferendumCard/ReferendumCardRococo" export const ToastSidebarReferendums = () => { const { t } = useTranslation() const referendums = useReferendums("ongoing") const providers = useProviderRpcUrlStore() - const rococoProvider = [ - "hydradx-rococo-rpc.play.hydration.cloud", - "mining-rpc.hydradx.io", - ].find( + const rococoProvider = [PASEO_WS_URL, "mining-rpc.hydradx.io"].find( (rpc) => (providers.rpcUrl ?? import.meta.env.VITE_PROVIDER_URL) === `wss://${rpc}`, diff --git a/src/sections/lending/ui/reserve-overview/EModeInfo.tsx b/src/sections/lending/ui/reserve-overview/EModeInfo.tsx index 7a97c872e..ec0f5b2bd 100644 --- a/src/sections/lending/ui/reserve-overview/EModeInfo.tsx +++ b/src/sections/lending/ui/reserve-overview/EModeInfo.tsx @@ -1,7 +1,6 @@ import { DataValue, DataValueList } from "components/DataValue" import { Text } from "components/Typography/Text/Text" import { PercentageValue } from "components/PercentageValue" -import { ROUTES } from "sections/lending/components/primitives/Link" import { getEmodeMessage } from "sections/lending/components/transactions/Emode/EmodeNaming" import { ComputedReserveData } from "sections/lending/hooks/app-data-provider/useAppDataProvider" diff --git a/src/sections/migration/components/MigrationWarning.tsx b/src/sections/migration/components/MigrationWarning.tsx index f661b32f0..1acd850e6 100644 --- a/src/sections/migration/components/MigrationWarning.tsx +++ b/src/sections/migration/components/MigrationWarning.tsx @@ -10,6 +10,7 @@ import LinkIcon from "assets/icons/LinkIcon.svg?react" import { Separator } from "components/Separator/Separator" import { useWalletAssetsTotals } from "sections/wallet/assets/WalletAssets.utils" import { useAccount } from "sections/web3-connect/Web3Connect.utils" +import BigNumber from "bignumber.js" export type MigrationWarningProps = { onClick: () => void @@ -27,7 +28,7 @@ export const MigrationWarning: React.FC = ({ address: account?.address, }) - if (isLoading || balanceTotal?.isZero()) return null + if (isLoading || BigNumber(balanceTotal).isZero()) return null return ( diff --git a/src/sections/pools/farms/position/FarmingPosition.utils.tsx b/src/sections/pools/farms/position/FarmingPosition.utils.tsx index 45b33232b..19fe744f2 100644 --- a/src/sections/pools/farms/position/FarmingPosition.utils.tsx +++ b/src/sections/pools/farms/position/FarmingPosition.utils.tsx @@ -188,7 +188,7 @@ export const useFarmDepositsTotal = (address?: string) => { poolsTotal = poolsTotal.plus(xykTotal) } - return poolsTotal + return poolsTotal.toString() }, [omnipool, xyk]) return { isLoading: isLoading, value: total } diff --git a/src/sections/pools/header/MyFarmsTotal.tsx b/src/sections/pools/header/MyFarmsTotal.tsx index b3c984ce8..9d731d10e 100644 --- a/src/sections/pools/header/MyFarmsTotal.tsx +++ b/src/sections/pools/header/MyFarmsTotal.tsx @@ -1,8 +1,14 @@ import { useFarmDepositsTotal } from "sections/pools/farms/position/FarmingPosition.utils" import { HeaderTotalData } from "./PoolsHeaderTotal" +import BigNumber from "bignumber.js" export const MyFarmsTotal = () => { const total = useFarmDepositsTotal() - return + return ( + + ) } diff --git a/src/sections/pools/header/MyLiquidityTotal.tsx b/src/sections/pools/header/MyLiquidityTotal.tsx index 3c867382a..6abe37b38 100644 --- a/src/sections/pools/header/MyLiquidityTotal.tsx +++ b/src/sections/pools/header/MyLiquidityTotal.tsx @@ -7,6 +7,7 @@ import { Text } from "components/Typography/Text/Text" import { DisplayValue } from "components/DisplayValue/DisplayValue" import { Trans, useTranslation } from "react-i18next" import BN from "bignumber.js" +import BigNumber from "bignumber.js" export const MyLiquidityTotal = ({ xykTotal, @@ -41,7 +42,7 @@ export const MyLiquidityTotal = ({ subValue={ - + } diff --git a/src/sections/staking/sections/dashboard/components/Referenda/Referenda.tsx b/src/sections/staking/sections/dashboard/components/Referenda/Referenda.tsx index 5dff50e83..c59cab7c9 100644 --- a/src/sections/staking/sections/dashboard/components/Referenda/Referenda.tsx +++ b/src/sections/staking/sections/dashboard/components/Referenda/Referenda.tsx @@ -7,7 +7,7 @@ import { SContainer } from "sections/staking/StakingPage.styled" import GovernanceIcon from "assets/icons/GovernanceIcon.svg?react" import { Icon } from "components/Icon/Icon" import { ReferendumCardRococo } from "components/ReferendumCard/ReferendumCardRococo" -import { useProviderRpcUrlStore } from "api/provider" +import { PASEO_WS_URL, useProviderRpcUrlStore } from "api/provider" import { theme } from "theme" type ReferendaProps = { @@ -24,10 +24,7 @@ export const ReferendaWrapper = () => { export const Referenda = ({ data, loading }: ReferendaProps) => { const { t } = useTranslation() const providers = useProviderRpcUrlStore() - const rococoProvider = [ - "hydradx-rococo-rpc.play.hydration.cloud", - "mining-rpc.hydradx.io", - ].find( + const rococoProvider = [PASEO_WS_URL, "mining-rpc.hydradx.io"].find( (rpc) => (providers.rpcUrl ?? import.meta.env.VITE_PROVIDER_URL) === `wss://${rpc}`, diff --git a/src/sections/trade/sections/bonds/details/components/BondInfoCards/BondInfoCards.tsx b/src/sections/trade/sections/bonds/details/components/BondInfoCards/BondInfoCards.tsx index 0cb106ffb..38755ffb6 100644 --- a/src/sections/trade/sections/bonds/details/components/BondInfoCards/BondInfoCards.tsx +++ b/src/sections/trade/sections/bonds/details/components/BondInfoCards/BondInfoCards.tsx @@ -74,7 +74,7 @@ export const BondInfoCards = ({ ? getAsset(accumulatedAssetId.toString()) : undefined const accumulatedAssetBalance = isPast - ? hisroticalBalance.data?.pools[0]?.historicalBalances[0].assetABalance + ? hisroticalBalance.data?.lbpPoolHistoricalData.nodes[0]?.assetABalance : undefined const currentAccumulatedAssetValue = removeBlock diff --git a/src/sections/wallet/assets/WalletAssets.utils.ts b/src/sections/wallet/assets/WalletAssets.utils.ts index 6e64af403..8ce9807f4 100644 --- a/src/sections/wallet/assets/WalletAssets.utils.ts +++ b/src/sections/wallet/assets/WalletAssets.utils.ts @@ -7,6 +7,7 @@ import { BN_0, BN_NAN } from "utils/constants" import { useDisplayShareTokenPrice } from "utils/displayAsset" import { useAssetsData } from "./table/data/WalletAssetsTableData.utils" import { useAccountAssets } from "api/deposits" +import BigNumber from "bignumber.js" type AssetCategory = "all" | "assets" | "liquidity" | "farming" @@ -48,40 +49,41 @@ export const useWalletAssetsTotals = ({ const assets = useAssetsData({ isAllAssets: false, address }) const lpPositions = useOmnipoolPositionsData({ address }) const farmsTotal = useFarmDepositsTotal(address) - const balances = useAccountAssets(address) + const { data: balances, isLoading: isAccountAssetsLoading } = + useAccountAssets(address) const shareTokenBalances = useMemo( - () => [...(balances.data?.accountShareTokensMap.values() ?? [])], - [balances.data?.accountShareTokensMap], + () => [...(balances?.accountShareTokensMap.values() ?? [])], + [balances?.accountShareTokensMap], ) const spotPrices = useDisplayShareTokenPrice( - shareTokenBalances?.map((token) => token.asset.id), + shareTokenBalances.map((token) => token.asset.id), ) - const assetsTotal = useMemo(() => { - if (!assets.data) return BN_0 - - return assets.data.reduce((acc, cur) => { - if (!cur.totalDisplay.isNaN()) { - return acc.plus(cur.totalDisplay) - } - return acc - }, BN_0) - }, [assets]) - - const lpTotal = useMemo(() => { - if (!lpPositions.data) return BN_0 + const assetsTotal = useMemo( + () => + assets.data.reduce((acc, cur) => { + if (cur.totalDisplay) { + return BigNumber(acc).plus(cur.totalDisplay).toString() + } + return acc + }, "0"), + [assets.data], + ) - return lpPositions.data.reduce( - (acc, { valueDisplay }) => acc.plus(BN(valueDisplay)), - BN_0, - ) - }, [lpPositions.data]) + const lpTotal = useMemo( + () => + lpPositions.data.reduce( + (acc, { valueDisplay }) => BigNumber(acc).plus(valueDisplay).toString(), + "0", + ), + [lpPositions.data], + ) const xykTotal = useMemo(() => { - if (!shareTokenBalances || !spotPrices.data) return BN_0 - return shareTokenBalances.reduce((acc, { asset, balance }) => { + if (!shareTokenBalances || !spotPrices.data) return BN_NAN + return shareTokenBalances.reduce((acc, { asset, balance }) => { if (BN(balance.freeBalance).gt(0)) { const meta = asset const spotPrice = spotPrices.data.find( @@ -92,24 +94,36 @@ export const useWalletAssetsTotals = ({ .shiftedBy(-meta.decimals) .multipliedBy(spotPrice?.spotPrice ?? BN_NAN) - return acc.plus(!value.isNaN() ? value : BN_0) + return BN(acc) + .plus(!value.isNaN() ? value : BN_0) + .toString() } + return acc - }, BN_0) + }, "0") }, [shareTokenBalances, spotPrices.data]) - const balanceTotal = assetsTotal - .plus(farmsTotal.value) - .plus(lpTotal) - .plus(xykTotal) + const balanceTotal = useMemo( + () => + BigNumber(assetsTotal) + .plus(farmsTotal.value) + .plus(lpTotal) + .plus(xykTotal) + .toString(), + [assetsTotal, farmsTotal.value, lpTotal, xykTotal], + ) const isLoading = - assets.isLoading || lpPositions.isLoading || farmsTotal.isLoading + assets.isLoading || + lpPositions.isLoading || + farmsTotal.isLoading || + isAccountAssetsLoading || + spotPrices.isInitialLoading return { assetsTotal, farmsTotal: farmsTotal.value, - lpTotal: lpTotal.plus(xykTotal), + lpTotal: BigNumber(lpTotal).plus(xykTotal).toString(), balanceTotal, isLoading, } diff --git a/src/sections/wallet/assets/header/WalletAssetsHeader.tsx b/src/sections/wallet/assets/header/WalletAssetsHeader.tsx index 88f7b6a25..05a195bbb 100644 --- a/src/sections/wallet/assets/header/WalletAssetsHeader.tsx +++ b/src/sections/wallet/assets/header/WalletAssetsHeader.tsx @@ -71,12 +71,12 @@ const WalletAssetsHeaderDisplay = ({ }: { isLoading: boolean fontSize?: [number, number] - value: BN + value: string }) => { return (
diff --git a/src/sections/wallet/assets/table/WalletAssetsTable.utils.tsx b/src/sections/wallet/assets/table/WalletAssetsTable.utils.tsx index 7c4d76918..1ab6d4943 100644 --- a/src/sections/wallet/assets/table/WalletAssetsTable.utils.tsx +++ b/src/sections/wallet/assets/table/WalletAssetsTable.utils.tsx @@ -22,7 +22,7 @@ import { defaultPaginationState, useTablePagination, } from "components/Table/TablePagination" -import BigNumber from "bignumber.js" +import { bnSort } from "utils/helpers" export const useAssetsTable = ( data: AssetsTableData[], @@ -57,11 +57,10 @@ export const useAssetsTable = ( id: "transferable", header: t("wallet.assets.table.header.transferable"), sortingFn: (a, b) => - BigNumber(a.original.transferableDisplay).gt( + bnSort( + a.original.transferableDisplay, b.original.transferableDisplay, - ) - ? 1 - : -1, + ), cell: ({ row }) => (
{!isDesktop && ( @@ -90,7 +89,7 @@ export const useAssetsTable = ( id: "total", header: t("wallet.assets.table.header.total"), sortingFn: (a, b) => - a.original.totalDisplay.gt(b.original.totalDisplay) ? 1 : -1, + bnSort(a.original.totalDisplay, b.original.totalDisplay), cell: ({ row }) => ( { const { account } = useAccount() const { t } = useTranslation() @@ -416,10 +416,10 @@ const NativeLocks = ({ {t("wallet.assets.table.details.reserved")} - {t("value.token", { value: reserved })} + {t("value.token", { value: BN(reserved) })} - +
@@ -460,8 +460,8 @@ const Locks = ({ reserved, reservedDisplay, }: { - reserved: BN - reservedDisplay: BN + reserved: string + reservedDisplay?: string }) => { const { t } = useTranslation() @@ -472,10 +472,10 @@ const Locks = ({ {t("wallet.assets.table.details.reserved")} - {t("value.token", { value: reserved })} + {t("value.token", { value: BN(reserved) })} - +
diff --git a/src/sections/wallet/assets/table/data/WalletAssetsTableData.tsx b/src/sections/wallet/assets/table/data/WalletAssetsTableData.tsx index 157b680e6..8ebe34cc8 100644 --- a/src/sections/wallet/assets/table/data/WalletAssetsTableData.tsx +++ b/src/sections/wallet/assets/table/data/WalletAssetsTableData.tsx @@ -4,14 +4,15 @@ import { DollarAssetValue } from "components/DollarAssetValue/DollarAssetValue" import { Text } from "components/Typography/Text/Text" import { useTranslation } from "react-i18next" import { theme } from "theme" +import { BN_NAN } from "utils/constants" export const WalletAssetsTableBalance = (props: { - balance: BN - balanceDisplay: BN + balance: string + balanceDisplay?: string }) => { const { t } = useTranslation() - const usdValue = props.balanceDisplay || "-" + const usdValue = BN(props.balanceDisplay ?? BN_NAN) return (
- {t("value.token", { value: props.balance })} + {t("value.token", { value: BN(props.balance) })} { - if (balances.data) { + if (balances) { const filteredTokens = - balances.data.balances?.filter((balance) => { + balances.balances?.filter((balance) => { const meta = getAsset(balance.assetId) return ( @@ -63,14 +64,15 @@ export const useAssetsData = ({ } return [] - }, [balances.data, getAsset]) + }, [balances, getAsset]) const tokensWithBalanceIds = tokensWithBalance.map( (tokenWithBalance) => tokenWithBalance.assetId, ) - const currencyId = useAccountCurrency(address).data - const acceptedCurrencies = useAcceptedCurrencies(tokensWithBalanceIds) + const { data: currencyId } = useAccountCurrency(address) + const { data: acceptedCurrencies } = + useAcceptedCurrencies(tokensWithBalanceIds) const spotPrices = useDisplayPrices(tokensWithBalanceIds) @@ -80,7 +82,8 @@ export const useAssetsData = ({ ) const data = useMemo(() => { - if (balances.isInitialLoading || !spotPrices.data) return [] + if (isBalancesLoading || !spotPrices.data) return [] + const rowsWithBalance = tokensWithBalance.map((balance) => { const asset = getAssetWithFallback(balance.assetId) const isExternalInvalid = asset.isExternal && !asset.symbol @@ -94,22 +97,28 @@ export const useAssetsData = ({ const { decimals, id, name, symbol } = meta const inTradeRouter = tradable.some((tradeAsset) => tradeAsset.id === id) - const spotPrice = - spotPrices.data?.find((spotPrice) => spotPrice?.tokenIn === id) - ?.spotPrice ?? BN_NAN + const spotPrice = spotPrices.data?.find( + (spotPrice) => spotPrice?.tokenIn === id, + )?.spotPrice const reserved = BigNumber(balance.reservedBalance).shiftedBy(-decimals) - const reservedDisplay = reserved.times(spotPrice) + const reservedDisplay = spotPrice?.isFinite() + ? reserved.times(spotPrice).toString() + : undefined const total = BigNumber(balance.total).shiftedBy(-decimals) - const totalDisplay = total.times(spotPrice) + const totalDisplay = spotPrice?.isFinite() + ? total.times(spotPrice).toString() + : undefined const transferable = isExternalInvalid ? BN_NAN : BigNumber(balance.balance).shiftedBy(-decimals) - const transferableDisplay = transferable.times(spotPrice).toString() + const transferableDisplay = spotPrice?.isFinite() + ? transferable.times(spotPrice).toString() + : undefined - const isAcceptedCurrency = !!acceptedCurrencies.data?.find( + const isAcceptedCurrency = !!acceptedCurrencies?.find( (acceptedCurrencie) => acceptedCurrencie.id === id, )?.accepted @@ -129,11 +138,11 @@ export const useAssetsData = ({ meta, isPaymentFee, couldBeSetAsPaymentFee, - reserved, + reserved: reserved.toString(), reservedDisplay, - total, + total: total.toString(), totalDisplay, - transferable, + transferable: transferable.toString(), transferableDisplay, tradability, isExternalInvalid, @@ -168,11 +177,11 @@ export const useAssetsData = ({ meta, isPaymentFee: false, couldBeSetAsPaymentFee: false, - reserved: BN_0, - reservedDisplay: BN_0, - total: BN_0, - totalDisplay: BN_0, - transferable: BN_0, + reserved: "0", + reservedDisplay: "0", + total: "0", + totalDisplay: "0", + transferable: "0", transferableDisplay: "0", tradability, isExternalInvalid, @@ -205,13 +214,13 @@ export const useAssetsData = ({ getAssetWithFallback, getExternalMeta, tradable, - acceptedCurrencies.data, + acceptedCurrencies, currencyId, - balances.isInitialLoading, + isBalancesLoading, rugCheck.tokensMap, ]) - return { data, isLoading: balances.isLoading || spotPrices.isInitialLoading } + return { data, isLoading: isBalancesLoading || spotPrices.isInitialLoading } } export type AssetsTableData = ReturnType["data"][number] diff --git a/src/sections/wallet/assets/table/details/WalletAssetsTableDetails.tsx b/src/sections/wallet/assets/table/details/WalletAssetsTableDetails.tsx index e4ee595d5..65e1ca9b7 100644 --- a/src/sections/wallet/assets/table/details/WalletAssetsTableDetails.tsx +++ b/src/sections/wallet/assets/table/details/WalletAssetsTableDetails.tsx @@ -15,7 +15,7 @@ import { import BN from "bignumber.js" import { Button } from "components/Button/Button" import { Separator } from "components/Separator/Separator" -import { BN_0 } from "utils/constants" +import { BN_0, BN_NAN } from "utils/constants" import { useAccount } from "sections/web3-connect/Web3Connect.utils" import { TOAST_MESSAGES } from "state/toasts" import { ToastMessage } from "state/store" @@ -61,8 +61,8 @@ const NativeAssetDetails = ({ reserved, reservedDisplay, }: { - reserved: BN - reservedDisplay: BN + reserved: string + reservedDisplay?: string }) => { const { account } = useAccount() const { t } = useTranslation() @@ -198,10 +198,10 @@ const NativeAssetDetails = ({ {t("wallet.assets.table.details.reserved")} - {t("value.token", { value: reserved })} + {t("value.token", { value: BN(reserved) })} - +
@@ -232,8 +232,8 @@ const AssetDetails = ({ reservedDisplay, id, }: { - reserved: BN - reservedDisplay: BN + reserved: string + reservedDisplay?: string id: string }) => { const { t } = useTranslation() @@ -279,10 +279,10 @@ const AssetDetails = ({ {t("wallet.assets.table.details.reserved")} - {t("value.token", { value: reserved })} + {t("value.token", { value: BN(reserved) })} - +
diff --git a/src/sections/web3-connect/Web3Connect.utils.ts b/src/sections/web3-connect/Web3Connect.utils.ts index 02e37b286..b4180fe3b 100644 --- a/src/sections/web3-connect/Web3Connect.utils.ts +++ b/src/sections/web3-connect/Web3Connect.utils.ts @@ -60,7 +60,6 @@ import { chainsMap } from "@galacticcouncil/xcm-cfg" import { EvmChain } from "@galacticcouncil/xcm-core" import { MetadataStore } from "@galacticcouncil/ui" import { create } from "zustand" -import BN from "bignumber.js" export type { WalletProvider } from "./wallets" export { WalletProviderType, getSupportedWallets } @@ -578,8 +577,8 @@ export function getWalletModeIcon(mode: WalletMode) { } export const useAccountBalanceMap = create<{ - balanceMap: Map - setBalanceMap: (address: string, balance: BN) => void + balanceMap: Map + setBalanceMap: (address: string, balance: string) => void }>((set) => ({ balanceMap: new Map(), setBalanceMap: (address, balance) => { diff --git a/src/sections/web3-connect/accounts/Web3ConnectAccount.tsx b/src/sections/web3-connect/accounts/Web3ConnectAccount.tsx index c699cb430..faea351f4 100644 --- a/src/sections/web3-connect/accounts/Web3ConnectAccount.tsx +++ b/src/sections/web3-connect/accounts/Web3ConnectAccount.tsx @@ -7,12 +7,10 @@ import { getAddressVariants } from "utils/formatting" import { SAccountItem } from "./Web3ConnectAccount.styled" import { Web3ConnectAccountSelect } from "./Web3ConnectAccountSelect" -import BN from "bignumber.js" - type Props = Account & { isProxy?: boolean isActive?: boolean - balance?: BN + balance?: string onClick?: (account: Account) => void } diff --git a/src/sections/web3-connect/accounts/Web3ConnectAccountList.tsx b/src/sections/web3-connect/accounts/Web3ConnectAccountList.tsx index 6fbefe7c8..b1a69468c 100644 --- a/src/sections/web3-connect/accounts/Web3ConnectAccountList.tsx +++ b/src/sections/web3-connect/accounts/Web3ConnectAccountList.tsx @@ -30,6 +30,7 @@ import { EVM_PROVIDERS } from "sections/web3-connect/constants/providers" import { Web3ConnectModeFilter } from "sections/web3-connect/modal/Web3ConnectModeFilter" import { useShallow } from "hooks/useShallow" import { isEvmAccount } from "utils/evm" +import BigNumber from "bignumber.js" const getAccountComponentByType = (type: WalletProviderType | null) => { if (!type) return Fragment @@ -125,7 +126,7 @@ export const Web3ConnectAccountList: FC<{ const aBalance = balanceMap.get(a.address) const bBalance = balanceMap.get(b.address) if (!aBalance || !bBalance) return 0 - return bBalance.comparedTo(aBalance) + return BigNumber(bBalance).comparedTo(aBalance) }) }, [account, accounts, balanceMap, isReady, filter, search]) diff --git a/src/sections/web3-connect/accounts/Web3ConnectAccountSelect.tsx b/src/sections/web3-connect/accounts/Web3ConnectAccountSelect.tsx index c3c297273..bc09e2f1c 100644 --- a/src/sections/web3-connect/accounts/Web3ConnectAccountSelect.tsx +++ b/src/sections/web3-connect/accounts/Web3ConnectAccountSelect.tsx @@ -19,7 +19,7 @@ type Props = { name: string genesisHash?: `0x${string}` address: string - balance?: BigNumber + balance?: string onClick?: () => void provider?: WalletProviderType | null isProxy?: boolean @@ -72,8 +72,11 @@ export const Web3ConnectAccountSelect = ({ )} - {balance?.isFinite() && ( - + {balance && ( + )} diff --git a/src/utils/displayAsset.ts b/src/utils/displayAsset.ts index 762040e5b..e83788222 100644 --- a/src/utils/displayAsset.ts +++ b/src/utils/displayAsset.ts @@ -33,24 +33,25 @@ export const useDisplayValue = (props: Props) => { export const useDisplayPrice = (id: string | u32 | undefined) => { const displayAsset = useDisplayAssetStore() - const spotPrice = useSpotPrice(id, displayAsset.id) - const usdPrice = useCoingeckoUsdPrice() - - const isLoading = spotPrice.isInitialLoading || usdPrice.isInitialLoading + const { data: spotPrice, isInitialLoading: isSpotPriceInitialLoading } = + useSpotPrice(id, displayAsset.id) + const { data: usdPrice, isInitialLoading: isUsdPriceInitialLoading } = + useCoingeckoUsdPrice() + const isLoading = isSpotPriceInitialLoading || isUsdPriceInitialLoading const data = useMemo(() => { if (isLoading) return undefined - if (displayAsset.isRealUSD && usdPrice.data) - return spotPrice.data + if (displayAsset.isRealUSD && usdPrice) + return spotPrice ? { - ...spotPrice.data, - spotPrice: spotPrice.data.spotPrice.times(usdPrice.data), + ...spotPrice, + spotPrice: spotPrice.spotPrice.times(usdPrice), } : undefined - return spotPrice.data - }, [displayAsset.isRealUSD, isLoading, spotPrice.data, usdPrice.data]) + return spotPrice + }, [displayAsset.isRealUSD, isLoading, spotPrice, usdPrice]) return { data, isLoading, isInitialLoading: isLoading } } @@ -145,23 +146,24 @@ export const useDisplayPrices = ( ) => { const displayAsset = useDisplayAssetStore() const spotPrices = useSpotPrices(ids, displayAsset.id, noRefresh) - const usdPrice = useCoingeckoUsdPrice() + const { data: usdPrice, isInitialLoading: isUsdPriceInitialLoading } = + useCoingeckoUsdPrice() const isLoading = - spotPrices.some((q) => q.isInitialLoading) || usdPrice.isInitialLoading + spotPrices.some((q) => q.isInitialLoading) || isUsdPriceInitialLoading const data = useMemo(() => { if (isLoading) return undefined - if (displayAsset.isRealUSD && usdPrice.data) + if (displayAsset.isRealUSD && usdPrice) return spotPrices.map((sp) => sp.data - ? { ...sp.data, spotPrice: sp.data.spotPrice.times(usdPrice.data) } + ? { ...sp.data, spotPrice: sp.data.spotPrice.times(usdPrice) } : undefined, ) return spotPrices.map((sp) => sp.data) - }, [displayAsset.isRealUSD, isLoading, spotPrices, usdPrice.data]) + }, [displayAsset.isRealUSD, isLoading, spotPrices, usdPrice]) return { data, isLoading, isInitialLoading: isLoading } } diff --git a/src/utils/farms/claiming.tsx b/src/utils/farms/claiming.tsx index 3ed64b3fd..0bf9d4afe 100644 --- a/src/utils/farms/claiming.tsx +++ b/src/utils/farms/claiming.tsx @@ -46,24 +46,28 @@ export const useClaimFarmMutation = ( depositId: string joinFarms: Array<[string, string]> exitFarms: Array + isActiveFarm: boolean + yieldFarmId: string }> >((acc, farm) => { - const { yieldFarmId, globalFarmId, depositId } = farm + const { yieldFarmId, globalFarmId, depositId, isActiveFarm } = farm const liquidityPositionId = farm.liquidityPositionId! const existingEntry = acc.find( (entry) => entry.liquidityPositionId === liquidityPositionId, ) - if (existingEntry) { + if (existingEntry && isActiveFarm) { existingEntry.joinFarms.push([globalFarmId, yieldFarmId]) existingEntry.exitFarms.push(yieldFarmId) } else { acc.push({ liquidityPositionId, - joinFarms: [[globalFarmId, yieldFarmId]], - exitFarms: [yieldFarmId], + joinFarms: isActiveFarm ? [[globalFarmId, yieldFarmId]] : [], + exitFarms: isActiveFarm ? [yieldFarmId] : [], depositId, + isActiveFarm, + yieldFarmId, }) } @@ -71,14 +75,26 @@ export const useClaimFarmMutation = ( }, []) const omnipoolTxs = farmEntries.flatMap((farmEntry) => [ - api.tx.omnipoolLiquidityMining.exitFarms( - farmEntry.depositId, - farmEntry.exitFarms, - ), - api.tx.omnipoolLiquidityMining.joinFarms( - farmEntry.joinFarms, - farmEntry.liquidityPositionId, - ), + ...(farmEntry.exitFarms.length + ? [ + api.tx.omnipoolLiquidityMining.exitFarms( + farmEntry.depositId, + farmEntry.exitFarms, + ), + api.tx.omnipoolLiquidityMining.joinFarms( + farmEntry.joinFarms, + farmEntry.liquidityPositionId, + ), + ] + : []), + ...(farmEntry.isActiveFarm + ? [] + : [ + api.tx.omnipoolLiquidityMining.withdrawShares( + farmEntry.depositId, + farmEntry.yieldFarmId, + ), + ]), ]) return omnipoolTxs @@ -94,9 +110,18 @@ export const useClaimFarmMutation = ( exitFarms: Array assetPair: AssetPair shares: string + yieldFarmId: string + isActiveFarm: boolean }> >((acc, farm) => { - const { yieldFarmId, globalFarmId, depositId, shares, poolId } = farm + const { + yieldFarmId, + globalFarmId, + depositId, + shares, + poolId, + isActiveFarm, + } = farm const meta = getShareTokenByAddress(poolId) if (meta) { @@ -104,19 +129,21 @@ export const useClaimFarmMutation = ( (entry) => entry.depositId === depositId, ) - if (existingEntry) { + if (existingEntry && isActiveFarm) { existingEntry.joinFarms.push([globalFarmId, yieldFarmId]) existingEntry.exitFarms.push(yieldFarmId) } else { acc.push({ depositId, - joinFarms: [[globalFarmId, yieldFarmId]], - exitFarms: [yieldFarmId], + joinFarms: isActiveFarm ? [[globalFarmId, yieldFarmId]] : [], + exitFarms: isActiveFarm ? [yieldFarmId] : [], assetPair: { assetIn: meta.assets[0].id, assetOut: meta.assets[1].id, }, shares, + isActiveFarm, + yieldFarmId, }) } } @@ -125,16 +152,29 @@ export const useClaimFarmMutation = ( }, []) const xykTxs = farmEntries.flatMap((farmEntry) => [ - api.tx.xykLiquidityMining.exitFarms( - farmEntry.depositId, - farmEntry.assetPair, - farmEntry.exitFarms, - ), - api.tx.xykLiquidityMining.joinFarms( - farmEntry.joinFarms, - farmEntry.assetPair, - farmEntry.shares, - ), + ...(farmEntry.exitFarms.length + ? [ + api.tx.xykLiquidityMining.exitFarms( + farmEntry.depositId, + farmEntry.assetPair, + farmEntry.exitFarms, + ), + api.tx.xykLiquidityMining.joinFarms( + farmEntry.joinFarms, + farmEntry.assetPair, + farmEntry.shares, + ), + ] + : []), + ...(farmEntry.isActiveFarm + ? [] + : [ + api.tx.xykLiquidityMining.withdrawShares( + farmEntry.depositId, + farmEntry.yieldFarmId, + farmEntry.assetPair, + ), + ]), ]) return xykTxs diff --git a/src/utils/helpers.ts b/src/utils/helpers.ts index 07cab3c4c..eb78c9d1c 100644 --- a/src/utils/helpers.ts +++ b/src/utils/helpers.ts @@ -342,7 +342,7 @@ export const isJson = (item: string) => { export const sortAssets = ( assets: Array, - balanceKey: Extract, string>, + balanceKey: Extract, string>, firstAssetId?: string, ) => { const tickerOrder = [ @@ -431,3 +431,9 @@ export const arraysEqual = (arr1: T[], arr2: T[]): boolean => { export const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)) + +export const bnSort = (valueA?: string, valueB?: string) => { + if (valueA === undefined || valueB === undefined) return -1 + + return BN(valueA).gt(valueB) ? 1 : -1 +} diff --git a/src/utils/queryKeys.ts b/src/utils/queryKeys.ts index dcfd426dc..eb941d121 100644 --- a/src/utils/queryKeys.ts +++ b/src/utils/queryKeys.ts @@ -78,13 +78,19 @@ export const QUERY_KEYS = { poolId?.toString(), ], omnipoolActiveFarms: ["omnipoolActiveFarms"], - omnipoolFarms: (address?: string) => [ + omnipoolFarms: [QUERY_KEY_PREFIX, "omnipoolFarms"], + stoppedOmnipoolFarms: (address?: string) => [ QUERY_KEY_PREFIX, - "omnipoolFarms", + "stoppedOmnipoolFarms", address, ], xykActiveFarms: ["xykActiveFarms"], - xykFarms: (address?: string) => [QUERY_KEY_PREFIX, "xykFarms", address], + xykFarms: [QUERY_KEY_PREFIX, "xykFarms"], + stoppedXykFarms: (address?: string) => [ + QUERY_KEY_PREFIX, + "stoppedXykFarms", + address, + ], totalIssuances: ["totalIssuances"], reserves: (id: Maybe, address: Maybe) => [ QUERY_KEY_PREFIX, diff --git a/yarn.lock b/yarn.lock index 600cbf7e7..30102728f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2268,10 +2268,10 @@ resolved "https://registry.yarnpkg.com/@galacticcouncil/math-xyk/-/math-xyk-1.0.0.tgz#eeb6f3693587c96131647a24af31536cab423d96" integrity sha512-n44M7jKes5Rxr4RQZ5W7kscTfoO4xwhW3VL/VyaEP1KEHMavlICpDNOlCwO/k6RTr+UXU8cHLJZdBzGFa2soJA== -"@galacticcouncil/sdk@^5.0.1": - version "5.0.1" - resolved "https://registry.yarnpkg.com/@galacticcouncil/sdk/-/sdk-5.0.1.tgz#0d4490e0ca32e8975a0554aa94277d589d6fd907" - integrity sha512-TPIxweaNMPtj1FyRzyXwdhU4GghIUGSOrrrKilpiRUkaL6TABH4MRw8zYDXsh5b1XD1pRu6cA0hgZYIZRg6+CQ== +"@galacticcouncil/sdk@^5.1.0": + version "5.1.0" + resolved "https://registry.yarnpkg.com/@galacticcouncil/sdk/-/sdk-5.1.0.tgz#20471487117d78a7d77e2dfb3b5452fe50b08f29" + integrity sha512-+/t5KX69fSYmSoDlPXL5xYtcIwKCcVU+3xuOjYTdi84gMbCR2ny7p0tzzgnDc+FIV64JRlUqaATWfawiVNAJ+Q== dependencies: "@galacticcouncil/math-lbp" "^1.0.0" "@galacticcouncil/math-liquidity-mining" "^1.0.0" @@ -2294,10 +2294,10 @@ lit "^3.1.4" ts-debounce "^4.0.0" -"@galacticcouncil/xcm-cfg@^5.6.0": - version "5.6.0" - resolved "https://registry.yarnpkg.com/@galacticcouncil/xcm-cfg/-/xcm-cfg-5.6.0.tgz#c58f1a6931d374b34c0ad6012b3eb1dc3392c964" - integrity sha512-y42O/L2rkYAkio+lxMpRLwDVCAKD43IJ5NrnIGy4i2lvGyH6PcuKGaB7szHxM6QGUPyL4IMXGaNdxoe9IfeStA== +"@galacticcouncil/xcm-cfg@^5.7.1": + version "5.7.1" + resolved "https://registry.yarnpkg.com/@galacticcouncil/xcm-cfg/-/xcm-cfg-5.7.1.tgz#6675625ddafbb3937233b7318ce6104975dda669" + integrity sha512-Be+lNGcfx96Q3wWpaC460AcNcSawJNJrPF8FgIXmoFcXTFcCXzG/Ut75CYGv67Z/3Z//jjIVXJFB5X08QlmVPw== dependencies: "@galacticcouncil/xcm-core" "^5.4.0"