Skip to content

Commit

Permalink
Merge pull request #5594 from LiskHQ/5580-remove-service-dependency
Browse files Browse the repository at this point in the history
Remove lisk-service dependencies
  • Loading branch information
shuse2 authored Jul 25, 2024
2 parents 1c4c3d7 + 49f357d commit e49c4f3
Show file tree
Hide file tree
Showing 40 changed files with 1,201 additions and 580 deletions.
115 changes: 7 additions & 108 deletions setup/react/app/ApplicationBootstrap.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
/* eslint-disable complexity */
/* eslint-disable max-statements */
import React, { createContext, useEffect, useRef, useState } from 'react';
import { useTransactionUpdate } from '@transaction/hooks';
import useSettings from '@settings/hooks/useSettings';
import {
useApplicationManagement,
useCurrentApplication,
} from '@blockchainApplication/manage/hooks';
import { useNetworkStatus, useIndexStatus } from '@network/hooks/queries';
import { useBlockchainApplicationMeta } from '@blockchainApplication/manage/hooks/queries/useBlockchainApplicationMeta';
import React, { createContext } from 'react';
import { useCurrentAccount } from 'src/modules/account/hooks';
import { Client } from 'src/utils/api/client';
import { useReduxStateModifier } from 'src/utils/useReduxStateModifier';
import { useLedgerDeviceListener } from '@libs/hardwareWallet/ledger/ledgerDeviceListener/useLedgerDeviceListener';
import { useValidServiceUrl } from '@blockchainApplication/manage/hooks/useValidServiceUrl';
import { useRewardsClaimable } from 'src/modules/pos/reward/hooks/queries';

export const ApplicationBootstrapContext = createContext({
Expand All @@ -25,97 +15,8 @@ export const ApplicationBootstrapContext = createContext({
});

const ApplicationBootstrap = ({ children }) => {
const { mainChainNetwork } = useSettings('mainChainNetwork');
const [isFirstTimeLoading, setIsFirstTimeLoading] = useState(true);
const [currentApplication, setCurrentApplication] = useCurrentApplication();
const { setApplications } = useApplicationManagement();
const [currentAccount] = useCurrentAccount();
const accountAddress = currentAccount?.metadata?.address;
const queryClient = useRef();

queryClient.current = new Client({
http: mainChainNetwork?.serviceUrl,
ws: mainChainNetwork?.wsServiceUrl,
});

useTransactionUpdate();
const networkStatus = useNetworkStatus({
options: { enabled: !!mainChainNetwork },
client: queryClient.current,
});
const indexStatus = useIndexStatus({
options: {
enabled: !!mainChainNetwork,
},
client: queryClient.current,
});

const blockchainAppsMeta = useBlockchainApplicationMeta({
config: {
params: {
chainID: [...new Set([networkStatus.data?.data?.chainID, currentApplication.chainID])]
.filter((item) => item)
.join(','),
},
},
options: { enabled: !!networkStatus.data && !!mainChainNetwork },
client: queryClient.current,
});

const serviceUrls = blockchainAppsMeta.data?.data.find(
({ chainID }) => networkStatus.data?.data?.chainID === chainID
)?.serviceURLs;

const { validServiceUrl } = useValidServiceUrl(serviceUrls);

const mainChainApplication = blockchainAppsMeta.data?.data?.find(
({ chainID }) => chainID === networkStatus?.data?.data?.chainID
);

const isError =
((networkStatus.isError && !networkStatus.data) || blockchainAppsMeta.isError) &&
!!mainChainNetwork;

useEffect(() => {
if (mainChainApplication && validServiceUrl) {
const refreshedCurrentApplication = blockchainAppsMeta?.data?.data?.find(
({ chainID }) => chainID === currentApplication?.chainID
);
const networkCode = mainChainApplication.chainID.match(/^\d{4}/g)[0];
const currentAppToSelect =
refreshedCurrentApplication?.chainID?.indexOf(networkCode) === 0
? refreshedCurrentApplication
: mainChainApplication;

const currentApplicationWithValidServiceUrlAtTheTop = {
...currentAppToSelect,
serviceURLs: currentAppToSelect.serviceURLs.sort((a, b) => {
const nameA = a.http === validServiceUrl;
const nameB = b.http === validServiceUrl;
if (nameA && nameB) {
return 0;
}
if (nameA) {
return -1;
}
return 1;
}),
};

setCurrentApplication(currentApplicationWithValidServiceUrlAtTheTop);
setApplications([mainChainApplication]);
}

if (isFirstTimeLoading && blockchainAppsMeta.isFetched && !blockchainAppsMeta.isError) {
setIsFirstTimeLoading(false);
}
}, [
mainChainNetwork,
blockchainAppsMeta.isFetched,
blockchainAppsMeta.isError,
blockchainAppsMeta.isLoading,
validServiceUrl,
]);

useLedgerDeviceListener();
useReduxStateModifier();
Expand All @@ -127,14 +28,12 @@ const ApplicationBootstrap = ({ children }) => {
return (
<ApplicationBootstrapContext.Provider
value={{
queryClient,
hasNetworkError: isError && !blockchainAppsMeta.isFetching,
isLoadingNetwork:
(blockchainAppsMeta.isFetching && !blockchainAppsMeta.data) ||
(networkStatus.isFetching && !networkStatus.data),
indexStatus: indexStatus?.data?.data || {},
error: networkStatus.error || blockchainAppsMeta.error,
refetchNetwork: blockchainAppsMeta.refetch,
queryClient: {},
hasNetworkError: false,
isLoadingNetwork: false,
indexStatus: {},
error: null,
refetchNetwork: false,
appEvents: { transactions: { rewards: rewardsData?.data ?? [] } },
}}
>
Expand Down
2 changes: 1 addition & 1 deletion setup/react/app/ApplicationBootstrap.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('ApplicationBootstrap', () => {
validServiceUrl: mockBlockchainAppMeta.data[0].serviceURLs[0].http,
});

it('Should set main chain application for the selected network', async () => {
it.skip('Should set main chain application for the selected network', async () => {
smartRender(ApplicationBootstrap, props, renderConfig);

await waitFor(() => {
Expand Down
2 changes: 0 additions & 2 deletions setup/react/app/MainRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { SIGNING_METHODS } from '@libs/wcm/constants/permissions';
import routesMap from 'src/routes/routesMap';
import NotFound from '@common/components/NotFound';
import CustomRoute from '@common/components/customRoute';
import RewardsNotification from '@common/components/notification/rewardsNotification';
import routes from 'src/routes/routes';
import styles from './app.css';

Expand Down Expand Up @@ -42,7 +41,6 @@ const MainRouter = ({ history }) => {

return (
<div className={`${styles.mainContent} ${styles.mainBox}`}>
<RewardsNotification />
<Switch>
{routesList.map((route) => (
<CustomRoute
Expand Down
22 changes: 2 additions & 20 deletions setup/react/app/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
/* istanbul ignore file */
// This is covered by e2e tests
import React, { useContext, useEffect, useState } from 'react';
import React, { useEffect, useState } from 'react';
import { withRouter } from 'react-router-dom';
import { useDispatch, useSelector } from 'react-redux';
import { settingsRetrieved } from 'src/modules/settings/store/actions';
import { ToastContainer } from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';
import { hot } from 'react-hot-loader/root';
import { bookmarksRetrieved } from 'src/modules/bookmark/store/action';
import { watchListRetrieved } from 'src/modules/pos/validator/store/actions/watchList';
import useIpc from '@update/hooks/useIpc';
import ConnectionProvider from '@libs/wcm/context/connectionProvider';
import FlashMessageHolder from 'src/theme/flashMessage/holder';
Expand All @@ -17,12 +16,9 @@ import OfflineWrapper from 'src/modules/common/components/offlineWrapper';
import NavigationBars from 'src/modules/common/components/bars';
import ThemeContext from 'src/theme/themeProvider';
import { MOCK_SERVICE_WORKER } from 'src/const/config';
import NetworkError from 'src/modules/common/components/NetworkError/NetworkError';
import PageLoader from 'src/modules/common/components/pageLoader';
import MainRouter from './MainRouter';
import './variables.css';
import styles from './app.css';
import { ApplicationBootstrapContext } from './ApplicationBootstrap';

if (MOCK_SERVICE_WORKER) {
const { worker } = require('src/service/mock/runtime');
Expand All @@ -32,19 +28,6 @@ if (MOCK_SERVICE_WORKER) {
})();
}

const AppContent = () => {
const { hasNetworkError, refetchNetwork, error, isLoadingNetwork, indexStatus } = useContext(
ApplicationBootstrapContext
);
const { percentageIndexed, chainLength, numBlocksIndexed } = indexStatus;
const shouldShowIndexingLoader = chainLength - numBlocksIndexed >= 5;

if (isLoadingNetwork) return <PageLoader />;
if (shouldShowIndexingLoader) return <PageLoader progress={percentageIndexed} />;

return hasNetworkError ? <NetworkError onRetry={refetchNetwork} error={error} /> : <MainRouter />;
};

// eslint-disable-next-line max-statements
const App = ({ history }) => {
const dispatch = useDispatch();
Expand All @@ -57,7 +40,6 @@ const App = ({ history }) => {
setLoaded(true);
dispatch(bookmarksRetrieved());
dispatch(settingsRetrieved());
dispatch(watchListRetrieved());
}, []);

return (
Expand All @@ -79,7 +61,7 @@ const App = ({ history }) => {
<main className={`${styles.bodyWrapper} ${loaded ? styles.loaded : ''}`}>
<section className="scrollContainer">
<FlashMessageHolder />
<AppContent />
<MainRouter />
</section>
</main>
</OfflineWrapper>
Expand Down
10 changes: 5 additions & 5 deletions src/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"Account details": "Account details",
"Account was removed": "Account was removed",
"Account(s) to use on this application": "Account(s) to use on this application",
"Accounts": "Accounts",
"Action": "Action",
"Activated": "Activated",
"Active validators": "Active validators",
Expand All @@ -28,7 +27,6 @@
"Add application": "Add application",
"Add bookmark": "Add bookmark",
"Add message (Optional)": "Add message (Optional)",
"Add network": "Add network",
"Add new": "Add new",
"Add to staking queue": "Add to staking queue",
"Add to watched": "Add to watched",
Expand Down Expand Up @@ -86,7 +84,6 @@
"Block details": "Block details",
"Block height": "Block height",
"Block status": "Block status",
"Blocks": "Blocks",
"Blocks generated": "Blocks generated",
"Blocks overview": "Blocks overview",
"Bookmarks": "Bookmarks",
Expand Down Expand Up @@ -223,11 +220,13 @@
"Enter network name, e.g Testnet": "Enter network name, e.g Testnet",
"Enter password": "Enter password",
"Enter password confirmation": "Enter password confirmation",
"Enter private key": "Enter private key",
"Enter public key": "Enter public key",
"Enter service URL, e.g. https://testnet-service.lisk.com": "Enter service URL, e.g. https://testnet-service.lisk.com",
"Enter stake amount": "Enter stake amount",
"Enter websocket service URL, e.g. wss://testnet-service.lisk.com": "Enter websocket service URL, e.g. wss://testnet-service.lisk.com",
"Enter your account password": "Enter your account password",
"Enter your private key to manage your account.": "Enter your private key to manage your account.",
"Enter your secret recovery phrase to manage your account.": "Enter your secret recovery phrase to manage your account.",
"Error": "Error",
"Error loading application data": "Error loading application data",
Expand Down Expand Up @@ -299,6 +298,7 @@
"If you just made the transaction, it will take up to a few minutes to be included in the blockchain. Please open this page later.": "If you just made the transaction, it will take up to a few minutes to be included in the blockchain. Please open this page later.",
"Import account": "Import account",
"Import account from hardware wallet": "Import account from hardware wallet",
"Import private key": "Import private key",
"In order to use this feature you need to sign in to your Lisk account.": "In order to use this feature you need to sign in to your Lisk account.",
"Index": "Index",
"Information": "Information",
Expand Down Expand Up @@ -394,7 +394,6 @@
"Multisignature params signatures": "Multisignature params signatures",
"My validator profile": "My validator profile",
"Name": "Name",
"Network": "Network",
"Network Connection Issues": "Network Connection Issues",
"Network fee": "Network fee",
"Network statistics": "Network statistics",
Expand Down Expand Up @@ -488,6 +487,8 @@
"Priority": "Priority",
"Privacy": "Privacy",
"Privacy policy": "Privacy policy",
"Private key": "Private key",
"Private key should be represented as a hexadecimal string with length of 64 characters.": "Private key should be represented as a hexadecimal string with length of 64 characters.",
"Provide Feedback": "Provide Feedback",
"Provide a correct amount of {{token}}": "Provide a correct amount of {{token}}",
"Provide a correct wallet address or the name of a bookmarked account": "Provide a correct wallet address or the name of a bookmarked account",
Expand Down Expand Up @@ -787,7 +788,6 @@
"View profile": "View profile",
"View remaining": "View remaining",
"Volume": "Volume",
"Wallet": "Wallet",
"Wallet address:": "Wallet address:",
"Wallet balance": "Wallet balance",
"Wallet connections": "Wallet connections",
Expand Down
Loading

0 comments on commit e49c4f3

Please sign in to comment.