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 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
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,15 +1,13 @@
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'
import { ether } from '../../constants'

export function OneNovaTransferDialog(
props: UseDialogProps & {
Expand All @@ -32,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 || ether.symbol
}&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 @@ -77,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 @@ -55,22 +55,34 @@ export function USDCDepositConfirmationDialog(props: Props) {

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
@@ -1,4 +1,4 @@
import { useEffect, useState } from 'react'
import { useState } from 'react'

import { Tab, Dialog as HeadlessUIDialog } from '@headlessui/react'
import { XMarkIcon } from '@heroicons/react/24/outline'
Expand All @@ -7,9 +7,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 @@ -32,26 +32,34 @@ export function USDCWithdrawalConfirmationDialog(
const toNetworkName = getNetworkName(to.id)
const tokenSymbol = SpecialTokenSymbol.USDC

useEffect(() => {
setAllCheckboxesChecked(false)
}, [props.isOpen])

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 @@ -28,6 +28,7 @@ import { useIsConnectedToArbitrum } from '../../hooks/useIsConnectedToArbitrum'
import { CONFIRMATION_PERIOD_ARTICLE_LINK } from '../../constants'
import { useChainLayers } from '../../hooks/useChainLayers'
import { useNativeCurrency } from '../../hooks/useNativeCurrency'
import { FastBridgeNames } from '../../util/fastBridges'

const SECONDS_IN_DAY = 86400
const SECONDS_IN_HOUR = 3600
Expand Down Expand Up @@ -66,11 +67,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 ?? nativeCurrency.symbol,
amount: props.amount
const fastBridges = getFastBridges<'bridge'>({
deepLinkInfo: {
from: from.id,
to: to.id,
tokenSymbol: selectedToken?.symbol ?? 'ETH',
amount: props.amount
},
disabledFastBridgeNames: [
FastBridgeNames.LIFI,
FastBridgeNames.Router,
FastBridgeNames.Wormhole
]
})

const [checkbox1Checked, setCheckbox1Checked] = useState(false)
Expand All @@ -93,7 +101,7 @@ export function WithdrawalConfirmationDialog(
}`
}

const { isArbitrumOne, isOrbitChain } = isNetwork(l2.network.id)
const { isArbitrumOne } = isNetwork(l2.network.id)

function closeWithReset(confirmed: boolean) {
props.onClose(confirmed)
Expand Down
Loading
Loading