Skip to content

Commit

Permalink
Bean UI - Withdraw - Use Destination setting for Rinse operation (#662)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xalecks committed Oct 17, 2023
2 parents 062d5f3 + 12ee353 commit 6dfc7a9
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 5 deletions.
7 changes: 5 additions & 2 deletions projects/ui/src/components/Common/Form/FormTxnProvider.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -81,6 +81,7 @@ const useInitFormTxnContext = () => {

/// Context State
const [txnBundler, setTxnBundler] = useState(new FormTxnBundler(sdk, {}));
const [destination, setDestination] = useState<FarmToMode | undefined>();

/// On any change, update the txn bundler
useEffect(() => {
Expand Down Expand Up @@ -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)
Expand All @@ -135,6 +136,7 @@ const useInitFormTxnContext = () => {
farmerSilo.beans.earned,
getBDV,
sdk,
destination
]);

useEffect(() => {
Expand Down Expand Up @@ -196,6 +198,7 @@ const useInitFormTxnContext = () => {
txnBundler,
plantAndDoX,
refetch,
setDestination
} as const;
};

Expand Down
6 changes: 5 additions & 1 deletion projects/ui/src/components/Silo/Actions/Withdraw.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -113,6 +114,7 @@ export type FormTxnSummaryMap = {
export default function useFarmerFormTxnsSummary() {
///
const sdk = useSdk();
const { values } = useFormikContext<any>();

/// Farmer
const farmerSilo = useFarmerSilo();
Expand Down Expand Up @@ -257,6 +259,7 @@ export default function useFarmerFormTxnsSummary() {
{
type: ActionType.RINSE,
amount: rinsableSprouts,
destination: values.destination,
},
],
},
Expand Down Expand Up @@ -296,6 +299,7 @@ export default function useFarmerFormTxnsSummary() {
revitalizedSeeds,
revitalizedStalk,
sdk.tokens,
values.destination
]);

/**
Expand Down
2 changes: 1 addition & 1 deletion projects/ui/src/lib/Txn/FarmSteps/barn/RinseFarmStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion projects/ui/src/util/Actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ export type SellPodsAction = {
export type RinseAction = {
type: ActionType.RINSE;
amount: BigNumber;
destination?: FarmToMode;
hideGraphic?: boolean;
};

Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit 6dfc7a9

Please sign in to comment.