From 7d2e72c83f45ea289920ec79ec32ad7b05dacdbc Mon Sep 17 00:00:00 2001 From: thoreyjona Date: Wed, 25 Sep 2024 13:11:06 +0000 Subject: [PATCH 01/15] feat: add user agent to api requests --- apps/native/app/src/graphql/client.ts | 2 ++ apps/native/app/src/utils/user-agent.ts | 10 ++++++++++ 2 files changed, 12 insertions(+) create mode 100644 apps/native/app/src/utils/user-agent.ts diff --git a/apps/native/app/src/graphql/client.ts b/apps/native/app/src/graphql/client.ts index fbac7b3719a1..7ae288ec2805 100644 --- a/apps/native/app/src/graphql/client.ts +++ b/apps/native/app/src/graphql/client.ts @@ -20,6 +20,7 @@ import { environmentStore } from '../stores/environment-store' import { createMMKVStorage } from '../stores/mmkv' import { offlineStore } from '../stores/offline-store' import { MainBottomTabs } from '../utils/component-registry' +import { getCustomUserAgent } from '../utils/user-agent' const apolloMMKVStorage = createMMKVStorage({ withEncryption: true }) @@ -134,6 +135,7 @@ const authLink = setContext(async (_, { headers }) => ({ 'X-Cognito-Token': `Bearer ${ environmentStore.getState().cognito?.accessToken }`, + 'X-User-Agent': getCustomUserAgent(), cookie: [authStore.getState().cookies] .filter((x) => String(x) !== '') .join('; '), diff --git a/apps/native/app/src/utils/user-agent.ts b/apps/native/app/src/utils/user-agent.ts new file mode 100644 index 000000000000..977da4e1aceb --- /dev/null +++ b/apps/native/app/src/utils/user-agent.ts @@ -0,0 +1,10 @@ +import { Platform } from 'react-native' +import DeviceInfo from 'react-native-device-info' + +export const getCustomUserAgent = () => { + return [ + `IslandIsApp (${DeviceInfo.getVersion()})`, + `Build/${DeviceInfo.getBuildNumber()}`, + `(${Platform.OS}/${Platform.Version})`, + ].join(' ') +} From c64aae6397be32cb468718a7afb91fe70ef332af Mon Sep 17 00:00:00 2001 From: thoreyjona Date: Wed, 25 Sep 2024 14:53:53 +0000 Subject: [PATCH 02/15] feat: add first version of upgrade wall --- apps/native/app/package.json | 1 + apps/native/app/src/messages/en.ts | 6 + apps/native/app/src/messages/is.ts | 6 + apps/native/app/src/screens/home/home.tsx | 11 ++ .../app/src/screens/update-app/update-app.tsx | 103 ++++++++++++++++++ .../app/src/utils/component-registry.ts | 3 +- .../src/utils/lifecycle/setup-components.tsx | 2 + .../app/src/utils/lifecycle/setup-routes.ts | 15 +++ .../native/app/src/utils/minum-app-version.ts | 10 ++ yarn.lock | 8 ++ 10 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 apps/native/app/src/screens/update-app/update-app.tsx create mode 100644 apps/native/app/src/utils/minum-app-version.ts diff --git a/apps/native/app/package.json b/apps/native/app/package.json index fdcf1cede4ab..c7319cdd1cdb 100644 --- a/apps/native/app/package.json +++ b/apps/native/app/package.json @@ -52,6 +52,7 @@ "@react-native/metro-config": "0.74.87", "@react-native/typescript-config": "0.74.87", "apollo3-cache-persist": "0.15.0", + "compare-versions": "6.1.1", "configcat-js": "7.0.0", "dynamic-color": "0.3.0", "expo": "51.0.25", diff --git a/apps/native/app/src/messages/en.ts b/apps/native/app/src/messages/en.ts index 0662636e4777..ff63ee0cf073 100644 --- a/apps/native/app/src/messages/en.ts +++ b/apps/native/app/src/messages/en.ts @@ -596,4 +596,10 @@ export const en: TranslatedMessages = { 'passkeys.skipButton': 'Skip', 'passkeys.errorRegistering': 'Error', 'passkeys.errorRegisteringMessage': 'Could not create a passkey', + + // update app + 'updateApp.title': 'Update app', + 'updateApp.description': + 'You are about to use an old version of the Island.is app. Please update the app to be able to continue.', + 'updateApp.button': 'Update', } diff --git a/apps/native/app/src/messages/is.ts b/apps/native/app/src/messages/is.ts index 19e80cf23b38..06bbfa9389a5 100644 --- a/apps/native/app/src/messages/is.ts +++ b/apps/native/app/src/messages/is.ts @@ -595,4 +595,10 @@ export const is = { 'passkeys.skipButton': 'Sleppa', 'passkeys.errorRegistering': 'Villa', 'passkeys.errorRegisteringMessage': 'Tókst ekki að búa til aðgangslykil', + + // update app + 'updateApp.title': 'Uppfæra app', + 'updateApp.description': + 'Þú ert að fara að nota gamla útgáfu af Ísland.is appinu. Vinsamlegast uppfærðu appið til að halda áfram.', + 'updateApp.button': 'Uppfæra', } diff --git a/apps/native/app/src/screens/home/home.tsx b/apps/native/app/src/screens/home/home.tsx index 07106e266c41..755118902223 100644 --- a/apps/native/app/src/screens/home/home.tsx +++ b/apps/native/app/src/screens/home/home.tsx @@ -28,8 +28,10 @@ import { } from '../../stores/preferences-store' import { useUiStore } from '../../stores/ui-store' import { isAndroid } from '../../utils/devices' +import { needsToUpdateAppVersion } from '../../utils/minum-app-version' import { getRightButtons } from '../../utils/get-main-root' import { testIDs } from '../../utils/test-ids' +import { navigateTo } from '../../lib/deep-linking' import { AirDiscountModule, useGetAirDiscountQuery, @@ -254,12 +256,21 @@ export const MainHomeScreen: NavigationFunctionComponent = ({ const keyExtractor = useCallback((item: ListItem) => item.id, []) const scrollY = useRef(new Animated.Value(0)).current + const checkAppVersion = useCallback(async () => { + const needsUpdate = await needsToUpdateAppVersion() + if (needsUpdate) { + navigateTo('/update-app') + } + }, []) + useEffect(() => { // Sync push tokens and unseen notifications syncToken() checkUnseen() // Get user locale from server getAndSetLocale() + // Check if upgrade wall should be shown + checkAppVersion() }, []) const refetch = useCallback(async () => { diff --git a/apps/native/app/src/screens/update-app/update-app.tsx b/apps/native/app/src/screens/update-app/update-app.tsx new file mode 100644 index 000000000000..3a57ef2df0ca --- /dev/null +++ b/apps/native/app/src/screens/update-app/update-app.tsx @@ -0,0 +1,103 @@ +import { Button, Typography, NavigationBarSheet } from '@ui' +import React from 'react' +import { useIntl, FormattedMessage } from 'react-intl' +import { View, Image, SafeAreaView } from 'react-native' +import styled, { useTheme } from 'styled-components/native' +import { NavigationFunctionComponent } from 'react-native-navigation' +import { createNavigationOptionHooks } from '../../hooks/create-navigation-option-hooks' +import logo from '../../assets/logo/logo-64w.png' +import illustrationSrc from '../../assets/illustrations/digital-services-m1.png' + +const Text = styled.View` + margin-horizontal: ${({ theme }) => theme.spacing[7]}px; + text-align: center; + margin-bottom: ${({ theme }) => theme.spacing[5]}px; + margin-top: ${({ theme }) => theme.spacing[5]}px; +` + +const { getNavigationOptions, useNavigationOptions } = + createNavigationOptionHooks(() => ({ + topBar: { + visible: false, + }, + })) + +export const UpdateAppScreen: NavigationFunctionComponent = ({ + componentId, +}) => { + useNavigationOptions(componentId) + const intl = useIntl() + const theme = useTheme() + + return ( + + console.log('tried to close')} + style={{ marginHorizontal: 16 }} + /> + + + + + + + + + + + + + + +