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

better logging, hide empty lp #1126

Merged
merged 2 commits into from
Jun 23, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
1 change: 0 additions & 1 deletion src/pages/Farm/ClaimRewardsDlg.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ export default function ClaimRewardsDlg({
</Typography>
<Typography>Stake your LP token and collect incentives.</Typography>
<Box>
<Typography>LP Staked:</Typography>
<Typography mt={2}>Rewards:</Typography>
<UserRewards userGaugeRewards={userGauge?.userGaugeRewards} />
</Box>
Expand Down
30 changes: 27 additions & 3 deletions src/pages/Farm/StakeDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ import {
} from "@mui/material"
import React, { useCallback, useState } from "react"
import { TRANSACTION_TYPES, readableDecimalNumberRegex } from "../../constants"
import { commify, formatBNToString, getContract } from "../../utils"
import {
commify,
formatBNToString,
getContract,
missingKeys,
} from "../../utils"
import { enqueuePromiseToast, enqueueToast } from "../../components/Toastify"
import { formatUnits, parseUnits } from "ethers/lib/utils"
import { useDispatch, useSelector } from "react-redux"
Expand Down Expand Up @@ -50,8 +55,18 @@ export default function StakeDialog({

const onClickStake = useCallback(async () => {
try {
if (!userGauge || !chainId || !gaugeAddress || !account || !library)
if (!userGauge || !chainId || !gaugeAddress || !account || !library) {
console.error(
`Could not stake: ${missingKeys({
userGauge,
chainId,
gaugeAddress,
account,
library,
}).join(", ")} missing`,
)
return
}
const inputBN = parseUnits(amountInput)
const lpTokenContract = getContract(
userGauge.lpToken.address,
Expand Down Expand Up @@ -101,7 +116,15 @@ export default function StakeDialog({

const onClickUnstake = useCallback(async () => {
try {
if (!userGauge || !chainId) return
if (!userGauge || !chainId) {
console.error(
`Could not unstake: ${missingKeys({
userGauge,
chainId,
}).join(", ")} missing`,
)
return
}
const inputBN = parseUnits(amountInput)
const txn = await userGauge?.unstake(inputBN)
await enqueuePromiseToast(chainId, txn.wait(), "unstake", {
Expand Down Expand Up @@ -130,6 +153,7 @@ export default function StakeDialog({
onClose={() => {
onClose()
setStakeStatus("stake")
setAmountInput(defaultInput)
}}
fullWidth
maxWidth="xs"
Expand Down
6 changes: 6 additions & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -622,3 +622,9 @@ export function getPriceDataForPool(
totalLocked: tokenBalancesSum1e18,
}
}

export function missingKeys(itemsMap: { [key: string]: unknown }): string[] {
return Object.keys(itemsMap)
.map((key) => itemsMap[key] == null && key)
.filter(Boolean) as string[]
}