Skip to content

Commit

Permalink
Fix format
Browse files Browse the repository at this point in the history
  • Loading branch information
chrstph-dvx committed Sep 20, 2024
2 parents ef088f3 + 4204152 commit 213b593
Show file tree
Hide file tree
Showing 11 changed files with 229 additions and 94 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/formatSpecfiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ switch (testType) {
}
case "cctp": {
// Running CCTP tests in parallel cause nonce issues, we're running the two tests sequentially
test.push({
tests.push({
name: "cctp",
file: "tests/e2e/specs/**/*Cctp.cy.{js,jsx,ts,tsx}",
recordVideo: false,
Expand Down
90 changes: 71 additions & 19 deletions .github/workflows/run-cctp-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,39 @@ jobs:
- uses: ./.github/actions/check-files
id: check-files

anything:
name: "debug test"
should-run-tests:
runs-on: ubuntu-latest
needs: [check-files]
outputs:
should_run: ${{ steps.should-run-tests.outputs.should_run }}
steps:
- name: "step"
- name: Check trigger type and conditions
id: should-run-tests
run: |
echo ${{ github.event.comment.body }}
if [[ "${{ github.event_name }}" == "issue_comment" ]]; then
if [[ "${{ contains(fromJson('["OWNER", "MEMBER"]'), github.event.comment.author_association) }}" == "false" ]]; then
echo "should_run=false" >> $GITHUB_OUTPUT
elif [[ "${{ github.event.comment.body }}" == "/run-cctp-tests" && "${{ github.event.issue.pull_request }}" != "" ]]; then
echo "should_run=true" >> $GITHUB_OUTPUT
else
echo "should_run=false" >> $GITHUB_OUTPUT
fi
elif [[ "${{ github.event_name }}" == "pull_request_review" ]]; then
if [[ "${{ github.event.review.state }}" == "approved" && "${{ needs.check-files.outputs.run_tests }}" == "true" && "${{ contains(github.event.pull_request.title, 'hotfix') }}" == "false" ]]; then
echo "should_run=true" >> $GITHUB_OUTPUT
else
echo "should_run=false" >> $GITHUB_OUTPUT
fi
else
echo "should_run=false" >> $GITHUB_OUTPUT
fi
build:
name: "Build"
runs-on: ubuntu-latest
needs: [check-files]
if: >
(needs.check-files.outputs.run_tests == 'true' && ${{ !contains(github.event.pull_request.title, 'hotfix') }}) ||
(contains(github.event.comment.html_url, '/pull/') && github.event.comment.body == '/run-cctp-tests')
needs: [should-run-tests]
if: needs.should-run-tests.outputs.should_run == 'true'
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -69,22 +87,56 @@ jobs:
cctp-e2e-tests:
name: "CCTP E2E Tests"
needs: [build, check-files]
# Only run CCTP tests when the PR was just approved
uses: ./.github/workflows/e2e-tests.yml
with:
test_type: 'cctp'
secrets: inherit

test-e2e-success:
name: "Test E2E Success"
runs-on: ubuntu-latest
update-pr-status:
name: "Update PR Status"
needs: [cctp-e2e-tests]
runs-on: ubuntu-latest
if: always()
steps:
- name: Regular E2E Succeeded
if: needs.cctp-e2e-tests.result == 'success' || needs.cctp-e2e-tests.result == 'skipped'
run: echo "Regular E2E tests passed"

- name: Regular E2E Failed
if: needs.cctp-e2e-tests.result != 'success' && needs.cctp-e2e-tests.result != 'skipped'
run: exit 1
- name: Create check run
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const { owner, repo } = context.repo;
let pull_number;
if ('${{ github.event_name }}' === 'issue_comment') {
pull_number = context.issue.number;
} else if ('${{ github.event_name }}' === 'pull_request_review') {
pull_number = context.payload.pull_request.number;
} else {
console.log('Unexpected event type');
return;
}
// Fetch the PR data to get the latest SHA
const { data: pr } = await github.rest.pulls.get({
owner,
repo,
pull_number: pull_number,
});
const head_sha = pr.head.sha;
// Construct the URL for this workflow run
const workflowUrl = `https://github.com/${owner}/${repo}/actions/runs/${context.runId}`;
await github.rest.checks.create({
owner,
repo,
name: 'CCTP Tests',
head_sha: head_sha,
status: 'completed',
conclusion: '${{ needs.cctp-e2e-tests.result }}',
output: {
title: 'CCTP Tests Result',
summary: `The CCTP tests have completed with status: ${{ needs.cctp-e2e-tests.result }}.`,
text: `For detailed information, please check the [workflow run](${workflowUrl}).`
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,13 @@ enum DestinationAddressWarnings {
}

type DestinationAddressStore = {
error: DestinationAddressErrors | null
destinationAddress: string | undefined
setError: (error: DestinationAddressErrors | null) => void
setDestinationAddress: (destinationAddress: string | undefined) => void
}

export const useDestinationAddressStore = create<DestinationAddressStore>(
set => ({
error: null,
destinationAddress: undefined,
setError: error => set(() => ({ error })),
setDestinationAddress: destinationAddress =>
set(() => ({ destinationAddress }))
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { ERC20BridgeToken } from '../../hooks/arbTokenBridge.types'
import { warningToast } from '../common/atoms/Toast'
import { useNetworks } from '../../hooks/useNetworks'
import { useNetworksRelationship } from '../../hooks/useNetworksRelationship'
import { isWithdrawOnlyToken } from '../../util/WithdrawOnlyUtils'
import { isTransferDisabledToken } from '../../util/TokenTransferDisabledUtils'
import { useTransferDisabledDialogStore } from './TransferDisabledDialog'
import { TokenInfo } from './TokenInfo'
Expand Down Expand Up @@ -300,12 +299,6 @@ export function TokenImportDialog({
})
}

// do not allow import of withdraw-only tokens at deposit mode
if (isDepositMode && isWithdrawOnlyToken(l1Address, childChain.id)) {
openTransferDisabledDialog()
return
}

if (isTransferDisabledToken(l1Address, childChain.id)) {
openTransferDisabledDialog()
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import { TokenRow } from './TokenRow'
import { useNetworks } from '../../hooks/useNetworks'
import { useNetworksRelationship } from '../../hooks/useNetworksRelationship'
import { useTransferDisabledDialogStore } from './TransferDisabledDialog'
import { isWithdrawOnlyToken } from '../../util/WithdrawOnlyUtils'
import { isTransferDisabledToken } from '../../util/TokenTransferDisabledUtils'
import { useTokenFromSearchParams } from './TransferPanelUtils'
import { Switch } from '../common/atoms/Switch'
Expand Down Expand Up @@ -371,6 +370,8 @@ function TokensPanel({
isArbitrumOne,
isArbitrumSepolia,
isOrbitChain,
isParentChainArbitrumOne,
isParentChainArbitrumSepolia,
getBalance,
nativeCurrency
])
Expand Down Expand Up @@ -535,7 +536,6 @@ export function TokenSearch({
childChainProvider,
parentChain,
parentChainProvider,
isDepositMode,
isTeleportMode
} = useNetworksRelationship(networks)
const { updateUSDCBalances } = useUpdateUSDCBalances({ walletAddress })
Expand Down Expand Up @@ -631,12 +631,6 @@ export function TokenSearch({
})
}

// do not allow import of withdraw-only tokens at deposit mode
if (isDepositMode && isWithdrawOnlyToken(_token.address, childChain.id)) {
openTransferDisabledDialog()
return
}

if (isTransferDisabledToken(_token.address, childChain.id)) {
openTransferDisabledDialog()
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ChainId, getNetworkName } from '../../util/networks'
import { getL2ConfigForTeleport } from '../../token-bridge-sdk/teleport'
import { useNetworksRelationship } from '../../hooks/useNetworksRelationship'
import { withdrawOnlyTokens } from '../../util/WithdrawOnlyUtils'
import { useSelectedTokenIsWithdrawOnly } from './hooks/useSelectedTokenIsWithdrawOnly'

type TransferDisabledDialogStore = {
isOpen: boolean
Expand All @@ -26,14 +27,17 @@ export const useTransferDisabledDialogStore =

export function TransferDisabledDialog() {
const [networks] = useNetworks()
const { isTeleportMode } = useNetworksRelationship(networks)
const { isDepositMode, isTeleportMode } = useNetworksRelationship(networks)
const { app } = useAppState()
const { selectedToken } = app
const {
app: { setSelectedToken }
} = useActions()
const { isSelectedTokenWithdrawOnly, isSelectedTokenWithdrawOnlyLoading } =
useSelectedTokenIsWithdrawOnly()
const {
isOpen: isOpenTransferDisabledDialog,
openDialog: openTransferDisabledDialog,
closeDialog: closeTransferDisabledDialog
} = useTransferDisabledDialogStore()
const unsupportedToken = sanitizeTokenSymbol(selectedToken?.symbol ?? '', {
Expand All @@ -57,6 +61,22 @@ export function TransferDisabledDialog() {
updateL2ChainIdForTeleport()
}, [isTeleportMode, networks.destinationChainProvider])

useEffect(() => {
// do not allow import of withdraw-only tokens at deposit mode
if (
isDepositMode &&
isSelectedTokenWithdrawOnly &&
!isSelectedTokenWithdrawOnlyLoading
) {
openTransferDisabledDialog()
}
}, [
isSelectedTokenWithdrawOnly,
isDepositMode,
openTransferDisabledDialog,
isSelectedTokenWithdrawOnlyLoading
])

const onClose = () => {
setSelectedToken(null)
closeTransferDisabledDialog()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,11 @@ import { useBalances } from '../../hooks/useBalances'
import { captureSentryErrorWithExtraData } from '../../util/SentryUtils'
import { useIsBatchTransferSupported } from '../../hooks/TransferPanel/useIsBatchTransferSupported'
import { normalizeTimestamp } from '../../state/app/utils'
import { getDestinationAddressError } from './hooks/useDestinationAddressError'
import { useDestinationAddressError } from './hooks/useDestinationAddressError'
import { useIsCctpTransfer } from './hooks/useIsCctpTransfer'

const signerUndefinedError = 'Signer is undefined'

export function TransferPanel() {
const { tokenFromSearchParams, setTokenQueryParam } =
useTokenFromSearchParams()
Expand Down Expand Up @@ -172,6 +174,8 @@ export function TransferPanel() {

const { transferReady } = useTransferReadiness()

const { destinationAddressError } = useDestinationAddressError()

const { color: destinationChainUIcolor } = getBridgeUiConfigForChain(
networks.destinationChain.id
)
Expand Down Expand Up @@ -389,11 +393,6 @@ export function TransferPanel() {
if (!withdrawalConfirmation) return
}

const destinationAddressError = await getDestinationAddressError({
destinationAddress,
isSenderSmartContractWallet: isSmartContractWallet,
isTeleportMode
})
if (destinationAddressError) {
console.error(destinationAddressError)
return
Expand Down Expand Up @@ -535,9 +534,20 @@ export function TransferPanel() {
}
}

const transfer = async () => {
const signerUndefinedError = 'Signer is undefined'
const isTransferAllowed = useMemo(() => {
if (!isConnected) {
return false
}
if (!walletAddress) {
return false
}
if (!!destinationAddressError) {
return false
}
return true
}, [destinationAddressError, isConnected, walletAddress])

const transfer = async () => {
try {
setTransferring(true)
if (chainId !== networks.sourceChain.id) {
Expand All @@ -547,10 +557,7 @@ export function TransferPanel() {
setTransferring(false)
}

if (!isConnected) {
return
}
if (!walletAddress) {
if (!isTransferAllowed) {
return
}

Expand All @@ -559,16 +566,6 @@ export function TransferPanel() {
throw signerUndefinedError
}

const destinationAddressError = await getDestinationAddressError({
destinationAddress,
isSenderSmartContractWallet: isSmartContractWallet,
isTeleportMode
})
if (destinationAddressError) {
console.error(destinationAddressError)
return
}

// SC ETH transfers aren't enabled yet. Safety check, shouldn't be able to get here.
if (isSmartContractWallet && !selectedToken) {
console.error("ETH transfers aren't enabled for smart contract wallets.")
Expand Down Expand Up @@ -716,12 +713,6 @@ export function TransferPanel() {
return
}

// if destination address is added, validate it
const destinationAddressError = await getDestinationAddressError({
destinationAddress,
isSenderSmartContractWallet: isSmartContractWallet,
isTeleportMode
})
if (destinationAddressError) {
console.error(destinationAddressError)
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,17 +185,16 @@ function ErrorMessage({
case TransferReadinessRichErrorMessage.TOKEN_WITHDRAW_ONLY:
case TransferReadinessRichErrorMessage.TOKEN_TRANSFER_DISABLED:
return (
<>
<span className="text-sm text-brick">
This token can&apos;t be bridged over.
</span>{' '}
<div className="text-sm text-brick">
<span>This token can&apos;t be bridged over.</span>{' '}
<button
className="arb-hover underline"
onClick={openTransferDisabledDialog}
>
Learn more.
Learn more
</button>
</>
<span>.</span>
</div>
)
}
}
Expand Down
Loading

0 comments on commit 213b593

Please sign in to comment.