Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/issue-1799' into upgrade-ui
Browse files Browse the repository at this point in the history
  • Loading branch information
dominhquang committed Sep 28, 2024
2 parents b21460c + 9cabed1 commit 6c860ac
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 27 deletions.
10 changes: 5 additions & 5 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ PODS:
- libwebp/sharpyuv (1.3.2)
- libwebp/webp (1.3.2):
- libwebp/sharpyuv
- MMKV (1.3.5):
- MMKVCore (~> 1.3.5)
- MMKVCore (1.3.5)
- MMKV (1.3.9):
- MMKVCore (~> 1.3.9)
- MMKVCore (1.3.9)
- RCT-Folly (2021.07.22.00):
- boost
- DoubleConversion
Expand Down Expand Up @@ -846,8 +846,8 @@ SPEC CHECKSUMS:
JWT: ef71dfb03e1f842081e64dc42eef0e164f35d251
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
libwebp: 1786c9f4ff8a279e4dac1e8f385004d5fc253009
MMKV: 506311d0494023c2f7e0b62cc1f31b7370fa3cfb
MMKVCore: 9e2e5fd529b64a9fe15f1a7afb3d73b2e27b4db9
MMKV: 817ba1eea17421547e01e087285606eb270a8dcb
MMKVCore: af055b00e27d88cd92fad301c5fecd1ff9b26dd9
RCT-Folly: 424b8c9a7a0b9ab2886ffe9c3b041ef628fd4fb1
RCTRequired: b4d3068afa6f52ec5260a8417053b1f1b421483d
RCTTypeSafety: a4551b3d338c96435f63bf06d564055c1d3cc0ac
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"@subwallet/react-ui": "^5.1.2-b77",
"@subwallet/ui-keyring": "0.1.6",
"@walletconnect/utils": "2.8.4",
"compare-versions": "^6.1.1",
"deprecated-react-native-prop-types": "^4.0.0",
"eventemitter3": "^5.0.0",
"humanize-duration": "^3.31.0",
Expand Down
55 changes: 44 additions & 11 deletions src/hooks/static-content/useHandleAppBannerMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import { useDispatch, useSelector } from 'react-redux';
import { RootState } from 'stores/index';
import { AppBannerData } from '@subwallet/extension-base/services/mkt-campaign-service/types';
import { getCountry } from 'react-native-localize';
import { Platform } from 'react-native';
import { getOsVersion } from 'utils/common';
import { satisfies } from 'compare-versions';
import { getVersion } from 'react-native-device-info';

export const useHandleAppBannerMap = () => {
const dispatch = useDispatch();
Expand Down Expand Up @@ -50,21 +54,50 @@ export const useHandleAppBannerMap = () => {
[bannerHistoryMap, dispatch],
);

const filteredDataByLocation = useMemo(() => {
return appBannerData.filter(({ locations }) => {
if (locations && locations.length) {
const countryId = getCountry();
const locationIds = locations.map(item => item.split('_')[1]);
return locationIds.includes(countryId);
} else {
return true;
const filteredAppBannerByTimeAndPlatform = useMemo(() => {
return appBannerData.filter(({ info }) => {
if (info) {
if (info.os) {
return info.platforms.includes('mobile') && info.os.toLowerCase() === Platform.OS;
} else {
return info.platforms.includes('mobile');
}
}
});
}, [appBannerData]);

const filteredData = useMemo(() => {
return filteredAppBannerByTimeAndPlatform.filter(
({ locations, comparison_operator, os_version_range, app_version_range }) => {
const validConditionArr = [];
if (locations && locations.length) {
const countryId = getCountry();
const locationIds = locations.map(item => item.split('_')[1]);
validConditionArr.push(locationIds.includes(countryId));
}

if (os_version_range) {
const osVersion = getOsVersion();
validConditionArr.push(satisfies(osVersion.toString(), os_version_range));
}

if (app_version_range) {
const appVersion = getVersion();
validConditionArr.push(satisfies(appVersion, app_version_range));
}

if (comparison_operator === 'AND') {
return validConditionArr.every(c => c);
} else {
return validConditionArr.some(c => c);
}
},
);
}, [filteredAppBannerByTimeAndPlatform]);

const appBannerMap = useMemo(() => {
if (filteredDataByLocation) {
const result: Record<string, AppBannerData[]> = filteredDataByLocation.reduce((r, a) => {
if (filteredData) {
const result: Record<string, AppBannerData[]> = filteredData.reduce((r, a) => {
r[a.position] = r[a.position] || [];
r[a.position].push(a);
return r;
Expand All @@ -74,7 +107,7 @@ export const useHandleAppBannerMap = () => {
} else {
return {};
}
}, [filteredDataByLocation]);
}, [filteredData]);

return {
updateBannerHistoryMap,
Expand Down
55 changes: 44 additions & 11 deletions src/hooks/static-content/useHandleAppPopupMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import { useDispatch, useSelector } from 'react-redux';
import { RootState } from 'stores/index';
import { AppPopupData } from '@subwallet/extension-base/services/mkt-campaign-service/types';
import { getCountry } from 'react-native-localize';
import { satisfies } from 'compare-versions';
import { getOsVersion } from 'utils/common';
import { Platform } from 'react-native';
import { getVersion } from 'react-native-device-info';

export const useHandleAppPopupMap = () => {
const { appPopupData, popupHistoryMap } = useSelector((state: RootState) => state.staticContent);
Expand Down Expand Up @@ -42,21 +46,50 @@ export const useHandleAppPopupMap = () => {
[dispatch, popupHistoryMap],
);

const filteredDataByLocation = useMemo(() => {
return appPopupData.filter(({ locations }) => {
if (locations && locations.length) {
const countryId = getCountry();
const locationIds = locations.map(item => item.split('_')[1]);
return locationIds.includes(countryId);
} else {
return true;
const filteredAppPopupByTimeAndPlatform = useMemo(() => {
return appPopupData.filter(({ info }) => {
if (info) {
if (info.os) {
return info.platforms.includes('mobile') && info.os.toLowerCase() === Platform.OS;
} else {
return info.platforms.includes('mobile');
}
}
});
}, [appPopupData]);

const filteredData = useMemo(() => {
return filteredAppPopupByTimeAndPlatform.filter(
({ locations, comparison_operator, os_version_range, app_version_range }) => {
const validConditionArr = [];
if (locations && locations.length) {
const countryId = getCountry();
const locationIds = locations.map(item => item.split('_')[1]);
validConditionArr.push(locationIds.includes(countryId));
}

if (os_version_range) {
const osVersion = getOsVersion();
validConditionArr.push(satisfies(osVersion.toString(), os_version_range));
}

if (app_version_range) {
const appVersion = getVersion();
validConditionArr.push(satisfies(appVersion, app_version_range));
}

if (comparison_operator === 'AND') {
return validConditionArr.every(c => c);
} else {
return validConditionArr.some(c => c);
}
},
);
}, [filteredAppPopupByTimeAndPlatform]);

const appPopupMap = useMemo(() => {
if (filteredDataByLocation) {
const result: Record<string, AppPopupData[]> = filteredDataByLocation.reduce((r, a) => {
if (filteredData) {
const result: Record<string, AppPopupData[]> = filteredData.reduce((r, a) => {
r[a.position] = r[a.position] || [];
r[a.position].push(a);
return r;
Expand All @@ -66,7 +99,7 @@ export const useHandleAppPopupMap = () => {
} else {
return {};
}
}, [filteredDataByLocation]);
}, [filteredData]);

return {
updatePopupHistoryMap,
Expand Down
11 changes: 11 additions & 0 deletions src/utils/common.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Platform } from 'react-native';

export const simpleDeepClone = <T>(s: T) => {
return JSON.parse(JSON.stringify(s)) as T;
};
Expand All @@ -9,3 +11,12 @@ export function shuffle<T = any>(array: T[]) {
[array[i], array[j]] = [array[j], array[i]];
}
}

export const getOsVersion = (): string | number => {
if (Platform.OS === 'ios') {
return Platform.Version;
} else {
// @ts-ignore
return Platform.constants['Release'];
}
};
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8588,6 +8588,11 @@ commondir@^1.0.1:
resolved "https://registry.yarnpkg.com/commondir/-/commondir-1.0.1.tgz#ddd800da0c66127393cca5950ea968a3aaf1253b"
integrity sha512-W9pAhw0ja1Edb5GVdIF1mjZw/ASI0AlShXM83UUGe2DVr5TdAPEA1OA8m/g8zWp9x6On7gqufY+FatDbC3MDQg==

compare-versions@^6.1.1:
version "6.1.1"
resolved "https://registry.yarnpkg.com/compare-versions/-/compare-versions-6.1.1.tgz#7af3cc1099ba37d244b3145a9af5201b629148a9"
integrity sha512-4hm4VPpIecmlg59CHXnRDnqGplJFrbLG4aFEl5vl6cK1u76ws3LLvX7ikFnTDl5vo39sjWD6AaDPYodJp/NNHg==

component-emitter@^1.3.0:
version "1.3.1"
resolved "https://registry.yarnpkg.com/component-emitter/-/component-emitter-1.3.1.tgz#ef1d5796f7d93f135ee6fb684340b26403c97d17"
Expand Down

0 comments on commit 6c860ac

Please sign in to comment.