import 'react-native-gesture-handler';
import 'expo-splash-screen';
import { QueryClientProvider } from '@tanstack/react-query';
import { NavigationContainer } from '@react-navigation/native';
import { queryClient } from 'src/utils/queryClient';
import * as Sentry from '@sentry/react-native';
import Route from './Route';
import { ConnectionProvider } from 'src/contexts/ConnectionContext';
import ConnectionBanner from 'src/components/ConnectionBanner/ConnectionBanner';
import { RegionProvider } from 'src/contexts/RegionContext';
import { ErrorProvider, useError } from 'src/contexts/ErrorContext';
import { useEffect, useState } from 'react';
import { setupInterceptors } from 'src/utils/request';
import { ErrorModal, WarningModal } from 'src/components';
import React from 'react';
import { Linking, Platform } from 'react-native';
import { API_HOST, API_URL, APP_VERSION } from 'src/constants';
import axios from 'axios';
import { API } from 'src/types';
import { storage, StoreType } from 'src/storage';
import { setupGlobalErrorHandler } from 'src/utils/globalErrorHandler';
const IOS_STORE_URL = 'https://apps.apple.com/app/id6502843543';
const ANDROID_STORE_URL =
'https://play.google.com/store/apps/details?id=com.nomadmania.presentation';
const userId = (storage.get('uid', StoreType.STRING) as string) ?? 'not_logged_in';
const routingInstrumentation = Sentry.reactNavigationIntegration({
enableTimeToInitialDisplay: true
});
Sentry.init({
dsn: 'https://c9b37005f4be22a17a582603ebc17598@o4507781200543744.ingest.de.sentry.io/4507781253824592',
integrations: [Sentry.reactNativeTracingIntegration({ routingInstrumentation })],
debug: false,
enableNative: true,
enableNativeCrashHandling: true,
ignoreErrors: ['Network Error', 'ECONNABORTED', 'timeout of 10000ms exceeded'],
beforeSend(event, hint) {
if (userId) {
event.user = {
...event.user,
userId: userId
};
}
const isNonError = hint?.originalException instanceof Error === false;
if (isNonError || event.message?.match(/Non-Error exception captured/)) {
return {
...event,
message: `Processed Non-Error: ${event.message || 'No message'}`,
level: 'warning',
contexts: {
...event.contexts,
non_error: {
type: typeof hint?.originalException,
value: JSON.stringify(hint?.originalException)
}
}
};
}
return event;
}
});
const linking = {
prefixes: [API_HOST, 'nomadmania://'],
config: {
screens: {
publicProfileView: '/profile/:userId',
inAppEvent: '/event/:url',
inAppMapTab: '/map/:lon/:lat'
}
}
};
const App = () => {
return (
);
};
const InnerApp = () => {
const errorContext = useError();
const navigation = React.useRef(null);
const [isUpdateAvailable, setIsUpdateAvailable] = useState(false);
useEffect(() => {
setupGlobalErrorHandler(navigation);
}, []);
useEffect(() => {
setupInterceptors(errorContext);
}, [errorContext]);
useEffect(() => {
const checkLatestVersion = async () => {
try {
const response = await axios.get(API_URL + '/' + API.LATEST_VERSION, {
headers: {
'App-Version': APP_VERSION,
Platform: Platform.OS
}
});
const { version } = response.data;
const formatVersion = (versionString: string) => {
return parseInt(versionString.replace(/\./g, ''), 10);
};
const currentVersionInt = formatVersion(APP_VERSION);
const latestVersionInt = formatVersion(version);
if (latestVersionInt > currentVersionInt) {
setIsUpdateAvailable(true);
}
} catch (error) {
console.error('Failed to check latest version:', error);
}
};
checkLatestVersion();
}, []);
const handleUpdatePress = () => {
const storeUrl = Platform.OS === 'ios' ? IOS_STORE_URL : ANDROID_STORE_URL;
Linking.openURL(storeUrl).catch((err) => console.error('Failed to open store URL:', err));
};
return (
{
routingInstrumentation.registerNavigationContainer(navigation);
}}
linking={linking}
>
setIsUpdateAvailable(false)}
/>
);
};
export default Sentry.wrap(App);