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

feat: custom deposit times for Orbit chains #1550

Open
wants to merge 6 commits into
base: master
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { DepositCountdown } from '../common/DepositCountdown'
import { useRemainingTime } from '../../state/cctpState'
import { isDepositReadyToRedeem } from '../../state/app/utils'
import { Address } from '../../util/AddressUtils'
import { getBridgeUiConfigForChain } from '../../util/bridgeUiConfig'

function getTransferDurationText(tx: MergedTransaction) {
const { isTestnet, isOrbitChain } = isNetwork(tx.childChainId)
Expand All @@ -37,7 +38,10 @@ function getTransferDurationText(tx: MergedTransaction) {

if (!tx.isWithdrawal) {
if (isOrbitChain) {
return 'a minute'
const { depositTimeMinutes } = getBridgeUiConfigForChain(tx.childChainId)
return depositTimeMinutes
? `${depositTimeMinutes} minute${depositTimeMinutes > 1 ? 's' : ''}`
: '15 minutes'
}
return isTestnet ? '10 minutes' : '15 minutes'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,38 @@ import dayjs from 'dayjs'

import { DepositStatus, MergedTransaction } from '../../state/app/state'
import { isNetwork } from '../../util/networks'
import { getBridgeUiConfigForChain } from '../../util/bridgeUiConfig'

function getMinutesRemainingText(minutesRemaining: number): string {
function getMinutesRemainingText({
minutesRemaining,
unknownCompletionTime
}: {
minutesRemaining: number
unknownCompletionTime: boolean
}): string {
if (minutesRemaining <= 1) {
return 'Less than a minute'
}

return `${minutesRemaining} minutes`
const prefix = unknownCompletionTime ? 'up to ' : '~'

return `${prefix}${minutesRemaining} minutes`
}

function getEstimatedDepositDurationInMinutes(
parentChainId: number | undefined
childChainId: number | undefined
) {
if (!parentChainId) {
if (!childChainId) {
return 15
}

const { isEthereumMainnetOrTestnet, isTestnet } = isNetwork(parentChainId)
const { isOrbitChain, isTestnet } = isNetwork(childChainId)

// this covers orbit chains
if (!isEthereumMainnetOrTestnet) {
return 1
if (isOrbitChain) {
return getBridgeUiConfigForChain(childChainId).depositTimeMinutes ?? 15
}

// L2 chains
return isTestnet ? 10 : 15
}

Expand All @@ -44,11 +53,21 @@ export function DepositCountdown({
) {
// Subtract the diff from the initial deposit time
const minutesRemaining =
getEstimatedDepositDurationInMinutes(tx.parentChainId) -
getEstimatedDepositDurationInMinutes(tx.childChainId) -
now.diff(whenCreated, 'minutes')

const { isOrbitChain } = isNetwork(tx.childChainId)

// we can't estimate how much time certain Orbit chain will take to finalize a deposit
// if this time is not specified by us, then it is an unknown completion time and we will display it a bit differently in the UI
const unknownCompletionTime =
isOrbitChain &&
typeof getBridgeUiConfigForChain(tx.childChainId).depositTimeMinutes ===
'undefined'

return (
<span className="whitespace-nowrap">
{getMinutesRemainingText(minutesRemaining)}
{getMinutesRemainingText({ minutesRemaining, unknownCompletionTime })}
</span>
)
}
Expand Down
3 changes: 2 additions & 1 deletion packages/arb-token-bridge-ui/src/util/bridgeUiConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ export function getBridgeUiConfigForChain(chainId: number): BridgeUiConfig {
logo: '/images/StylusLogo.svg',
description:
'An experimental playground for Arbitrum Stylus smart contracts.'
}
},
depositTimeMinutes: 1
}
default: {
// added Orbit chains
Expand Down
5 changes: 4 additions & 1 deletion packages/arb-token-bridge-ui/src/util/orbitChainsList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export type BridgeUiConfig = {
description?: string
}
nativeTokenData?: NativeCurrencyBase
depositTimeMinutes?: number
}

type OrbitChainConfig = ChainWithRpcUrl & { bridgeUiConfig: BridgeUiConfig }
Expand Down Expand Up @@ -77,7 +78,8 @@ export const orbitMainnets: {
symbol: 'XAI',
decimals: 18,
logoUrl: '/images/XaiLogo.svg'
}
},
depositTimeMinutes: 1
}
},
1380012617: {
Expand Down Expand Up @@ -332,6 +334,7 @@ export const orbitTestnets: { [key in number]: OrbitChainConfig } = {
logo: '/images/XaiLogo.svg',
description: 'The testnet for Xai’s gaming chain.'
},
depositTimeMinutes: 1,
nativeTokenData: {
name: 'Xai',
symbol: 'sXAI',
Expand Down
Loading