Skip to content

Commit 7edb3cb

Browse files
committed
Implement versionCheck
1 parent 93cbe1d commit 7edb3cb

File tree

5 files changed

+61
-0
lines changed

5 files changed

+61
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased (develop)
44

5+
- added: "Update Available" modal
6+
57
## 4.22.0 (staging)
68

79
- added: `NotificationCenterScene`

src/locales/en_US.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,6 +1684,7 @@ const strings = {
16841684
notifications_recent: 'Recent',
16851685
notifications_none: `You're all caught up!`,
16861686
swap: 'Swap',
1687+
update_available: 'Update Available',
16871688

16881689
// Currency Labels
16891690
currency_label_AFN: 'Afghani',

src/locales/strings/enUS.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,6 +1454,7 @@
14541454
"notifications_recent": "Recent",
14551455
"notifications_none": "You're all caught up!",
14561456
"swap": "Swap",
1457+
"update_available": "Update Available",
14571458
"currency_label_AFN": "Afghani",
14581459
"currency_label_ALL": "Lek",
14591460
"currency_label_DZD": "Algerian Dinar",

src/util/network.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { getVersion } from 'react-native-device-info'
66

77
import { config } from '../theme/appConfig'
88
import { asyncWaterfall, getOsVersion, shuffleArray } from './utils'
9+
import { checkAppVersion } from './versionCheck'
910
const INFO_SERVERS = ['https://info1.edge.app', 'https://info2.edge.app']
1011
const RATES_SERVERS = ['https://rates1.edge.app', 'https://rates2.edge.app']
1112

@@ -87,6 +88,7 @@ export const initInfoServer = async () => {
8788
} else {
8889
const infoData = await response.json()
8990
infoServerData.rollup = asInfoRollup(infoData)
91+
await checkAppVersion()
9092
}
9193
} catch (e) {
9294
console.warn('initInfoServer: Failed to ping info server')

src/util/versionCheck.tsx

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import * as React from 'react'
2+
import { Linking, Platform } from 'react-native'
3+
import { getVersion } from 'react-native-device-info'
4+
5+
import { ButtonsModal } from '../components/modals/ButtonsModal'
6+
import { Airship } from '../components/services/AirshipInstance'
7+
import { getLocaleOrDefaultString } from '../locales/intl'
8+
import { lstrings } from '../locales/strings'
9+
import { config } from '../theme/appConfig'
10+
import { infoServerData } from './network'
11+
12+
const compareVersions = (v1: string, v2: string): number => {
13+
const v1Parts = v1.split('.').map(Number)
14+
const v2Parts = v2.split('.').map(Number)
15+
16+
for (let i = 0; i < 3; i++) {
17+
if (v1Parts[i] > v2Parts[i]) return 1
18+
if (v1Parts[i] < v2Parts[i]) return -1
19+
}
20+
return 0
21+
}
22+
23+
export const checkAppVersion = async (): Promise<void> => {
24+
const currentVersion = getVersion()
25+
const platform = Platform.OS
26+
27+
// Get latest version from info server
28+
const updateInfo = infoServerData.rollup?.updateInfo
29+
if (updateInfo == null) return
30+
const { updateVersion, localeMessage } = updateInfo[platform]
31+
32+
const message = getLocaleOrDefaultString(localeMessage)
33+
34+
// Compare versions
35+
if (compareVersions(updateVersion, currentVersion) > 0) {
36+
// Show update modal
37+
const updateRes = await Airship.show<'update' | undefined>(bridge => (
38+
<ButtonsModal
39+
bridge={bridge}
40+
title={lstrings.update_available}
41+
message={message}
42+
buttons={{
43+
update: {
44+
label: lstrings.update_now,
45+
type: 'primary'
46+
}
47+
}}
48+
/>
49+
))
50+
if (updateRes === 'update') {
51+
const url = Platform.OS === 'android' ? config.playStore : config.appStore
52+
await Linking.openURL(url)
53+
}
54+
}
55+
}

0 commit comments

Comments
 (0)