Skip to content

Commit

Permalink
base fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Digberi committed Sep 14, 2023
1 parent 074c6d4 commit 7bd0078
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 70 deletions.
6 changes: 4 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
6 changes: 4 additions & 2 deletions src/modules/liquidity/api/blockchain/dex-two-liquidity.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ 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
export class BlockchainDexTwoLiquidityApi {
static async getBucketContract(tezos: TezosToolkit, contractAddress: string, poolId: BigNumber) {
const storage = await getStorageInfo<DexTwoContractStorage>(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);
Expand Down
8 changes: 4 additions & 4 deletions src/modules/liquidity/pages/cpmm-item/cpmm-page-router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ 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';
import { LiquidityTabs } from '../../liquidity-routes.enum';
import { LiquidityCreatePage } from '../create';

export const CpmmPageRouter: FC = observer(() => {
const { isInitialized, title } = useCpmmViewModel();
const { isInitialized } = useCpmmViewModel();

return (
<StateWrapper isLoading={!isInitialized} loaderFallback={<LoaderFallback />}>
Expand All @@ -25,8 +25,8 @@ export const CpmmPageRouter: FC = observer(() => {
<Route path={`${LiquidityTabs.add}/:pairSlug`} element={<DexTwoAddLiq />} />
<Route path={`${LiquidityTabs.remove}/${NOT_FOUND_ROUTE_NAME}`} element={<PageNotFoundPage />} />
<Route path={`${LiquidityTabs.remove}/:pairSlug`} element={<DexTwoRemoveLiq />} />
<Route path={`${LiquidityTabs.claim}/${NOT_FOUND_ROUTE_NAME}`} element={<PageNotFoundPage />} />
<Route path={`${LiquidityTabs.claim}/:pairSlug`} element={<CpmmDexTwoClaimRewards title={title} />} />
{/* <Route path={`${LiquidityTabs.claim}/${NOT_FOUND_ROUTE_NAME}`} element={<PageNotFoundPage />} />
<Route path={`${LiquidityTabs.claim}/:pairSlug`} element={<CpmmDexTwoClaimRewards title={title} />} /> */}
<Route path={`${LiquidityTabs.create}`} element={<LiquidityCreatePage />} />
<Route path="*" element={<PageNotFoundPage />} />
</SentryRoutes>
Expand Down
53 changes: 0 additions & 53 deletions src/modules/liquidity/pages/liquidity/hooks/helpers/find-dex.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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 ({
Expand Down
4 changes: 2 additions & 2 deletions src/modules/liquidity/types/api.ts
Original file line number Diff line number Diff line change
@@ -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 {}

Expand All @@ -19,7 +19,7 @@ export interface DexTwoPair {
token_b_price_cml: nat;
total_supply: nat;
last_block_timestamp: Date | string;
bucket: Nullable<string>;
bucket: Option<string>;
}

export interface DexTwoContractStorage {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -49,9 +49,8 @@ const getSinglePoolStakerInfo = async (
) => {
const { storage } = await getStorageInfo<StableswapStorage>(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<nat, EarningsValue>(earningsMapSchema)
};
Expand Down
24 changes: 24 additions & 0 deletions src/overrides.ts
Original file line number Diff line number Diff line change
@@ -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 <T>(
keyToEncode: BigMapKeyType,
block?: number
): Promise<T | undefined> {
const promiseResponse = originalGet.call(this, keyToEncode, block) as Promise<T>;

try {
return await promiseResponse;
} catch (error) {
if (error instanceof HttpResponseError && error.status === STATUS_CODE.NOT_FOUND) {
return undefined;
}

throw error;
}
};
1 change: 1 addition & 0 deletions src/shared/helpers/blockchain/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './batch-operations';
export * from './get-blockchain-timestamp';
export * from './unpack-option';
5 changes: 5 additions & 0 deletions src/shared/helpers/blockchain/unpack-option.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Option } from '@shared/types';

export const unpackOption = <T>(option: Option<T>): T | null => {
return option?.Some ?? null;
};
2 changes: 2 additions & 0 deletions src/shared/types/contract-storage.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,5 @@ export interface FA2Token {
}

export type TokensValue = TezToken | FA12Token | FA2Token;

export type Option<T> = { Some: T } | null;
3 changes: 1 addition & 2 deletions src/shared/utils/toasts/use-toasts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
Expand Down

0 comments on commit 7bd0078

Please sign in to comment.