|
1 |
| -import React from 'react'; |
| 1 | +import React, { lazy } from 'react'; |
2 | 2 | import { Route, Switch } from 'react-router-dom';
|
3 | 3 | import { useWalletAccountsList } from '@deriv/api-v2';
|
4 |
| -import { WalletNoWalletFoundState } from '../components'; |
5 |
| -import { CashierModalRoute } from './CashierModalRoute'; |
6 |
| -import { CompareAccountsRoute } from './CompareAccountsRoute'; |
7 |
| -import { WalletsListingRoute } from './WalletsListingRoute'; |
| 4 | +import { Loader } from '../components/Loader'; |
| 5 | + |
| 6 | +const LazyWalletsNotFoundState = lazy( |
| 7 | + () => |
| 8 | + import( |
| 9 | + /* webpackChunkName: "wallets-not-found-route" */ '../components/WalletNoWalletFoundState/WalletNoWalletFoundState' |
| 10 | + ) |
| 11 | +); |
| 12 | + |
| 13 | +const LazyWalletsListingRoute = lazy( |
| 14 | + () => import(/* webpackChunkName: "wallets-listing-route" */ './WalletsListingRoute/WalletsListingRoute') |
| 15 | +); |
| 16 | +const LazyCashierModalRoute = lazy( |
| 17 | + () => import(/* webpackChunkName: "cashier-modal-route" */ './CashierModalRoute/CashierModalRoute') |
| 18 | +); |
| 19 | + |
| 20 | +const LazyCompareAccountsRoute = lazy( |
| 21 | + () => import(/* webpackChunkName: "compare-accounts-route" */ './CompareAccountsRoute/CompareAccountsRoute') |
| 22 | +); |
8 | 23 |
|
9 | 24 | const walletsPrefix = '/wallets';
|
10 | 25 |
|
@@ -58,13 +73,43 @@ const Router: React.FC = () => {
|
58 | 73 | const { data: walletAccounts, isLoading } = useWalletAccountsList();
|
59 | 74 |
|
60 | 75 | if ((!walletAccounts || !walletAccounts.length) && !isLoading)
|
61 |
| - return <Route component={WalletNoWalletFoundState} path={walletsPrefix} />; |
| 76 | + return ( |
| 77 | + <Route |
| 78 | + path={walletsPrefix} |
| 79 | + render={() => ( |
| 80 | + <React.Suspense fallback={<Loader />}> |
| 81 | + <LazyWalletsNotFoundState /> |
| 82 | + </React.Suspense> |
| 83 | + )} |
| 84 | + /> |
| 85 | + ); |
62 | 86 |
|
63 | 87 | return (
|
64 | 88 | <Switch>
|
65 |
| - <Route component={CompareAccountsRoute} path={`${walletsPrefix}/compare-accounts`} /> |
66 |
| - <Route component={CashierModalRoute} path={`${walletsPrefix}/cashier`} /> |
67 |
| - <Route component={WalletsListingRoute} path={walletsPrefix} /> |
| 89 | + <Route |
| 90 | + path={`${walletsPrefix}/compare-accounts`} |
| 91 | + render={() => ( |
| 92 | + <React.Suspense fallback={<Loader />}> |
| 93 | + <LazyCompareAccountsRoute /> |
| 94 | + </React.Suspense> |
| 95 | + )} |
| 96 | + /> |
| 97 | + <Route |
| 98 | + path={`${walletsPrefix}/cashier`} |
| 99 | + render={() => ( |
| 100 | + <React.Suspense fallback={<Loader />}> |
| 101 | + <LazyCashierModalRoute /> |
| 102 | + </React.Suspense> |
| 103 | + )} |
| 104 | + /> |
| 105 | + <Route |
| 106 | + path={walletsPrefix} |
| 107 | + render={() => ( |
| 108 | + <React.Suspense fallback={<Loader />}> |
| 109 | + <LazyWalletsListingRoute /> |
| 110 | + </React.Suspense> |
| 111 | + )} |
| 112 | + /> |
68 | 113 | </Switch>
|
69 | 114 | );
|
70 | 115 | };
|
|
0 commit comments