Skip to content

Commit

Permalink
disable merged claim withdraw code, only withdraw directly to lp token
Browse files Browse the repository at this point in the history
  • Loading branch information
silochad committed Jul 8, 2023
1 parent a6f41fc commit 3eb5893
Showing 1 changed file with 79 additions and 79 deletions.
158 changes: 79 additions & 79 deletions projects/ui/src/components/Silo/Actions/Withdraw.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useCallback, useMemo } from 'react';
import { Box, Divider, Stack, Typography } from '@mui/material';
import { Box, Divider, Stack } from '@mui/material';
import BigNumber from 'bignumber.js';
import { Form, Formik, FormikHelpers, FormikProps } from 'formik';
import { useSelector } from 'react-redux';
Expand All @@ -10,8 +10,8 @@ import {
TokenValue,
BeanstalkSDK,
FarmToMode,
FarmFromMode,
StepGenerator,
// FarmFromMode,
// StepGenerator,
} from '@beanstalk/sdk';
import { SEEDS, STALK } from '~/constants/tokens';
import {
Expand Down Expand Up @@ -44,13 +44,13 @@ import FormTxnProvider from '~/components/Common/Form/FormTxnProvider';
import useFormTxnContext from '~/hooks/sdk/useFormTxnContext';
import { FormTxn, PlantAndDoX, WithdrawFarmStep } from '~/lib/Txn';
import FarmModeField from '~/components/Common/Form/FarmModeField';
import useToggle from '~/hooks/display/useToggle';
import PillRow from '~/components/Common/Form/PillRow';
import TokenIcon from '~/components/Common/TokenIcon';
import TokenSelectDialogNew, {
TokenSelectMode,
} from '~/components/Common/Form/TokenSelectDialogNew';
import { QuoteHandlerWithParams } from '~/hooks/ledger/useQuoteWithParams';
// import useToggle from '~/hooks/display/useToggle';
// import PillRow from '~/components/Common/Form/PillRow';
// import TokenIcon from '~/components/Common/TokenIcon';
// import TokenSelectDialogNew, {
// TokenSelectMode,
// } from '~/components/Common/Form/TokenSelectDialogNew';
// import { QuoteHandlerWithParams } from '~/hooks/ledger/useQuoteWithParams';

// -----------------------------------------------------------------------

Expand Down Expand Up @@ -143,84 +143,84 @@ const WithdrawForm: FC<
const isReady =
withdrawResult &&
!withdrawResult.amount.lt(0) &&
values.settings.destination !==
undefined(whitelistedToken.isLP ? values.tokenOut !== undefined : true);
values.settings.destination !== undefined;
// && (whitelistedToken.isLP ? values.tokenOut !== undefined : true);

const disabledActions = useMemo(
() => (whitelistedToken.isUnripe ? [FormTxn.ENROOT] : undefined),
[whitelistedToken.isUnripe]
);

//
const [isTokenSelectVisible, showTokenSelect, hideTokenSelect] = useToggle();
const pool = useMemo(
() => sdk.pools.getPoolByLPToken(whitelistedToken),
[sdk.pools, whitelistedToken]
);
const claimableTokens = useMemo(
() => [
whitelistedToken,
...((whitelistedToken.isLP && pool?.tokens) || []),
],
[pool, whitelistedToken]
);
// const [isTokenSelectVisible, showTokenSelect, hideTokenSelect] = useToggle();
// const pool = useMemo(
// () => sdk.pools.getPoolByLPToken(whitelistedToken),
// [sdk.pools, whitelistedToken]
// );
// const claimableTokens = useMemo(
// () => [
// whitelistedToken,
// ...((whitelistedToken.isLP && pool?.tokens) || []),
// ],
// [pool, whitelistedToken]
// );

//
const handleSelectTokens = useCallback(
(_tokens: Set<Token>) => {
const _token = Array.from(_tokens)[0];
setFieldValue('tokenOut', _token);
},
[setFieldValue]
);

const handleQuote = useCallback<
QuoteHandlerWithParams<QuoteHandlerWithParams>
>(
async (_tokenIn, _amountIn, _tokenOut, { toMode }) => {
if (_tokenIn === _tokenOut) return { amountOut: _amountIn };
const amountIn = _tokenIn.amount(_amountIn.toString());

const { curve } = sdk.contracts;

// Require pooldata to be loaded first.
if (!pool || !_tokenIn.isLP) return null;

const work = sdk.farm.create();
work.add(
new sdk.farm.actions.RemoveLiquidityOneToken(
pool.address,
curve.registries.metaFactory.address,
_tokenOut.address,
FarmFromMode.INTERNAL,
toMode
)
);
const estimate = await work.estimate(amountIn);

return {
amountOut: tokenValueToBN(_tokenOut.fromBlockchain(estimate)),
steps: work.generators as StepGenerator[],
};
},
[sdk.contracts, sdk.farm, pool]
);

const claimableBalance = values.tokens[0].amount || ZERO_BN;
// const handleSelectTokens = useCallback(
// (_tokens: Set<Token>) => {
// const _token = Array.from(_tokens)[0];
// setFieldValue('tokenOut', _token);
// },
// [setFieldValue]
// );

// const handleQuote = useCallback<
// QuoteHandlerWithParams<QuoteHandlerWithParams>
// >(
// async (_tokenIn, _amountIn, _tokenOut, { toMode }) => {
// if (_tokenIn === _tokenOut) return { amountOut: _amountIn };
// const amountIn = _tokenIn.amount(_amountIn.toString());

// const { curve } = sdk.contracts;

// // Require pooldata to be loaded first.
// if (!pool || !_tokenIn.isLP) return null;

// const work = sdk.farm.create();
// work.add(
// new sdk.farm.actions.RemoveLiquidityOneToken(
// pool.address,
// curve.registries.metaFactory.address,
// _tokenOut.address,
// FarmFromMode.INTERNAL,
// toMode
// )
// );
// const estimate = await work.estimate(amountIn);

// return {
// amountOut: tokenValueToBN(_tokenOut.fromBlockchain(estimate)),
// steps: work.generators as StepGenerator[],
// };
// },
// [sdk.contracts, sdk.farm, pool]
// );

// const claimableBalance = values.tokens[0].amount || ZERO_BN;

// This should be memoized to prevent an infinite reset loop
const quoteHandlerParams = useMemo(
() => ({
quoteSettings: {
ignoreSameToken: false,
onReset: () => ({ amountOut: claimableBalance }),
},
params: {
toMode: values.settings.destination || FarmToMode.INTERNAL,
},
}),
[claimableBalance, values.settings.destination]
);
// const quoteHandlerParams = useMemo(
// () => ({
// quoteSettings: {
// ignoreSameToken: false,
// onReset: () => ({ amountOut: claimableBalance }),
// },
// params: {
// toMode: values.settings.destination || FarmToMode.INTERNAL,
// },
// }),
// [claimableBalance, values.settings.destination]
// );

if (!tokenOut) return;

Expand Down Expand Up @@ -261,7 +261,7 @@ const WithdrawForm: FC<
{/** Setting: Destination */}
<FarmModeField name="settings.destination" />
{/* Setting: Claim LP */}
<>
{/* <>
{whitelistedToken.isLP ? (
<PillRow
isOpen={isTokenSelectVisible}
Expand All @@ -283,7 +283,7 @@ const WithdrawForm: FC<
tokenList={claimableTokens as Token[]}
mode={TokenSelectMode.SINGLE}
/>
</>
</> */}
<AddPlantTxnToggle />
{isReady ? (
<Stack direction="column" gap={1}>
Expand Down

0 comments on commit 3eb5893

Please sign in to comment.