Skip to content

Commit

Permalink
Bean UI - Fixed pre-fill swap (#627)
Browse files Browse the repository at this point in the history
  • Loading branch information
hellofromguy authored Sep 4, 2023
2 parents 1232fd7 + 6de81e8 commit 5902e90
Showing 1 changed file with 6 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ const FillListingForm: FC<{

// Checks
if (!podListing) throw new Error('No Pod Listing found');
if (!signer) throw new Error('Connect a wallet');
if (!signer || !account) throw new Error('Connect a wallet');
if (values.tokens.length > 1)
throw new Error('Only one input token supported');
if (
Expand Down Expand Up @@ -422,12 +422,14 @@ const FillListingForm: FC<{
const swap = sdk.swap.buildSwap(
tokenInNew,
sdk.tokens.BEAN,
optimizeFromMode(formData.amount, balances[tokenIn.address])
account,
optimizeFromMode(formData.amount, balances[tokenIn.address]),
FarmToMode.INTERNAL
);

// At the end of the Swap step, the assets will be in our INTERNAL balance.
// The Swap decides where to route them from (see handleQuote).
finalFromMode = FarmFromMode.INTERNAL_TOLERANT;
finalFromMode = FarmFromMode.INTERNAL;
farm = swap.getFarm();
}

Expand All @@ -436,17 +438,6 @@ const FillListingForm: FC<{
podListing
);

// If not using Bean, add Bean approval step after conversion
if (tokenIn !== Bean) {
farm.add((amountInStep) =>
beanstalk.interface.encodeFunctionData('approveToken', [
beanstalk.address,
Bean.address,
amountInStep
])
);
}

farm.add((amountInStep) =>
beanstalk.interface.encodeFunctionData('fillPodListing', [
{
Expand Down Expand Up @@ -506,7 +497,7 @@ const FillListingForm: FC<{
balances,
sdk,
beanstalk.interface,
beanstalk.address
account
]
);

Expand Down

0 comments on commit 5902e90

Please sign in to comment.