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

Changes to load the BNB Testnet Anchorage txs #623

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/containers/Bridging/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
1 change: 1 addition & 0 deletions src/containers/history/History.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ const History = () => {
syncTransactions()
}, [])

// TODO: setup tx with refresh option.
// useInterval(syncTransactions, POLL_INTERVAL)

return (
Expand Down
11 changes: 11 additions & 0 deletions src/containers/history/TransactionsResolver.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ import {
TRANSACTION_FILTER_STATUS,
TRANSACTION_STATUS,
} from './types'
import { useNetworkInfo } from 'hooks/useNetworkInfo'

export const TransactionsResolver: React.FC<ITransactionsResolverProps> = ({
transactions,
transactionsFilter,
loading = false,
}) => {
const dispatch = useDispatch<any>()
const { isActiveNetworkBnb, isActiveNetworkBnbTestnet } = useNetworkInfo()
const [currentTransactions, setCurrentTransactions] = useState<
ITransaction[]
>([])
Expand Down Expand Up @@ -179,6 +181,15 @@ export const TransactionsResolver: React.FC<ITransactionsResolverProps> = ({
symbol: 'ETH',
decimals: 18,
}

if (isActiveNetworkBnb || isActiveNetworkBnbTestnet) {
token = {
name: 'BNB',
symbol: 'BNB',
decimals: 18,
}
}

if (
TokenInfo[transaction.originChainId.toString()]?.[
transaction?.action?.token?.toLowerCase()
Expand Down
7 changes: 0 additions & 7 deletions src/hooks/useNetworkInfo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export const useNetworkInfo = () => {
} else {
setIsActiveNetworkSepolia(false)
}

if (network === Network.BNB && networkType === NetworkType.TESTNET) {
setIsActiveNetworkBnbTestnet(true)
} else {
Expand All @@ -41,12 +40,6 @@ export const useNetworkInfo = () => {
} else {
setIsActiveNetworkBnb(false)
}

return () => {
setIsAnchorageEnabled(false)
setIsActiveNetworkBnb(false)
setIsActiveNetworkBnbTestnet(false)
}
}, [network, networkType])

return {
Expand Down
26 changes: 20 additions & 6 deletions src/services/transaction.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -28,7 +30,8 @@ interface ICrossDomainMessage {

class TransactionService {
async fetchAnchorageTransactions(
networkConfig = networkService.networkConfig
networkConfig = networkService.networkConfig,
isActiveNetworkBnb = false
): Promise<any[]> {
const address = await networkService.provider?.getSigner().getAddress()
if (!address) {
Expand All @@ -40,7 +43,8 @@ class TransactionService {
networkService.L1Provider,
networkService.L2Provider,
address,
networkConfig!
networkConfig!,
isActiveNetworkBnb
)

const depositTransactions =
Expand Down Expand Up @@ -127,7 +131,7 @@ class TransactionService {
*
*/
async getTransactions() {
console.log(`loading tx`)
console.log(`loading tx `)
const networksArray = Array.from(Object.values(AllNetworkConfigs))
const networkConfigsArray = networksArray.flatMap((network) => {
return [network.Testnet, network.Mainnet]
Expand All @@ -142,10 +146,20 @@ 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)
networkService.network === Network.BNB &&
networkService.networkType === NetworkType.TESTNET
) {
if (
[97].includes(config.L1.chainId) ||
[9728].includes(config.L2.chainId)
) {
promiseCalls.push(this.fetchAnchorageTransactions(config, true))
}
} else if (
[11155111, 1].includes(config.L1.chainId) ||
[28882, 288].includes(config.L2.chainId)
) {
promiseCalls.push(this.fetchAnchorageTransactions(config))
promiseCalls.push(this.fetchAnchorageTransactions(config, false))
}

// invoke watcher only for BNB mainnet
Expand Down
Loading