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 all commits
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
6 changes: 4 additions & 2 deletions src/pages/Farm/ClaimRewardsDlg.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ export default function ClaimRewardsDlg({
const dispatch = useDispatch()

const onClickClaim = useCallback(async () => {
if (!chainId) return
if (!chainId) {
enqueueToast("error", "Unable to claim reward")
return
}
try {
const txns = await userGauge?.claim()

Expand Down Expand Up @@ -67,7 +70,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
38 changes: 33 additions & 5 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 @@ -49,9 +54,21 @@ export default function StakeDialog({
const { infiniteApproval } = useSelector((state: AppState) => state.user)

const onClickStake = useCallback(async () => {
const errorMsg = "Unable to stake"
try {
if (!userGauge || !chainId || !gaugeAddress || !account || !library)
if (!userGauge || !chainId || !gaugeAddress || !account || !library) {
console.error(
`${errorMsg}: ${missingKeys({
userGauge,
chainId,
gaugeAddress,
account,
library,
}).join(", ")} missing`,
)
enqueueToast("error", errorMsg)
return
}
const inputBN = parseUnits(amountInput)
const lpTokenContract = getContract(
userGauge.lpToken.address,
Expand Down Expand Up @@ -85,7 +102,7 @@ export default function StakeDialog({
setAmountInput(defaultInput)
} catch (e) {
console.error(e)
enqueueToast("error", "Unable to stake")
enqueueToast("error", errorMsg)
}
}, [
userGauge,
Expand All @@ -100,8 +117,18 @@ export default function StakeDialog({
])

const onClickUnstake = useCallback(async () => {
const errorMsg = "Unable to unstake"
try {
if (!userGauge || !chainId) return
if (!userGauge || !chainId) {
console.error(
`${errorMsg}: ${missingKeys({
userGauge,
chainId,
}).join(", ")} missing`,
)
enqueueToast("error", errorMsg)
return
}
const inputBN = parseUnits(amountInput)
const txn = await userGauge?.unstake(inputBN)
await enqueuePromiseToast(chainId, txn.wait(), "unstake", {
Expand All @@ -115,7 +142,7 @@ export default function StakeDialog({
setAmountInput(defaultInput)
} catch (e) {
console.error(e)
enqueueToast("error", "Unable to unstake")
enqueueToast("error", errorMsg)
}
}, [userGauge, amountInput, chainId, farmName, dispatch])

Expand All @@ -130,6 +157,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[]
}