|
| 1 | +import React, { useMemo } from "react" |
| 2 | +import BigNumber from "bignumber.js" |
| 3 | +import DoubleIcon from "./DoubleIcon" |
| 4 | +import * as Icons from "./Icons" |
| 5 | +import { SubmitButton } from "./Button" |
| 6 | +import Card from "./Card" |
| 7 | +import { displayAmount } from "../utils/token.utils" |
| 8 | +import { gt } from "../utils/arithmetics.utils" |
| 9 | +import { Skeleton } from "./skeletons" |
| 10 | + |
| 11 | +const LiquidityRewardCard = ({ |
| 12 | + title, |
| 13 | + liquidityPairContractName, |
| 14 | + MainIcon, |
| 15 | + SecondaryIcon, |
| 16 | + viewPoolLink, |
| 17 | + apy, |
| 18 | + // Percentage of the deposited liquidity tokens in the `LPRewards` pool. |
| 19 | + percentageOfTotalPool, |
| 20 | + // Current reward balance earned in `LPRewards` contract. |
| 21 | + rewardBalance, |
| 22 | + // Balance of the wrapped token. |
| 23 | + wrappedTokenBalance, |
| 24 | + // Balance of wrapped token deposited in the `LPRewards` contract. |
| 25 | + lpBalance, |
| 26 | + isFetching, |
| 27 | + wrapperClassName = "", |
| 28 | + addLpTokens, |
| 29 | + withdrawLiquidityRewards, |
| 30 | +}) => { |
| 31 | + const formattedApy = useMemo(() => { |
| 32 | + const bn = new BigNumber(apy) |
| 33 | + if (bn.isEqualTo(Infinity)) return <span>∞</span> |
| 34 | + |
| 35 | + return bn.isLessThan(0.01) && bn.isGreaterThan(0) |
| 36 | + ? "<0.01%" |
| 37 | + : bn.multipliedBy(100).decimalPlaces(2, BigNumber.ROUND_DOWN).toString() + |
| 38 | + "%" |
| 39 | + }, [apy]) |
| 40 | + |
| 41 | + const formattedPercentageOfTotalPool = useMemo(() => { |
| 42 | + const bn = new BigNumber(percentageOfTotalPool) |
| 43 | + return bn.isLessThan(0.01) && bn.isGreaterThan(0) |
| 44 | + ? "<0.01" |
| 45 | + : bn.decimalPlaces(2, BigNumber.ROUND_DOWN) |
| 46 | + }, [percentageOfTotalPool]) |
| 47 | + |
| 48 | + return ( |
| 49 | + <Card className={`liquidity__card tile ${wrapperClassName}`}> |
| 50 | + <Icons.SantaHat className="liquidity-card__santa-hat" /> |
| 51 | + <div className={"liquidity__card-title"}> |
| 52 | + <DoubleIcon |
| 53 | + MainIcon={MainIcon} |
| 54 | + SecondaryIcon={SecondaryIcon} |
| 55 | + className={`liquidity__double-icon-container`} |
| 56 | + /> |
| 57 | + <h2 className={"h2--alt text-grey-70"}>{title}</h2> |
| 58 | + </div> |
| 59 | + <h4 className="liquidity__card-subtitle text-grey-40"> |
| 60 | + Uniswap Pool |
| 61 | + <a |
| 62 | + target="_blank" |
| 63 | + rel="noopener noreferrer" |
| 64 | + href={viewPoolLink} |
| 65 | + className="text-small" |
| 66 | + > |
| 67 | + View pool |
| 68 | + </a> |
| 69 | + </h4> |
| 70 | + <div className={"liquidity__info text-grey-60 mt-2"}> |
| 71 | + <div className={"liquidity__info-tile bg-mint-10"}> |
| 72 | + <h2 className={"liquidity__info-tile__title text-mint-100"}> |
| 73 | + {formattedApy}* |
| 74 | + </h2> |
| 75 | + <h6>Annual % yield (APY)</h6> |
| 76 | + </div> |
| 77 | + <div className={"liquidity__info-tile bg-mint-10"}> |
| 78 | + {isFetching ? ( |
| 79 | + <Skeleton tag="h2" shining color="mint-20" /> |
| 80 | + ) : ( |
| 81 | + <h2 |
| 82 | + className={"liquidity__info-tile__title text-mint-100"} |
| 83 | + >{`${formattedPercentageOfTotalPool}%`}</h2> |
| 84 | + )} |
| 85 | + <h6>% of total pool</h6> |
| 86 | + </div> |
| 87 | + </div> |
| 88 | + <div className={"text-smaller text-grey-70 text-center mb-2"}> |
| 89 | + * APY calculated assuming $1M pool |
| 90 | + </div> |
| 91 | + <div className={"liquidity__token-balance"}> |
| 92 | + <span className={"liquidity__token-balance_title text-grey-70"}> |
| 93 | + Reward |
| 94 | + </span> |
| 95 | + <div className={"liquidity__token-balance_values text-grey-70"}> |
| 96 | + <h3 className={"liquidity__token-balance_values_label"}> |
| 97 | + <Icons.KeepOutline /> |
| 98 | + <span>KEEP</span> |
| 99 | + </h3> |
| 100 | + {isFetching ? ( |
| 101 | + <Skeleton tag="h3" shining color="grey-20" className="ml-3" /> |
| 102 | + ) : ( |
| 103 | + <h3>{displayAmount(rewardBalance)}</h3> |
| 104 | + )} |
| 105 | + </div> |
| 106 | + </div> |
| 107 | + <SubmitButton |
| 108 | + className={`liquidity__add-more-tokens btn btn-primary btn-lg w-100`} |
| 109 | + disabled={!gt(wrappedTokenBalance, 0)} |
| 110 | + onSubmitAction={(awaitingPromise) => |
| 111 | + addLpTokens( |
| 112 | + wrappedTokenBalance, |
| 113 | + liquidityPairContractName, |
| 114 | + awaitingPromise |
| 115 | + ) |
| 116 | + } |
| 117 | + > |
| 118 | + add more lp tokens |
| 119 | + </SubmitButton> |
| 120 | + |
| 121 | + <SubmitButton |
| 122 | + className={"liquidity__withdraw btn btn-secondary btn-lg w-100"} |
| 123 | + disabled={!gt(rewardBalance, 0)} |
| 124 | + onSubmitAction={(awaitingPromise) => |
| 125 | + withdrawLiquidityRewards(liquidityPairContractName, awaitingPromise) |
| 126 | + } |
| 127 | + > |
| 128 | + withdraw all |
| 129 | + </SubmitButton> |
| 130 | + {gt(rewardBalance, 0) && ( |
| 131 | + <div className={"text-validation text-center"}> |
| 132 | + Withdraw includes rewards and principal |
| 133 | + </div> |
| 134 | + )} |
| 135 | + </Card> |
| 136 | + ) |
| 137 | +} |
| 138 | + |
| 139 | +export default LiquidityRewardCard |
0 commit comments