Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes-13.09.23 #1381

Merged
merged 3 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion craco.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ module.exports = {
plugins: [
'babel-plugin-transform-typescript-metadata',
['@babel/plugin-proposal-decorators', { legacy: true }],
['@babel/plugin-proposal-class-properties', { loose: true }]
['@babel/plugin-proposal-class-properties', { loose: true }],
['@babel/plugin-transform-private-property-in-object', { loose: true }],
['@babel/plugin-transform-private-methods', { loose: true }]
],
loaderOptions: babelLoaderOptions => {
return babelLoaderOptions;
Expand Down
53 changes: 53 additions & 0 deletions src/modules/liquidity/pages/liquidity/hooks/helpers/find-dex.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
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<FoundDex> {
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<any>();
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<any>();
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();
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { findDex, FoundDex, Token as QuipuswapSdkToken } from '@quipuswap/sdk';
import { FoundDex, Token as QuipuswapSdkToken } 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
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, toArray } from '@shared/helpers';
import { isExist, isNull, resolveOrNull, toArray } from '@shared/helpers';
import { nat, Nullable } from '@shared/types';

import { earningsMapSchema, rewardMapSchema } from '../../../schemas/get-staker-info.schemas';
Expand Down Expand Up @@ -49,7 +49,9 @@ const getSinglePoolStakerInfo = async (
) => {
const { storage } = await getStorageInfo<StableswapStorage>(tezos, contractAddress);
const { pools, stakers_balance } = storage;
const stakerAccum = (await stakers_balance.get([accountPkh, poolId])) ?? {
const _stakerAccum = await resolveOrNull(stakers_balance.get([accountPkh, poolId]));

const stakerAccum = _stakerAccum ?? {
balance: new BigNumber(ZERO_AMOUNT),
earnings: new MichelsonMap<nat, EarningsValue>(earningsMapSchema)
};
Expand Down
1 change: 1 addition & 0 deletions src/shared/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,4 @@ export * from './math';
export * from './get-precentage-from-number';
export * from './set-caret-position';
export * from './can-use-three-route-api';
export * from './resolve-or-null';
7 changes: 7 additions & 0 deletions src/shared/helpers/resolve-or-null.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const resolveOrNull = async <T>(value: Promise<T>): Promise<T | null> => {
try {
return await value;
} catch (e) {
return null;
}
};
Loading