Skip to content

Commit

Permalink
[Issue-1753] Fix bug when use @chainflip new version
Browse files Browse the repository at this point in the history
  • Loading branch information
dominhquang committed Sep 26, 2024
1 parent 0c4dd45 commit 23bc238
Show file tree
Hide file tree
Showing 11 changed files with 774 additions and 397 deletions.
2 changes: 0 additions & 2 deletions metro.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ const config = {
resolver: {
assetExts: assetExts.filter(ext => ext !== 'svg'),
sourceExts: [...sourceExts, 'svg'],
unstable_enablePackageExports: true,
unstable_conditionNames: ['browser', 'import', 'react-native'],
},
};

Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"prepare": "husky install"
},
"dependencies": {
"@chainflip/sdk": "1.6.0-beta.2",
"@chainflip/sdk": "^1.3.0",
"@coinbase/cbpay-js": "^1.7.0",
"@fortawesome/fontawesome-svg-core": "^6.2.1",
"@fortawesome/free-brands-svg-icons": "^6.2.1",
Expand Down Expand Up @@ -151,7 +151,7 @@
"@react-native/eslint-config": "^0.72.2",
"@react-native/metro-config": "^0.72.11",
"@subwallet/chain-list": "0.2.88-beta.1",
"@subwallet/extension-base": "1.2.30-0",
"@subwallet/extension-base": "1.2.29-0",
"@tsconfig/react-native": "^3.0.0",
"@types/humanize-duration": "^3.27.3",
"@types/jest": "^29.2.3",
Expand All @@ -167,6 +167,7 @@
"@typescript-eslint/eslint-plugin": "^5.45.0",
"@typescript-eslint/parser": "^5.45.0",
"assert": "^2.0.0",
"axios": "^1.4.0",
"babel-jest": "^29.3.1",
"babel-loader": "^9.1.0",
"babel-plugin-module-resolver": "^4.1.0",
Expand Down Expand Up @@ -203,10 +204,10 @@
"@polkadot/util-crypto": "^12.6.2",
"@polkadot/types": "^12.0.2",
"@subwallet/chain-list": "0.2.88-beta.1",
"@subwallet/extension-base": "1.2.30-0",
"@subwallet/extension-base": "1.2.29-0",
"react-native-svg": "^13.6.0",
"sails-js": "0.1.6",
"@chainflip/sdk": "1.6.0-beta.2"
"@chainflip/sdk": "^1.3.0"
},
"engines": {
"node": ">=16"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/node_modules/@subwallet/extension-base/services/swap-service/utils.js b/node_modules/@subwallet/extension-base/services/swap-service/utils.js
index 77ffa31..5bf8666 100644
index 1b57d06..ee7c93f 100644
--- a/node_modules/@subwallet/extension-base/services/swap-service/utils.js
+++ b/node_modules/@subwallet/extension-base/services/swap-service/utils.js
@@ -1,7 +1,6 @@
Expand All @@ -9,8 +9,8 @@ index 77ffa31..5bf8666 100644
-import { Assets, Chains } from '@chainflip/sdk/swap';
import { COMMON_ASSETS, COMMON_CHAIN_SLUGS } from '@subwallet/chain-list';
import { _getAssetDecimals } from '@subwallet/extension-base/services/chain-service/utils';
import { CHAINFLIP_BROKER_API } from '@subwallet/extension-base/services/swap-service/handler/chainflip-handler';
@@ -10,22 +9,22 @@ import BigN from 'bignumber.js';
import { SwapProviderId } from '@subwallet/extension-base/types/swap';
@@ -9,22 +8,22 @@ import BigN from 'bignumber.js';
export const CHAIN_FLIP_TESTNET_EXPLORER = 'https://blocks-perseverance.chainflip.io';
export const CHAIN_FLIP_MAINNET_EXPLORER = 'https://scan.chainflip.io';
export const CHAIN_FLIP_SUPPORTED_MAINNET_MAPPING = {
Expand Down
4 changes: 3 additions & 1 deletion src/components/common/ErrorFallbackScreen/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { House, Share } from 'phosphor-react-native';
import ErrorStyles from './style';
import { useSubWalletTheme } from 'hooks/useSubWalletTheme';
import { Images } from 'assets/index';
import axios from 'axios';
import { FallbackComponentProps } from 'react-native-error-boundary';
import { Toast } from 'react-native-toast-notifications';
import { getBrand, getBuildNumber, getSystemVersion, getVersion } from 'react-native-device-info';
Expand Down Expand Up @@ -43,7 +44,8 @@ const ErrorFallbackScreen: React.FC<FallbackComponentProps> = ({ error, resetErr
app_version: `${getVersion()}-(${getBuildNumber()}) b-${bundleVersion}`,
current_routes: JSON.stringify(currentRoutes.current),
};
fetch('https://mobile-feedback.subwallet.app/gelf', { method: 'POST', body: JSON.stringify(body) })
axios
.post('https://mobile-feedback.subwallet.app/gelf', body)
.then(() => {
resetError();
})
Expand Down
8 changes: 5 additions & 3 deletions src/hooks/static-content/useGetAppInstructionData.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useCallback } from 'react';
import axios from 'axios';
import { STATIC_DATA_DOMAIN } from 'constants/index';
import { mmkvStore } from 'utils/storage';
import { StaticDataProps } from 'components/Modal/Earning/EarningPoolDetailModal';
Expand All @@ -8,13 +9,14 @@ import { EARNING_POOL_DETAIL_DATA, UNSTAKE_ALERT_DATA } from 'constants/earning/

export const useGetAppInstructionData = (language: string) => {
const getAppInstructionData = useCallback(async () => {
fetch(`${STATIC_DATA_DOMAIN}/instructions/preview-${language}.json`)
.then(data => {
axios
.get(`${STATIC_DATA_DOMAIN}/instructions/preview-${language}.json`)
.then(({ data }) => {
const earningDetailData: StaticDataProps[] = [];
const unstakeStaticData: StaticDataProps[] = [];
const mktCampaignStaticData: StaticDataProps[] = [];

(data as unknown as StaticDataProps[]).forEach(item => {
(data as StaticDataProps[]).forEach(item => {
if (item.group && item.group === 'earning') {
if (item.slug === 'UNSTAKE_INFO') {
unstakeStaticData.push(item);
Expand Down
6 changes: 4 additions & 2 deletions src/hooks/static-content/useGetConfig.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import axios from 'axios';
import { useCallback } from 'react';
import { getStaticContentByDevMode, mmkvStore } from 'utils/storage';
import { STATIC_DATA_DOMAIN } from 'constants/index';
Expand All @@ -6,9 +7,10 @@ const dataByDevModeStatus = getStaticContentByDevMode();

export function useGetConfig() {
const getConfig = useCallback(async () => {
fetch(`${STATIC_DATA_DOMAIN}/config/remind-backup/${dataByDevModeStatus}.json`)
axios
.get(`${STATIC_DATA_DOMAIN}/config/remind-backup/${dataByDevModeStatus}.json`)
.then(res => {
mmkvStore.set('storedRemindBackupTimeout', res.backupTimeout);
mmkvStore.set('storedRemindBackupTimeout', res.data.backupTimeout);
})
.catch(() => {
const remindBackupTimeout = mmkvStore.getNumber('storedRemindBackupTimeout');
Expand Down
21 changes: 12 additions & 9 deletions src/hooks/static-content/useGetDAppList.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { useCallback } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { RootState } from 'stores/index';
import axios from 'axios';
import { updateBrowserDApps } from 'stores/base/Settings';
import { DAppCategory, DAppInfo } from 'types/browser';
import { DAppInfo } from 'types/browser';
import { useGetDesktopMode } from 'hooks/screen/Home/Browser/DesktopMode/useGetDesktopMode';
import { fetchStaticData } from 'utils/fetchStaticData';
import { getStaticContentByDevMode } from 'utils/storage';
import { STATIC_DATA_DOMAIN } from 'constants/index';

const dataByDevModeStatus = getStaticContentByDevMode();
export function useGetDAppList() {
const browserDApps = useSelector((state: RootState) => state.settings.browserDApps);
const {
Expand All @@ -19,15 +22,15 @@ export function useGetDAppList() {
const dispatch = useDispatch();

const getDAppsData = useCallback(async () => {
const dApps = await fetchStaticData<DAppInfo[]>('dapps');
const dAppCategories = await fetchStaticData<DAppCategory[]>('categories');
const payload = { dApps: dApps, dAppCategories: dAppCategories };
if (!!dApps && dApps.length) {
const dApps = await axios.get(`${STATIC_DATA_DOMAIN}/dapps/${dataByDevModeStatus}.json`);
const dAppCategories = await axios.get(`${STATIC_DATA_DOMAIN}/categories/${dataByDevModeStatus}.json`);
const payload = { dApps: dApps.data, dAppCategories: dAppCategories.data };
if (!!dApps && dApps.data.length) {
dispatch(updateBrowserDApps(payload));
}
if (dApps) {
if (dApps.data) {
// Add default desktop mode DApps.
const notFlagedDApps = dApps.filter((dApp: DAppInfo) => desktopModeData.indexOf(dApp.url || '') === -1);
const notFlagedDApps = dApps.data.filter((dApp: DAppInfo) => desktopModeData.indexOf(dApp.url || '') === -1);
const needFlagedDApps = notFlagedDApps.filter((dApp: DAppInfo) => !!dApp.desktop_mode);
const newDefaultDesktopModeDApps: string[] = [];
needFlagedDApps.forEach((dApp: DAppInfo) => {
Expand All @@ -42,7 +45,7 @@ export function useGetDAppList() {
}

// Remove not default desktop mode DApps.
const flagedDApps = dApps.filter((dApp: DAppInfo) => desktopModeData.indexOf(dApp.url || '') !== -1);
const flagedDApps = dApps.data.filter((dApp: DAppInfo) => desktopModeData.indexOf(dApp.url || '') !== -1);
const needRemoveFlaggedDapps = flagedDApps.filter((dApp: DAppInfo) => !dApp.desktop_mode);
const newRemoveDefaultDesktopModeDApps: string[] = [];
needRemoveFlaggedDapps.forEach((dApp: DAppInfo) => {
Expand Down
6 changes: 4 additions & 2 deletions src/hooks/static-content/useGetTermAndConditionData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { RootState } from 'stores/index';
import { useCallback } from 'react';
import { getStaticContentByDevMode, mmkvStore } from 'utils/storage';
import { STATIC_DATA_DOMAIN } from 'constants/index';
import axios from 'axios';
import { TermAndCondition } from 'constants/termAndCondition';

const dataByDevModeStatus = getStaticContentByDevMode();
Expand All @@ -11,9 +12,10 @@ export function useGetTermAndCondition() {
const language = useSelector((state: RootState) => state.settings.language);

const getTermAndCondition = useCallback(async () => {
fetch(`${STATIC_DATA_DOMAIN}/markdown-contents/term_and_condition/${dataByDevModeStatus}-${language}.json`)
axios
.get(`${STATIC_DATA_DOMAIN}/markdown-contents/term_and_condition/${dataByDevModeStatus}-${language}.json`)
.then(res => {
mmkvStore.set('generalTermContent', res.content);
mmkvStore.set('generalTermContent', res.data.content);
})
.catch(() => {
const generalTermData = mmkvStore.getString(`generalTerm${language}Content`);
Expand Down
7 changes: 5 additions & 2 deletions src/hooks/static-content/useShowBuyToken.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Platform } from 'react-native';
import { getVersion } from 'react-native-device-info';
import axios from 'axios';
import { TOKEN_CONFIG_URL } from 'constants/index';
import { useDispatch, useSelector } from 'react-redux';
import { updateIsShowByToken } from 'stores/base/Settings';
Expand All @@ -15,8 +16,10 @@ export function useShowBuyToken() {
return;
}
const currentAppVersion = getVersion();
fetch(TOKEN_CONFIG_URL).then(res => {
if (res?.buy?.includes(currentAppVersion)) {
axios.get(TOKEN_CONFIG_URL).then(res => {
const tokenConfig = res.data;

if (tokenConfig?.buy?.includes(currentAppVersion)) {
dispatch(updateIsShowByToken(true));
return;
}
Expand Down
19 changes: 5 additions & 14 deletions src/utils/fetchStaticData.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
import axios from 'axios';
import { getStaticContentByDevMode } from './storage';
import { fetchJson, fetchText } from '@subwallet/extension-base/utils';
import { staticData, StaticKey } from '@subwallet/extension-base/utils/staticData';
import { STATIC_DATA_DOMAIN } from 'constants/index';

export async function fetchStaticData<T>(slug: string, targetFile?: string, isJson = true) {
export async function fetchStaticData<T>(slug: string, targetFile?: string) {
const dataByDevModeStatus = getStaticContentByDevMode();
const fetchFile = targetFile || dataByDevModeStatus;
const rs = await axios.get(`${STATIC_DATA_DOMAIN}/${slug}/${fetchFile}.json`);

try {
if (isJson) {
return await fetchJson<T>(`https://static-data.subwallet.app/${slug}/${fetchFile}`);
} else {
return await fetchText<T>(`https://static-data.subwallet.app/${slug}/${fetchFile}`);
}
} catch (e) {
console.log('error fetching static data', e);

return staticData[slug as StaticKey] as T;
}
return rs.data as T;
}
Loading

0 comments on commit 23bc238

Please sign in to comment.