Skip to content

Commit

Permalink
feat: clean up UI for deposits
Browse files Browse the repository at this point in the history
  • Loading branch information
Space-Bean committed Oct 8, 2024
1 parent 54115a8 commit 8dbc3b3
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 92 deletions.
4 changes: 2 additions & 2 deletions projects/ui/src/components/Common/Form/TxnPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,10 @@ const TxnStep: FC<{
width: '80px',
height: '100%', // of TXN_PREVIEW_HEIGHT
textAlign: 'center',
'&:first-child': {
'&:first-of-type': {
textAlign: 'left',
},
'&:last-child': {
'&:last-of-type': {
textAlign: 'right',
},
}}
Expand Down
88 changes: 8 additions & 80 deletions projects/ui/src/components/Silo/Actions/Deposit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,7 @@ const DepositForm: FC<
whitelistedToken,
combinedTokenState,
getAmountsBySource(),
amountToBdv,
getLegacyToken
amountToBdv
);

// Memoized params to prevent infinite loop
Expand Down Expand Up @@ -497,14 +496,12 @@ const DepositPropProvider: FC<{
swapQuote,
tokenIn,
amountIn,
target.fromHuman(amountOut.toString()),
whitelistedToken,
account,
balanceFromToMode(values.balanceFrom)
);

console.log('operation: nodes', operation?.quote?.nodes || '');
console.log('operation: farm', operation?.getFarm() || '');

txToast = new TransactionToast({
loading: `Depositing ${displayFullBN(
amountOut.plus(amountOutFromClaimed),
Expand All @@ -521,8 +518,6 @@ const DepositPropProvider: FC<{
values.farmActions.transferToMode || FarmToMode.INTERNAL
);

console.log('claimAndDoX: ', claimAndDoX);

const depositTxn = new DepositFarmStep(sdk, target);
depositTxn.build(
tokenIn,
Expand All @@ -533,11 +528,7 @@ const DepositPropProvider: FC<{
claimAndDoX
);

console.log('depositTxn: ', depositTxn);

const actionsPerformed = txnBundler.setFarmSteps(values.farmActions);
console.log('actionsPerformed: ', actionsPerformed);
console.log('bundling...');
const { execute } = await txnBundler.bundle(
depositTxn,
amountIn,
Expand Down Expand Up @@ -682,6 +673,7 @@ function getSwapOperation(
swapQuote: BeanSwapNodeQuote | undefined,
sellToken: Token,
sellAmount: TokenValue,
buyAmount: TokenValue,
target: Token,
account: string,
fromMode: FarmFromMode
Expand Down Expand Up @@ -709,6 +701,11 @@ function getSwapOperation(
`Sell amount mismatch. Expected: ${sellAmount} Got: ${swapQuote.sellAmount}`
);
}
if (!buyAmount.eq(swapQuote.buyAmount)) {
throw new Error(
`Buy amount mismatch. Expected: ${buyAmount} Got: ${swapQuote.buyAmount}`
);
}

const operation = BeanSwapOperation.buildWithQuote(
swapQuote,
Expand All @@ -720,72 +717,3 @@ function getSwapOperation(

return operation;
}

// leaving as reference for any deposit w/o claim & do x
// const farmDeposit = sdk.silo.buildDeposit(target, account);
// farmDeposit.setInputToken(tokenIn);
// const aFarm = sdk.farm.createAdvancedFarm();

// aFarm.add([...farmDeposit.workflow.generators] as any[]);
// await aFarm.estimate(amountIn);

// await farmDeposit.estimate(amountIn);

// const farmDepositTx = await aFarm.execute(amountIn, {
// slippage: values.settings.slippage,
// });
// const farmDepositReceipt = await farmDepositTx.wait();

// txToast.success(farmDepositReceipt);
// formActions.resetForm();

// const initTokenList = useMemo(() => {
// const tokens = sdk.tokens;
// if (tokens.BEAN.equals(whitelistedToken)) {
// return [
// tokens.BEAN,
// tokens.ETH,
// tokens.WETH,
// tokens.WSTETH,
// tokens.DAI,
// tokens.USDC,
// tokens.USDT,
// ];
// }
// return [
// tokens.BEAN,
// tokens.ETH,
// tokens.WETH,
// tokens.WSTETH,
// whitelistedToken,
// tokens.DAI,
// tokens.USDC,
// tokens.USDT,
// ];
// }, [sdk.tokens, whitelistedToken]);

// const priorityList = useMemo(() => {
// const tokens = sdk.tokens;
// if (tokens.BEAN.equals(whitelistedToken)) {
// return [
// tokens.BEAN,
// tokens.ETH,
// tokens.WETH,
// tokens.WSTETH,
// tokens.DAI,
// tokens.USDC,
// tokens.USDT,
// ];
// }
// return [
// whitelistedToken,
// tokens.ETH,
// tokens.WETH,
// tokens.WSTETH,
// tokens.BEAN,
// tokens.CRV3,
// tokens.DAI,
// tokens.USDC,
// tokens.USDT,
// ];
// }, [sdk.tokens, whitelistedToken]);
2 changes: 1 addition & 1 deletion projects/ui/src/constants/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ export const WSTETH = makeChainToken(WSTETH_ADDRESSES, 18, {

export const WEETH = makeChainToken(WEETH_ADDRESSES, 18, {
name: 'Wrapped Ether',
symbol: 'WEETH',
symbol: 'weETH',
logo: weethIcon,
});

Expand Down
6 changes: 3 additions & 3 deletions projects/ui/src/hooks/beanstalk/useTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,17 +334,17 @@ const oldTokenMap: Record<string, ChainConstant<LegacyToken> | LegacyToken> = {
} as const;

export const useGetLegacyToken = () => {
const { chainId, fallbackChainId } = useChainState();
const { fallbackChainId } = useChainState();

const getLegacyToken = useCallback(
(token: TokenInstance): LegacyToken => {
if (!isSdkToken(token)) return token;
const oldToken = oldTokenMap[token.symbol];

if (oldToken instanceof LegacyToken) return oldToken;
return oldToken[chainId] || oldToken[fallbackChainId];
return oldToken[fallbackChainId];
},
[chainId, fallbackChainId]
[fallbackChainId]
);

return getLegacyToken;
Expand Down
10 changes: 4 additions & 6 deletions projects/ui/src/lib/Beanstalk/Silo/Deposit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ import { Action, ActionType } from '~/util/Actions';
import { ZERO_BN } from '~/constants';
import { tokenValueToBN } from '~/util';
import { AmountsBySource } from '~/hooks/beanstalk/useBalancesUsedBySource';
import { useGetLegacyToken } from '~/hooks/beanstalk/useTokens';

export function depositSummary(
to: Token,
tokens: FormStateNew['tokens'],
amountsBySource: AmountsBySource[],
amountToBDV: (amount: BigNumber) => BigNumber,
getLegacyToken: ReturnType<typeof useGetLegacyToken>
amountToBDV: (amount: BigNumber) => BigNumber
) {
const summary = tokens.reduce(
(agg, curr, idx) => {
Expand Down Expand Up @@ -52,8 +50,8 @@ export function depositSummary(
agg.actions.push({
type: ActionType.SWAP,
amountsBySource: bySource,
tokenIn: getLegacyToken(curr.token),
tokenOut: getLegacyToken(to),
tokenIn: curr.token,
tokenOut: to,
amountIn: curr.amount,
amountOut: curr.amountOut,
});
Expand All @@ -76,7 +74,7 @@ export function depositSummary(
type: ActionType.DEPOSIT,
amount: summary.amount,
// from the perspective of the deposit, the token is "coming in".
token: getLegacyToken(to),
token: to,
});
summary.actions.push({
type: ActionType.UPDATE_SILO_REWARDS,
Expand Down

0 comments on commit 8dbc3b3

Please sign in to comment.