App.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import 'react-native-gesture-handler';
  2. import 'expo-splash-screen';
  3. import { QueryClientProvider } from '@tanstack/react-query';
  4. import { NavigationContainer } from '@react-navigation/native';
  5. import { queryClient } from 'src/utils/queryClient';
  6. import * as Sentry from '@sentry/react-native';
  7. import Route from './Route';
  8. import { ConnectionProvider } from 'src/contexts/ConnectionContext';
  9. import ConnectionBanner from 'src/components/ConnectionBanner/ConnectionBanner';
  10. import { RegionProvider } from 'src/contexts/RegionContext';
  11. import { ErrorProvider, useError } from 'src/contexts/ErrorContext';
  12. import { useEffect, useState } from 'react';
  13. import { setupInterceptors } from 'src/utils/request';
  14. import { ErrorModal, WarningModal } from 'src/components';
  15. import { NotificationProvider } from 'src/contexts/NotificationContext';
  16. import React from 'react';
  17. import { Linking, Platform } from 'react-native';
  18. import { API_URL, APP_VERSION } from 'src/constants';
  19. import axios from 'axios';
  20. import { API } from 'src/types';
  21. const IOS_STORE_URL = 'https://apps.apple.com/app/id6502843543';
  22. const ANDROID_STORE_URL =
  23. 'https://play.google.com/store/apps/details?id=com.nomadmania.presentation';
  24. const routingInstrumentation = Sentry.reactNavigationIntegration({
  25. enableTimeToInitialDisplay: true
  26. });
  27. Sentry.init({
  28. dsn: 'https://c9b37005f4be22a17a582603ebc17598@o4507781200543744.ingest.de.sentry.io/4507781253824592',
  29. integrations: [Sentry.reactNativeTracingIntegration({ routingInstrumentation })],
  30. debug: false,
  31. ignoreErrors: ['Network Error', 'ECONNABORTED', 'timeout of 10000ms exceeded']
  32. });
  33. const App = () => {
  34. return (
  35. <QueryClientProvider client={queryClient}>
  36. <NotificationProvider>
  37. <ErrorProvider>
  38. <InnerApp />
  39. </ErrorProvider>
  40. </NotificationProvider>
  41. </QueryClientProvider>
  42. );
  43. };
  44. const InnerApp = () => {
  45. const errorContext = useError();
  46. const navigation = React.useRef(null);
  47. const [isUpdateAvailable, setIsUpdateAvailable] = useState(false);
  48. useEffect(() => {
  49. setupInterceptors(errorContext);
  50. }, [errorContext]);
  51. useEffect(() => {
  52. const checkLatestVersion = async () => {
  53. try {
  54. const response = await axios.get(API_URL + '/' + API.LATEST_VERSION, {
  55. headers: {
  56. 'App-Version': APP_VERSION,
  57. Platform: Platform.OS
  58. }
  59. });
  60. const { version } = response.data;
  61. const formatVersion = (versionString: string) => {
  62. return parseInt(versionString.replace(/\./g, ''), 10);
  63. };
  64. const currentVersionInt = formatVersion(APP_VERSION);
  65. const latestVersionInt = formatVersion(version);
  66. if (latestVersionInt > currentVersionInt) {
  67. setIsUpdateAvailable(true);
  68. }
  69. } catch (error) {
  70. console.error('Failed to check latest version:', error);
  71. }
  72. };
  73. checkLatestVersion();
  74. }, []);
  75. const handleUpdatePress = () => {
  76. const storeUrl = Platform.OS === 'ios' ? IOS_STORE_URL : ANDROID_STORE_URL;
  77. Linking.openURL(storeUrl).catch((err) => console.error('Failed to open store URL:', err));
  78. };
  79. return (
  80. <ConnectionProvider>
  81. <RegionProvider>
  82. <NavigationContainer
  83. ref={navigation}
  84. onReady={() => {
  85. routingInstrumentation.registerNavigationContainer(navigation);
  86. }}
  87. >
  88. <Route />
  89. <ConnectionBanner />
  90. <ErrorModal />
  91. <WarningModal
  92. isVisible={isUpdateAvailable}
  93. type="success"
  94. title="Update Available"
  95. message="A new version of the NomadMania app is available. Please update to the latest version."
  96. action={handleUpdatePress}
  97. onClose={() => setIsUpdateAvailable(false)}
  98. />
  99. </NavigationContainer>
  100. </RegionProvider>
  101. </ConnectionProvider>
  102. );
  103. };
  104. export default Sentry.wrap(App);