adding mounted flags

This commit is contained in:
Blake Kaufman
2026-01-19 11:50:58 -05:00
parent 6a15e03497
commit d8e8dd718c
9 changed files with 49 additions and 12 deletions
@@ -33,6 +33,7 @@ export default function ConfirmChatGPTPage(props) {
const [invoiceInformation, setInvoiceInformation] = useState(null); const [invoiceInformation, setInvoiceInformation] = useState(null);
useEffect(() => { useEffect(() => {
let mounted = true;
async function geneateInvoiceAndFee() { async function geneateInvoiceAndFee() {
try { try {
let creditPrice = props.price; let creditPrice = props.price;
@@ -45,6 +46,7 @@ export default function ConfirmChatGPTPage(props) {
if (!didGetData) throw new Error('Unable to get lnurl data'); if (!didGetData) throw new Error('Unable to get lnurl data');
input = { type: InputTypes.LNURL_PAY, data: didGetData }; input = { type: InputTypes.LNURL_PAY, data: didGetData };
} catch (err) { } catch (err) {
if (!mounted) return;
setError(t('errormessages.invoiceRetrivalError')); setError(t('errormessages.invoiceRetrivalError'));
return; return;
} }
@@ -72,6 +74,7 @@ export default function ConfirmChatGPTPage(props) {
}), }),
); );
} }
if (!mounted) return;
setInvoiceInformation({ setInvoiceInformation({
fee: fee.fee, fee: fee.fee,
supportFee: fee.supportFee, supportFee: fee.supportFee,
@@ -79,8 +82,8 @@ export default function ConfirmChatGPTPage(props) {
}); });
} catch (err) { } catch (err) {
console.log('Error generating invoice and fee for chatGPT:', err); console.log('Error generating invoice and fee for chatGPT:', err);
if (!mounted) return;
setError(err.message); setError(err.message);
return;
} }
} }
requestAnimationFrame(() => { requestAnimationFrame(() => {
@@ -88,6 +91,9 @@ export default function ConfirmChatGPTPage(props) {
geneateInvoiceAndFee(); geneateInvoiceAndFee();
}); });
}); });
return () => {
mounted = false;
};
}, []); }, []);
const onSwipeSuccess = useCallback(() => { const onSwipeSuccess = useCallback(() => {
@@ -47,6 +47,7 @@ export default function ConfirmGiftCardPurchase(props) {
const darkModeType = props?.darkModeTyoe; const darkModeType = props?.darkModeTyoe;
useEffect(() => { useEffect(() => {
let mounted = true;
async function getGiftCardInfo() { async function getGiftCardInfo() {
try { try {
const postData = { const postData = {
@@ -98,6 +99,7 @@ export default function ConfirmGiftCardPurchase(props) {
const description = decodedInvoice.tags.filter( const description = decodedInvoice.tags.filter(
item => item.tagName === 'description', item => item.tagName === 'description',
); );
if (!mounted) return;
setRetrivedInformation({ setRetrivedInformation({
countryInfo: countryInfo, countryInfo: countryInfo,
productInfo: productInfo:
@@ -112,10 +114,14 @@ export default function ConfirmGiftCardPurchase(props) {
}); });
} catch (err) { } catch (err) {
console.log(err); console.log(err);
if (!mounted) return;
setError(err.message); setError(err.message);
} }
} }
getGiftCardInfo(); getGiftCardInfo();
return () => {
mounted = false;
};
}, []); }, []);
const fee = const fee =
@@ -73,6 +73,7 @@ export default function ViewOnlineListings({ removeUserLocal }) {
setUserLocal(removeUserLocal); setUserLocal(removeUserLocal);
}, [removeUserLocal]); }, [removeUserLocal]);
useEffect(() => { useEffect(() => {
let mounted = true;
const fetchListings = async () => { const fetchListings = async () => {
try { try {
const [shopSavedLocation, res] = await Promise.all([ const [shopSavedLocation, res] = await Promise.all([
@@ -89,6 +90,7 @@ export default function ViewOnlineListings({ removeUserLocal }) {
fetchListings(); fetchListings();
reTryCounter.current += 1; reTryCounter.current += 1;
} }
if (!mounted) return;
setData(json); setData(json);
} catch (e) { } catch (e) {
console.error('Failed to fetch listings', e); console.error('Failed to fetch listings', e);
@@ -97,6 +99,9 @@ export default function ViewOnlineListings({ removeUserLocal }) {
} }
}; };
fetchListings(); fetchListings();
return () => {
mounted = false;
};
}, []); }, []);
// Preprocess businesses once (lowercased fields, sorted) // Preprocess businesses once (lowercased fields, sorted)
@@ -450,6 +455,7 @@ const styles = StyleSheet.create({
width: '100%', width: '100%',
alignSelf: 'center', alignSelf: 'center',
marginBottom: 30, marginBottom: 30,
maxHeight: 100,
}, },
flatList: { flex: 1, width: '95%', alignSelf: 'center' }, flatList: { flex: 1, width: '95%', alignSelf: 'center' },
listContent: { paddingTop: 10, paddingBottom: 20 }, listContent: { paddingTop: 10, paddingBottom: 20 },
@@ -61,6 +61,7 @@ export default function ConfirmSMSPayment(props) {
}, [invoiceInformation]); }, [invoiceInformation]);
useEffect(() => { useEffect(() => {
let mounted = true;
async function fetchInvoice() { async function fetchInvoice() {
try { try {
const payload = { const payload = {
@@ -104,6 +105,7 @@ export default function ConfirmSMSPayment(props) {
t('errormessages.insufficientBalanceError', { planType: 'SMS' }), t('errormessages.insufficientBalanceError', { planType: 'SMS' }),
); );
} }
if (!mounted) return;
setInvoiceInformation({ setInvoiceInformation({
fee: fee.fee, fee: fee.fee,
supportFee: fee.supportFee, supportFee: fee.supportFee,
@@ -113,10 +115,14 @@ export default function ConfirmSMSPayment(props) {
}); });
} catch (err) { } catch (err) {
console.log('Error fetching invoice:', err); console.log('Error fetching invoice:', err);
if (!mounted) return;
setError(err.message); setError(err.message);
} }
} }
fetchInvoice(); fetchInvoice();
return () => {
mounted = false;
};
}, []); }, []);
if (error) { if (error) {
@@ -49,6 +49,7 @@ export default function ConfirmSMSReceiveCode(props) {
}, [invoiceInformation]); }, [invoiceInformation]);
useEffect(() => { useEffect(() => {
let mounted = true;
async function fetchInvoice() { async function fetchInvoice() {
try { try {
const payload = { const payload = {
@@ -92,6 +93,7 @@ export default function ConfirmSMSReceiveCode(props) {
); );
} }
console.log(data); console.log(data);
if (!mounted) return;
setInvoiceInformation({ setInvoiceInformation({
fee: fee.fee, fee: fee.fee,
supportFee: fee.supportFee, supportFee: fee.supportFee,
@@ -105,6 +107,7 @@ export default function ConfirmSMSReceiveCode(props) {
}); });
} catch (err) { } catch (err) {
console.log('Error fetching invoice:', err); console.log('Error fetching invoice:', err);
if (!mounted) return;
setError(err.message); setError(err.message);
} }
} }
@@ -113,6 +116,9 @@ export default function ConfirmSMSReceiveCode(props) {
fetchInvoice(); fetchInvoice();
}); });
}); });
return () => {
mounted = false;
};
}, []); }, []);
if (error) { if (error) {
@@ -103,20 +103,17 @@ export default function AddContactsHalfModal({
await Promise.all( await Promise.all(
results.map(async savedContact => { results.map(async savedContact => {
if (!savedContact) return false; if (!savedContact) return false;
if ( const uniqueName = savedContact?.uniqueName;
savedContact.uniqueName === const contactUUID = savedContact?.uuid;
globalContactsInformation.myProfile.uniqueName const hasProfileImage = savedContact?.hasProfileImage;
) if (uniqueName === globalContactsInformation.myProfile.uniqueName)
return false; return false;
if (!savedContact?.uuid) return false; if (!contactUUID) return false;
let responseData; let responseData;
if ( if (hasProfileImage || typeof hasProfileImage === 'boolean') {
savedContact.hasProfileImage || responseData = await getCachedProfileImage(contactUUID);
typeof savedContact.hasProfileImage === 'boolean'
) {
responseData = await getCachedProfileImage(savedContact.uuid);
console.log(responseData, 'response'); console.log(responseData, 'response');
} }
@@ -68,7 +68,7 @@ export default function ExpandedContactsPage(props) {
useEffect(() => { useEffect(() => {
//listening for messages when you're on the contact //listening for messages when you're on the contact
async function updateSeenTransactions() { function updateSeenTransactions() {
const newMessagesList = []; const newMessagesList = [];
let consecutiveSeenCount = 0; let consecutiveSeenCount = 0;
const REQUIRED_CONSECUTIVE_SEEN = 100; const REQUIRED_CONSECUTIVE_SEEN = 100;
+7
View File
@@ -157,6 +157,8 @@ export default function ExploreUsers() {
}, [timeFrame, t, formattedCurrentTime]); }, [timeFrame, t, formattedCurrentTime]);
useEffect(() => { useEffect(() => {
let mounted = true;
async function loadExploreData() { async function loadExploreData() {
try { try {
const pastExploreData = await getLocalStorageItem( const pastExploreData = await getLocalStorageItem(
@@ -170,6 +172,7 @@ export default function ExploreUsers() {
if (masterInfoObject.exploreData && !shouldLoadExporeDataResp) return; if (masterInfoObject.exploreData && !shouldLoadExporeDataResp) return;
if (!shouldLoadExporeDataResp) { if (!shouldLoadExporeDataResp) {
if (!mounted) return;
toggleMasterInfoObject({ exploreData: pastExploreData.data }); toggleMasterInfoObject({ exploreData: pastExploreData.data });
throw new Error('Blocking call since data is up to date'); throw new Error('Blocking call since data is up to date');
} }
@@ -182,6 +185,7 @@ export default function ExploreUsers() {
); );
if (freshExploreData) { if (freshExploreData) {
if (!mounted) return;
toggleMasterInfoObject({ exploreData: freshExploreData }); toggleMasterInfoObject({ exploreData: freshExploreData });
await setLocalStorageItem( await setLocalStorageItem(
'savedExploreData', 'savedExploreData',
@@ -198,6 +202,9 @@ export default function ExploreUsers() {
} }
} }
loadExploreData(); loadExploreData();
return () => {
mounted = false;
};
}, []); }, []);
if (isLoading) { if (isLoading) {
+3
View File
@@ -1,4 +1,7 @@
{ {
"compilerOptions": {
"jsx": "react"
},
"extends": "@react-native/typescript-config", "extends": "@react-native/typescript-config",
"include": ["**/*.ts", "**/*.tsx"], "include": ["**/*.ts", "**/*.tsx"],
"exclude": ["**/node_modules", "**/Pods"] "exclude": ["**/node_modules", "**/Pods"]