From acb2f1f2dfa63e0ad790a0a689d30a3c61243430 Mon Sep 17 00:00:00 2001 From: totop716 Date: Sun, 2 Jan 2022 22:44:06 -0500 Subject: [PATCH] add a modal to find pool, update question helper icon and fix issue with modal. --- src/assets/images/HelpIcon2.svg | 1 - src/components/AddLiquidity/AddLiquidity.tsx | 56 ++-- .../PoolFinderModal/PoolFinderModal.tsx | 243 ++++++++++++++++++ src/components/PoolFinderModal/index.ts | 1 + src/components/PositionCard/PositionCard.tsx | 85 +++--- .../QuestionHelper/QuestionHelper.tsx | 29 ++- src/components/Swap/Swap.tsx | 40 +-- src/components/index.ts | 1 + src/pages/PoolsPage/PoolsPage.tsx | 47 +++- src/pages/SwapPage/SwapPage.tsx | 10 +- 10 files changed, 407 insertions(+), 106 deletions(-) delete mode 100644 src/assets/images/HelpIcon2.svg create mode 100644 src/components/PoolFinderModal/PoolFinderModal.tsx create mode 100644 src/components/PoolFinderModal/index.ts diff --git a/src/assets/images/HelpIcon2.svg b/src/assets/images/HelpIcon2.svg deleted file mode 100644 index e220c249c..000000000 --- a/src/assets/images/HelpIcon2.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/src/components/AddLiquidity/AddLiquidity.tsx b/src/components/AddLiquidity/AddLiquidity.tsx index 2fe32827c..a630e0b3d 100755 --- a/src/components/AddLiquidity/AddLiquidity.tsx +++ b/src/components/AddLiquidity/AddLiquidity.tsx @@ -426,33 +426,35 @@ const AddLiquidity: React.FC<{ return ( - - addLiquidityErrorMessage ? ( - - ) : ( - - ) - } - pendingText={pendingText} - modalContent={ - txPending - ? 'Submitted transaction to add liquidity' - : 'Successfully added liquidity' - } - /> + {showConfirm && ( + + addLiquidityErrorMessage ? ( + + ) : ( + + ) + } + pendingText={pendingText} + modalContent={ + txPending + ? 'Submitted transaction to add liquidity' + : 'Successfully added liquidity' + } + /> + )} ({ + borderedCard: { + border: `1px solid ${palette.divider}`, + padding: 8, + borderRadius: 10, + cursor: 'pointer', + '&:hover': { + border: `1px solid ${palette.text.primary}`, + }, + }, +})); + +enum Fields { + TOKEN0 = 0, + TOKEN1 = 1, +} + +interface PoolFinderModalProps { + open: boolean; + onClose: () => void; +} + +const PoolFinderModal: React.FC = ({ open, onClose }) => { + const classes = useStyles(); + const { palette } = useTheme(); + + const { account } = useActiveWeb3React(); + + const [showSearch, setShowSearch] = useState(false); + const [activeField, setActiveField] = useState(Fields.TOKEN1); + + const [currency0, setCurrency0] = useState(ETHER); + const [currency1, setCurrency1] = useState(null); + + const [pairState, pair] = usePair( + currency0 ?? undefined, + currency1 ?? undefined, + ); + const addPair = usePairAdder(); + useEffect(() => { + if (pair) { + addPair(pair); + } + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [pair?.liquidityToken.address, addPair]); + + const validPairNoLiquidity: boolean = + pairState === PairState.NOT_EXISTS || + Boolean( + pairState === PairState.EXISTS && + pair && + JSBI.equal(pair.reserve0.raw, JSBI.BigInt(0)) && + JSBI.equal(pair.reserve1.raw, JSBI.BigInt(0)), + ); + + const position: TokenAmount | undefined = useTokenBalance( + account ?? undefined, + pair?.liquidityToken, + ); + const hasPosition = Boolean( + position && JSBI.greaterThan(position.raw, JSBI.BigInt(0)), + ); + + const handleCurrencySelect = useCallback( + (currency: Currency) => { + if (activeField === Fields.TOKEN0) { + setCurrency0(currency); + } else { + setCurrency1(currency); + } + }, + [activeField], + ); + + const handleSearchDismiss = useCallback(() => { + setShowSearch(false); + }, [setShowSearch]); + + return ( + + + + + + Import Pool + + + + { + setShowSearch(true); + setActiveField(Fields.TOKEN0); + }} + > + {currency0 ? ( + + + + {currency0.symbol} + + + ) : ( + Select a Token + )} + + + + + { + setShowSearch(true); + setActiveField(Fields.TOKEN1); + }} + > + {currency1 ? ( + + + + {currency1.symbol} + + + ) : ( + Select a Token + )} + + {hasPosition && ( + + Pool Found! + + Manage this pool. + + + )} + + {currency0 && currency1 ? ( + pairState === PairState.EXISTS ? ( + hasPosition && pair ? ( + + ) : ( + + + You don’t have liquidity in this pool yet. + + + Add liquidity. + + + ) + ) : validPairNoLiquidity ? ( + + No pool found. + + Create pool. + + + ) : pairState === PairState.INVALID ? ( + Invalid pair. + ) : pairState === PairState.LOADING ? ( + Loading... + ) : null + ) : ( + + {!account + ? 'Connect to a wallet to find pools' + : 'Select a token to find your liquidity.'} + + )} + + + {showSearch && ( + + )} + + ); +}; + +export default PoolFinderModal; diff --git a/src/components/PoolFinderModal/index.ts b/src/components/PoolFinderModal/index.ts new file mode 100644 index 000000000..566650e58 --- /dev/null +++ b/src/components/PoolFinderModal/index.ts @@ -0,0 +1 @@ +export { default } from './PoolFinderModal'; diff --git a/src/components/PositionCard/PositionCard.tsx b/src/components/PositionCard/PositionCard.tsx index 82c5c8157..d1f051176 100755 --- a/src/components/PositionCard/PositionCard.tsx +++ b/src/components/PositionCard/PositionCard.tsx @@ -13,7 +13,7 @@ import { CurrencyLogo, DoubleCurrencyLogo } from 'components'; const useStyles = makeStyles(({ palette }) => ({ minimalCardWrapper: { - border: `1px solid ${palette.divider}`, + width: '100%', borderRadius: 16, padding: 12, '& p': { @@ -31,6 +31,7 @@ interface PositionCardProps { export const MinimalPositionCard: React.FC = ({ pair, + border, showUnwrapped = false, }) => { const { account } = useActiveWeb3React(); @@ -77,54 +78,68 @@ export const MinimalPositionCard: React.FC = ({ : [undefined, undefined]; return ( - + {userPoolBalance && JSBI.greaterThan(userPoolBalance.raw, JSBI.BigInt(0)) ? ( Your position - setShowMore(!showMore)}> - + setShowMore(!showMore)} + > + - + {currency0.symbol}/{currency1.symbol} - - - {userPoolBalance ? userPoolBalance.toSignificant(4) : '-'} - - + + {userPoolBalance ? userPoolBalance.toSignificant(4) : '-'} + - - - Your pool share: - - {poolTokenPercentage - ? poolTokenPercentage.toFixed(6) + '%' - : '-'} - - - - {currency0.symbol}: - {token0Deposited ? ( - {token0Deposited?.toSignificant(6)} - ) : ( - '-' - )} - - - {currency1.symbol}: - {token1Deposited ? ( - {token1Deposited?.toSignificant(6)} - ) : ( - '-' - )} - + + Your pool share: + + {poolTokenPercentage ? poolTokenPercentage.toFixed(6) + '%' : '-'} + + + + {currency0.symbol}: + {token0Deposited ? ( + {token0Deposited?.toSignificant(6)} + ) : ( + '-' + )} + + + {currency1.symbol}: + {token1Deposited ? ( + {token1Deposited?.toSignificant(6)} + ) : ( + '-' + )} ) : ( diff --git a/src/components/QuestionHelper/QuestionHelper.tsx b/src/components/QuestionHelper/QuestionHelper.tsx index 2b947d876..75ae8b25f 100755 --- a/src/components/QuestionHelper/QuestionHelper.tsx +++ b/src/components/QuestionHelper/QuestionHelper.tsx @@ -15,7 +15,7 @@ const useStyles = makeStyles(({ palette }) => ({ outline: 'none', cursor: 'default', borderRadius: 36, - color: palette.text.primary, + color: (props: any) => (props.color ? props.color : palette.text.primary), '&:hover, &:focus': { opacity: 0.7, }, @@ -32,7 +32,7 @@ const useStyles = makeStyles(({ palette }) => ({ borderRadius: 36, width: 24, height: 24, - color: 'white', + color: (props: any) => (props.color ? props.color : 'white'), '&:hover, &:focus': { opacity: 0.7, }, @@ -42,11 +42,12 @@ const useStyles = makeStyles(({ palette }) => ({ }, })); -const QuestionHelper: React.FC<{ text: string; size?: number }> = ({ - text, - size = 16, -}) => { - const classes = useStyles(); +const QuestionHelper: React.FC<{ + text: string; + size?: number; + color?: string; +}> = ({ text, size = 16, color }) => { + const classes = useStyles({ color }); return ( @@ -59,8 +60,11 @@ const QuestionHelper: React.FC<{ text: string; size?: number }> = ({ export default QuestionHelper; -export const PlusHelper: React.FC<{ text: string }> = ({ text }) => { - const classes = useStyles(); +export const PlusHelper: React.FC<{ text: string; color?: string }> = ({ + text, + color, +}) => { + const classes = useStyles({ color }); return ( @@ -71,8 +75,11 @@ export const PlusHelper: React.FC<{ text: string }> = ({ text }) => { ); }; -export const LightQuestionHelper: React.FC<{ text: string }> = ({ text }) => { - const classes = useStyles(); +export const LightQuestionHelper: React.FC<{ text: string; color: string }> = ({ + text, + color, +}) => { + const classes = useStyles({ color }); return ( diff --git a/src/components/Swap/Swap.tsx b/src/components/Swap/Swap.tsx index 075df1965..3834b680e 100755 --- a/src/components/Swap/Swap.tsx +++ b/src/components/Swap/Swap.tsx @@ -531,24 +531,28 @@ const Swap: React.FC<{ return ( - setOpenSettingsModal(false)} - /> - + {openSettingsModal && ( + setOpenSettingsModal(false)} + /> + )} + {showConfirm && ( + + )} ({ const PoolsPage: React.FC = () => { const classes = useStyles(); + const { palette } = useTheme(); const { account } = useActiveWeb3React(); const [openSettingsModal, setOpenSettingsModal] = useState(false); + const [openPoolFinder, setOpenPoolFinder] = useState(false); const parsedQuery = useParsedQueryString(); const qCurrency0 = useCurrency( parsedQuery && parsedQuery.currency0 @@ -125,10 +132,18 @@ const PoolsPage: React.FC = () => { return ( - setOpenSettingsModal(false)} - /> + {openSettingsModal && ( + setOpenSettingsModal(false)} + /> + )} + {openPoolFinder && ( + setOpenPoolFinder(false)} + /> + )} { - + setOpenSettingsModal(true)} /> @@ -180,7 +199,11 @@ const PoolsPage: React.FC = () => { ) : allV2PairsWithLiquidity.length > 0 ? ( - Don’t see a pool you joined? Import it.
+ Don’t see a pool you joined?{' '} + setOpenPoolFinder(true)}> + Import it + + .
Unstake your LP Tokens from Farms to see them here.
{allV2PairsWithLiquidity.map((pair, ind) => ( @@ -207,7 +230,11 @@ const PoolsPage: React.FC = () => { className={classes.noLiquidityImage} /> - Don’t see a pool you joined? Import it.
+ Don’t see a pool you joined?{' '} + setOpenPoolFinder(true)}> + Import it + + .
Unstake your LP Tokens from Farms to see them here.
diff --git a/src/pages/SwapPage/SwapPage.tsx b/src/pages/SwapPage/SwapPage.tsx index 76717887b..6c4fe507a 100755 --- a/src/pages/SwapPage/SwapPage.tsx +++ b/src/pages/SwapPage/SwapPage.tsx @@ -275,10 +275,12 @@ const SwapPage: React.FC = () => { return ( - setOpenSettingsModal(false)} - /> + {openSettingsModal && ( + setOpenSettingsModal(false)} + /> + )}