Skip to content

Commit

Permalink
Merge pull request #1382 from madfish-solutions/v3.4.1
Browse files Browse the repository at this point in the history
Merge pull request #1380 from madfish-solutions/main
  • Loading branch information
Digberi authored Sep 13, 2023
2 parents c5f168e + edeef67 commit 1d2e3db
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 5 deletions.
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "quipuswap-webapp-2",
"version": "3.4.0",
"version": "3.4.1",
"private": true,
"scripts": {
"pre-build": "node -v && npm -v && yarn -v && node ./scripts/build.js",
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;
}
};

1 comment on commit 1d2e3db

@vercel
Copy link

@vercel vercel bot commented on 1d2e3db Sep 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.