Skip to content

Commit

Permalink
fix: Swap warning error when currency undefined (#10790)
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
This PR focuses on updating the `useWarningImport` hook and the
`shouldShowSwapWarning` utility function to handle optional `Currency`
parameters. This enhances the flexibility of the code by allowing the
functions to work with undefined values for currency inputs.

### Detailed summary
- Updated `swapWarningHandler` to accept an optional `Currency`
parameter.
- Modified `shouldShowSwapWarning` to accept an optional `Currency`
parameter instead of a required `Token`.
- Added a check for `swapCurrency` being defined before processing in
`shouldShowSwapWarning`.

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

<!-- end pr-codex -->
  • Loading branch information
memoyil authored Oct 8, 2024
1 parent 14487c3 commit a17bd8d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions apps/web/src/utils/shouldShowSwapWarning.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Token } from '@pancakeswap/sdk'
import { Currency } from '@pancakeswap/sdk'
import { ChainId } from '@pancakeswap/chains'
import SwapWarningTokens from 'config/constants/swapWarningTokens'

const shouldShowSwapWarning = (chainId: ChainId | undefined, swapCurrency: Token): boolean => {
if (chainId && SwapWarningTokens[chainId]) {
const shouldShowSwapWarning = (chainId: ChainId | undefined, swapCurrency?: Currency): boolean => {
if (chainId && SwapWarningTokens[chainId] && swapCurrency) {
const swapWarningTokens = Object.values(SwapWarningTokens[chainId])
return swapWarningTokens.some((warningToken) => warningToken.equals(swapCurrency))
}
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/views/Swap/hooks/useWarningImport.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Token } from '@pancakeswap/sdk'
import { Currency, Token } from '@pancakeswap/sdk'
import { useModal } from '@pancakeswap/uikit'
import { useCallback, useEffect, useMemo, useState } from 'react'

Expand Down Expand Up @@ -63,7 +63,7 @@ export default function useWarningImport() {
}, [swapWarningCurrency])

const swapWarningHandler = useCallback(
(currencyInput) => {
(currencyInput?: Currency) => {
const showSwapWarning = shouldShowSwapWarning(chainId, currencyInput)
if (showSwapWarning) {
setSwapWarningCurrency(currencyInput)
Expand Down

0 comments on commit a17bd8d

Please sign in to comment.