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: show Ether for custom gas token chains #1764

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

brtkx
Copy link
Contributor

@brtkx brtkx commented Jul 18, 2024

ETH transfers to custom gas token chains PR no. 1

This will be hidden behind a feature flag.

This is a prerequisite for https://linear.app/offchain-labs/issue/FS-139/enable-wrapping-eth-and-depositing-into-a-custom-gas-token-network.

It allows us to select ETH for custom gas token chains. For now only ETH detection and being able to select it has been implemented and can be merged on its own.

Testing

Screenshot 2024-07-18 at 13 58 28
  • When a chain with custom gas token is selected, you should be able to see both the native currency on child chain and parent chain (ETH). You should be able to select either and it should update the selected token.
  • Balances should display accordingly.
  • You should not be able to select ETH when withdrawing. It's deposit only.
  • Note that you won't be able to deposit. If you try, it will deposit the native currency. We will hide ETH selection behind a feature flag once reviewed and tested.

Copy link

vercel bot commented Jul 18, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
arbitrum-token-bridge ✅ Ready (Inspect) Visit Preview Jul 23, 2024 3:28pm

@cla-bot cla-bot bot added the cla-signed label Jul 18, 2024
@@ -90,7 +90,7 @@ const ArbTokenBridgeStoreSyncWrapper = (): JSX.Element | null => {
selectedTokenAddress === nativeCurrency.address ||
selectedTokenL2Address === nativeCurrency.address
) {
actions.app.setSelectedToken(null)
actions.app.setSelectedToken({ token: null })
Copy link
Contributor Author

@brtkx brtkx Jul 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setSelectedToken payload has changed to include an optional flag isSelectedTokenEther.

When isSelectedTokenEther === true and token === null, everything will assume that the native currency is Ether.

When isSelectedTokenEther === false and token === null, everything will work as previously, which means it will default to the native currency on the child chain. Note this still could be ETH, isSelectedTokenEther just serves as an override to cover custom gas token scenarios.

When isSelectedTokenEther is not provided it will always set it to false, so that we don't have to refactor the majority of the existing code. All we have to do is to pass a token object instead.

See actions.ts and state.ts for more.

} = useAppState()
const [networks] = useNetworks()
const { childChainProvider } = useNetworksRelationship(networks)

const nativeCurrency = useNativeCurrency({ provider: childChainProvider })

const tokenLogo = useMemo<string | undefined>(() => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not used

function TokenListInfo({
token
}: {
token: ERC20BridgeToken | NativeCurrencyEther | null
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, and in some of the following methods, we pass an additional NativeCurrencyEther. This way we can check for it and return ETH details as needed.

const { isCustom: childChainNativeCurrencyIsCustom } = useNativeCurrency({
provider: childChainProvider
})

const tokenListInfo = useMemo(() => {
if (isNativeCurrencyEther(token)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isNativeCurrencyEther is a type guard method that checks for NativeCurrencyEther type. This way we can early check for ETH stuff and keep the rest of the code as-is.

See useNativeCurrency.ts for more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant