Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
While refactoring Deposit Details page for Bitcoin on Base we encountered a problem with data fetch in our new Page Layout. The Page Layout uses the data in two sections which indicated that we might need to move the data fetch to redux-toolkit and store it in the redux store. That's what I did here. The problematic parts before this commit were: 1) `useFetchDepositDetails` hook was used two times - one for main page and one for right section. This is not good because it is a costly operation, 2) No one source of truth - we had two subscriptions that listened for optimistic minting events and we store them both in redux store AND in local state which lead to confusion, 3) Actual implementation of `useFetchDepositDetails` had bugs - if the optimistic minting event was fired during the data fetch, we could potentially override the new data with old data that was fetched during the fetch. To solve this problem I moved everything related to DepositDetails completely to redux store, under tbtcSlice -> depositDetails. The main changes are: 1. Remove unnecessary optimistic minting event subscriptions Up to this point we had two subscriptions for optimistic minting events. The ones placed in `useSubscribeToOptimisticMintingRequestedEvents` and `useSubscribeToOptimisticMintingFinalizedEvents` were subscribing to the event for currently connected account. The other two, placed in `useSubscribeToOptimisticMintingEvents`, were subscribing to the event based on deposit key. Turned out that the `useSubscribeToOptimisticMintingRequestedEvents` is not needed at all and `useSubscribeToOptimisticMintingFinalizedEvents` is only needed to update the bridge activity (which is not currently visible in bitcoin on base). I've decided to move subscriptions from `useSubscribeToOptimisticMintingEvents` to those two file I mentioned so that now they are subscribe to the events based on deposit key. I've also separated subscription to the optimistic minting finalized event (previously `useSubscribeToOptimisticMintingFinalizedEvents`) to a separate hook called `useSubscribeToOptimisticMintingFinalizedEventForCurrentAccount` 2. Move deposit details data to the store This was needed because we needed that data in two places in our layout. I've moved the fetching logic to a separate redux-toolkit effect that is called in deposit details page each time the depositKey parameter is changed. To prevent fetching the data for the wrong deposit, we also keep depositKey in the store, so that the store is not updated if the depositKey in the store was changed. We use useEffect's cleanup function to clearTheDepositData (including depositKey) from the store. 3. Remove unnecessary variables from tbtcSlice We are removing `txConfirmations`, `optimisticMintingRequestedTxHash` and `optimisticMintingFinalizedTxHash` from the tbtcSlice. Well, technically, we are not removing them but moving it to `depositDetails` object in tbtcSlice. 4. Fire confirmation listener after deposit details data is fetched in redux-toolkit Previously we've fired it in useEffect in DepositDetails manually. Now, we are moving it to redux-toolkit and fire after the depositDetails data is fetched. Of course only if it's needed - if the confirmations surpass the required confirmations value then listener is not needed.
- Loading branch information