Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(mobile): Auto-updates modal for all #815

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 27 additions & 6 deletions packages/mobile/src/core/ModalContainer/UpdateApp/UpdateApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@ import { Button, Icon, Spacer, Text, View } from '$uikit';
import { bytesToMegabytes, delay } from '$utils';
import { Steezy } from '$styles';
import { useUpdatesStore } from '$store/zustand/updates/useUpdatesStore';
import { Linking, Platform } from 'react-native';
import { APPLE_STORE_URL, GOOGLE_PLAY_URL } from '$shared/constants';

export const UpdateAppModal = memo(() => {
export interface UpdateAppModalProps {
isApkInstall: boolean;
}

export const UpdateAppModal = memo<UpdateAppModalProps>((props) => {
const nav = useNavigation();
const meta = useUpdatesStore((state) => state.meta);
const { declineUpdate, startUpdate } = useUpdatesStore((state) => state.actions);
Expand All @@ -22,8 +28,18 @@ export const UpdateAppModal = memo(() => {
const handleUpdate = useCallback(async () => {
nav.goBack();
await delay(400);
if (!props.isApkInstall) {
return Linking.openURL(
Platform.select({
ios: APPLE_STORE_URL,
android: GOOGLE_PLAY_URL,
default: '',
}),
);
}

startUpdate();
}, [nav, startUpdate]);
}, [nav, props.isApkInstall, startUpdate]);

return (
<Modal>
Expand All @@ -37,8 +53,12 @@ export const UpdateAppModal = memo(() => {
<Spacer y={4} />
<Text variant="body1" color="textSecondary" textAlign="center">
{t('update.version', { version: meta?.version })}
<Text color="textTertiary"> · </Text>
{t('update.mb', { size: bytesToMegabytes(meta?.size || 0) })}
{props.isApkInstall && (
<>
<Text color="textTertiary"> · </Text>
{t('update.mb', { size: bytesToMegabytes(meta?.size || 0) })}
</>
)}
</Text>
<Spacer y={4} />
<Text variant="body1" color="textSecondary" textAlign="center">
Expand All @@ -53,7 +73,7 @@ export const UpdateAppModal = memo(() => {
</Button>
<Spacer y={16} />
<Button mode="secondary" onPress={handleRemindLater}>
{t('update.remindLater')}
{props.isApkInstall ? t('update.remindLater') : t('update.later')}
</Button>
</View>
<Spacer y={16} />
Expand All @@ -74,10 +94,11 @@ const styles = Steezy.create({
},
});

export const openUpdateAppModal = async () => {
export const openUpdateAppModal = async (isApkInstall: boolean) => {
push('SheetsProvider', {
$$action: SheetActions.ADD,
component: UpdateAppModal,
params: { isApkInstall },
path: 'UpdateApp',
});

Expand Down
14 changes: 5 additions & 9 deletions packages/mobile/src/hooks/useCheckForUpdates.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
import { useEffect } from 'react';
import { useUpdatesStore } from '$store/zustand/updates/useUpdatesStore';
import { openUpdateAppModal } from '$core/ModalContainer/UpdateApp/UpdateApp';
import { Platform } from 'react-native';
import Config from 'react-native-config';
import { useWallet } from '@tonkeeper/shared/hooks';

const SHOULD_CHECK_FOR_UPDATES =
Platform.OS === 'android' && Config.CHECK_FOR_UPDATES === 'true';
import Config from 'react-native-config';

export function useCheckForUpdates() {
const wallet = useWallet();
const { fetchMeta } = useUpdatesStore((s) => s.actions);
const shouldUpdate = useUpdatesStore((s) => s.shouldUpdate);
useEffect(() => {
if (!wallet || !SHOULD_CHECK_FOR_UPDATES) {
if (!wallet) {
return;
}
fetchMeta();
}, [fetchMeta]);
fetchMeta(Config.CHECK_FOR_UPDATES === 'true');
}, [fetchMeta, wallet]);

useEffect(() => {
if (shouldUpdate) {
// open update modal
openUpdateAppModal();
openUpdateAppModal(Config.CHECK_FOR_UPDATES === 'true');
}
}, [shouldUpdate]);
}
3 changes: 3 additions & 0 deletions packages/mobile/src/shared/constants/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
export const GOOGLE_PACKAGE_NAME = 'com.ton_keeper';
export const APPLE_STORE_ID = '1587742107';

export const APPLE_STORE_URL = `https://apps.apple.com/us/app/tonkeeper-ton-wallet/id${APPLE_STORE_ID}`;
export const GOOGLE_PLAY_URL = `https://play.google.com/store/apps/details?id=${GOOGLE_PACKAGE_NAME}`;

export enum CryptoCurrencies {
Ton = 'ton',
TonLocked = 'ton_locked',
Expand Down
2 changes: 1 addition & 1 deletion packages/mobile/src/store/zustand/updates/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export interface IUpdatesStore {
progress: number;
};
actions: {
fetchMeta: () => Promise<void>;
fetchMeta: (shouldUnlinkApk: boolean) => Promise<void>;
declineUpdate: () => void;
startUpdate: () => Promise<void>;
};
Expand Down
6 changes: 4 additions & 2 deletions packages/mobile/src/store/zustand/updates/useUpdatesStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const useUpdatesStore = create(
(set, getState) => ({
...initialState,
actions: {
fetchMeta: async () => {
fetchMeta: async (shouldUnlinkApk) => {
set({ isLoading: true });
const oldMeta = getState().meta;
const res = await fetch(`${config.get('tonkeeperEndpoint')}/check-for-updates`);
Expand All @@ -40,7 +40,9 @@ export const useUpdatesStore = create(
} else {
set({ update: { state: UpdateState.NOT_STARTED, progress: 0 } });
try {
RNFS.unlink(getUpdatePath());
if (shouldUnlinkApk) {
RNFS.unlink(getUpdatePath());
}
} catch (e) {}
}
},
Expand Down
1 change: 1 addition & 0 deletions packages/shared/i18n/locales/tonkeeper/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,7 @@
"downloading": "Downloading… {{progress}}%",
"mb": "{{size}} MB",
"remindLater": "Remind me later",
"later": "Later",
"retry": "Download error. Tap to retry.",
"tap": "Tap to update",
"title": "Update Tonkeeper",
Expand Down
1 change: 1 addition & 0 deletions packages/shared/i18n/locales/tonkeeper/ru-RU.json
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,7 @@
"downloading" : "Скачивание… {{progress}}%",
"mb" : "{{size}} МБ",
"remindLater" : "Напомнить позже",
"later": "Позже",
"retry" : "Ошибка загрузки. Нажмите, чтобы повторить попытку.",
"tap" : "Нажмите, чтобы обновить",
"title" : "Обновление Tonkeeper",
Expand Down