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

fix: Crash in bridge input pasted non-numeric and add v1link translation #11132

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions apps/web/src/pages/bridge/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useTranslation } from '@pancakeswap/localization'
import { Flex, useMatchBreakpoints } from '@pancakeswap/uikit'
import ConnectWalletButton from 'components/ConnectWalletButton'
import { PUBLIC_NODES } from 'config/nodes'
Expand All @@ -11,6 +12,7 @@ const CanonicalBridge = lazy(() =>

const BridgePage = () => {
const { isMobile } = useMatchBreakpoints()
const { t } = useTranslation()

return (
<Page removePadding hideFooterOnDesktop={false} showExternalLink={false} showHelpLink={false} noMinHeight>
Expand All @@ -31,6 +33,7 @@ const BridgePage = () => {
supportedChainIds={CHAIN_IDS}
// @ts-ignore
rpcConfig={PUBLIC_NODES}
v1LinkText={t('V1 Bridge supports bridging to/from Aptos')}
/>
</Suspense>
</Flex>
Expand Down
3 changes: 2 additions & 1 deletion packages/canonical-bridge/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"@solana/wallet-adapter-react": "^0",
"@tronweb3/tronwallet-adapter-react-hooks": "^1",
"@pancakeswap/uikit": "workspace:*",
"@pancakeswap/localization": "workspace:*"
"@pancakeswap/localization": "workspace:*",
"@pancakeswap/hooks": "workspace:*"
},
"dependencies": {
"@bnb-chain/canonical-bridge-widget": "0.5.15",
Expand Down
4 changes: 2 additions & 2 deletions packages/canonical-bridge/src/components/V1BridgeLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { Flex, Link } from '@pancakeswap/uikit'
import { styled } from 'styled-components'
import { ExternalLinkIcon } from './icons/ExternalLinkIcon'

export function V1BridgeLink() {
export function V1BridgeLink({ v1LinkText }: { v1LinkText: string }) {
return (
<Flex marginTop="16px" alignItems="center" justifyContent="center">
<StyledLink href="https://bridge.pancakeswap.finance/" target="_blank" rel="noopener">
V1 Bridge supports bridging to/from Aptos
{v1LinkText}
<ExternalLinkIcon />
</StyledLink>
</Flex>
Expand Down
34 changes: 31 additions & 3 deletions packages/canonical-bridge/src/views/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useTranslation } from '@pancakeswap/localization'
import { Flex, useToast } from '@pancakeswap/uikit'
import { useCallback, useMemo } from 'react'
import { useCallback, useEffect, useMemo } from 'react'

import {
BridgeRoutes,
Expand All @@ -11,6 +11,7 @@ import {
} from '@bnb-chain/canonical-bridge-widget'
import { useTheme } from 'styled-components'
import { useAccount } from 'wagmi'
import { useLastUpdated } from '@pancakeswap/hooks'
import { RefreshingIcon } from '../components/RefreshingIcon'
import { V1BridgeLink } from '../components/V1BridgeLink'
import { chains, env } from '../configs'
Expand All @@ -26,15 +27,42 @@ export interface CanonicalBridgeProps {
connectWalletButton: CanonicalBridgeProviderProps['connectWalletButton']
supportedChainIds: number[]
rpcConfig: Record<number, string[]>
v1LinkText: string
}

export const CanonicalBridge = (props: CanonicalBridgeProps) => {
const { connectWalletButton, supportedChainIds } = props
const { connectWalletButton, supportedChainIds, v1LinkText } = props

const transferConfig = useTransferConfig()
const { currentLanguage } = useTranslation()
const theme = useTheme()
const toast = useToast()
const { setLastUpdated: refresh } = useLastUpdated()

useEffect(() => {
if (typeof document !== 'undefined' && document) {
const inputElement = document.querySelector('.bccb-widget-transfer-input') as HTMLInputElement | null
if (inputElement) {
inputElement.setAttribute('pattern', '^[0-9]*[.,]?[0-9]*$')

const handlePaste = (e: ClipboardEvent) => {
const pastedValue = e?.clipboardData?.getData('Text')

if (!pastedValue || !/^[0-9]*[.,]?[0-9]*$/.test(pastedValue)) {
e.preventDefault()
}
}

inputElement.addEventListener('paste', handlePaste)
refresh()

return () => {
inputElement.removeEventListener('paste', handlePaste)
}
}
}
return undefined
}, [refresh])

const config = useMemo<ICanonicalBridgeConfig>(
() => ({
Expand Down Expand Up @@ -89,7 +117,7 @@ export const CanonicalBridge = (props: CanonicalBridgeProps) => {
>
<Flex flexDirection="column" justifyContent="center" maxWidth="480px" width="100%">
<BridgeTransfer />
<V1BridgeLink />
<V1BridgeLink v1LinkText={v1LinkText} />
</Flex>
<BridgeRoutes />
</CanonicalBridgeProvider>
Expand Down
3 changes: 2 additions & 1 deletion packages/localization/src/config/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -3778,5 +3778,6 @@
"If you've already set this up manually, no action is needed - just proceed with the swap!": "If you've already set this up manually, no action is needed - just proceed with the swap!",
"MEV Protected": "MEV Protected",
"Add automatically on BNB Smart Chain: PancakeSwap MEV Guard": "Add automatically on BNB Smart Chain: PancakeSwap MEV Guard",
"Dual Incentives are Completed! You will continue to earn trading fees and check the Finished farms tab to find your positions.": "Dual Incentives are Completed! You will continue to earn trading fees and check the Finished farms tab to find your positions."
"Dual Incentives are Completed! You will continue to earn trading fees and check the Finished farms tab to find your positions.": "Dual Incentives are Completed! You will continue to earn trading fees and check the Finished farms tab to find your positions.",
"V1 Bridge supports bridging to/from Aptos": "V1 Bridge supports bridging to/from Aptos"
}
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading