Skip to content

Commit

Permalink
Merge branch 'master' into b3-subgraph
Browse files Browse the repository at this point in the history
  • Loading branch information
soilking committed Oct 12, 2024
2 parents cb57a6c + b007508 commit 76b4d02
Show file tree
Hide file tree
Showing 22 changed files with 892 additions and 230 deletions.
3 changes: 2 additions & 1 deletion projects/dex-ui/src/components/Swap/TokenInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Token, TokenValue } from "@beanstalk/sdk";

import { size } from "src/breakpoints";
import { useTokenBalance } from "src/tokens/useTokenBalance";
import { getTokenIndex } from "src/tokens/utils";
import { FC } from "src/types";

import { BasicInput } from "./BasicInput";
Expand Down Expand Up @@ -130,7 +131,7 @@ export const TokenInput: FC<TokenInput> = ({
<BalanceRow>
<Balance onClick={handleClickMax}>
{balanceLabel}:{" "}
{isBalanceLoading ? <Spinner size={12} /> : balance?.[token.address]?.toHuman("short")}
{isBalanceLoading ? <Spinner size={12} /> : balance?.[getTokenIndex(token)]?.toHuman("short")}
</Balance>
</BalanceRow>
)}
Expand Down
2 changes: 1 addition & 1 deletion projects/ui/codegen-individual.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ generates:
# BSTODO: Do we need beanft subgraph?
./src/graph/schema-beanft.graphql:
schema:
- https://graph.node.bean.money/subgraphs/name/beanft
- https://graph.bean.money/beanft_eth
plugins:
- 'schema-ast'
#./src/graph/schema-snapshot2.graphql:
Expand Down
18 changes: 11 additions & 7 deletions projects/ui/src/components/Common/Form/TokenSelectDialogNew.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import { displayBN } from '~/util';
import { ZERO_BN } from '~/constants';
import { ApplicableBalance, FarmerBalances } from '~/state/farmer/balances';
import { FarmerSilo } from '~/state/farmer/silo';
import { BeanstalkPalette, FontSize, IconSize } from '../../App/muiTheme';
import Row from '~/components/Common/Row';
import BalanceFromRow, { BalanceFrom } from './BalanceFromRow';
import useSdk from '~/hooks/sdk';
import { BeanstalkPalette, FontSize, IconSize } from '../../App/muiTheme';
import BalanceFromRow, { BalanceFrom } from './BalanceFromRow';

export enum TokenSelectMode {
MULTI,
Expand Down Expand Up @@ -107,15 +107,18 @@ const TokenSelectDialogNew: TokenSelectDialogC = React.memo(
const [selectedInternal, setSelectedInternal] = useState<Set<Token>>(
new Set()
);
const [balanceFromInternal, setBalanceFromInternal] = useState<BalanceFrom>(BalanceFrom.TOTAL);
const [balanceFromInternal, setBalanceFromInternal] = useState<BalanceFrom>(
BalanceFrom.TOTAL
);

const getBalance = useCallback(
(addr: string) => {
if (!_balances) return ZERO_BN;
if (balancesType === 'farm')
return (
(_balances as TokenBalanceMode['farm'])?.[addr]?.[balanceFromInternal] ||
ZERO_BN
(_balances as TokenBalanceMode['farm'])?.[addr]?.[
balanceFromInternal
] || ZERO_BN
);
return (
(_balances as TokenBalanceMode['silo-deposits'])?.[addr]?.deposited
Expand Down Expand Up @@ -177,7 +180,7 @@ const TokenSelectDialogNew: TokenSelectDialogC = React.memo(
const setBalanceFromAndClose = useCallback(() => {
if (setBalanceFrom) {
setBalanceFrom(balanceFromInternal);
};
}
handleClose(); // hide dialog
}, [handleClose, setBalanceFrom, balanceFromInternal]);

Expand All @@ -189,7 +192,8 @@ const TokenSelectDialogNew: TokenSelectDialogC = React.memo(
(_newSelection: Set<Token>) => () => {
handleSubmit(_newSelection); // update form state
setBalanceFromAndClose();
}, [handleSubmit, setBalanceFromAndClose]
},
[handleSubmit, setBalanceFromAndClose]
);

// Click an item in the token list.
Expand Down
32 changes: 15 additions & 17 deletions projects/ui/src/components/Common/GasTag.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { Box, Divider, Tooltip, Typography } from '@mui/material';
import BigNumber from 'bignumber.js';
import React from 'react';
import BigNumber from 'bignumber.js';
import { Box, Tooltip } from '@mui/material';
import { useSelector } from 'react-redux';
import { DateTime } from 'luxon';
import useGasToUSD from '~/hooks/ledger/useGasToUSD';
import { AppState } from '~/state';
import { AppState, useAppSelector } from '~/state';
import { displayFullBN, displayUSD } from '~/util';

import { FC } from '~/types';
import StatHorizontal from '~/components/Common/StatHorizontal';
import { ZERO_BN } from '~/constants';

const WEI_TO_GWEI = new BigNumber(10).pow(9);

const GasTag: FC<{
gasLimit: BigNumber | null;
Expand All @@ -17,8 +19,13 @@ const GasTag: FC<{
const prices = useSelector<AppState, AppState['app']['ethPrices']>(
(state) => state.app.ethPrices
);
const ethPrice = useAppSelector((state) => state._beanstalk.tokenPrices.eth);
const getGasUSD = useGasToUSD();
const gasUSD = gasLimit ? getGasUSD(gasLimit) : null;

const baseFeeInWei = prices?.baseFeePerGas ?? ZERO_BN;
const baseFeeGwei = baseFeeInWei.div(WEI_TO_GWEI);

return (
<Tooltip
title={
Expand All @@ -27,22 +34,13 @@ const GasTag: FC<{
{gasLimit ? displayFullBN(gasLimit) : '?'}
</StatHorizontal>
<StatHorizontal label="Base fee">
{prices?.gas.safe ? `${prices.gas.safe} gwei` : '?'}
{baseFeeGwei?.gt(0)
? `${baseFeeGwei.toExponential(2, BigNumber.ROUND_UP)} gwei`
: '?'}
</StatHorizontal>
<StatHorizontal label="ETH price">
{prices?.ethusd ? `$${prices.ethusd}` : '?'}
{ethPrice ? `$${ethPrice.toFormat(2, BigNumber.ROUND_DOWN)}` : '?'}
</StatHorizontal>
{prices?.lastRefreshed && (
<>
<Divider color="secondary" sx={{ my: 1 }} />
<Typography variant="bodySmall" color="gray">
Refreshed at{' '}
{DateTime.fromMillis(
parseInt(prices.lastRefreshed, 10)
).toLocaleString(DateTime.TIME_24_WITH_SHORT_OFFSET)}
</Typography>
</>
)}
</>
}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { FormTxn, ConvertFarmStep } from '~/lib/Txn';
import StatHorizontal from '~/components/Common/StatHorizontal';
import { BeanstalkPalette, FontSize } from '~/components/App/muiTheme';
import { AppState } from '~/state';
import { useCalcWellHasMinReserves } from '~/hooks/beanstalk/useCalcWellHasMinReserves';
import { ConvertQuoteHandlerParams, BaseConvertFormProps } from './types';

interface Props extends BaseConvertFormProps {
Expand All @@ -50,6 +51,8 @@ export const DefaultConvertForm: FC<Props> = ({
setFieldValue,
conversion,
}) => {
const calcHasMinReserves = useCalcWellHasMinReserves();

/// Local state
const [isTokenSelectVisible, showTokenSelect, hideTokenSelect] = useToggle();
const getBDV = useBDV();
Expand All @@ -72,7 +75,9 @@ export const DefaultConvertForm: FC<Props> = ({
const tokenOut = values.tokenOut; // converting to token
const amountOut = values.tokens[0].amountOut; // amount of to token
const maxAmountIn = values.maxAmountIn;
const canConvert = maxAmountIn?.gt(0) || false;
const hasMinReserves = calcHasMinReserves(tokenOut);

const canConvert = (maxAmountIn?.gt(0) && hasMinReserves) || false;

// FIXME: these use old structs instead of SDK
const siloBalance = siloBalances[tokenIn.address];
Expand Down Expand Up @@ -246,10 +251,11 @@ export const DefaultConvertForm: FC<Props> = ({
} else {
pool += ' pool';
}
if (['urBEANETH', 'urBEAN'].includes(tokenIn.symbol)) pool = 'BEANETH Well';
if (['urBEANwstETH', 'urBEAN'].includes(tokenIn.symbol))
pool = 'BEANwstETH Well';

const lowerOrGreater =
tokenIn.isLP || tokenIn.symbol === 'urBEANETH' ? 'less' : 'greater';
tokenIn.isLP || tokenIn.symbol === 'urBEANwstETH' ? 'less' : 'greater';

const message = `${tokenIn.symbol} can only be Converted to ${tokenOut?.symbol} when deltaB in the ${pool} is ${lowerOrGreater} than 0.`;

Expand Down Expand Up @@ -335,6 +341,12 @@ export const DefaultConvertForm: FC<Props> = ({
</WarningAlert>
</Box>
) : null}
{!hasMinReserves && (
<WarningAlert>
The BEAN reserves for the {tokenOut?.symbol} Well are below the
minimum required to Convert.
</WarningAlert>
)}
{/* Outputs */}
{totalAmountIn &&
tokenOut &&
Expand Down
15 changes: 14 additions & 1 deletion projects/ui/src/components/Silo/Actions/Deposit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ import useFormTxnContext from '~/hooks/sdk/useFormTxnContext';
import { ClaimAndDoX, DepositFarmStep, FormTxn } from '~/lib/Txn';
import useGetBalancesUsedBySource from '~/hooks/beanstalk/useBalancesUsedBySource';
import { selectBdvPerToken } from '~/state/beanstalk/silo';
import { useCalcWellHasMinReserves } from '~/hooks/beanstalk/useCalcWellHasMinReserves';
import WarningAlert from '~/components/Common/Alert/WarningAlert';

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

Expand Down Expand Up @@ -119,6 +121,9 @@ const DepositForm: FC<
const beanstalkSilo = useSilo();
const siblingRef = useRef<HTMLDivElement | null>(null);

const calcHasMinReserves = useCalcWellHasMinReserves();
const hasMinReserves = calcHasMinReserves(whitelistedToken);

/// Handlers
// This handler does not run when _tokenIn = _tokenOut (direct deposit)
const handleQuote = useCallback<QuoteHandlerWithParams<{ slippage: number }>>(
Expand Down Expand Up @@ -280,6 +285,8 @@ const DepositForm: FC<
key={`tokens.${index}`}
name={`tokens.${index}`}
tokenOut={whitelistedToken}
disabled={!hasMinReserves}
disableTokenSelect={!hasMinReserves}
balance={balance}
state={tokenState}
showTokenSelect={showTokenSelect}
Expand All @@ -290,6 +297,12 @@ const DepositForm: FC<
);
})}
{false && <ClaimBeanDrawerToggle actionText="Deposit" />}
{!hasMinReserves && (
<WarningAlert>
The BEAN reserves for this Well are below the minimum required for
deposit.
</WarningAlert>
)}
{isReady ? (
<>
<TxnSeparator />
Expand Down Expand Up @@ -342,7 +355,7 @@ const DepositForm: FC<
) : null}
<SmartSubmitButton
loading={isSubmitting}
disabled={isSubmitting || noAmount}
disabled={isSubmitting || noAmount || !hasMinReserves}
type="submit"
variant="contained"
color="primary"
Expand Down
20 changes: 0 additions & 20 deletions projects/ui/src/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,6 @@ interface ImportMetaEnv {
* API key for used for ZeroX Swap API
*/
readonly VITE_ZERO_X_API_KEY: string;

/**
*
*/
readonly VITE_TENDERLY_ACCOUNT_SLUG: string;

/**
*
*/
readonly VITE_TENDERLY_PROJECT_SLUG: string;

/**
*
*/
readonly VITE_TENDERLY_ACCESS_KEY: string;

/**
* Tenderly Virtual Network ID for testnet
*/
readonly VITE_TENDERLY_VNET_ID?: string;
}

interface ImportMeta {
Expand Down
117 changes: 0 additions & 117 deletions projects/ui/src/functions/ethprice/ethprice.ts

This file was deleted.

Loading

0 comments on commit 76b4d02

Please sign in to comment.