diff --git a/src/App.tsx b/src/App.tsx index f7ca533d..a209b0f1 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -46,7 +46,10 @@ const ErrorComponent = ({ resetError }: FallbackComponentProps) => { }; const App = () => { - const { accountConfig } = useAccountConfig({ refresh: false }); + const { accountConfig } = useAccountConfig({ + refresh: false, + listenAppState: true + }); const navigate = useNavigate(); useDeepLink(); diff --git a/src/hooks/useAccountConfig.ts b/src/hooks/useAccountConfig.ts index 8c5e68fd..1b13fc19 100644 --- a/src/hooks/useAccountConfig.ts +++ b/src/hooks/useAccountConfig.ts @@ -18,10 +18,11 @@ const oldAppRootUrl = "https://checkout.swiss-bitcoin-pay.ch"; type UseAccountConfigParams = { refresh?: boolean; + listenAppState?: boolean; }; export const useAccountConfig = (props?: UseAccountConfigParams) => { - const { refresh = true } = props || {}; + const { refresh = true, listenAppState = false } = props || {}; const navigate = useNavigate(); const { accountConfig, setUserType, setAccountConfig } = useContext(SBPContext); @@ -69,7 +70,7 @@ export const useAccountConfig = (props?: UseAccountConfigParams) => { const appState = useRef(AppState.currentState); useEffect(() => { - if (accountConfig?.apiKey && AppState.isAvailable) { + if (listenAppState && accountConfig?.apiKey && AppState.isAvailable) { const subscription = AppState.addEventListener( "change", (nextAppState) => { @@ -86,7 +87,7 @@ export const useAccountConfig = (props?: UseAccountConfigParams) => { return () => subscription.remove(); } - }, [accountConfig?.apiKey]); + }, [listenAppState, accountConfig?.apiKey]); const onScan = useCallback( async (scannedValue: string) => {