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

refactor: make getFastBridges reusable across components #1056

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 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
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ export function DepositConfirmationDialog(
tokenAddress && bridgeInfo && bridgeInfo.tokenSymbolOnArbitrum

const fastBridges = [
...getFastBridges({
from: from.id,
to: to.id,
tokenSymbol,
amount: props.amount
...getFastBridges<'bridge'>({
deepLinkInfo: {
from: from.id,
to: to.id,
tokenSymbol,
amount: props.amount
}
})
].filter(bridge => {
return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { Dialog as HeadlessUIDialog, Tab } from '@headlessui/react'
import { XMarkIcon } from '@heroicons/react/24/outline'
import Hop from '@/images/bridge/hop.png'

import { useAppState } from '../../state'
import { Button } from '../common/Button'
import { TabButton } from '../common/Tab'
import { BridgesTable } from '../common/BridgesTable'
import { Dialog, UseDialogProps } from '../common/Dialog'
import { FastBridgeInfo, FastBridgeNames } from '../../util/fastBridges'
import { FastBridgeNames, getFastBridges } from '../../util/fastBridges'
import { ChainId, getNetworkName } from '../../util/networks'

export function OneNovaTransferDialog(
Expand All @@ -31,19 +30,15 @@ export function OneNovaTransferDialog(
? ChainId.ArbitrumOne
: ChainId.ArbitrumNova

const sourceNetworkSlug =
sourceChainId === ChainId.ArbitrumOne ? 'arbitrum' : 'nova'
const destinationNetworkSlug =
destinationChainId === ChainId.ArbitrumOne ? 'arbitrum' : 'nova'

const bridgeDeepLink = `https://app.hop.exchange/#/send?sourceNetwork=${sourceNetworkSlug}&destNetwork=${destinationNetworkSlug}&token=${
selectedToken?.symbol || 'ETH'
}&amount=${props.amount}`

// only enable Hop for now
const fastBridgeList: FastBridgeInfo[] = [
{ name: FastBridgeNames.Hop, imageSrc: Hop, href: bridgeDeepLink }
]
const fastBridges = getFastBridges<'bridge'>({
deepLinkInfo: {
from: sourceChainId,
to: destinationChainId,
tokenSymbol: selectedToken?.symbol || 'ETH',
amount: props.amount
},
supportedFastBridgeNames: [FastBridgeNames.Hop]
})

return (
<Dialog {...props} isCustom>
Expand Down Expand Up @@ -76,7 +71,7 @@ export function OneNovaTransferDialog(
</p>
</div>

<BridgesTable bridgeList={fastBridgeList} />
<BridgesTable bridgeList={fastBridges} />
<div className="mt-2 flex flex-row justify-end space-x-2">
<Button variant="secondary" onClick={() => props.onClose(false)}>
Cancel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { Button } from '../../common/Button'
import { ExternalLink } from '../../common/ExternalLink'
import {
SpecialTokenSymbol,
USDCFastBridges,
FastBridgeInfo
getFastBridges,
FastBridgeNames
} from '../../../util/fastBridges'
import { TabButton } from '../../common/Tab'
import { BridgesTable } from '../../common/BridgesTable'
Expand Down Expand Up @@ -51,22 +51,34 @@ export function USDCDepositConfirmationDialog(

const tokenSymbol = SpecialTokenSymbol.USDC

const fastBridges: FastBridgeInfo[] = USDCFastBridges.map(USDCFastBridge => ({
name: USDCFastBridge.name,
imageSrc: USDCFastBridge.imageSrc,
href: USDCFastBridge.getHref({
from: from.id,
to: to.id,
fromTokenAddress: isArbitrumGoerli
? CommonAddress.Goerli.USDC
: CommonAddress.Mainnet.USDC,
toTokenAddress: isArbitrumGoerli
? CommonAddress.ArbitrumGoerli.USDC
: CommonAddress.ArbitrumOne.USDC,
amount: props.amount,
transferMode: 'deposit'
const fastBridges = [
...getFastBridges<'bridge'>({
deepLinkInfo: {
from: from.id,
to: to.id,
tokenSymbol: 'USDC',
amount: props.amount
},
supportedFastBridgeNames: [
FastBridgeNames.Celer,
FastBridgeNames.Wormhole
]
}),
...getFastBridges<'swap'>({
deepLinkInfo: {
from: from.id,
to: to.id,
fromTokenAddress: isArbitrumGoerli
? CommonAddress.Goerli.USDC
: CommonAddress.Mainnet.USDC,
toTokenAddress: isArbitrumGoerli
? CommonAddress.ArbitrumGoerli.USDC
: CommonAddress.ArbitrumOne.USDC,
amount: props.amount
},
supportedFastBridgeNames: [FastBridgeNames.LIFI, FastBridgeNames.Router]
})
}))
]

return (
<Dialog {...props} isCustom>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { Dialog, UseDialogProps } from '../../common/Dialog'
import { Button } from '../../common/Button'
import { ExternalLink } from '../../common/ExternalLink'
import {
SpecialTokenSymbol,
USDCFastBridges,
FastBridgeInfo
getFastBridges,
FastBridgeNames,
SpecialTokenSymbol
} from '../../../util/fastBridges'
import { TabButton } from '../../common/Tab'
import { BridgesTable } from '../../common/BridgesTable'
Expand All @@ -28,22 +28,34 @@ export function USDCWithdrawalConfirmationDialog(
const toNetworkName = getNetworkName(to.id)
const tokenSymbol = SpecialTokenSymbol.USDC

const fastBridges: FastBridgeInfo[] = USDCFastBridges.map(USDCFastBridge => ({
name: USDCFastBridge.name,
imageSrc: USDCFastBridge.imageSrc,
href: USDCFastBridge.getHref({
from: from.id,
to: to.id,
fromTokenAddress: isArbitrumGoerli
? CommonAddress.ArbitrumGoerli.USDC
: CommonAddress.ArbitrumOne.USDC,
toTokenAddress: isArbitrumGoerli
? CommonAddress.Goerli.USDC
: CommonAddress.Mainnet.USDC,
amount: props.amount,
transferMode: 'withdraw'
const fastBridges = [
...getFastBridges<'bridge'>({
deepLinkInfo: {
from: from.id,
to: to.id,
tokenSymbol: 'USDC',
amount: props.amount
},
supportedFastBridgeNames: [
FastBridgeNames.Celer,
FastBridgeNames.Wormhole
]
}),
...getFastBridges<'swap'>({
deepLinkInfo: {
from: from.id,
to: to.id,
fromTokenAddress: isArbitrumGoerli
? CommonAddress.ArbitrumGoerli.USDC
: CommonAddress.ArbitrumOne.USDC,
toTokenAddress: isArbitrumGoerli
? CommonAddress.Goerli.USDC
: CommonAddress.Mainnet.USDC,
amount: props.amount
},
supportedFastBridgeNames: [FastBridgeNames.LIFI, FastBridgeNames.Router]
})
}))
]

return (
<Dialog {...props} isCustom>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,18 @@ export function WithdrawalConfirmationDialog(
const from = isConnectedToArbitrum ? l2.network : l1.network
const to = isConnectedToArbitrum ? l1.network : l2.network

const fastBridges = getFastBridges({
from: from.id,
to: to.id,
tokenSymbol: selectedToken?.symbol,
amount: props.amount
const fastBridges = getFastBridges<'bridge'>({
deepLinkInfo: {
from: from.id,
to: to.id,
tokenSymbol: selectedToken?.symbol,
amount: props.amount
},
disabledFastBridgeNames: [
FastBridgeNames.LIFI,
FastBridgeNames.Router,
FastBridgeNames.Wormhole
]
})

const [checkbox1Checked, setCheckbox1Checked] = useState(false)
Expand Down
Loading
Loading