From 1382e8e1f0bb7768b1878f0a7700c17f3f8200bd Mon Sep 17 00:00:00 2001 From: Sahil Kashetwar Date: Thu, 22 Aug 2024 12:43:44 +0530 Subject: [PATCH 1/3] change: - refactored fetch transaction function for bnb and other networks. - fetching based on currently connected networks such as active network bnb testnet to load data from subgraph. --- src/actions/networkAction.ts | 6 ++++-- src/containers/Bridging/index.tsx | 5 +++-- src/containers/history/History.tsx | 23 ++++++++++++--------- src/hooks/useNetworkInfo/index.ts | 7 ------- src/services/transaction.service.ts | 31 +++++++++++++++++++++-------- 5 files changed, 44 insertions(+), 28 deletions(-) diff --git a/src/actions/networkAction.ts b/src/actions/networkAction.ts index 5dfca4f0..bdb6b292 100644 --- a/src/actions/networkAction.ts +++ b/src/actions/networkAction.ts @@ -25,8 +25,10 @@ export const fetchBalances = () => export const addTokenList = () => createAction('TOKENLIST/GET', () => networkService.addTokenList()) -export const fetchTransactions = () => - createAction('TRANSACTION/GETALL', () => transactionService.getTransactions()) +export const fetchTransactions = (payload) => + createAction('TRANSACTION/GETALL', () => + transactionService.getTransactions(payload) + ) export const exitBOBA = (token: string, value: BigNumberish) => createAction('EXIT/CREATE', () => networkService.exitBOBA(token, value)) diff --git a/src/containers/Bridging/index.tsx b/src/containers/Bridging/index.tsx index 2717e95c..b2f1fe05 100644 --- a/src/containers/Bridging/index.tsx +++ b/src/containers/Bridging/index.tsx @@ -31,14 +31,15 @@ const Bridging = () => { useBridgeCleanUp() useBridgeAlerts() const accountEnabled = useSelector(selectAccountEnabled()) - const { isAnchorageEnabled } = useNetworkInfo() + const { isAnchorageEnabled, isActiveNetworkBnbTestnet } = useNetworkInfo() const reenterWithdrawConfig = useSelector(selectReenterWithdrawalConfig()) useEffect(() => { const triggerReenterCheck = async () => { const config = await checkBridgeWithdrawalReenter( - networkService as MinimalNetworkService + networkService as MinimalNetworkService, + isActiveNetworkBnbTestnet ) if (config) { dispatch(setReenterWithdrawalConfig(config)) diff --git a/src/containers/history/History.tsx b/src/containers/history/History.tsx index f2f94044..d6ba17d6 100644 --- a/src/containers/history/History.tsx +++ b/src/containers/history/History.tsx @@ -80,12 +80,13 @@ import { CHAIN_NAME, TRANSACTION_FILTER_STATUS } from './types' import { Typography } from 'components/global/typography' import DatePicker from './DatePicker' +import { useNetworkInfo } from 'hooks/useNetworkInfo' const History = () => { const [toNetwork, setToNetwork] = useState(ALL_NETWORKS) const [fromNetwork, setFromNetwork] = useState(ALL_NETWORKS) const [switched, setSwitched] = useState(false) - + const { isActiveNetworkBnbTestnet } = useNetworkInfo() const networkType = useSelector(selectNetworkType()) const network = useSelector(selectNetwork()) const isOnLimitedNetwork: boolean = networkLimitedAvailability( @@ -158,17 +159,21 @@ const History = () => { ) } - const syncTransactions = useCallback(() => { - if (accountEnabled) { - dispatch(resetTransaction()) - dispatch(fetchTransactions()) - } - }, [accountEnabled]) + const syncTransactions = useCallback( + (isActiveNetworkBnbTestnet) => { + if (accountEnabled) { + dispatch(resetTransaction()) + dispatch(fetchTransactions(isActiveNetworkBnbTestnet)) + } + }, + [accountEnabled] + ) useEffect(() => { - syncTransactions() - }, []) + syncTransactions(isActiveNetworkBnbTestnet) + }, [isActiveNetworkBnbTestnet]) + // TODO: setup tx with refresh option. // useInterval(syncTransactions, POLL_INTERVAL) return ( diff --git a/src/hooks/useNetworkInfo/index.ts b/src/hooks/useNetworkInfo/index.ts index 950c42dd..c8313d52 100644 --- a/src/hooks/useNetworkInfo/index.ts +++ b/src/hooks/useNetworkInfo/index.ts @@ -29,7 +29,6 @@ export const useNetworkInfo = () => { } else { setIsActiveNetworkSepolia(false) } - if (network === Network.BNB && networkType === NetworkType.TESTNET) { setIsActiveNetworkBnbTestnet(true) } else { @@ -41,12 +40,6 @@ export const useNetworkInfo = () => { } else { setIsActiveNetworkBnb(false) } - - return () => { - setIsAnchorageEnabled(false) - setIsActiveNetworkBnb(false) - setIsActiveNetworkBnbTestnet(false) - } }, [network, networkType]) return { diff --git a/src/services/transaction.service.ts b/src/services/transaction.service.ts index bf89f310..91bfcbb2 100644 --- a/src/services/transaction.service.ts +++ b/src/services/transaction.service.ts @@ -28,7 +28,8 @@ interface ICrossDomainMessage { class TransactionService { async fetchAnchorageTransactions( - networkConfig = networkService.networkConfig + networkConfig = networkService.networkConfig, + isActiveNetworkBnb = false ): Promise { const address = await networkService.provider?.getSigner().getAddress() if (!address) { @@ -40,7 +41,8 @@ class TransactionService { networkService.L1Provider, networkService.L2Provider, address, - networkConfig! + networkConfig!, + isActiveNetworkBnb ) const depositTransactions = @@ -126,8 +128,8 @@ class TransactionService { * loads L1Txs, l2Txs, l0Txs, L1PendingTxs * */ - async getTransactions() { - console.log(`loading tx`) + async getTransactions(isActiveNetworkBnb) { + console.log(`loading ${isActiveNetworkBnb ? 'BNB' : ''} tx `) const networksArray = Array.from(Object.values(AllNetworkConfigs)) const networkConfigsArray = networksArray.flatMap((network) => { return [network.Testnet, network.Mainnet] @@ -141,11 +143,24 @@ class TransactionService { // check for ethereum and invoke anchorage data. // [sepolia, bnb tesnet, eth mainnet] - if ( - [11155111, 97, 1].includes(config.L1.chainId) || - [28882, 9728, 288].includes(config.L2.chainId) + if (isActiveNetworkBnb) { + if ( + [97].includes(config.L1.chainId) || + [9728].includes(config.L2.chainId) + ) { + console.log(`calling anchorage tx for bnb`, isActiveNetworkBnb) + promiseCalls.push( + this.fetchAnchorageTransactions(config, isActiveNetworkBnb) + ) + } + } else if ( + [11155111, 1].includes(config.L1.chainId) || + [28882, 288].includes(config.L2.chainId) ) { - promiseCalls.push(this.fetchAnchorageTransactions(config)) + console.log(`calling anchorage tx for eth`, isActiveNetworkBnb) + promiseCalls.push( + this.fetchAnchorageTransactions(config, isActiveNetworkBnb) + ) } // invoke watcher only for BNB mainnet From d8ba48b5dc90f98033e8f5a0b20ad0d7a16d1d29 Mon Sep 17 00:00:00 2001 From: Sahil Kashetwar Date: Thu, 22 Aug 2024 18:44:36 +0530 Subject: [PATCH 2/3] change reverted is active bnb testnet fix --- src/actions/networkAction.ts | 6 ++---- src/containers/history/History.tsx | 22 +++++++++------------- src/services/transaction.service.ts | 21 ++++++++++----------- 3 files changed, 21 insertions(+), 28 deletions(-) diff --git a/src/actions/networkAction.ts b/src/actions/networkAction.ts index bdb6b292..5dfca4f0 100644 --- a/src/actions/networkAction.ts +++ b/src/actions/networkAction.ts @@ -25,10 +25,8 @@ export const fetchBalances = () => export const addTokenList = () => createAction('TOKENLIST/GET', () => networkService.addTokenList()) -export const fetchTransactions = (payload) => - createAction('TRANSACTION/GETALL', () => - transactionService.getTransactions(payload) - ) +export const fetchTransactions = () => + createAction('TRANSACTION/GETALL', () => transactionService.getTransactions()) export const exitBOBA = (token: string, value: BigNumberish) => createAction('EXIT/CREATE', () => networkService.exitBOBA(token, value)) diff --git a/src/containers/history/History.tsx b/src/containers/history/History.tsx index d6ba17d6..6dcbf63d 100644 --- a/src/containers/history/History.tsx +++ b/src/containers/history/History.tsx @@ -80,13 +80,12 @@ import { CHAIN_NAME, TRANSACTION_FILTER_STATUS } from './types' import { Typography } from 'components/global/typography' import DatePicker from './DatePicker' -import { useNetworkInfo } from 'hooks/useNetworkInfo' const History = () => { const [toNetwork, setToNetwork] = useState(ALL_NETWORKS) const [fromNetwork, setFromNetwork] = useState(ALL_NETWORKS) const [switched, setSwitched] = useState(false) - const { isActiveNetworkBnbTestnet } = useNetworkInfo() + const networkType = useSelector(selectNetworkType()) const network = useSelector(selectNetwork()) const isOnLimitedNetwork: boolean = networkLimitedAvailability( @@ -159,19 +158,16 @@ const History = () => { ) } - const syncTransactions = useCallback( - (isActiveNetworkBnbTestnet) => { - if (accountEnabled) { - dispatch(resetTransaction()) - dispatch(fetchTransactions(isActiveNetworkBnbTestnet)) - } - }, - [accountEnabled] - ) + const syncTransactions = useCallback(() => { + if (accountEnabled) { + dispatch(resetTransaction()) + dispatch(fetchTransactions()) + } + }, [accountEnabled]) useEffect(() => { - syncTransactions(isActiveNetworkBnbTestnet) - }, [isActiveNetworkBnbTestnet]) + syncTransactions() + }, []) // TODO: setup tx with refresh option. // useInterval(syncTransactions, POLL_INTERVAL) diff --git a/src/services/transaction.service.ts b/src/services/transaction.service.ts index 91bfcbb2..5b697c34 100644 --- a/src/services/transaction.service.ts +++ b/src/services/transaction.service.ts @@ -12,6 +12,8 @@ import { AllNetworkConfigs, CHAIN_ID_LIST, getRpcUrlByChainId, + Network, + NetworkType, } from 'util/network/network.util' import { NetworkDetailChainConfig } from '../util/network/config/network-details.types' import networkService from './networkService' @@ -128,8 +130,8 @@ class TransactionService { * loads L1Txs, l2Txs, l0Txs, L1PendingTxs * */ - async getTransactions(isActiveNetworkBnb) { - console.log(`loading ${isActiveNetworkBnb ? 'BNB' : ''} tx `) + async getTransactions() { + console.log(`loading tx `) const networksArray = Array.from(Object.values(AllNetworkConfigs)) const networkConfigsArray = networksArray.flatMap((network) => { return [network.Testnet, network.Mainnet] @@ -143,24 +145,21 @@ class TransactionService { // check for ethereum and invoke anchorage data. // [sepolia, bnb tesnet, eth mainnet] - if (isActiveNetworkBnb) { + if ( + networkService.network === Network.BNB && + networkService.networkType === NetworkType.TESTNET + ) { if ( [97].includes(config.L1.chainId) || [9728].includes(config.L2.chainId) ) { - console.log(`calling anchorage tx for bnb`, isActiveNetworkBnb) - promiseCalls.push( - this.fetchAnchorageTransactions(config, isActiveNetworkBnb) - ) + promiseCalls.push(this.fetchAnchorageTransactions(config, true)) } } else if ( [11155111, 1].includes(config.L1.chainId) || [28882, 288].includes(config.L2.chainId) ) { - console.log(`calling anchorage tx for eth`, isActiveNetworkBnb) - promiseCalls.push( - this.fetchAnchorageTransactions(config, isActiveNetworkBnb) - ) + promiseCalls.push(this.fetchAnchorageTransactions(config, false)) } // invoke watcher only for BNB mainnet From 4d0e0d9defd6ffd1099fb1f845ff04c3d5cb2fa5 Mon Sep 17 00:00:00 2001 From: Sahil Kashetwar Date: Fri, 23 Aug 2024 08:53:40 +0530 Subject: [PATCH 3/3] change update token on details for bnb deposit to L2. --- src/containers/history/TransactionsResolver.tsx | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/containers/history/TransactionsResolver.tsx b/src/containers/history/TransactionsResolver.tsx index be1cb9b5..82d6bb6b 100644 --- a/src/containers/history/TransactionsResolver.tsx +++ b/src/containers/history/TransactionsResolver.tsx @@ -41,6 +41,7 @@ import { TRANSACTION_FILTER_STATUS, TRANSACTION_STATUS, } from './types' +import { useNetworkInfo } from 'hooks/useNetworkInfo' export const TransactionsResolver: React.FC = ({ transactions, @@ -48,6 +49,7 @@ export const TransactionsResolver: React.FC = ({ loading = false, }) => { const dispatch = useDispatch() + const { isActiveNetworkBnb, isActiveNetworkBnbTestnet } = useNetworkInfo() const [currentTransactions, setCurrentTransactions] = useState< ITransaction[] >([]) @@ -179,6 +181,15 @@ export const TransactionsResolver: React.FC = ({ symbol: 'ETH', decimals: 18, } + + if (isActiveNetworkBnb || isActiveNetworkBnbTestnet) { + token = { + name: 'BNB', + symbol: 'BNB', + decimals: 18, + } + } + if ( TokenInfo[transaction.originChainId.toString()]?.[ transaction?.action?.token?.toLowerCase()