From e4fc50fe2788e68d4789fe9259e5902da94d0035 Mon Sep 17 00:00:00 2001 From: Sahil Kashetwar Date: Wed, 12 Oct 2022 14:57:27 +0530 Subject: [PATCH] changes: - updated the gas poll interval to 30000 - moved fetchGasPrice calls to gasSwitcher component - removed unused gasReducer, gasSelector - updated readme --- packages/boba/gateway/.env.example | 1 + packages/boba/gateway/readme.md | 1 + .../mainMenu/gasSwitcher/GasSwitcher.js | 24 ++++++++++++-- .../boba/gateway/src/containers/home/Home.js | 7 +---- .../boba/gateway/src/reducers/gasReducer.js | 31 ------------------- packages/boba/gateway/src/reducers/index.js | 2 -- .../boba/gateway/src/selectors/gasSelector.js | 18 ----------- packages/boba/gateway/src/util/constant.js | 1 + 8 files changed, 25 insertions(+), 60 deletions(-) delete mode 100644 packages/boba/gateway/src/reducers/gasReducer.js delete mode 100644 packages/boba/gateway/src/selectors/gasSelector.js diff --git a/packages/boba/gateway/.env.example b/packages/boba/gateway/.env.example index 4839b98dc6..f81434f3c3 100644 --- a/packages/boba/gateway/.env.example +++ b/packages/boba/gateway/.env.example @@ -1,6 +1,7 @@ REACT_APP_INFURA_ID= REACT_APP_ETHERSCAN_API= REACT_APP_POLL_INTERVAL=15000 +REACT_APP_GAS_POLL_INTERVAL=30000 SKIP_PREFLIGHT_CHECK=true REACT_APP_WALLET_VERSION=1.0.10 REACT_APP_ENV=dev diff --git a/packages/boba/gateway/readme.md b/packages/boba/gateway/readme.md index a50d32f971..0f918bd848 100644 --- a/packages/boba/gateway/readme.md +++ b/packages/boba/gateway/readme.md @@ -18,3 +18,4 @@ gateway.boba.betwork. | REACT_APP_GA4_MEASUREMENT_ID | Yes | N/A | Google analytics api key | | REACT_APP_SENTRY_DSN | Yes | N/A | Sentry DSN url to catch the error on frontend | | REACT_APP_ENABLE_LOCK_PAGE | No | N/A | to enable the lock page on gateway menu | +| REACT_APP_GAS_POLL_INTERVAL | Yes | 30000 | Poll interval to fetch the gas price and verifier status | diff --git a/packages/boba/gateway/src/components/mainMenu/gasSwitcher/GasSwitcher.js b/packages/boba/gateway/src/components/mainMenu/gasSwitcher/GasSwitcher.js index e44b402f90..81fea89790 100644 --- a/packages/boba/gateway/src/components/mainMenu/gasSwitcher/GasSwitcher.js +++ b/packages/boba/gateway/src/components/mainMenu/gasSwitcher/GasSwitcher.js @@ -1,19 +1,38 @@ import React, { useEffect, useState } from 'react' +import { useDispatch, useSelector } from 'react-redux' -import { useSelector } from 'react-redux' import * as S from './GasSwitcher.styles.js' import { selectGas } from 'selectors/balanceSelector' import { selectVerifierStatus } from 'selectors/verifierSelector' +import { selectBaseEnabled } from 'selectors/setupSelector.js' + +import { fetchGas } from 'actions/networkAction.js' +import { fetchVerifierStatus } from 'actions/verifierAction.js' import networkService from 'services/networkService.js' -function GasSwitcher({ isMobile }) { +import useInterval from 'hooks/useInterval.js' + +import { GAS_POLL_INTERVAL } from 'util/constant.js' +function GasSwitcher() { + const dispatch = useDispatch() + + const baseEnabled = useSelector(selectBaseEnabled()) const gas = useSelector(selectGas) + const verifierStatus = useSelector(selectVerifierStatus) + const [ savings, setSavings ] = useState(0) + useInterval(() => { + if (baseEnabled) { + dispatch(fetchGas()) + dispatch(fetchVerifierStatus()) + } + }, GAS_POLL_INTERVAL) + useEffect(() => { async function getGasSavings() { if (networkService.networkGateway === 'mainnet') { @@ -31,7 +50,6 @@ function GasSwitcher({ isMobile }) { getGasSavings() }, [ gas ]) - const verifierStatus = useSelector(selectVerifierStatus) return ( diff --git a/packages/boba/gateway/src/containers/home/Home.js b/packages/boba/gateway/src/containers/home/Home.js index cd1edfdc93..c5ce452525 100644 --- a/packages/boba/gateway/src/containers/home/Home.js +++ b/packages/boba/gateway/src/containers/home/Home.js @@ -43,10 +43,9 @@ import { import { checkVersion } from 'actions/serviceAction' import { closeAlert, closeError } from 'actions/uiAction' import { getFS_Saves, getFS_Info } from 'actions/fixedAction' -import { fetchVerifierStatus } from 'actions/verifierAction' + import { fetchBalances, - fetchGas, addTokenList, fetchExits } from 'actions/networkAction' @@ -189,8 +188,6 @@ function Home() { dispatch(getMonsterInfo()) // account specific } if(baseEnabled /*== we only have have Base L1 and L2 providers*/) { - dispatch(fetchGas()) - dispatch(fetchVerifierStatus()) dispatch(getProposalThreshold()) dispatch(fetchDaoProposals()) } @@ -200,8 +197,6 @@ function Home() { if (maintenance) return // load the following functions when the home page is open checkVersion() - dispatch(fetchGas()) - dispatch(fetchVerifierStatus()) dispatch(getProposalThreshold()) }, [ dispatch, maintenance ]) diff --git a/packages/boba/gateway/src/reducers/gasReducer.js b/packages/boba/gateway/src/reducers/gasReducer.js deleted file mode 100644 index 3ae34b408a..0000000000 --- a/packages/boba/gateway/src/reducers/gasReducer.js +++ /dev/null @@ -1,31 +0,0 @@ -/* -Copyright 2021-present Boba Network. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. */ - -const initialState = { - slow: 0, - normal: 0, - fast: 0 -}; - -function gasReducer (state = initialState, action) { - switch (action.type) { - case 'GAS/GET/SUCCESS': - return { ...state, ...action.payload }; - default: - return state; - } -} - -export default gasReducer; diff --git a/packages/boba/gateway/src/reducers/index.js b/packages/boba/gateway/src/reducers/index.js index 783fa61101..966ebe10cc 100644 --- a/packages/boba/gateway/src/reducers/index.js +++ b/packages/boba/gateway/src/reducers/index.js @@ -26,7 +26,6 @@ import queueReducer from './queueReducer' import tokenReducer from './tokenReducer' import nftReducer from './nftReducer' import feeReducer from './feeReducer' -import gasReducer from './gasReducer' import uiReducer from './uiReducer' import setupReducer from './setupReducer' import notificationReducer from './notificationReducer' @@ -53,7 +52,6 @@ const rootReducer = combineReducers({ tokenList: tokenReducer, nft: nftReducer, fees: feeReducer, - gas: gasReducer, ui: uiReducer, setup: setupReducer, notification: notificationReducer, diff --git a/packages/boba/gateway/src/selectors/gasSelector.js b/packages/boba/gateway/src/selectors/gasSelector.js deleted file mode 100644 index 84f2f7a0d6..0000000000 --- a/packages/boba/gateway/src/selectors/gasSelector.js +++ /dev/null @@ -1,18 +0,0 @@ -/* -Copyright 2021-present Boba Network. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. */ - -export function selectGas (state) { - return state.gas; -} diff --git a/packages/boba/gateway/src/util/constant.js b/packages/boba/gateway/src/util/constant.js index 13a9645748..b199ecd64d 100644 --- a/packages/boba/gateway/src/util/constant.js +++ b/packages/boba/gateway/src/util/constant.js @@ -7,6 +7,7 @@ import moment from 'moment' require('dotenv').config() export const POLL_INTERVAL = process.env.REACT_APP_POLL_INTERVAL || 20000 +export const GAS_POLL_INTERVAL = process.env.REACT_APP_GAS_POLL_INTERVAL || 40000 export const GA4_MEASUREMENT_ID = process.env.REACT_APP_GA4_MEASUREMENT_ID || null export const APP_ENV = process.env.REACT_APP_ENV || 'dev' export const APP_CHAIN = process.env.REACT_APP_CHAIN