Skip to content

Commit

Permalink
fix: fix some edge cases in pool share displays
Browse files Browse the repository at this point in the history
  • Loading branch information
danielattilasimon committed Apr 8, 2021
1 parent 6d00a66 commit 90fb59b
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 27 deletions.
18 changes: 11 additions & 7 deletions packages/dev-frontend/src/components/Farm/views/Active/Active.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const Active: React.FC = () => {
transactionState.type === "waitingForApproval" ||
transactionState.type === "waitingForConfirmation";

const poolShare = liquidityMiningStake.div(totalStakedUniTokens).mul(100);
const poolShare = liquidityMiningStake.mulDiv(100, totalStakedUniTokens);

return (
<Card>
Expand All @@ -61,12 +61,16 @@ export const Active: React.FC = () => {
amount={liquidityMiningStake.prettify(4)}
unit={LP}
/>
<StaticRow
label="Pool share"
inputId="farm-share"
amount={poolShare.prettify(4)}
unit={"%"}
/>
{poolShare.infinite ? (
<StaticRow label="Pool share" inputId="farm-share" amount="N/A" />
) : (
<StaticRow
label="Pool share"
inputId="farm-share"
amount={poolShare.prettify(4)}
unit={"%"}
/>
)}
<Flex sx={{ alignItems: "center" }}>
<StaticRow
label="Reward"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,11 @@ export const Adjusting: React.FC = () => {
? totalStakedUniTokens.sub(liquidityMiningStake).add(amount)
: totalStakedUniTokens;

const originalPoolShare = liquidityMiningStake.div(nextTotalStakedUniTokens).mul(100);

const poolShare = nextTotalStakedUniTokens.gt(0)
? Decimal.min(Decimal.max(amount.div(nextTotalStakedUniTokens).mul(100), 0), 100)
: Decimal.ZERO;
const originalPoolShare = liquidityMiningStake.mulDiv(100, totalStakedUniTokens);
const poolShare = amount.mulDiv(100, nextTotalStakedUniTokens);

const poolShareChange =
originalPoolShare.nonZero && Difference.between(poolShare, originalPoolShare).nonZero;
liquidityMiningStake.nonZero && Difference.between(poolShare, originalPoolShare).nonZero;

return (
<Card>
Expand Down Expand Up @@ -92,14 +89,18 @@ export const Adjusting: React.FC = () => {
maxedOut={hasSetMaximumAmount}
></EditableRow>

<StaticRow
label="Pool share"
inputId="farm-share"
amount={poolShare.prettify(4)}
unit="%"
pendingAmount={poolShareChange?.prettify().concat("%")}
pendingColor={poolShareChange?.positive ? "success" : "danger"}
/>
{poolShare.infinite ? (
<StaticRow label="Pool share" inputId="farm-share" amount="N/A" />
) : (
<StaticRow
label="Pool share"
inputId="farm-share"
amount={poolShare.prettify(4)}
unit="%"
pendingAmount={poolShareChange?.prettify().concat("%")}
pendingColor={poolShareChange?.positive ? "success" : "danger"}
/>
)}

<StaticRow
label="Reward"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ export const Staking: React.FC = () => {

const nextTotalStakedUniTokens = totalStakedUniTokens.add(amount);

const poolShare = nextTotalStakedUniTokens.gt(0)
? Decimal.min(Decimal.max(amount.div(nextTotalStakedUniTokens).mul(100), 0), 100)
: Decimal.ZERO;
const poolShare = amount.mulDiv(100, nextTotalStakedUniTokens);

return (
<Card>
Expand Down Expand Up @@ -70,7 +68,16 @@ export const Staking: React.FC = () => {
maxedOut={hasSetMaximumStake}
></EditableRow>

<StaticRow label="Pool share" inputId="farm-share" amount={poolShare.prettify(4)} unit="%" />
{poolShare.infinite ? (
<StaticRow label="Pool share" inputId="farm-share" amount="N/A" />
) : (
<StaticRow
label="Pool share"
inputId="farm-share"
amount={poolShare.prettify(4)}
unit="%"
/>
)}

{isDirty && <Validation amount={amount} />}
<Description amount={amount} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ export const StabilityDepositEditor: React.FC<StabilityDepositEditorProps> = ({
const originalPoolShare = originalDeposit.currentLUSD.mulDiv(100, lusdInStabilityPool);
const newPoolShare = editedLUSD.mulDiv(100, lusdInStabilityPoolAfterChange);
const poolShareChange =
originalPoolShare.nonZero && Difference.between(newPoolShare, originalPoolShare).nonZero;
originalDeposit.currentLUSD.nonZero &&
Difference.between(newPoolShare, originalPoolShare).nonZero;

return (
<Card>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const StakingEditor: React.FC<StakingEditorProps> = ({
const originalPoolShare = originalStake.stakedLQTY.mulDiv(100, totalStakedLQTY);
const newPoolShare = editedLQTY.mulDiv(100, totalStakedLQTYAfterChange);
const poolShareChange =
originalPoolShare.nonZero && Difference.between(newPoolShare, originalPoolShare).nonZero;
originalStake.stakedLQTY.nonZero && Difference.between(newPoolShare, originalPoolShare).nonZero;

return (
<Card>
Expand Down

0 comments on commit 90fb59b

Please sign in to comment.