Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basin UI (3) - Yield info + misc fixes #713

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f9ac082
WellYieldWithTooltip - create UI component
Space-Bean Nov 21, 2023
99927fc
add silo apy query
Space-Bean Nov 22, 2023
577a63f
add fetch hooks
Space-Bean Nov 22, 2023
f9f6cf1
add APY to Well.tsx
Space-Bean Nov 22, 2023
4824622
add tooltips to liquidityBox. Fixing positions later
Space-Bean Nov 22, 2023
7de44cf
create useMultiFlowPumpTWAReserves hook + update whitelist hook
Space-Bean Nov 27, 2023
48a82b4
clean up
Space-Bean Nov 27, 2023
c0edb79
implement hooks + components
Space-Bean Nov 27, 2023
d9f1259
adjust twareserves tooltip props
Space-Bean Nov 27, 2023
68486e6
fix links on tooltips
Space-Bean Nov 27, 2023
95dab4f
update tooltip props
Space-Bean Nov 27, 2023
31296c8
cosmetic changes
hellofromguy Nov 30, 2023
992f9b7
add deployNewWell example script
Space-Bean Dec 1, 2023
d1de2eb
update links + housekeeping
Space-Bean Dec 1, 2023
c72ee9b
fix home Get Started Button styling + update comments
Space-Bean Dec 1, 2023
9e0e975
fix: disallow input gt than balance in remove liquidity input
Space-Bean Dec 2, 2023
eb62ef3
fix: fix overlapping breakpoints
Space-Bean Dec 2, 2023
09ea705
remove unused vars
Space-Bean Dec 2, 2023
c220e5c
housekeeping + update URLs
Space-Bean Dec 2, 2023
4908f00
fix chart not working due to duplicate keys
Space-Bean Dec 2, 2023
19f227f
fix: fix formatting on wells page
Space-Bean Dec 2, 2023
75af384
fix: update chart + Contract Info Marquee
Space-Bean Dec 7, 2023
1abb8bb
fix: remove console logs
Space-Bean Dec 7, 2023
c84f498
fix lag loading + remoe console logs + update useBeanstalkSiloWhiteli…
Space-Bean Dec 10, 2023
208d54e
update: create addresses file
Space-Bean Dec 11, 2023
c718b73
fix: refactor useBeanstalkSiloWhitelist.tsx & apy hook
Space-Bean Dec 13, 2023
8ac8ad8
Update useBeanstalkSiloWhitelist.ts - remove unused types
Space-Bean Dec 13, 2023
35d414f
fix: fix function typings
Space-Bean Dec 13, 2023
8c3f424
Merge branch 'spacebean/dex-ui/design-fixes' into spacebean/dex-ui/yi…
Space-Bean Dec 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion projects/dex-ui/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { CodegenConfig } from "@graphql-codegen/cli";

const config: CodegenConfig = {
overwrite: true,
schema: "graphql.schema.json",
schema: [
"graphql.schema.json",
// beanstalk subgraph
"https://graph.node.bean.money/subgraphs/name/beanstalk"
],
documents: "src/**/*.graphql",
ignoreNoDocuments: true,
generates: {
Expand Down
115 changes: 115 additions & 0 deletions projects/dex-ui/src/abi/MULTI_PUMP_ABI.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
[
{
"inputs": [
{ "internalType": "bytes16", "name": "_maxPercentIncrease", "type": "bytes16" },
{ "internalType": "bytes16", "name": "_maxPercentDecrease", "type": "bytes16" },
{ "internalType": "uint256", "name": "_capInterval", "type": "uint256" },
{ "internalType": "bytes16", "name": "_alpha", "type": "bytes16" }
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{ "inputs": [], "name": "NoTimePassed", "type": "error" },
{ "inputs": [], "name": "NotInitialized", "type": "error" },
{
"inputs": [],
"name": "ALPHA",
"outputs": [{ "internalType": "bytes16", "name": "", "type": "bytes16" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "CAP_INTERVAL",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "LOG_MAX_DECREASE",
"outputs": [{ "internalType": "bytes16", "name": "", "type": "bytes16" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "LOG_MAX_INCREASE",
"outputs": [{ "internalType": "bytes16", "name": "", "type": "bytes16" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [{ "internalType": "address", "name": "well", "type": "address" }],
"name": "readCappedReserves",
"outputs": [{ "internalType": "uint256[]", "name": "cappedReserves", "type": "uint256[]" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{ "internalType": "address", "name": "well", "type": "address" },
{ "internalType": "bytes", "name": "", "type": "bytes" }
],
"name": "readCumulativeReserves",
"outputs": [{ "internalType": "bytes", "name": "cumulativeReserves", "type": "bytes" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{ "internalType": "address", "name": "well", "type": "address" },
{ "internalType": "bytes", "name": "", "type": "bytes" }
],
"name": "readInstantaneousReserves",
"outputs": [{ "internalType": "uint256[]", "name": "emaReserves", "type": "uint256[]" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [{ "internalType": "address", "name": "well", "type": "address" }],
"name": "readLastCappedReserves",
"outputs": [{ "internalType": "uint256[]", "name": "lastCappedReserves", "type": "uint256[]" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [{ "internalType": "address", "name": "well", "type": "address" }],
"name": "readLastCumulativeReserves",
"outputs": [{ "internalType": "bytes16[]", "name": "cumulativeReserves", "type": "bytes16[]" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [{ "internalType": "address", "name": "well", "type": "address" }],
"name": "readLastInstantaneousReserves",
"outputs": [{ "internalType": "uint256[]", "name": "emaReserves", "type": "uint256[]" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{ "internalType": "address", "name": "well", "type": "address" },
{ "internalType": "bytes", "name": "startCumulativeReserves", "type": "bytes" },
{ "internalType": "uint256", "name": "startTimestamp", "type": "uint256" },
{ "internalType": "bytes", "name": "", "type": "bytes" }
],
"name": "readTwaReserves",
"outputs": [
{ "internalType": "uint256[]", "name": "twaReserves", "type": "uint256[]" },
{ "internalType": "bytes", "name": "cumulativeReserves", "type": "bytes" }
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{ "internalType": "uint256[]", "name": "reserves", "type": "uint256[]" },
{ "internalType": "bytes", "name": "", "type": "bytes" }
],
"name": "update",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
]
13 changes: 13 additions & 0 deletions projects/dex-ui/src/assets/images/start-sparkle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 11 additions & 9 deletions projects/dex-ui/src/breakpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,32 @@ const mediaSizes = {
desktop: 1200
};

/// we add 1px to the mobile and tablet sizes so that the media queries don't overlap
const BP_GAP = 0.05;

/// we subtract 0.05px to some queries to prevent overlapping
export const mediaQuery = {
sm: {
// 769px & above
up: `@media (min-width: ${mediaSizes.mobile}px)`,
// 768px & below
only: `@media (max-width: ${mediaSizes.mobile - 1}px)`
// 768.95px & below
only: `@media (max-width: ${mediaSizes.mobile - BP_GAP}px)`
},
md: {
// 1024px & above
up: `@media (min-width: ${mediaSizes.tablet}px)`,
// between 769px & 1024px
only: `@media (min-width: ${mediaSizes.mobile}px) and (max-width: ${mediaSizes.tablet - 1}px)`,
// between 769px & 1023.95px
only: `@media (min-width: ${mediaSizes.mobile}px) and (max-width: ${mediaSizes.tablet - BP_GAP}px)`,
// 1024px & below
down: `@media (max-width: ${mediaSizes.tablet}px)`
down: `@media (max-width: ${mediaSizes.tablet - BP_GAP}px)`
},
lg: {
// 1200px & below
down: `@media (max-width: ${mediaSizes.desktop}px)`,
down: `@media (max-width: ${mediaSizes.desktop - BP_GAP}px)`,
// 1200px & above
only: `@media (min-width: ${mediaSizes.desktop}px)`
},
between: {
// between 769px & 1200px
smAndLg: `@media (min-width: ${mediaSizes.mobile}px) and (max-width: ${mediaSizes.desktop - 1}px)`
// between 769px & 1199.95px
smAndLg: `@media (min-width: ${mediaSizes.mobile}px) and (max-width: ${mediaSizes.desktop - BP_GAP}px)`
}
};
6 changes: 3 additions & 3 deletions projects/dex-ui/src/components/Frame/ContractInfoMarquee.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type ContractMarqueeInfo = Record<string, { display: string; to?: string; url?:
const CarouselData: ContractMarqueeInfo = {
ADDRESS: [
{
display: "0x1584B668643617D18321a0BEc6EF3786F4b8Eb7B",
display: "0xBA51AAAA95aeEFc1292515b36D86C51dC7877773",
url: "https://etherscan.io/address/0xBA51AAAA95aeEFc1292515b36D86C51dC7877773"
}
],
Expand All @@ -19,10 +19,10 @@ const CarouselData: ContractMarqueeInfo = {
V1: [{ display: "WHITEPAPER", url: "/basin.pdf" }]
};

const speedPerItem = 16; // approx same speed as TokenMarquee
const speedPerItem = 16; // approx same speed as TokenMarque
const itemGap = 24;
const numItems = 4;
const singleItemWidth = 1107.44;
const singleItemWidth = 1112.06;

export const ContractInfoMarquee = () => {
const data = Object.entries(CarouselData);
Expand Down
32 changes: 8 additions & 24 deletions projects/dex-ui/src/components/Liquidity/RemoveLiquidity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { Checkbox } from "../Checkbox";
import { size } from "src/breakpoints";
import { displayTokenSymbol } from "src/utils/format";
import { LoadingTemplate } from "../LoadingTemplate";
import { useLPPositionSummary } from "src/tokens/useLPPositionSummary";

type BaseRemoveLiquidityProps = {
slippage: number;
Expand All @@ -42,11 +43,13 @@ const RemoveLiquidityContent = ({ well, slippage, slippageSettingsClickHandler,
const [singleTokenIndex, setSingleTokenIndex] = useState<number>(0);
const [amounts, setAmounts] = useState<TokenValue[]>([]);
const [prices, setPrices] = useState<(TokenValue | null)[]>();
const [hasEnoughBalance, setHasEnoughBalance] = useState(false);
const [tokenAllowance, setTokenAllowance] = useState<boolean>(false);

const sdk = useSdk();
const { getPositionWithWell } = useLPPositionSummary();
const { reserves: wellReserves, refetch: refetchWellReserves } = useWellReserves(well);
const sdk = useSdk();

const lpBalance = useMemo(() => getPositionWithWell(well)?.external, [getPositionWithWell, well]);

useEffect(() => {
const run = async () => {
Expand All @@ -70,6 +73,8 @@ const RemoveLiquidityContent = ({ well, slippage, slippageSettingsClickHandler,
const { oneTokenQuote } = oneToken;
const { customRatioQuote } = custom;

const hasEnoughBalance = !address || !wellLpToken || !lpTokenAmount || !lpBalance ? false : lpTokenAmount.lte(lpBalance);

useEffect(() => {
if (well.lpToken) {
let lpTokenWithMetadata = well.lpToken;
Expand All @@ -79,28 +84,6 @@ const RemoveLiquidityContent = ({ well, slippage, slippageSettingsClickHandler,
}
}, [well.lpToken]);

useEffect(() => {
const checkBalances = async () => {
if (!address || !wellLpToken || !lpTokenAmount) {
setHasEnoughBalance(false);
return;
}

let insufficientBalances = false;

if (lpTokenAmount.gt(TokenValue.ZERO)) {
const balance = await wellLpToken.getBalance(address);
if (lpTokenAmount.gt(balance)) {
insufficientBalances = true;
}
}

setHasEnoughBalance(!insufficientBalances);
};

checkBalances();
}, [address, lpTokenAmount, wellLpToken]);

useEffect(() => {
if (customRatioQuote) {
setLpTokenAmount(customRatioQuote.quote);
Expand Down Expand Up @@ -318,6 +301,7 @@ const RemoveLiquidityContent = ({ well, slippage, slippageSettingsClickHandler,
canChangeValue={removeLiquidityMode !== REMOVE_LIQUIDITY_MODE.Custom}
showBalance={true}
loading={false}
clamp
/>
</TokenContainer>
<MediumGapContainer>
Expand Down
19 changes: 15 additions & 4 deletions projects/dex-ui/src/components/Swap/BasicInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type Props = {
onFocus?: FocusEventHandler<HTMLInputElement>;
onBlur?: FocusEventHandler<HTMLInputElement>;
canChangeValue?: boolean;
max?: TokenValue;
};

export const BasicInput: FC<Props> = ({
Expand All @@ -24,7 +25,8 @@ export const BasicInput: FC<Props> = ({
onFocus,
onBlur,
inputRef,
canChangeValue = true
canChangeValue = true,
max
}) => {
const [id, _] = useState(_id ?? Math.random().toString(36).substring(2, 7));
const [displayValue, setDisplayValue] = useState(value);
Expand All @@ -42,6 +44,15 @@ export const BasicInput: FC<Props> = ({
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [value]);

const maxNum = max && parseFloat(max.toHuman());
const clamp = useCallback(
(amount: string) => {
if (amount === "" || amount === ".") return amount;
return maxNum !== undefined ? Math.min(parseFloat(amount), maxNum).toString() : amount;
},
[maxNum]
);

const handleChange = useCallback(
(e: React.ChangeEvent<HTMLInputElement>) => {
let rawValue = e.target.value;
Expand All @@ -55,10 +66,10 @@ export const BasicInput: FC<Props> = ({
rawValue = `0${rawValue}`;
}

setDisplayValue(rawValue);
onChange?.(cleanValue);
setDisplayValue(clamp(rawValue));
onChange?.(clamp(cleanValue));
},
[onChange]
[onChange, clamp]
);

const filterKeyDown = useCallback(
Expand Down
5 changes: 4 additions & 1 deletion projects/dex-ui/src/components/Swap/TokenInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type TokenInput = {
onTokenChange?: (t: Token) => void;
canChangeValue?: boolean;
debounceTime?: number;
clamp?: boolean;
};

export const TokenInput: FC<TokenInput> = ({
Expand All @@ -44,7 +45,8 @@ export const TokenInput: FC<TokenInput> = ({
loading = false,
allowNegative = false,
canChangeValue = true,
debounceTime = 500
debounceTime = 500,
clamp = false
}) => {
const inputRef = useRef<HTMLInputElement>(null);

Expand Down Expand Up @@ -97,6 +99,7 @@ export const TokenInput: FC<TokenInput> = ({
inputRef={inputRef}
allowNegative={allowNegative}
canChangeValue={!!canChangeValue}
max={clamp ? balance?.[token.symbol] : undefined}
/>
<TokenPicker token={token} editable={canChangeToken} onChange={handleTokenChange} connectorFor={id} />
</TopRow>
Expand Down
Loading