utils#currencyId TypeScript Examples
The following examples show how to use
utils#currencyId.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PoolFinderModal.tsx From interface-v2 with GNU General Public License v3.0 | 4 votes |
PoolFinderModal: React.FC<PoolFinderModalProps> = ({ open, onClose }) => {
const classes = useStyles();
const { palette } = useTheme();
const { account } = useActiveWeb3React();
const [showSearch, setShowSearch] = useState<boolean>(false);
const [activeField, setActiveField] = useState<number>(Fields.TOKEN1);
const [currency0, setCurrency0] = useState<Currency | null>(ETHER);
const [currency1, setCurrency1] = useState<Currency | null>(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 (
<CustomModal open={open} onClose={onClose}>
<Box paddingX={3} paddingY={4}>
<Box display='flex' alignItems='center' justifyContent='space-between'>
<ArrowLeft
color={palette.text.secondary}
style={{ cursor: 'pointer' }}
onClick={onClose}
/>
<Typography
variant='subtitle2'
style={{ color: palette.text.primary }}
>
Import Pool
</Typography>
<CloseIcon style={{ cursor: 'pointer' }} onClick={onClose} />
</Box>
<Box
mt={2}
className={classes.borderedCard}
onClick={() => {
setShowSearch(true);
setActiveField(Fields.TOKEN0);
}}
>
{currency0 ? (
<Box display='flex' alignItems='center'>
<CurrencyLogo currency={currency0} size='20px' />
<Typography variant='h6' style={{ marginLeft: 6 }}>
{currency0.symbol}
</Typography>
</Box>
) : (
<Typography variant='h6'>Select a Token</Typography>
)}
</Box>
<Box my={1} display='flex' justifyContent='center'>
<Plus size='20' color={palette.text.secondary} />
</Box>
<Box
className={classes.borderedCard}
onClick={() => {
setShowSearch(true);
setActiveField(Fields.TOKEN1);
}}
>
{currency1 ? (
<Box display='flex'>
<CurrencyLogo currency={currency1} />
<Typography variant='h6' style={{ marginLeft: 6 }}>
{currency1.symbol}
</Typography>
</Box>
) : (
<Typography variant='h6'>Select a Token</Typography>
)}
</Box>
{hasPosition && (
<Box textAlign='center' mt={2}>
<Typography variant='body1'>Pool Found!</Typography>
<Typography
variant='body1'
style={{ cursor: 'pointer', color: palette.primary.main }}
onClick={onClose}
>
Manage this pool.
</Typography>
</Box>
)}
<Box
mt={2}
p={1}
borderRadius={10}
display='flex'
justifyContent='center'
border={`1px solid ${palette.divider}`}
>
{currency0 && currency1 ? (
pairState === PairState.EXISTS ? (
hasPosition && pair ? (
<MinimalPositionCard pair={pair} border='none' />
) : (
<Box textAlign='center'>
<Typography>
You don’t have liquidity in this pool yet.
</Typography>
<Link
to={`/pools?currency0=${currencyId(
currency0,
)}¤cy1=${currencyId(currency1)}`}
style={{
color: palette.primary.main,
textDecoration: 'none',
}}
onClick={onClose}
>
<Typography>Add liquidity.</Typography>
</Link>
</Box>
)
) : validPairNoLiquidity ? (
<Box textAlign='center'>
<Typography>No pool found.</Typography>
<Link
to={`/pools?currency0=${currencyId(
currency0,
)}¤cy1=${currencyId(currency1)}`}
style={{
color: palette.primary.main,
textDecoration: 'none',
}}
onClick={onClose}
>
Create pool.
</Link>
</Box>
) : pairState === PairState.INVALID ? (
<Typography>Invalid pair.</Typography>
) : pairState === PairState.LOADING ? (
<Typography>Loading...</Typography>
) : null
) : (
<Typography>
{!account
? 'Connect to a wallet to find pools'
: 'Select a token to find your liquidity.'}
</Typography>
)}
</Box>
</Box>
{showSearch && (
<CurrencySearchModal
isOpen={showSearch}
onCurrencySelect={handleCurrencySelect}
onDismiss={handleSearchDismiss}
showCommonBases
selectedCurrency={
(activeField === Fields.TOKEN0 ? currency1 : currency0) ?? undefined
}
/>
)}
</CustomModal>
);
}
Example #2
Source File: PoolPositionCardDetails.tsx From interface-v2 with GNU General Public License v3.0 | 4 votes |
PoolPositionCardDetails: React.FC<{ pair: Pair }> = ({ pair }) => {
const classes = useStyles();
const history = useHistory();
const { breakpoints } = useTheme();
const isMobile = useMediaQuery(breakpoints.down('xs'));
const { account } = useActiveWeb3React();
const [openRemoveModal, setOpenRemoveModal] = useState(false);
const currency0 = unwrappedToken(pair.token0);
const currency1 = unwrappedToken(pair.token1);
const userPoolBalance = useTokenBalance(
account ?? undefined,
pair.liquidityToken,
);
const totalPoolTokens = useTotalSupply(pair.liquidityToken);
const poolTokenPercentage =
!!userPoolBalance &&
!!totalPoolTokens &&
JSBI.greaterThanOrEqual(totalPoolTokens.raw, userPoolBalance.raw)
? new Percent(userPoolBalance.raw, totalPoolTokens.raw)
: undefined;
const [token0Deposited, token1Deposited] =
!!pair &&
!!totalPoolTokens &&
!!userPoolBalance &&
// this condition is a short-circuit in the case where useTokenBalance updates sooner than useTotalSupply
JSBI.greaterThanOrEqual(totalPoolTokens.raw, userPoolBalance.raw)
? [
pair.getLiquidityValue(
pair.token0,
totalPoolTokens,
userPoolBalance,
false,
),
pair.getLiquidityValue(
pair.token1,
totalPoolTokens,
userPoolBalance,
false,
),
]
: [undefined, undefined];
return (
<>
<Box px={isMobile ? 1.5 : 3} mb={3}>
<Box className={classes.cardRow}>
<Typography variant='body2'>Your pool tokens:</Typography>
<Typography variant='body2'>
{formatTokenAmount(userPoolBalance)}
</Typography>
</Box>
<Box className={classes.cardRow}>
<Typography variant='body2'>Pooled {currency0.symbol}:</Typography>
<Box display='flex' alignItems='center'>
<Typography variant='body2' style={{ marginRight: 10 }}>
{formatTokenAmount(token0Deposited)}
</Typography>
<CurrencyLogo size='20px' currency={currency0} />
</Box>
</Box>
<Box className={classes.cardRow}>
<Typography variant='body2'>Pooled {currency1.symbol}:</Typography>
<Box display='flex' alignItems='center'>
<Typography variant='body2' style={{ marginRight: 10 }}>
{formatTokenAmount(token1Deposited)}
</Typography>
<CurrencyLogo size='20px' currency={currency1} />
</Box>
</Box>
<Box className={classes.cardRow}>
<Typography variant='body2'>Your pool share:</Typography>
<Typography variant='body2'>
{poolTokenPercentage
? poolTokenPercentage.toSignificant() + '%'
: '-'}
</Typography>
</Box>
<Box className={classes.poolButtonRow}>
<Button
variant='outlined'
onClick={() =>
history.push(`/analytics/pair/${pair.liquidityToken.address}`)
}
>
<Typography variant='body2'>View Analytics</Typography>
</Button>
<Button
variant='contained'
onClick={() => {
history.push(
`/pools?currency0=${currencyId(
currency0,
)}¤cy1=${currencyId(currency1)}`,
);
}}
>
<Typography variant='body2'>Add</Typography>
</Button>
<Button
variant='contained'
onClick={() => {
setOpenRemoveModal(true);
}}
>
<Typography variant='body2'>Remove</Typography>
</Button>
</Box>
</Box>
{openRemoveModal && (
<RemoveLiquidityModal
currency0={currency0}
currency1={currency1}
open={openRemoveModal}
onClose={() => setOpenRemoveModal(false)}
/>
)}
</>
);
}
Example #3
Source File: PositionCard.tsx From interface-v2 with GNU General Public License v3.0 | 4 votes |
FullPositionCard: React.FC<PositionCardProps> = ({ pair }) => {
const { account } = useActiveWeb3React();
const currency0 = unwrappedToken(pair.token0);
const currency1 = unwrappedToken(pair.token1);
const [showMore, setShowMore] = useState(false);
const userPoolBalance = useTokenBalance(
account ?? undefined,
pair.liquidityToken,
);
const totalPoolTokens = useTotalSupply(pair.liquidityToken);
const poolTokenPercentage =
!!userPoolBalance &&
!!totalPoolTokens &&
JSBI.greaterThanOrEqual(totalPoolTokens.raw, userPoolBalance.raw)
? new Percent(userPoolBalance.raw, totalPoolTokens.raw)
: undefined;
const [token0Deposited, token1Deposited] =
!!pair &&
!!totalPoolTokens &&
!!userPoolBalance &&
// this condition is a short-circuit in the case where useTokenBalance updates sooner than useTotalSupply
JSBI.greaterThanOrEqual(totalPoolTokens.raw, userPoolBalance.raw)
? [
pair.getLiquidityValue(
pair.token0,
totalPoolTokens,
userPoolBalance,
false,
),
pair.getLiquidityValue(
pair.token1,
totalPoolTokens,
userPoolBalance,
false,
),
]
: [undefined, undefined];
return (
<Box>
<Box>
<Box>
<DoubleCurrencyLogo
currency0={currency0}
currency1={currency1}
margin={true}
size={20}
/>
<Typography>
{!currency0 || !currency1 ? (
<Typography>Loading</Typography>
) : (
`${currency0.symbol}/${currency1.symbol}`
)}
</Typography>
</Box>
<Button onClick={() => setShowMore(!showMore)}>
{showMore ? (
<>
{' '}
Manage
<ChevronUp size='20' style={{ marginLeft: '10px' }} />
</>
) : (
<>
Manage
<ChevronDown size='20' style={{ marginLeft: '10px' }} />
</>
)}
</Button>
</Box>
{showMore && (
<Box>
<Box>
<Typography>Your pool tokens:</Typography>
<Typography>{formatTokenAmount(userPoolBalance)}</Typography>
</Box>
<Box>
<Typography>Pooled {currency0.symbol}:</Typography>
<Box>
<Typography>{formatTokenAmount(token0Deposited)}</Typography>
<CurrencyLogo
size='20px'
style={{ marginLeft: '8px' }}
currency={currency0}
/>
</Box>
</Box>
<Box>
<Typography>Pooled {currency1.symbol}:</Typography>
<Box>
<Typography>{formatTokenAmount(token1Deposited)}</Typography>
<CurrencyLogo
size='20px'
style={{ marginLeft: '8px' }}
currency={currency1}
/>
</Box>
</Box>
<Box>
<Typography>Your pool share:</Typography>
<Typography>
{poolTokenPercentage ? poolTokenPercentage.toFixed(2) + '%' : '-'}
</Typography>
</Box>
<Button>
<a
style={{ width: '100%', textAlign: 'center' }}
href={`https://info.quickswap.exchange/account/${account}`}
target='_blank'
rel='noopener noreferrer'
>
View accrued fees and analytics
<span style={{ fontSize: '11px' }}>↗</span>
</a>
</Button>
<Box display='flex'>
<Box width='48%'>
<Link
to={`/add/${currencyId(currency0)}/${currencyId(currency1)}`}
>
Add
</Link>
</Box>
<Box width='48%'>
<Link
to={`/remove/${currencyId(currency0)}/${currencyId(currency1)}`}
>
Remove
</Link>
</Box>
</Box>
</Box>
)}
</Box>
);
}