From 081cdbb0bee60cc980ff73c4c9594456a3fa6bb2 Mon Sep 17 00:00:00 2001 From: yurixander <101931215+yurixander@users.noreply.github.com> Date: Wed, 2 Oct 2024 20:43:53 -0400 Subject: [PATCH] refactor(tangle-dapp): Get rid of Liquifier remenants --- .../UnstakeRequestsTable.tsx | 17 +--- .../data/liquidStaking/useLsExchangeRate.ts | 86 +------------------ 2 files changed, 5 insertions(+), 98 deletions(-) diff --git a/apps/tangle-dapp/components/LiquidStaking/unstakeRequestsTable/UnstakeRequestsTable.tsx b/apps/tangle-dapp/components/LiquidStaking/unstakeRequestsTable/UnstakeRequestsTable.tsx index 4b9076e5a..f8ed45efc 100644 --- a/apps/tangle-dapp/components/LiquidStaking/unstakeRequestsTable/UnstakeRequestsTable.tsx +++ b/apps/tangle-dapp/components/LiquidStaking/unstakeRequestsTable/UnstakeRequestsTable.tsx @@ -78,16 +78,11 @@ const COLUMNS = [ COLUMN_HELPER.accessor('unlockId', { header: () => , cell: (props) => { - const canSelect = - props.row.original.type === 'liquifierUnlockNft' - ? props.row.original.progress === 1 - : true; - return (
@@ -137,11 +132,7 @@ const COLUMNS = [ header: () => , cell: (props) => { const unstakeRequest = props.row.original; - - const tokenSymbol = - unstakeRequest.type === 'parachainUnstakeRequest' - ? unstakeRequest.currency.toUpperCase() - : unstakeRequest.symbol; + const tokenSymbol = unstakeRequest.currency.toUpperCase(); return ( { // If the remaining time unit is undefined, it means that the // request has completed its unlocking period. - return request.type === 'parachainUnstakeRequest' - ? request.progress === undefined - : request.progress === 1; + return request.progress === undefined; }); }, [selectedRowsUnlockIds, rows]); diff --git a/apps/tangle-dapp/data/liquidStaking/useLsExchangeRate.ts b/apps/tangle-dapp/data/liquidStaking/useLsExchangeRate.ts index 90ce55ed7..b1819d6ab 100644 --- a/apps/tangle-dapp/data/liquidStaking/useLsExchangeRate.ts +++ b/apps/tangle-dapp/data/liquidStaking/useLsExchangeRate.ts @@ -1,10 +1,7 @@ import { BN } from '@polkadot/util'; import { TANGLE_RESTAKING_PARACHAIN_LOCAL_DEV_NETWORK } from '@webb-tools/webb-ui-components/constants/networks'; -import { useCallback, useEffect, useMemo, useState } from 'react'; -import { erc20Abi } from 'viem'; +import { useCallback, useMemo, useState } from 'react'; -import LIQUIFIER_ADAPTER_ABI from '../../constants/liquidStaking/liquifierAdapterAbi'; -import LIQUIFIER_TG_TOKEN_ABI from '../../constants/liquidStaking/liquifierTgTokenAbi'; import { LsNetworkId, LsParachainCurrencyKey, @@ -12,8 +9,6 @@ import { import useApiRx from '../../hooks/useApiRx'; import calculateBnRatio from '../../utils/calculateBnRatio'; import getLsProtocolDef from '../../utils/liquidStaking/getLsProtocolDef'; -import useContractRead from '../evm/useContractRead'; -import { ContractReadOptions } from '../evm/useContractReadOnce'; import { useLsStore } from './useLsStore'; import usePolling from './usePolling'; @@ -83,72 +78,10 @@ const useLsExchangeRate = (type: ExchangeRateType) => { return computeExchangeRate(type, tokenPoolAmount, lstTotalIssuance); }, [lstTotalIssuance, tokenPoolAmount, type]); - const getTgTokenTotalSupplyOptions = useCallback((): ContractReadOptions< - typeof LIQUIFIER_TG_TOKEN_ABI, - 'totalSupply' - > | null => { - if (protocol.networkId !== LsNetworkId.ETHEREUM_MAINNET_LIQUIFIER) { - return null; - } - - return { - address: protocol.erc20TokenAddress, - functionName: 'totalSupply', - args: [], - }; - }, [protocol]); - - const getLiquifierTotalSharesOptions = useCallback((): ContractReadOptions< - typeof LIQUIFIER_ADAPTER_ABI, - 'totalShares' - > | null => { - if (protocol.networkId !== LsNetworkId.ETHEREUM_MAINNET_LIQUIFIER) { - return null; - } - - return { - address: protocol.liquifierContractAddress, - functionName: 'totalShares', - args: [], - }; - }, [protocol]); - - const { - value: tgTokenTotalSupply, - setIsPaused: setIsTgTokenTotalSupplyPaused, - } = useContractRead(erc20Abi, getTgTokenTotalSupplyOptions); - - const { - value: liquifierTotalShares, - setIsPaused: setIsLiquifierTotalSharesPaused, - } = useContractRead(LIQUIFIER_ADAPTER_ABI, getLiquifierTotalSharesOptions); - - const fetchLiquifierExchangeRate = useCallback(async () => { - // Propagate error or loading states. - if (typeof tgTokenTotalSupply !== 'bigint') { - return tgTokenTotalSupply; - } else if (typeof liquifierTotalShares !== 'bigint') { - return liquifierTotalShares; - } - - const tgTokenTotalSupplyBn = new BN(tgTokenTotalSupply.toString()); - const liquifierTotalSharesBn = new BN(liquifierTotalShares.toString()); - - return computeExchangeRate( - type, - tgTokenTotalSupplyBn, - liquifierTotalSharesBn, - ); - }, [liquifierTotalShares, tgTokenTotalSupply, type]); - const fetch = useCallback(async () => { let promise: Promise; switch (selectedNetworkId) { - case LsNetworkId.ETHEREUM_MAINNET_LIQUIFIER: - promise = fetchLiquifierExchangeRate(); - - break; case LsNetworkId.TANGLE_RESTAKING_PARACHAIN: promise = parachainExchangeRate; @@ -170,22 +103,7 @@ const useLsExchangeRate = (type: ExchangeRateType) => { } setExchangeRate(newExchangeRate); - }, [fetchLiquifierExchangeRate, parachainExchangeRate, selectedNetworkId]); - - // Pause or resume ERC20-based exchange rate fetching based - // on whether the requested protocol is a parachain or an ERC20 token. - // This helps prevent unnecessary requests. - useEffect(() => { - const isPaused = - protocol.networkId === LsNetworkId.TANGLE_RESTAKING_PARACHAIN; - - setIsTgTokenTotalSupplyPaused(isPaused); - setIsLiquifierTotalSharesPaused(isPaused); - }, [ - protocol.networkId, - setIsLiquifierTotalSharesPaused, - setIsTgTokenTotalSupplyPaused, - ]); + }, [parachainExchangeRate, selectedNetworkId]); const isRefreshing = usePolling({ effect: fetch });