Skip to content

Commit

Permalink
fix: unnecessary re-renders
Browse files Browse the repository at this point in the history
  • Loading branch information
Aditi-Singh16 committed Jul 18, 2023
1 parent 8a4089e commit 4158231
Showing 1 changed file with 22 additions and 23 deletions.
45 changes: 22 additions & 23 deletions app/screens/send-bitcoin-screen/send-bitcoin-success-screen.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect } from "react"
import React, { useCallback, useEffect } from "react"

import { GaloyIcon } from "@app/components/atomic/galoy-icon"
import { Screen } from "@app/components/screen"
Expand Down Expand Up @@ -30,7 +30,8 @@ const SendBitcoinSuccessScreen = () => {

const client = useApolloClient()
const feedbackShownData = useFeedbackModalShownQuery()
const modalShown = feedbackShownData?.data?.feedbackModalShown
const feedbackModalShown = feedbackShownData?.data?.feedbackModalShown
const { LL } = useI18nContext()

const dismiss = () => {
logAppFeedback({
Expand All @@ -53,26 +54,7 @@ const SendBitcoinSuccessScreen = () => {
})
}

const { LL } = useI18nContext()
const FEEDBACK_DELAY = 3000
const CALLBACK_DELAY = 3000
useEffect(() => {
if (!modalShown) {
const feedbackTimeout = setTimeout(() => {
showAlert()
}, FEEDBACK_DELAY)
return () => {
clearTimeout(feedbackTimeout)
}
}
if (!showSuggestionModal) {
const navigateToHomeTimeout = setTimeout(navigation.popToTop, CALLBACK_DELAY)
return () => clearTimeout(navigateToHomeTimeout)
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [client, modalShown, LL, showSuggestionModal, navigation])

const showAlert = () => {
const requestFeedback = useCallback(() => {
Alert.alert(
"",
LL.support.enjoyingApp(),
Expand All @@ -92,7 +74,24 @@ const SendBitcoinSuccessScreen = () => {
},
)
setFeedbackModalShown(client, true)
}
}, [LL, client])

const FEEDBACK_DELAY = 3000
const CALLBACK_DELAY = 3000
useEffect(() => {
if (!feedbackModalShown) {
const feedbackTimeout = setTimeout(() => {
requestFeedback()
}, FEEDBACK_DELAY)
return () => {
clearTimeout(feedbackTimeout)
}
}
if (!showSuggestionModal) {
const navigateToHomeTimeout = setTimeout(navigation.popToTop, CALLBACK_DELAY)
return () => clearTimeout(navigateToHomeTimeout)
}
}, [client, feedbackModalShown, LL, showSuggestionModal, navigation, requestFeedback])

return (
<Screen preset="scroll" style={styles.contentContainer}>
Expand Down

0 comments on commit 4158231

Please sign in to comment.