Skip to content

Commit

Permalink
fix: ts error (#9016)
Browse files Browse the repository at this point in the history
<!--
Before opening a pull request, please read the [contributing
guidelines](https://github.com/pancakeswap/pancake-frontend/blob/develop/CONTRIBUTING.md)
first
-->

<!-- start pr-codex -->

---

## PR-Codex overview
### Detailed summary
- Added eslint-disable-next-line comments for unused imports in multiple
files
- Removed unused import in `useGaugesVotingCount` function
- Added eslint-disable-next-line comments for unused imports in
`CreateProposal` component
- Reordered imports in `getStableSwapFee` function
- Removed unused import in `quote-worker.ts` file
- Reordered imports in `fetchFarmUser.ts` file
- Reordered imports in `CurrencySelect` component
- Reordered imports in `EasyMde` component
- Removed unused imports in `useUserVoteGauges` hook
- Reordered imports in `WalletModal` component
- Removed unused import in `AnniversaryAchievementModal` component

> The following files were skipped due to too many changes:
`apps/web/src/components/GlobalCheckClaimStatus/AnniversaryAchievementModal.tsx`

> ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your
question}`

<!-- end pr-codex -->

---------

Co-authored-by: chefilip <philip@pancakeswap.com>
Co-authored-by: ChefJoJo <94336009+chef-jojo@users.noreply.github.com>
  • Loading branch information
3 people authored Feb 15, 2024
1 parent 9d7be96 commit b0ec2a4
Show file tree
Hide file tree
Showing 13 changed files with 75 additions and 67 deletions.
10 changes: 5 additions & 5 deletions apps/web/src/components/CurrencySelect/index.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { styled } from 'styled-components'
import { ArrowDropDownIcon, Box, Button, Text, useModal, Flex, BoxProps } from '@pancakeswap/uikit'
import CurrencySearchModal, { CurrencySearchModalProps } from 'components/SearchModal/CurrencySearchModal'
import { useTranslation } from '@pancakeswap/localization'
import { ArrowDropDownIcon, Box, BoxProps, Button, Flex, Text, useModal } from '@pancakeswap/uikit'
import { formatNumber } from '@pancakeswap/utils/formatBalance'
import { formatAmount } from '@pancakeswap/utils/formatFractions'
import { useCurrencyBalance } from 'state/wallet/hooks'
import CurrencySearchModal, { CurrencySearchModalProps } from 'components/SearchModal/CurrencySearchModal'
import { useStablecoinPrice } from 'hooks/useStablecoinPrice'
import { useCurrencyBalance } from 'state/wallet/hooks'
import { styled } from 'styled-components'
import { useAccount } from 'wagmi'
import { AutoRow, RowBetween } from '../Layout/Row'
import { CurrencyLogo } from '../Logo'
import { RowBetween, AutoRow } from '../Layout/Row'

const DropDownHeader = styled.div`
width: 100%;
Expand Down
19 changes: 12 additions & 7 deletions apps/web/src/components/EasyMde/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TextareaHTMLAttributes, useEffect, useRef } from 'react'
import EasyMde from 'easymde'
import { styled } from 'styled-components'
import merge from 'lodash/merge'
import { TextareaHTMLAttributes, useEffect, useRef } from 'react'
import { styled } from 'styled-components'

import 'easymde/dist/easymde.min.css'

Expand Down Expand Up @@ -60,19 +60,24 @@ const defaultOptions: EasyMde.Options = {
}

const SimpleMde: React.FC<React.PropsWithChildren<SimpleMdeProps>> = ({ options, onTextChange, ...props }) => {
const ref = useRef()
const ref = useRef<HTMLTextAreaElement>(null)
const onTextChangeHandler = useRef(onTextChange)

useEffect(() => {
let simpleMde = new EasyMde(merge({ element: ref.current }, defaultOptions, options))
let simpleMde: EasyMde | null = new EasyMde(merge({ element: ref.current }, defaultOptions, options))

const handler = () => {
if (simpleMde) {
onTextChangeHandler.current(simpleMde.value())
}
}

simpleMde.codemirror.on('change', () => {
onTextChangeHandler.current(simpleMde.value())
})
simpleMde.codemirror.on('change', handler)

return () => {
if (simpleMde) {
simpleMde.toTextArea()
simpleMde.codemirror.off('change', handler)
simpleMde = null
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { AutoRenewIcon, Box, Button, Flex, Modal, Text, ModalV2, useToast } from '@pancakeswap/uikit'
import confetti from 'canvas-confetti'
import { ChainId } from '@pancakeswap/chains'
import { useTranslation } from '@pancakeswap/localization'
import delay from 'lodash/delay'
import React, { useRef, useEffect, useState } from 'react'
import { styled } from 'styled-components'
import { AutoRenewIcon, Box, Button, Flex, Modal, ModalV2, Text, useToast } from '@pancakeswap/uikit'
import confetti from 'canvas-confetti'
import Dots from 'components/Loader/Dots'
import { useRouter } from 'next/router'
import { useAccount } from 'wagmi'
import { ToastDescriptionWithTx } from 'components/Toast'
import { useActiveChainId } from 'hooks/useActiveChainId'
import { useAnniversaryAchievementContract } from 'hooks/useContract'
import useCatchTxError from 'hooks/useCatchTxError'
import { ToastDescriptionWithTx } from 'components/Toast'
import { useAnniversaryAchievementContract } from 'hooks/useContract'
import { useShowOnceAnniversaryModal } from 'hooks/useShowOnceAnniversaryModal'
import delay from 'lodash/delay'
import { useRouter } from 'next/router'
import React, { useEffect, useRef, useState } from 'react'
import { styled } from 'styled-components'
import { useAccount } from 'wagmi'

const AnniversaryImage = styled.img`
border-radius: 50%;
Expand Down Expand Up @@ -58,8 +58,8 @@ const AnniversaryAchievementModal: React.FC<AnniversaryModalProps> = ({ excludeL
// Check claim status
useEffect(() => {
const fetchClaimAnniversaryStatus = async () => {
const canClaimAnniversary = await contract.read.canClaim([account])
setCanClaimAnniversaryPoints(canClaimAnniversary)
const canClaimAnniversary = account && (await contract.read.canClaim([account]))
setCanClaimAnniversaryPoints(Boolean(canClaimAnniversary))
}

if (account && chainId === ChainId.BSC) {
Expand Down Expand Up @@ -117,7 +117,14 @@ const AnniversaryAchievementModal: React.FC<AnniversaryModalProps> = ({ excludeL
setIsLoading(true)

try {
const receipt = await fetchWithCatchTxError(() => contract.write.claimAnniversaryPoints({ account, chainId }))
const receipt =
account &&
(await fetchWithCatchTxError(() =>
contract.write.claimAnniversaryPoints({
account,
chain: contract.chain,
}),
))

if (receipt?.status) {
toastSuccess(t('Success!'), <ToastDescriptionWithTx txHash={receipt.transactionHash} />)
Expand Down
16 changes: 8 additions & 8 deletions apps/web/src/components/Menu/UserMenu/WalletModal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { parseEther } from 'viem'
import { useTranslation } from '@pancakeswap/localization'
import {
ButtonMenu,
ButtonMenuItem,
Expand All @@ -7,14 +7,14 @@ import {
IconButton,
InjectedModalProps,
ModalBody,
ModalTitle,
ModalWrapper,
ModalHeader as UIKitModalHeader,
ModalTitle,
} from '@pancakeswap/uikit'
import { useAccount, useBalance } from 'wagmi'
import { useState, useCallback } from 'react'
import { useTranslation } from '@pancakeswap/localization'
import { useCallback, useState } from 'react'
import { styled } from 'styled-components'
import { parseEther } from 'viem'
import { useAccount, useBalance } from 'wagmi'
import WalletInfo from './WalletInfo'
import WalletTransactions from './WalletTransactions'
import WalletWrongNetwork from './WalletWrongNetwork'
Expand Down Expand Up @@ -67,7 +67,7 @@ const WalletModal: React.FC<React.PropsWithChildren<WalletModalProps>> = ({
const { t } = useTranslation()
const { address: account } = useAccount()
const { data, isFetched } = useBalance({ address: account })
const hasLowNativeBalance = isFetched && data && data.value <= LOW_NATIVE_BALANCE
const hasLowNativeBalance = Boolean(isFetched && data && data.value <= LOW_NATIVE_BALANCE)

const handleClick = useCallback((newIndex: number) => {
setView(newIndex)
Expand All @@ -88,8 +88,8 @@ const WalletModal: React.FC<React.PropsWithChildren<WalletModalProps>> = ({
{view === WalletView.WALLET_INFO && (
<WalletInfo hasLowNativeBalance={hasLowNativeBalance} switchView={handleClick} onDismiss={onDismiss} />
)}
{view === WalletView.TRANSACTIONS && <WalletTransactions onDismiss={onDismiss} />}
{view === WalletView.WRONG_NETWORK && <WalletWrongNetwork onDismiss={onDismiss} />}
{view === WalletView.TRANSACTIONS && !!onDismiss && <WalletTransactions onDismiss={onDismiss} />}
{view === WalletView.WRONG_NETWORK && !!onDismiss && <WalletWrongNetwork onDismiss={onDismiss} />}
</ModalBody>
</ModalWrapper>
)
Expand Down
4 changes: 3 additions & 1 deletion apps/web/src/quote-worker.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import 'utils/workerPolyfill'

import { SmartRouter } from '@pancakeswap/smart-router/evm'
import { Call } from 'state/multicall/actions'
import { fetchChunk } from 'state/multicall/fetchChunk'
import { createViemPublicClientGetter } from 'utils/viem'
import { getLogger } from 'utils/datadog'
import { createViemPublicClientGetter } from 'utils/viem'

const { parseCurrency, parseCurrencyAmount, parsePool, serializeTrade } = SmartRouter.Transformer

Expand Down Expand Up @@ -157,6 +158,7 @@ addEventListener('message', (event: MessageEvent<WorkerEvent>) => {
const onChainProvider = createViemPublicClientGetter({ transportSignal: abortController.signal })
const onChainQuoteProvider = SmartRouter.createQuoteProvider({ onChainProvider, gasLimit })
const currencyAAmount = parseCurrencyAmount(chainId, amount)

const currencyB = parseCurrency(chainId, currency)

const pools = candidatePools.map((pool) => parsePool(chainId, pool as any))
Expand Down
10 changes: 5 additions & 5 deletions apps/web/src/state/farms/fetchFarmUser.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import BigNumber from 'bignumber.js'
import { ChainId } from '@pancakeswap/chains'
import BigNumber from 'bignumber.js'
import { masterChefV2ABI } from 'config/abi/masterchefV2'
import { nonBscVaultABI } from 'config/abi/nonBscVault'
import { getMasterChefV2Address, getNonBscVaultAddress } from 'utils/addressHelpers'
import { SerializedFarmConfig } from 'config/constants/types'
import { verifyBscNetwork } from 'utils/verifyBscNetwork'
import { getCrossFarmingReceiverContract } from 'utils/contractHelpers'
import { farmFetcher } from 'state/farms'
import { Address, erc20ABI } from 'wagmi'
import { getMasterChefV2Address, getNonBscVaultAddress } from 'utils/addressHelpers'
import { getCrossFarmingReceiverContract } from 'utils/contractHelpers'
import { verifyBscNetwork } from 'utils/verifyBscNetwork'
import { publicClient } from 'utils/wagmi'
import { ContractFunctionResult } from 'viem'
import { Address, erc20ABI } from 'wagmi'

export const fetchFarmUserAllowances = async (
account: Address,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { SUPPORT_CAKE_STAKING } from 'config/constants/supportChains'
import { useActiveChainId } from 'hooks/useActiveChainId'
import { useGaugesVotingContract } from 'hooks/useContract'

export const useGaugesVotingCount = (): bigint | undefined => {
export const useGaugesVotingCount = () => {
const { chainId } = useActiveChainId()
const gaugesVotingContract = useGaugesVotingContract()

Expand Down
5 changes: 3 additions & 2 deletions apps/web/src/views/GaugesVoting/hooks/useUserVote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export const useUserVote = (gauge?: Gauge, useProxyPool: boolean = true) => {
contracts: callsWithProxy,
allowFailure: false,
})

const [
[_proxySlope, _proxyPower, proxyEnd],
proxyLastVoteTime,
Expand Down Expand Up @@ -163,10 +164,10 @@ export const useUserVote = (gauge?: Gauge, useProxyPool: boolean = true) => {
ignoredSide,
}
}
const response = await publicClient.multicall({
const response = (await publicClient.multicall({
contracts: calls,
allowFailure: false,
})
})) as [[bigint, bigint, bigint], bigint]
const [[nativeSlope, nativePower, nativeEnd], lastVoteTime] = response
const voteLocked = dayjs.unix(Number(lastVoteTime)).add(10, 'day').isAfter(dayjs.unix(currentTimestamp))

Expand Down
29 changes: 10 additions & 19 deletions apps/web/src/views/GaugesVoting/hooks/useUserVoteGauges.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
import { gaugesVotingABI } from '@pancakeswap/gauges'
import { useQuery } from '@tanstack/react-query'
import useAccountActiveChain from 'hooks/useAccountActiveChain'
import { useGaugesVotingContract } from 'hooks/useContract'
import { useMemo } from 'react'
import {
ContractFunctionConfig,
ContractFunctionResult,
Hex,
MulticallContracts,
isAddressEqual,
zeroAddress,
} from 'viem'
import { Hex, isAddressEqual, zeroAddress } from 'viem'
import { useVeCakeUserInfo } from 'views/CakeStaking/hooks/useVeCakeUserInfo'
import { usePublicClient } from 'wagmi'
import { useGauges } from './useGauges'
Expand Down Expand Up @@ -46,14 +38,13 @@ export const useUserVoteSlopes = () => {

const hasProxy = userInfo?.cakePoolProxy && !isAddressEqual(userInfo?.cakePoolProxy, zeroAddress)

const contracts: MulticallContracts<ContractFunctionConfig<typeof gaugesVotingABI, 'voteUserSlopes'>[]> =
gauges.map((gauge) => {
return {
...gaugesVotingContract,
functionName: 'voteUserSlopes',
args: [account, gauge.hash as Hex],
} as const
})
const contracts = gauges.map((gauge) => {
return {
...gaugesVotingContract,
functionName: 'voteUserSlopes',
args: [account, gauge.hash as Hex],
} as const
})

if (hasProxy) {
gauges.forEach((gauge) => {
Expand All @@ -65,10 +56,10 @@ export const useUserVoteSlopes = () => {
})
}

const response = (await publicClient.multicall({
const response = await publicClient.multicall({
contracts,
allowFailure: false,
})) as ContractFunctionResult<typeof gaugesVotingABI, 'voteUserSlopes'>[]
})

const len = gauges.length
return gauges.map((gauge, index) => {
Expand Down
6 changes: 3 additions & 3 deletions apps/web/src/views/Voting/CreateProposal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import {
Flex,
Heading,
Input,
ReactMarkdown,
ScanLink,
Text,
useModal,
useToast,
ReactMarkdown,
ScanLink,
} from '@pancakeswap/uikit'
import snapshot from '@snapshot-labs/snapshot.js'
import isEmpty from 'lodash/isEmpty'
Expand All @@ -34,7 +34,7 @@ import { useAccount, useWalletClient } from 'wagmi'
import Layout from '../components/Layout'
import VoteDetailsModal from '../components/VoteDetailsModal'
import { ADMINS, PANCAKE_SPACE, VOTE_THRESHOLD } from '../config'
import Choices, { ChoiceIdValue, makeChoice, MINIMUM_CHOICES } from './Choices'
import Choices, { ChoiceIdValue, MINIMUM_CHOICES, makeChoice } from './Choices'
import { combineDateAndTime, getFormErrors } from './helpers'
import { FormErrors, Label, SecondaryLabel } from './styles'
import { FormState } from './types'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Currency, CurrencyAmount } from '@pancakeswap/sdk'
import { ChainId } from '@pancakeswap/chains'
import { Currency, CurrencyAmount } from '@pancakeswap/sdk'

import { infoStableSwapABI } from '../../evm/abis/InfoStableSwap'
import { STABLE_SWAP_INFO_ADDRESS } from '../../evm/constants'
import { wrappedCurrencyAmount } from '../../evm/utils/currency'
import { Provider, StableSwapFeeRaw, StableSwapPair } from '../types'
import { getOutputToken } from '../utils/pair'
import { StableSwapPair, Provider, StableSwapFeeRaw } from '../types'
import { STABLE_SWAP_INFO_ADDRESS } from '../../evm/constants'
import { infoStableSwapABI } from '../../evm/abis/InfoStableSwap'

export function getStableSwapFeeCall(pair: StableSwapPair, inputAmount: CurrencyAmount<Currency>) {
const { chainId } = inputAmount.currency
Expand Down
1 change: 1 addition & 0 deletions packages/uikit/src/components/Chart/index.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { LanguageProvider } from "@pancakeswap/localization";
import { Meta, Story } from "@storybook/react";
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import React from "react";
import { Box } from "../Box";
import { PairDataTimeWindowEnum, SwapLineChart, SwapLineChartNewProps } from "./PairPriceChart";
Expand Down
1 change: 1 addition & 0 deletions packages/uikit/src/components/Toast/Toast.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Meta, StoryObj } from "@storybook/react";
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import React from "react";
import { useToast } from "../../contexts";
import { Button } from "../Button";
Expand Down

0 comments on commit b0ec2a4

Please sign in to comment.