diff --git a/package.json b/package.json index a8572656a..86af86297 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "quipuswap-webapp-2", - "version": "3.4.1", + "version": "3.4.2", "private": true, "scripts": { "pre-build": "node -v && npm -v && yarn -v && node ./scripts/build.js", @@ -26,7 +26,7 @@ "@craco/craco": "^6.4.3", "@percy/cli": "^1.7.2", "@quipuswap/sdk": "^3.0.3", - "@quipuswap/tokens-whitelist": "^1.1.19", + "@quipuswap/tokens-whitelist": "^1.1.25", "@sentry/react": "^7.11.1", "@sentry/tracing": "^7.11.1", "@taquito/beacon-wallet": "17.3.0", diff --git a/src/index.tsx b/src/index.tsx index c55fb4cbe..af59bfbca 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -12,10 +12,12 @@ import { DAppProvider } from '@providers/use-dapp'; import { ExchangeRatesProvider, NewExchangeRatesProvider } from '@providers/use-new-exchange-rate'; import { sentryService } from '@shared/services'; -import { App } from './app'; +import { App } from './app'; // + +import './overrides'; // eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires -require('dotenv').config(); // +require('dotenv').config(); const container = document.getElementById('root'); diff --git a/src/modules/liquidity/api/blockchain/dex-two-liquidity.api.ts b/src/modules/liquidity/api/blockchain/dex-two-liquidity.api.ts index d8c4e6a70..cdd2be6ae 100644 --- a/src/modules/liquidity/api/blockchain/dex-two-liquidity.api.ts +++ b/src/modules/liquidity/api/blockchain/dex-two-liquidity.api.ts @@ -3,7 +3,7 @@ import BigNumber from 'bignumber.js'; import { BucketContractStorage, DexTwoContractStorage } from '@modules/liquidity/types'; import { getContract, getStorageInfo } from '@shared/dapp'; -import { defined } from '@shared/helpers'; +import { defined, unpackOption } from '@shared/helpers'; import { Nullable } from '@shared/types'; // TODO: https://madfish.atlassian.net/browse/QUIPU-613 @@ -11,7 +11,9 @@ export class BlockchainDexTwoLiquidityApi { static async getBucketContract(tezos: TezosToolkit, contractAddress: string, poolId: BigNumber) { const storage = await getStorageInfo(tezos, contractAddress); - const { bucket: bucketAddress } = defined(await storage.storage.pairs.get(poolId)); + const pair = await storage.storage.pairs.get(poolId); + + const bucketAddress = unpackOption(defined(pair).bucket); if (bucketAddress) { return await getContract(tezos, bucketAddress); diff --git a/src/modules/liquidity/pages/cpmm-item/cpmm-page-router.tsx b/src/modules/liquidity/pages/cpmm-item/cpmm-page-router.tsx index 53903cdc0..2360e8249 100644 --- a/src/modules/liquidity/pages/cpmm-item/cpmm-page-router.tsx +++ b/src/modules/liquidity/pages/cpmm-item/cpmm-page-router.tsx @@ -8,7 +8,7 @@ import { PageNotFoundPage } from '@modules/errors'; import { LoaderFallback, StateWrapper } from '@shared/components'; import { SentryRoutes } from '@shared/services'; -import { CpmmDexTwoClaimRewards } from './cpmm-dex-two-claim-rewards'; +// import { CpmmDexTwoClaimRewards } from './cpmm-dex-two-claim-rewards'; import { DexTwoAddLiq } from './dex-two-add-liq'; import { DexTwoRemoveLiq } from './dex-two-remove-liq'; import { useCpmmViewModel } from './use-dex-two-item-page.vm'; @@ -16,7 +16,7 @@ import { LiquidityTabs } from '../../liquidity-routes.enum'; import { LiquidityCreatePage } from '../create'; export const CpmmPageRouter: FC = observer(() => { - const { isInitialized, title } = useCpmmViewModel(); + const { isInitialized } = useCpmmViewModel(); return ( }> @@ -25,8 +25,8 @@ export const CpmmPageRouter: FC = observer(() => { } /> } /> } /> - } /> - } /> + {/* } /> + } /> */} } /> } /> diff --git a/src/modules/liquidity/pages/liquidity/hooks/helpers/find-dex.ts b/src/modules/liquidity/pages/liquidity/hooks/helpers/find-dex.ts deleted file mode 100644 index 255d906c5..000000000 --- a/src/modules/liquidity/pages/liquidity/hooks/helpers/find-dex.ts +++ /dev/null @@ -1,53 +0,0 @@ -import { - chooseDex, - ContractOrAddress, - DexNotFoundError, - Factories, - FoundDex, - isFA2Token, - Token as QuipuswapSdkToken, - toContract, - toContractAddress -} from '@quipuswap/sdk'; -import { TezosToolkit } from '@taquito/taquito'; - -import { resolveOrNull } from '@shared/helpers'; - -export async function findDex( - tezos: TezosToolkit, - { fa1_2Factory, fa2Factory }: Factories, - token: QuipuswapSdkToken -): Promise { - let factories = isFA2Token(token) ? fa2Factory : fa1_2Factory; - if (!Array.isArray(factories)) { - factories = [factories]; - } - - const tokenAddress = toContractAddress(token.contract); - const t2dexQuery = isFA2Token(token) ? [tokenAddress, token.id] : tokenAddress; - - const dexes: FoundDex[] = []; - await Promise.all( - factories.map(async factory => { - const facContract = await toContract(tezos, factory); - // eslint-disable-next-line @typescript-eslint/no-explicit-any - const facStorage = await facContract.storage(); - const dexAddress = await resolveOrNull(facStorage.token_to_exchange.get(t2dexQuery)); - - if (dexAddress) { - const dexContract = await toContract(tezos, dexAddress as ContractOrAddress); - // eslint-disable-next-line @typescript-eslint/no-explicit-any - const dexStorage = await dexContract.storage(); - dexes.push(new FoundDex(dexContract, dexStorage)); - } - }) - ); - - if (dexes.length > 1) { - return dexes.sort(chooseDex)[0]; - } else if (dexes.length === 1) { - return dexes[0]; - } else { - throw new DexNotFoundError(); - } -} diff --git a/src/modules/liquidity/pages/liquidity/hooks/helpers/load-tez-dex.ts b/src/modules/liquidity/pages/liquidity/hooks/helpers/load-tez-dex.ts index 8a111acb5..a45b94c8e 100644 --- a/src/modules/liquidity/pages/liquidity/hooks/helpers/load-tez-dex.ts +++ b/src/modules/liquidity/pages/liquidity/hooks/helpers/load-tez-dex.ts @@ -1,10 +1,9 @@ -import { FoundDex, Token as QuipuswapSdkToken } from '@quipuswap/sdk'; +import { FoundDex, Token as QuipuswapSdkToken, findDex } from '@quipuswap/sdk'; import { TezosToolkit } from '@taquito/taquito'; import { FACTORIES } from '@config/config'; import { Nullable, SupportedNetworks, Token } from '@shared/types'; -import { findDex } from './find-dex'; import { findNotTezToken } from '../../liquidity-cards/helpers'; export const loadTezDex = async ({ diff --git a/src/modules/liquidity/pages/v3-item-page/components/open-new-position/create-new-position.tsx b/src/modules/liquidity/pages/v3-item-page/components/open-new-position/create-new-position.tsx index 8d3bccb41..3284371fd 100644 --- a/src/modules/liquidity/pages/v3-item-page/components/open-new-position/create-new-position.tsx +++ b/src/modules/liquidity/pages/v3-item-page/components/open-new-position/create-new-position.tsx @@ -1,8 +1,9 @@ import { FC, useContext } from 'react'; import cx from 'classnames'; -import { useLocation } from 'react-router-dom'; +import { useLocation, useParams } from 'react-router-dom'; +import { IS_NETWORK_MAINNET } from '@config/config'; import { SLASH } from '@config/constants'; import { ColorModes, ColorThemeContext } from '@providers/color-theme-context'; import { Button, Card } from '@shared/components'; @@ -20,16 +21,51 @@ const modeClass = { export const OpenNewPosition: FC = () => { const { t } = useTranslation(); const { colorThemeMode } = useContext(ColorThemeContext); + const { pathname } = useLocation(); const sanitizedPathname = `/${getRouterParts(pathname).join(SLASH)}`; const url = `${sanitizedPathname}${LiquidityRoutes.create}`; + const params = useParams(); + + const is83 = params?.id === '83' && IS_NETWORK_MAINNET; + return ( - -

{t('liquidity|induceToOpenNewPosition')}

- + + {is83 ? ( +
+

The deposits to the pool are paused.

+
+ ) : ( + <> +

{t('liquidity|induceToOpenNewPosition')}

+ + + )}
); }; diff --git a/src/modules/liquidity/pages/v3-item-page/create-new-position.page.tsx b/src/modules/liquidity/pages/v3-item-page/create-new-position.page.tsx index 79b0e9534..13e147aa2 100644 --- a/src/modules/liquidity/pages/v3-item-page/create-new-position.page.tsx +++ b/src/modules/liquidity/pages/v3-item-page/create-new-position.page.tsx @@ -6,7 +6,7 @@ import { OpenNewPositionForm, PageTitleContainer, PoolDetailsCreate, PositionFor import { useCreateNewPositionPageViewModel } from './use-create-new-position-page.vm'; export const CreateNewPositionPage = observer(() => { - const { titleText, backHref, ...formProps } = useCreateNewPositionPageViewModel(); + const { titleText, backHref, isBlocked, ...formProps } = useCreateNewPositionPageViewModel(); return ( <> @@ -14,7 +14,26 @@ export const CreateNewPositionPage = observer(() => { - + {isBlocked ? ( +
+

The deposits to the pool are paused.

+
+ ) : ( + + )}
diff --git a/src/modules/liquidity/pages/v3-item-page/use-create-new-position-page.vm.ts b/src/modules/liquidity/pages/v3-item-page/use-create-new-position-page.vm.ts index 870061eeb..9ee1bf832 100644 --- a/src/modules/liquidity/pages/v3-item-page/use-create-new-position-page.vm.ts +++ b/src/modules/liquidity/pages/v3-item-page/use-create-new-position-page.vm.ts @@ -2,6 +2,7 @@ import { useEffect, useMemo } from 'react'; import BigNumber from 'bignumber.js'; +import { IS_NETWORK_MAINNET } from '@config/config'; import { ZERO_AMOUNT_BN } from '@config/constants'; import { useGetLiquidityV3ItemWithPositions, @@ -109,6 +110,7 @@ export const useCreateNewPositionPageViewModel = () => { rangeInputsProps, titleText: t('liquidity|createPosition'), backHref, - warningMessages + warningMessages, + isBlocked: poolStore.poolId?.toFixed() === '83' && IS_NETWORK_MAINNET }; }; diff --git a/src/modules/liquidity/pages/v3-item-page/use-v3-item-page.vm.ts b/src/modules/liquidity/pages/v3-item-page/use-v3-item-page.vm.ts index 8ee58d3a5..c61520f60 100644 --- a/src/modules/liquidity/pages/v3-item-page/use-v3-item-page.vm.ts +++ b/src/modules/liquidity/pages/v3-item-page/use-v3-item-page.vm.ts @@ -2,6 +2,7 @@ import { useEffect } from 'react'; import { useParams } from 'react-router-dom'; +import { IS_NETWORK_MAINNET } from '@config/config'; import { useLiquidityV3PoolStore, useLiquidityV3ItemTokens, @@ -35,5 +36,5 @@ export const useV3ItemPageViewModel = () => { void v3PositionsStore.positionsStore.load(); }, [getLiquidityV3ItemBalances, getLiquidityV3Pool, v3PositionsStore.positionsStore, poolId, tabId]); - return { isLoading, error, isAddLiqForm, tabId }; + return { isLoading, error, isAddLiqForm, tabId, isBlocked: poolId?.toFixed() === '83' && IS_NETWORK_MAINNET }; }; diff --git a/src/modules/liquidity/pages/v3-item-page/v3-item-page.tsx b/src/modules/liquidity/pages/v3-item-page/v3-item-page.tsx index 2d0958199..4b834139a 100644 --- a/src/modules/liquidity/pages/v3-item-page/v3-item-page.tsx +++ b/src/modules/liquidity/pages/v3-item-page/v3-item-page.tsx @@ -15,7 +15,7 @@ import styles from './v3-item-page.module.scss'; export const V3ItemPage: FC = observer(() => { const { t } = useTranslation(); - const { isLoading, isAddLiqForm, tabId } = useV3ItemPageViewModel(); + const { isLoading, isAddLiqForm, tabId, isBlocked } = useV3ItemPageViewModel(); return ( <> @@ -28,7 +28,30 @@ export const V3ItemPage: FC = observer(() => {
- {isAddLiqForm ? : } + {isAddLiqForm ? ( + isBlocked ? ( +
+

The deposits to the pool are paused.

+
+ ) : ( + + ) + ) : ( + + )}
diff --git a/src/modules/liquidity/types/api.ts b/src/modules/liquidity/types/api.ts index 4d2f3f779..0debbe127 100644 --- a/src/modules/liquidity/types/api.ts +++ b/src/modules/liquidity/types/api.ts @@ -1,4 +1,4 @@ -import { BigMap, BlockInfoWrap, nat, Nullable } from '@shared/types'; +import { BigMap, BlockInfoWrap, nat, Option } from '@shared/types'; export interface NewLiquidityStatsResponse extends IRawNewLiquidityStats, BlockInfoWrap {} @@ -19,7 +19,7 @@ export interface DexTwoPair { token_b_price_cml: nat; total_supply: nat; last_block_timestamp: Date | string; - bucket: Nullable; + bucket: Option; } export interface DexTwoContractStorage { diff --git a/src/modules/stableswap/api/blockchain/stabledividends/get-staker-info.api.ts b/src/modules/stableswap/api/blockchain/stabledividends/get-staker-info.api.ts index 96ad5ccc2..29cee4d68 100644 --- a/src/modules/stableswap/api/blockchain/stabledividends/get-staker-info.api.ts +++ b/src/modules/stableswap/api/blockchain/stabledividends/get-staker-info.api.ts @@ -3,7 +3,7 @@ import BigNumber from 'bignumber.js'; import { DEFAULT_STABLESWAP_POOL_ID, STABLESWAP_DIVIDENDS_ACCUM_PRECISION, ZERO_AMOUNT } from '@config/constants'; import { getStorageInfo } from '@shared/dapp/get-storage-info'; -import { isExist, isNull, resolveOrNull, toArray } from '@shared/helpers'; +import { isExist, isNull, toArray } from '@shared/helpers'; import { nat, Nullable } from '@shared/types'; import { earningsMapSchema, rewardMapSchema } from '../../../schemas/get-staker-info.schemas'; @@ -49,9 +49,8 @@ const getSinglePoolStakerInfo = async ( ) => { const { storage } = await getStorageInfo(tezos, contractAddress); const { pools, stakers_balance } = storage; - const _stakerAccum = await resolveOrNull(stakers_balance.get([accountPkh, poolId])); - const stakerAccum = _stakerAccum ?? { + const stakerAccum = (await stakers_balance.get([accountPkh, poolId])) ?? { balance: new BigNumber(ZERO_AMOUNT), earnings: new MichelsonMap(earningsMapSchema) }; diff --git a/src/overrides.ts b/src/overrides.ts new file mode 100644 index 000000000..fb5352af9 --- /dev/null +++ b/src/overrides.ts @@ -0,0 +1,24 @@ +/* eslint-disable no-console */ +import { HttpResponseError, STATUS_CODE } from '@taquito/http-utils'; +import { BigMapAbstraction } from '@taquito/taquito'; + +import { BigMapKeyType } from '@shared/types'; + +const originalGet = BigMapAbstraction.prototype.get; + +BigMapAbstraction.prototype.get = async function ( + keyToEncode: BigMapKeyType, + block?: number +): Promise { + const promiseResponse = originalGet.call(this, keyToEncode, block) as Promise; + + try { + return await promiseResponse; + } catch (error) { + if (error instanceof HttpResponseError && error.status === STATUS_CODE.NOT_FOUND) { + return undefined; + } + + throw error; + } +}; diff --git a/src/shared/helpers/blockchain/index.ts b/src/shared/helpers/blockchain/index.ts index d3ac8299a..f4558f152 100644 --- a/src/shared/helpers/blockchain/index.ts +++ b/src/shared/helpers/blockchain/index.ts @@ -1,2 +1,3 @@ export * from './batch-operations'; export * from './get-blockchain-timestamp'; +export * from './unpack-option'; diff --git a/src/shared/helpers/blockchain/unpack-option.ts b/src/shared/helpers/blockchain/unpack-option.ts new file mode 100644 index 000000000..e7e2a6edf --- /dev/null +++ b/src/shared/helpers/blockchain/unpack-option.ts @@ -0,0 +1,5 @@ +import { Option } from '@shared/types'; + +export const unpackOption = (option: Option): T | null => { + return option?.Some ?? null; +}; diff --git a/src/shared/types/contract-storage.types.ts b/src/shared/types/contract-storage.types.ts index e809b53a2..686d1b172 100644 --- a/src/shared/types/contract-storage.types.ts +++ b/src/shared/types/contract-storage.types.ts @@ -39,3 +39,5 @@ export interface FA2Token { } export type TokensValue = TezToken | FA12Token | FA2Token; + +export type Option = { Some: T } | null; diff --git a/src/shared/utils/toasts/use-toasts.ts b/src/shared/utils/toasts/use-toasts.ts index 8eb7116ac..ab68b782a 100644 --- a/src/shared/utils/toasts/use-toasts.ts +++ b/src/shared/utils/toasts/use-toasts.ts @@ -36,8 +36,7 @@ const getErrorMessage = (error: Error | object | string) => { } if (error instanceof HttpRequestFailed) { - // eslint-disable-next-line @typescript-eslint/no-unused-vars - const [_, url] = error.message.split(' '); + const [, url] = error.message.split(' '); return i18n.t('common|requestFailed', { url }); } diff --git a/yarn.lock b/yarn.lock index d26e1b74e..a566720fb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2615,10 +2615,10 @@ dependencies: bignumber.js "^9.1.0" -"@quipuswap/tokens-whitelist@^1.1.19": - version "1.1.19" - resolved "https://registry.yarnpkg.com/@quipuswap/tokens-whitelist/-/tokens-whitelist-1.1.19.tgz#50056322f00c2bbef0db3f2115cc860466a6bc6e" - integrity sha512-7cZ9MFeyFkLBXiV3nHTBQbT7AK37RlmJYD4ctuZrvWTFKJXbXXtTZJbVZXEoWVC7HUG6BQrncX1aRTYmJAIqLw== +"@quipuswap/tokens-whitelist@^1.1.25": + version "1.1.25" + resolved "https://registry.yarnpkg.com/@quipuswap/tokens-whitelist/-/tokens-whitelist-1.1.25.tgz#773b49d6e2ff23a3cf5f64bca17bf015834ceec4" + integrity sha512-0iX+4u0vVElDoO7IZXbEsoIZNlcVRrAhKI0U6+EYccJERbYf5WMd0zKomsyYnUUuD1yXx49nMrPsTO/GL0ddJA== "@remix-run/router@1.8.0": version "1.8.0"