1- import React , { memo , useEffect , useCallback , useState } from "react" ;
1+ import React , { memo , useEffect , useCallback , useState , useRef } from "react" ;
22import { View , Text , StyleSheet , Platform } from "react-native" ;
33import { useInterval } from "usehooks-ts" ;
44import {
@@ -27,6 +27,7 @@ import {
2727 runOnJS ,
2828 withSequence ,
2929 withTiming ,
30+ cancelAnimation ,
3031} from "react-native-reanimated" ;
3132
3233export interface TxButtonInnerProps {
@@ -45,8 +46,11 @@ export const TxButtonInner = memo(
4546 const { width } = useCachedWindowDimensions ( ) ;
4647 const { getFee, getSpeed } = useTransactionsStore ( ) ;
4748 const { isPaused } = useTransactionPause ( ) ;
48- const { getWorkingBlock } = useGameStore ( ) ;
49+ const blockIsFull = useGameStore (
50+ ( state ) => state . workingBlocks [ props . chainId ] ?. isBuilt ?? false ,
51+ ) ;
4952 const transactionUnlocked = props . feeLevel !== - 1 ;
53+ const isMountedRef = useRef ( true ) ;
5054
5155 // Get the images and check if they're loaded
5256 const iconImage = getTxIcon (
@@ -87,7 +91,7 @@ export const TxButtonInner = memo(
8791 const fee = getFee ( props . chainId , props . txId , props . isDapp ) ;
8892 const addNewTransaction = useCallback (
8993 async ( finished : boolean | undefined ) => {
90- if ( finished === false ) return ;
94+ if ( finished === false || ! isMountedRef . current ) return ;
9195
9296 // Trigger animation if provided
9397 if ( props . triggerTxAnimation ) {
@@ -109,8 +113,6 @@ export const TxButtonInner = memo(
109113
110114 const speed = getSpeed ( props . chainId , props . txId , props . isDapp ) ;
111115 const paused = isPaused ( props . chainId , props . txId , props . isDapp ) ;
112- const workingBlock = getWorkingBlock ( props . chainId ) ;
113- const blockIsFull = workingBlock ?. isBuilt ?? false ;
114116 const shouldAutomate = speed > 0 && ! paused && ! blockIsFull ;
115117
116118 useEffect ( ( ) => {
@@ -136,7 +138,9 @@ export const TxButtonInner = memo(
136138 }
137139
138140 return ( ) => {
141+ cancelAnimation ( automationAnimHeight ) ;
139142 automationAnimHeight . value = 94 ; // Reset to default height when unmounted
143+ isMountedRef . current = false ;
140144 } ;
141145 } , [ shouldAutomate , speed ] ) ;
142146 useInterval (
0 commit comments