diff --git a/projects/ui/src/components/Common/Form/FormTxnProvider.tsx b/projects/ui/src/components/Common/Form/FormTxnProvider.tsx index aaf572c598..24938f385b 100644 --- a/projects/ui/src/components/Common/Form/FormTxnProvider.tsx +++ b/projects/ui/src/components/Common/Form/FormTxnProvider.tsx @@ -1,5 +1,5 @@ import React, { useCallback, useEffect, useMemo, useState } from 'react'; -import { TokenValue } from '@beanstalk/sdk'; +import { FarmToMode, TokenValue } from '@beanstalk/sdk'; import { FC, MayPromise } from '~/types'; import useSdk from '~/hooks/sdk'; import useAccount from '~/hooks/ledger/useAccount'; @@ -81,6 +81,7 @@ const useInitFormTxnContext = () => { /// Context State const [txnBundler, setTxnBundler] = useState(new FormTxnBundler(sdk, {})); + const [destination, setDestination] = useState(); /// On any change, update the txn bundler useEffect(() => { @@ -118,7 +119,7 @@ const useInitFormTxnContext = () => { ? new HarvestFarmStep(sdk, plotIds).build() : undefined, [FormTxn.RINSE]: rinsable.gt(0) - ? new RinseFarmStep(sdk, fertilizerIds).build() + ? new RinseFarmStep(sdk, fertilizerIds, destination || FarmToMode.INTERNAL).build() : undefined, [FormTxn.CLAIM]: seasons?.length ? new ClaimFarmStep(sdk, BEAN, seasons).build(BEAN) @@ -135,6 +136,7 @@ const useInitFormTxnContext = () => { farmerSilo.beans.earned, getBDV, sdk, + destination ]); useEffect(() => { @@ -196,6 +198,7 @@ const useInitFormTxnContext = () => { txnBundler, plantAndDoX, refetch, + setDestination } as const; }; diff --git a/projects/ui/src/components/Silo/Actions/Withdraw.tsx b/projects/ui/src/components/Silo/Actions/Withdraw.tsx index bd4be638ed..0178b4ad60 100644 --- a/projects/ui/src/components/Silo/Actions/Withdraw.tsx +++ b/projects/ui/src/components/Silo/Actions/Withdraw.tsx @@ -1,4 +1,4 @@ -import React, { useCallback, useMemo } from 'react'; +import React, { useCallback, useMemo, useEffect } from 'react'; import { Box, Divider, Stack, Typography } from '@mui/material'; import BigNumber from 'bignumber.js'; import { Form, Formik, FormikHelpers, FormikProps } from 'formik'; @@ -156,6 +156,10 @@ const WithdrawForm: FC< values.farmActions.primary?.includes(FormTxn.PLANT) && sdk.tokens.BEAN.equals(whitelistedToken) ); + const { setDestination } = useFormTxnContext(); + useEffect(() => { + setDestination(values.destination); + }, [values.destination, setDestination]) const [isTokenSelectVisible, showTokenSelect, hideTokenSelect] = useToggle(); diff --git a/projects/ui/src/hooks/farmer/form-txn/useFarmerFormTxnsSummary.ts b/projects/ui/src/hooks/farmer/form-txn/useFarmerFormTxnsSummary.ts index f8ca61e62f..e263f793de 100644 --- a/projects/ui/src/hooks/farmer/form-txn/useFarmerFormTxnsSummary.ts +++ b/projects/ui/src/hooks/farmer/form-txn/useFarmerFormTxnsSummary.ts @@ -1,6 +1,7 @@ import { useCallback, useMemo } from 'react'; import { FarmToMode, Token } from '@beanstalk/sdk'; import BigNumber from 'bignumber.js'; +import { useFormikContext } from 'formik'; import { ZERO_BN } from '~/constants'; import useSdk, { getNewToOldToken } from '~/hooks/sdk'; @@ -113,6 +114,7 @@ export type FormTxnSummaryMap = { export default function useFarmerFormTxnsSummary() { /// const sdk = useSdk(); + const { values } = useFormikContext(); /// Farmer const farmerSilo = useFarmerSilo(); @@ -257,6 +259,7 @@ export default function useFarmerFormTxnsSummary() { { type: ActionType.RINSE, amount: rinsableSprouts, + destination: values.destination, }, ], }, @@ -296,6 +299,7 @@ export default function useFarmerFormTxnsSummary() { revitalizedSeeds, revitalizedStalk, sdk.tokens, + values.destination ]); /** diff --git a/projects/ui/src/lib/Txn/FarmSteps/barn/RinseFarmStep.ts b/projects/ui/src/lib/Txn/FarmSteps/barn/RinseFarmStep.ts index 0c5e2ffecc..7d3dd64b90 100644 --- a/projects/ui/src/lib/Txn/FarmSteps/barn/RinseFarmStep.ts +++ b/projects/ui/src/lib/Txn/FarmSteps/barn/RinseFarmStep.ts @@ -5,7 +5,7 @@ export class RinseFarmStep extends FarmStep implements EstimatesGas { constructor( sdk: BeanstalkSDK, private _fertilizerIds: string[], - private _toMode: FarmToMode = FarmToMode.INTERNAL + private _toMode: FarmToMode ) { super(sdk); this._fertilizerIds = _fertilizerIds; diff --git a/projects/ui/src/util/Actions.ts b/projects/ui/src/util/Actions.ts index 2003f6cfa7..4ae7360553 100644 --- a/projects/ui/src/util/Actions.ts +++ b/projects/ui/src/util/Actions.ts @@ -220,6 +220,7 @@ export type SellPodsAction = { export type RinseAction = { type: ActionType.RINSE; amount: BigNumber; + destination?: FarmToMode; hideGraphic?: boolean; }; @@ -391,7 +392,7 @@ export const parseActionMessage = (a: Action) => { return `Rinse ${displayFullBN( a.amount, SPROUTS.displayDecimals - )} Sprouts.`; + )} Sprouts${a.destination ? ` and send to your ${copy.MODES[a.destination]}.` : `.`}`; case ActionType.BUY_FERTILIZER: return `Buy ${displayFullBN(a.amountIn, 2)} Fertilizer at ${displayFullBN( a.humidity.multipliedBy(100),