From cebdbeef9019a4e2e9bbeb859581f08d23952f46 Mon Sep 17 00:00:00 2001 From: Doug <4741454+douglance@users.noreply.github.com> Date: Tue, 20 Aug 2024 10:40:51 -0400 Subject: [PATCH 1/3] ci: add monitoring test matrix (#1848) --- .github/workflows/assertion-monitor.yml | 19 ++++++ .github/workflows/batch-poster-monitor.yml | 19 ++++++ .../workflows/core-batch-poster-monitor.yml | 61 ----------------- .github/workflows/core-retryable-monitor.yml | 58 ---------------- .github/workflows/monitor-config.json | 30 ++++++++ .github/workflows/monitoring.yml | 68 +++++++++++++++++++ .../workflows/orbit-batch-poster-monitor.yml | 56 --------------- .github/workflows/orbit-retryable-monitor.yml | 56 --------------- .github/workflows/retryable-monitor.yml | 19 ++++++ 9 files changed, 155 insertions(+), 231 deletions(-) create mode 100644 .github/workflows/assertion-monitor.yml create mode 100644 .github/workflows/batch-poster-monitor.yml delete mode 100644 .github/workflows/core-batch-poster-monitor.yml delete mode 100644 .github/workflows/core-retryable-monitor.yml create mode 100644 .github/workflows/monitor-config.json create mode 100644 .github/workflows/monitoring.yml delete mode 100644 .github/workflows/orbit-batch-poster-monitor.yml delete mode 100644 .github/workflows/orbit-retryable-monitor.yml create mode 100644 .github/workflows/retryable-monitor.yml diff --git a/.github/workflows/assertion-monitor.yml b/.github/workflows/assertion-monitor.yml new file mode 100644 index 0000000000..a29ceae4ae --- /dev/null +++ b/.github/workflows/assertion-monitor.yml @@ -0,0 +1,19 @@ +name: Assertion Monitor + +on: + push: + workflow_dispatch: + schedule: + - cron: "0 */6 * * *" # Run every 6 hours + +jobs: + run-monitoring: + name: Assertion Monitor (${{ matrix.chain }}) + strategy: + matrix: + chain: [core, orbit] + uses: ./.github/workflows/monitoring.yml + with: + chain: ${{ matrix.chain }} + monitor: assertion + secrets: inherit diff --git a/.github/workflows/batch-poster-monitor.yml b/.github/workflows/batch-poster-monitor.yml new file mode 100644 index 0000000000..8d9af811f0 --- /dev/null +++ b/.github/workflows/batch-poster-monitor.yml @@ -0,0 +1,19 @@ +name: Batch Poster Monitor + +on: + push: + workflow_dispatch: + schedule: + - cron: "0 */6 * * *" # Run every 6 hours + +jobs: + run-monitoring: + name: Batch Poster Monitor (${{ matrix.chain }}) + strategy: + matrix: + chain: [core, orbit] + uses: ./.github/workflows/monitoring.yml + with: + chain: ${{ matrix.chain }} + monitor: batch-poster + secrets: inherit diff --git a/.github/workflows/core-batch-poster-monitor.yml b/.github/workflows/core-batch-poster-monitor.yml deleted file mode 100644 index bdd0b6f876..0000000000 --- a/.github/workflows/core-batch-poster-monitor.yml +++ /dev/null @@ -1,61 +0,0 @@ -name: Monitor Core Batch Posting - -on: - workflow_dispatch: - schedule: - # Run every 6 hours - - cron: "0 */6 * * *" - -env: - NEXT_PUBLIC_INFURA_KEY: ${{ secrets.NEXT_PUBLIC_INFURA_KEY }} - BATCH_POSTER_MONITORING_SLACK_TOKEN: ${{ secrets.CORE_CHAIN_BATCH_POSTER_MONITORING_SLACK_TOKEN }} - BATCH_POSTER_MONITORING_SLACK_CHANNEL: ${{ secrets.CORE_CHAIN_BATCH_POSTER_MONITORING_SLACK_CHANNEL }} - NOVA_MONITOR_RPC_URL: ${{ secrets.NOVA_MONITOR_RPC_URL }} - ARB_ONE_MONITOR_RPC_URL: ${{ secrets.ARB_ONE_MONITOR_RPC_URL }} - -jobs: - run-alerting: - runs-on: ubuntu-latest - - steps: - - name: Checkout Bridge - uses: actions/checkout@v4 - with: - repository: OffchainLabs/arbitrum-token-bridge - - - name: Install node_modules - uses: OffchainLabs/actions/node-modules/install@main - - - name: Generate chains JSON - run: yarn workspace arb-token-bridge-ui generateCoreChainsToMonitor - env: - NOVA_MONITOR_RPC_URL: ${{ secrets.NOVA_MONITOR_RPC_URL }} - ARB_ONE_MONITOR_RPC_URL: ${{ secrets.ARB_ONE_MONITOR_RPC_URL }} - BATCH_POSTER_MONITORING: true - - - name: Checkout Arbitrum Monitoring repository - uses: actions/checkout@v4 - with: - repository: OffchainLabs/arbitrum-monitoring - path: arbitrum-monitoring - - - name: Copy chains JSON to Arbitrum Monitoring - run: cp ./packages/arb-token-bridge-ui/public/__auto-generated-core-chains.json ./arbitrum-monitoring/packages/batch-poster-monitor/config.json - - - name: Setup Node for Arbitrum Monitoring - uses: actions/setup-node@v4 - with: - node-version: latest - - - name: Install dependencies for Arbitrum Monitoring - run: cd ./arbitrum-monitoring && yarn install - - - name: Run alerting command - run: cd ./arbitrum-monitoring && yarn batch-poster-monitor --enableAlerting - env: - NODE_ENV: "CI" - RETRYABLE_MONITORING_SLACK_TOKEN: ${{ secrets.CORE_CHAIN_BATCH_POSTER_MONITORING_SLACK_TOKEN }} - RETRYABLE_MONITORING_SLACK_CHANNEL: ${{ secrets.CORE_CHAIN_BATCH_POSTER_MONITORING_SLACK_CHANNEL }} - - - name: Clean up - run: rm ./packages/arb-token-bridge-ui/public/__auto-generated-core-chains.json diff --git a/.github/workflows/core-retryable-monitor.yml b/.github/workflows/core-retryable-monitor.yml deleted file mode 100644 index 7ca21eedb0..0000000000 --- a/.github/workflows/core-retryable-monitor.yml +++ /dev/null @@ -1,58 +0,0 @@ -name: Monitor Core Retryables - -on: - workflow_dispatch: - schedule: - # Run once a day at 08:03am GMT (https://github.com/OffchainLabs/arb-monitoring/blob/master/.github/workflows/retryables.yml#L5) - - cron: "3 8 * * *" - -env: - NEXT_PUBLIC_INFURA_KEY: ${{ secrets.NEXT_PUBLIC_INFURA_KEY }} - RETRYABLE_MONITORING_SLACK_TOKEN: ${{ secrets.CORE_CHAIN_RETRYABLE_MONITORING_SLACK_TOKEN }} - RETRYABLE_MONITORING_SLACK_CHANNEL: ${{ secrets.CORE_CHAIN_RETRYABLE_MONITORING_SLACK_CHANNEL }} - NOVA_MONITOR_RPC_URL: ${{ secrets.NOVA_MONITOR_RPC_URL }} - -jobs: - run-alerting: - runs-on: ubuntu-latest - - steps: - - name: Checkout Bridge - uses: actions/checkout@v4 - with: - repository: OffchainLabs/arbitrum-token-bridge - - - name: Install node_modules - uses: OffchainLabs/actions/node-modules/install@main - - - name: Generate chains JSON - run: yarn workspace arb-token-bridge-ui generateCoreChainsToMonitor - env: - NOVA_MONITOR_RPC_URL: ${{ secrets.NOVA_MONITOR_RPC_URL }} - - - name: Checkout Arbitrum Monitoring repository - uses: actions/checkout@v4 - with: - repository: OffchainLabs/arbitrum-monitoring - path: arbitrum-monitoring - - - name: Copy chains JSON to Arbitrum Monitoring - run: cp ./packages/arb-token-bridge-ui/public/__auto-generated-core-chains.json ./arbitrum-monitoring/packages/retryable-monitor/config.json - - - name: Setup Node for Arbitrum Monitoring - uses: actions/setup-node@v4 - with: - node-version: latest - - - name: Install dependencies for Arbitrum Monitoring - run: cd ./arbitrum-monitoring && yarn install - - - name: Run alerting command - run: cd ./arbitrum-monitoring && yarn retryable-monitor --enableAlerting - env: - NODE_ENV: "CI" - RETRYABLE_MONITORING_SLACK_TOKEN: ${{ secrets.CORE_CHAIN_RETRYABLE_MONITORING_SLACK_TOKEN }} - RETRYABLE_MONITORING_SLACK_CHANNEL: ${{ secrets.CORE_CHAIN_RETRYABLE_MONITORING_SLACK_CHANNEL }} - - - name: Clean up - run: rm ./packages/arb-token-bridge-ui/public/__auto-generated-core-chains.json diff --git a/.github/workflows/monitor-config.json b/.github/workflows/monitor-config.json new file mode 100644 index 0000000000..6f35882143 --- /dev/null +++ b/.github/workflows/monitor-config.json @@ -0,0 +1,30 @@ +{ + "core": { + "generateCommand": "generateCoreChainsToMonitor", + "configFile": "__auto-generated-core-chains.json", + "slackTokens": { + "assertion": "CORE_CHAIN_ASSERTION_MONITORING_SLACK_TOKEN", + "batch-poster": "CORE_CHAIN_BATCH_POSTER_MONITORING_SLACK_TOKEN", + "retryable": "CORE_CHAIN_RETRYABLE_MONITORING_SLACK_TOKEN" + }, + "slackChannels": { + "assertion": "CORE_CHAIN_ASSERTION_MONITORING_SLACK_CHANNEL", + "batch-poster": "CORE_CHAIN_BATCH_POSTER_MONITORING_SLACK_CHANNEL", + "retryable": "CORE_CHAIN_RETRYABLE_MONITORING_SLACK_CHANNEL" + } + }, + "orbit": { + "generateCommand": "generateOrbitChainsToMonitor", + "configFile": "__auto-generated-orbit-chains.json", + "slackTokens": { + "assertion": "ORBIT_CHAIN_ASSERTION_MONITORING_SLACK_TOKEN", + "batch-poster": "ORBIT_CHAIN_BATCH_POSTER_MONITORING_SLACK_TOKEN", + "retryable": "ORBIT_RETRYABLE_MONITORING_SLACK_TOKEN" + }, + "slackChannels": { + "assertion": "ORBIT_CHAIN_ASSERTION_MONITORING_SLACK_CHANNEL", + "batch-poster": "ORBIT_CHAIN_BATCH_POSTER_MONITORING_SLACK_CHANNEL", + "retryable": "ORBIT_RETRYABLE_MONITORING_SLACK_CHANNEL" + } + } +} diff --git a/.github/workflows/monitoring.yml b/.github/workflows/monitoring.yml new file mode 100644 index 0000000000..bf33675ba9 --- /dev/null +++ b/.github/workflows/monitoring.yml @@ -0,0 +1,68 @@ +name: Reusable Monitoring Workflow + +on: + workflow_call: + inputs: + chain: + required: true + type: string + monitor: + required: true + type: string + +env: + NEXT_PUBLIC_INFURA_KEY: ${{ secrets.NEXT_PUBLIC_INFURA_KEY }} + NOVA_MONITOR_RPC_URL: ${{ secrets.NOVA_MONITOR_RPC_URL }} + ARB_ONE_MONITOR_RPC_URL: ${{ secrets.ARB_ONE_MONITOR_RPC_URL }} + NODE_ENV: "CI" + +jobs: + run-monitoring: + runs-on: ubuntu-latest + steps: + - name: Checkout repositories + uses: actions/checkout@v4 + with: + repository: OffchainLabs/arbitrum-token-bridge + + - name: Install node_modules + uses: OffchainLabs/actions/node-modules/install@main + + - name: Checkout Arbitrum Monitoring repository + uses: actions/checkout@v4 + with: + repository: OffchainLabs/arbitrum-monitoring + path: arbitrum-monitoring + + - name: Setup Node and install dependencies + uses: actions/setup-node@v4 + with: + node-version: latest + - run: cd ./arbitrum-monitoring && yarn install + + - name: Load configuration + id: config + run: | + CONFIG=$(cat .github/workflows/monitor-config.json | jq -r '.${{ inputs.chain }}') + echo "generate_command=$(echo $CONFIG | jq -r '.generateCommand')" >> $GITHUB_OUTPUT + echo "config_file=$(echo $CONFIG | jq -r '.configFile')" >> $GITHUB_OUTPUT + echo "slack_token=$(echo $CONFIG | jq -r '.slackTokens.${{ inputs.monitor }}')" >> $GITHUB_OUTPUT + echo "slack_channel=$(echo $CONFIG | jq -r '.slackChannels.${{ inputs.monitor }}')" >> $GITHUB_OUTPUT + + - name: Generate chains JSON + run: yarn workspace arb-token-bridge-ui ${{ steps.config.outputs.generate_command }} + env: + BATCH_POSTER_MONITORING: ${{ inputs.monitor == 'batch-poster' }} + + - name: Copy chains JSON to Arbitrum Monitoring + run: cp ./packages/arb-token-bridge-ui/public/${{ steps.config.outputs.config_file }} ./arbitrum-monitoring/packages/${{ inputs.monitor }}-monitor/config.json + + - name: Run monitoring command + run: cd ./arbitrum-monitoring && yarn ${{ inputs.monitor }}-monitor --enableAlerting + env: + RETRYABLE_MONITORING_SLACK_TOKEN: ${{ secrets[steps.config.outputs.slack_token] }} + RETRYABLE_MONITORING_SLACK_CHANNEL: ${{ secrets[steps.config.outputs.slack_channel] }} + BATCH_POSTER_MONITORING_SLACK_TOKEN: ${{ secrets[steps.config.outputs.slack_token] }} + BATCH_POSTER_MONITORING_SLACK_CHANNEL: ${{ secrets[steps.config.outputs.slack_channel] }} + ASSERTION_MONITORING_SLACK_TOKEN: ${{ secrets[steps.config.outputs.slack_token] }} + ASSERTION_MONITORING_SLACK_CHANNEL: ${{ secrets[steps.config.outputs.slack_channel] }} diff --git a/.github/workflows/orbit-batch-poster-monitor.yml b/.github/workflows/orbit-batch-poster-monitor.yml deleted file mode 100644 index e72bbed120..0000000000 --- a/.github/workflows/orbit-batch-poster-monitor.yml +++ /dev/null @@ -1,56 +0,0 @@ -name: Monitor Orbit Batch Posting - -on: - workflow_dispatch: - schedule: - # Run every 6 hours - - cron: "0 */6 * * *" - -env: - NEXT_PUBLIC_INFURA_KEY: ${{ secrets.NEXT_PUBLIC_INFURA_KEY }} - BATCH_POSTER_MONITORING_SLACK_TOKEN: ${{ secrets.ORBIT_CHAIN_BATCH_POSTER_MONITORING_SLACK_TOKEN }} - BATCH_POSTER_MONITORING_SLACK_CHANNEL: ${{ secrets.ORBIT_CHAIN_BATCH_POSTER_MONITORING_SLACK_CHANNEL }} - -jobs: - run-alerting: - runs-on: ubuntu-latest - - steps: - - name: Checkout Bridge - uses: actions/checkout@v4 - with: - repository: OffchainLabs/arbitrum-token-bridge - - - name: Install node_modules - uses: OffchainLabs/actions/node-modules/install@main - - - name: Generate chains JSON - run: yarn workspace arb-token-bridge-ui generateOrbitChainsToMonitor - - - name: Checkout Arbitrum Monitoring repository - uses: actions/checkout@v4 - with: - repository: OffchainLabs/arbitrum-monitoring - path: arbitrum-monitoring - - - name: Copy chains JSON to Arbitrum Monitoring - run: cp ./packages/arb-token-bridge-ui/public/__auto-generated-orbit-chains.json ./arbitrum-monitoring/packages/batch-poster-monitor/config.json - - - name: Setup Node for Arbitrum Monitoring - uses: actions/setup-node@v4 - with: - node-version: latest - - - name: Install dependencies for Arbitrum Monitoring - run: cd ./arbitrum-monitoring && yarn install - - - name: Run alerting command - run: cd ./arbitrum-monitoring && yarn batch-poster-monitor --enableAlerting - env: - NODE_ENV: "CI" - BATCH_POSTER_MONITORING_SLACK_TOKEN: ${{ secrets.ORBIT_CHAIN_BATCH_POSTER_MONITORING_SLACK_TOKEN }} - BATCH_POSTER_MONITORING_SLACK_CHANNEL: ${{ secrets.ORBIT_CHAIN_BATCH_POSTER_MONITORING_SLACK_CHANNEL }} - - - - name: Clean up - run: rm ./packages/arb-token-bridge-ui/public/__auto-generated-orbit-chains.json diff --git a/.github/workflows/orbit-retryable-monitor.yml b/.github/workflows/orbit-retryable-monitor.yml deleted file mode 100644 index 84753b7f7a..0000000000 --- a/.github/workflows/orbit-retryable-monitor.yml +++ /dev/null @@ -1,56 +0,0 @@ -name: Monitor Orbit Retryables - -on: - workflow_dispatch: - schedule: - # Run once a day at 08:03am GMT (https://github.com/OffchainLabs/arb-monitoring/blob/master/.github/workflows/retryables.yml#L5) - - cron: "3 8 * * *" - -env: - NEXT_PUBLIC_INFURA_KEY: ${{ secrets.NEXT_PUBLIC_INFURA_KEY }} - RETRYABLE_MONITORING_SLACK_TOKEN: ${{ secrets.ORBIT_RETRYABLE_MONITORING_SLACK_TOKEN }} - RETRYABLE_MONITORING_SLACK_CHANNEL: ${{ secrets.ORBIT_RETRYABLE_MONITORING_SLACK_CHANNEL }} - -jobs: - run-alerting: - runs-on: ubuntu-latest - - steps: - - name: Checkout Bridge - uses: actions/checkout@v4 - with: - repository: OffchainLabs/arbitrum-token-bridge - - - name: Install node_modules - uses: OffchainLabs/actions/node-modules/install@main - - - name: Generate chains JSON - run: yarn workspace arb-token-bridge-ui generateOrbitChainsToMonitor - - - name: Checkout Arbitrum Monitoring repository - uses: actions/checkout@v4 - with: - repository: OffchainLabs/arbitrum-monitoring - path: arbitrum-monitoring - - - name: Copy chains JSON to Arbitrum Monitoring - run: cp ./packages/arb-token-bridge-ui/public/__auto-generated-orbit-chains.json ./arbitrum-monitoring/packages/retryable-monitor/config.json - - - name: Setup Node for Arbitrum Monitoring - uses: actions/setup-node@v4 - with: - node-version: latest - - - name: Install dependencies for Arbitrum Monitoring - run: cd ./arbitrum-monitoring && yarn install - - - name: Run alerting command - run: cd ./arbitrum-monitoring && yarn retryable-monitor --enableAlerting - env: - NODE_ENV: "CI" - RETRYABLE_MONITORING_SLACK_TOKEN: ${{ secrets.ORBIT_RETRYABLE_MONITORING_SLACK_TOKEN }} - RETRYABLE_MONITORING_SLACK_CHANNEL: ${{ secrets.ORBIT_RETRYABLE_MONITORING_SLACK_CHANNEL }} - - - - name: Clean up - run: rm ./packages/arb-token-bridge-ui/public/__auto-generated-orbit-chains.json diff --git a/.github/workflows/retryable-monitor.yml b/.github/workflows/retryable-monitor.yml new file mode 100644 index 0000000000..4b251bbbee --- /dev/null +++ b/.github/workflows/retryable-monitor.yml @@ -0,0 +1,19 @@ +name: Retryable Monitor + +on: + push: + workflow_dispatch: + schedule: + - cron: "3 8 * * *" # Run once a day at 08:03am GMT + +jobs: + run-retryable-monitoring: + name: Retryables Monitor (${{ matrix.chain }}) + strategy: + matrix: + chain: [core, orbit] + uses: ./.github/workflows/monitoring.yml + with: + chain: ${{ matrix.chain }} + monitor: retryable + secrets: inherit From 35eae5a6798e57821b920901ccafcce4bf62e7f0 Mon Sep 17 00:00:00 2001 From: Doug <4741454+douglance@users.noreply.github.com> Date: Tue, 20 Aug 2024 13:27:52 -0400 Subject: [PATCH 2/3] ci: fix trigger and naming for monitors (#1854) --- .github/workflows/assertion-monitor.yml | 3 +-- .github/workflows/batch-poster-monitor.yml | 3 +-- .github/workflows/monitoring.yml | 1 + .github/workflows/retryable-monitor.yml | 3 +-- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/.github/workflows/assertion-monitor.yml b/.github/workflows/assertion-monitor.yml index a29ceae4ae..6c0db84adb 100644 --- a/.github/workflows/assertion-monitor.yml +++ b/.github/workflows/assertion-monitor.yml @@ -1,14 +1,13 @@ name: Assertion Monitor on: - push: workflow_dispatch: schedule: - cron: "0 */6 * * *" # Run every 6 hours jobs: run-monitoring: - name: Assertion Monitor (${{ matrix.chain }}) + name: Assertion Monitor (${{ matrix.chain == 'orbit' && 'Orbit' || matrix.chain == 'core' && 'Core' || matrix.chain }}) strategy: matrix: chain: [core, orbit] diff --git a/.github/workflows/batch-poster-monitor.yml b/.github/workflows/batch-poster-monitor.yml index 8d9af811f0..4db8dc451d 100644 --- a/.github/workflows/batch-poster-monitor.yml +++ b/.github/workflows/batch-poster-monitor.yml @@ -1,14 +1,13 @@ name: Batch Poster Monitor on: - push: workflow_dispatch: schedule: - cron: "0 */6 * * *" # Run every 6 hours jobs: run-monitoring: - name: Batch Poster Monitor (${{ matrix.chain }}) + name: Batch Poster Monitor (${{ matrix.chain == 'orbit' && 'Orbit' || matrix.chain == 'core' && 'Core' || matrix.chain }}) strategy: matrix: chain: [core, orbit] diff --git a/.github/workflows/monitoring.yml b/.github/workflows/monitoring.yml index bf33675ba9..74ded940cf 100644 --- a/.github/workflows/monitoring.yml +++ b/.github/workflows/monitoring.yml @@ -18,6 +18,7 @@ env: jobs: run-monitoring: + name: Run runs-on: ubuntu-latest steps: - name: Checkout repositories diff --git a/.github/workflows/retryable-monitor.yml b/.github/workflows/retryable-monitor.yml index 4b251bbbee..b2be5996d6 100644 --- a/.github/workflows/retryable-monitor.yml +++ b/.github/workflows/retryable-monitor.yml @@ -1,14 +1,13 @@ name: Retryable Monitor on: - push: workflow_dispatch: schedule: - cron: "3 8 * * *" # Run once a day at 08:03am GMT jobs: run-retryable-monitoring: - name: Retryables Monitor (${{ matrix.chain }}) + name: Retryable Monitor (${{ matrix.chain == 'orbit' && 'Orbit' || matrix.chain == 'core' && 'Core' || matrix.chain }}) strategy: matrix: chain: [core, orbit] From 459263be1e154fed1c8673bac9f76e8e55c4ba76 Mon Sep 17 00:00:00 2001 From: Fionna Chan <13184582+fionnachan@users.noreply.github.com> Date: Wed, 21 Aug 2024 10:44:39 +0100 Subject: [PATCH 3/3] refactor: clean up gas summary code (#1853) --- .../src/hooks/TransferPanel/useGasSummary.ts | 70 +++++++++---------- 1 file changed, 32 insertions(+), 38 deletions(-) diff --git a/packages/arb-token-bridge-ui/src/hooks/TransferPanel/useGasSummary.ts b/packages/arb-token-bridge-ui/src/hooks/TransferPanel/useGasSummary.ts index 0baf591ff6..e888413c4d 100644 --- a/packages/arb-token-bridge-ui/src/hooks/TransferPanel/useGasSummary.ts +++ b/packages/arb-token-bridge-ui/src/hooks/TransferPanel/useGasSummary.ts @@ -20,12 +20,6 @@ import { useSelectedTokenDecimals } from './useSelectedTokenDecimals' import { percentIncrease } from '@/token-bridge-sdk/utils' import { DEFAULT_GAS_PRICE_PERCENT_INCREASE } from '@/token-bridge-sdk/Erc20DepositStarter' -const INITIAL_GAS_SUMMARY_RESULT: UseGasSummaryResult = { - status: 'loading', - estimatedParentChainGasFees: undefined, - estimatedChildChainGasFees: undefined -} - export type GasEstimationStatus = | 'loading' | 'success' @@ -50,9 +44,6 @@ export function useGasSummary(): UseGasSummaryResult { const [{ amount }] = useArbQueryParams() const debouncedAmount = useDebounce(amount, 300) - const [gasSummary, setGasSummary] = useState( - INITIAL_GAS_SUMMARY_RESULT - ) const decimals = useSelectedTokenDecimals() const amountBigNumber = useMemo(() => { @@ -69,15 +60,6 @@ export function useGasSummary(): UseGasSummaryResult { const parentChainGasPrice = useGasPrice({ provider: parentChainProvider }) const childChainGasPrice = useGasPrice({ provider: childChainProvider }) - const setGasSummaryStatus = useCallback( - (status: GasEstimationStatus) => - setGasSummary(previousGasSummary => ({ - ...previousGasSummary, - status - })), - [] - ) - const balance = useBalanceOnSourceChain(token) const { gasEstimates: estimateGasResult, error: gasEstimatesError } = @@ -137,56 +119,68 @@ export function useGasSummary(): UseGasSummaryResult { ) }, [childChainGasPrice, estimateGasResult, isDepositMode]) - useEffect(() => { + const gasSummary: UseGasSummaryResult = useMemo(() => { if ( !isDepositMode && (isTokenArbitrumOneNativeUSDC(token?.address) || isTokenArbitrumSepoliaNativeUSDC(token?.address)) ) { - setGasSummaryStatus('unavailable') - return + return { + status: 'unavailable', + estimatedParentChainGasFees: undefined, + estimatedChildChainGasFees: undefined + } } if (!balance) { - setGasSummaryStatus('loading') - return + return { + status: 'loading', + estimatedParentChainGasFees: undefined, + estimatedChildChainGasFees: undefined + } } // If user has input an amount over their balance, don't estimate gas if (amountBigNumber.gt(balance)) { - setGasSummaryStatus('insufficientBalance') - return + return { + status: 'insufficientBalance', + estimatedParentChainGasFees: undefined, + estimatedChildChainGasFees: undefined + } } if ( typeof estimatedParentChainGasFees === 'undefined' || typeof estimatedChildChainGasFees === 'undefined' ) { - setGasSummaryStatus('loading') - return + return { + status: 'loading', + estimatedParentChainGasFees: undefined, + estimatedChildChainGasFees: undefined + } } if (gasEstimatesError) { - setGasSummaryStatus('error') - return + return { + status: 'error', + estimatedParentChainGasFees: undefined, + estimatedChildChainGasFees: undefined + } } - setGasSummary({ + return { status: 'success', estimatedParentChainGasFees, estimatedChildChainGasFees - }) + } }, [ - walletAddress, - balance, - token, - childChainProvider, - setGasSummaryStatus, isDepositMode, + token?.address, + balance, + amountBigNumber, estimatedParentChainGasFees, estimatedChildChainGasFees, - gasEstimatesError, - amountBigNumber + gasEstimatesError ]) return gasSummary