Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrated from cra to vite #513

Merged
merged 17 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
isazaharadeen marked this conversation as resolved.
Show resolved Hide resolved
Binary file not shown.
6 changes: 3 additions & 3 deletions frontend/.env.dev
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
REACT_APP_STARKNET_NODE_URL=http://178.32.172.148:6060
REACT_APP_BACKEND_URL=http://localhost:8000
REACT_APP_IS_DEV=true
VITE_APP_STARKNET_NODE_URL=http://178.32.172.148:6060
VITE_APP_BACKEND_URL=http://localhost:8000
VITE_APP_IS_DEV=true
5 changes: 2 additions & 3 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ RUN yarn build
# Stage 2: Set up Nginx to serve the built app
FROM nginx:alpine

COPY --from=build /app/build /usr/share/nginx/html
COPY --from=build /app/dist /usr/share/nginx/html

RUN rm /etc/nginx/conf.d/default.conf
COPY spotnet.conf /etc/nginx/conf.d

EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

CMD ["nginx", "-g", "daemon off;"]
4 changes: 2 additions & 2 deletions frontend/Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ RUN yarn build
# Stage 2: Set up Nginx to serve the built app
FROM nginx:alpine

COPY --from=build /app/build /usr/share/nginx/html
COPY --from=build /app/dist /usr/share/nginx/html

RUN rm /etc/nginx/conf.d/default.conf
COPY spotnet_dev.conf /etc/nginx/conf.d

EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
CMD ["nginx", "-g", "daemon off;"]
71 changes: 28 additions & 43 deletions frontend/README.md
Original file line number Diff line number Diff line change
@@ -1,69 +1,54 @@
# Getting Started with Create React App
# Getting Started with Vite

This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
This project was migrated from [Create React App](https://github.com/facebook/create-react-app) to [Vite](https://vitejs.dev/), a fast and modern frontend build tool.

## Available Scripts

In the project directory, you can run:

### `npm start`
### `yarn start`

Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in your browser.
Runs the app in development mode.
Open [http://localhost:5173](http://localhost:5173) (default) to view it in your browser.

The page will reload when you make changes.\
You may also see any lint errors in the console.
The page will reload when you make changes.
You may also see any errors or warnings in the console.

### `npm test`
### `yarn test`

This launches the tests using the node environment provisioned by jest. After running the initial setup and the app is runnign , open another terminal shell, cd into the frontend directory and then run npm test.
Runs the tests using the environment provisioned by Jest. After running the initial setup and starting the app, open another terminal shell, navigate to the frontend directory, and run `yarn test`.

### `npm run build`
### `yarn build`

Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.
Builds the app for production to the `dist` folder.
It optimizes the build for the best performance using Vite's efficient bundling and minification process.

The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!
The production build is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `npm run eject`

**Note: this is a one-way operation. Once you `eject`, you can't go back!**

If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.

You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.
For more information on deployment, check out [Vite's deployment guide](https://vitejs.dev/guide/static-deploy.html).

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).

### Code Splitting

This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)

### Analyzing the Bundle Size
To learn more about Vite, visit the [Vite documentation](https://vitejs.dev/guide/).

This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
To learn React, check out the [React documentation](https://react.dev/).

### Making a Progressive Web App
## Code Splitting and Performance

This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
Vite supports efficient code splitting and performance optimization out of the box. Learn more in [Vite's guide to optimization](https://vitejs.dev/guide/features.html#code-splitting).

### Advanced Configuration
## Troubleshooting

This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
If you encounter any issues during development or deployment, refer to the [Vite Troubleshooting Guide](https://vitejs.dev/guide/troubleshooting.html).

### Deployment
## Migration Notes

This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
### Key Changes from Create React App:

### `npm run build` fails to minify
- The development server now runs on [Vite](https://vitejs.dev/), offering faster startup and rebuild times.
- `yarn dev` replaces `yarn start` for running the development server.
- Production builds are now output to the `dist` folder instead of the `build` folder.
- Vite uses [ES modules](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules) by default, ensuring modern, fast builds.
- Configuration has been simplified with a `vite.config.js` or `vite.config.ts` file.

This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
For help with the migration process, check out [Vite's guide for migrating from CRA](https://vitejs.dev/guide/migration-from-cra.html).
3 changes: 2 additions & 1 deletion frontend/babel.config.js
isazaharadeen marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module.exports = {
presets: [['@babel/preset-env', { targets: { node: 'current' } }], '@babel/preset-react'],
presets: ['@babel/preset-env', ['@babel/preset-react', { runtime: 'automatic' }]],
plugins: ['babel-plugin-transform-import-meta'],
};
41 changes: 34 additions & 7 deletions frontend/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,35 @@
import js from '@eslint/js';
import globals from 'globals';
import react from 'eslint-plugin-react';
import reactHooks from 'eslint-plugin-react-hooks';
import reactRefresh from 'eslint-plugin-react-refresh';

export default [
{
languageOptions: {
ecmaVersion: 2015,
sourceType: "script"
}
}
];
{ ignores: ['dist'] },
{
files: ['**/*.{js,jsx}'],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
parserOptions: {
ecmaVersion: 'latest',
ecmaFeatures: { jsx: true },
sourceType: 'module',
},
},
settings: { react: { version: '18.3' } },
plugins: {
react,
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
},
rules: {
...js.configs.recommended.rules,
...react.configs.recommended.rules,
...react.configs['jsx-runtime'].rules,
...reactHooks.configs.recommended.rules,
'react/jsx-no-target-blank': 'off',
'react-refresh/only-export-components': ['warn', { allowConstantExport: true }],
},
},
];
5 changes: 3 additions & 2 deletions frontend/public/index.html → frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" />
<!-- Font Awesome for Icons -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css" rel="stylesheet" />
<link rel="icon" href="%PUBLIC_URL%/logo192.png" type="image/svg+xml" />
<link rel="icon" href="/logo192.png" type="image/svg+xml" />
<!-- Telegram mini-apps integration -->
<script src="https://telegram.org/js/telegram-web-app.js"></script>
<script src="https://telegram.org/js/telegram-widget.js?22"></script>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
isazaharadeen marked this conversation as resolved.
Show resolved Hide resolved
<div id="root"></div>
<!-- Bootstrap JS (Optional) -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<!-- Load Starknet.js -->
<!-- <script src="https://cdn.jsdelivr.net/npm/@argent/get-starknet@latest/dist/index.umd.js"></script> -->

<script type="module" src="/src/index.jsx"></script>
</body>
</html>
1 change: 0 additions & 1 deletion frontend/jest.setup.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { TextEncoder, TextDecoder } from 'util';

global.TextEncoder = TextEncoder;
global.TextDecoder = TextDecoder;
41 changes: 25 additions & 16 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,45 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@babel/core": "^7.26.7",
"@babel/preset-env": "^7.26.7",
"@babel/preset-react": "^7.26.3",
"@popperjs/core": "^2.11.8",
"@tanstack/react-query": "^5.59.16",
"@tanstack/react-query-devtools": "^5.60.5",
"@tanstack/react-query": "^5.64.2",
"@tanstack/react-query-devtools": "^5.64.2",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"@vitejs/plugin-react": "^4.3.4",
"axios": "^1.7.7",
"babel-jest": "^29.7.0",
"babel-plugin-transform-import-meta": "^2.3.2",
"dotenv": "^16.4.5",
"lucide-react": "^0.454.0",
"react": "^18.3.1",
"react": "^19.0.0",
"react-bootstrap": "^2.10.5",
"react-dom": "^18.3.1",
"react-router-dom": "^6.27.0",
"react-scripts": "^5.0.1",
"react-dom": "^19.0.0",
"react-router-dom": "^7.1.3",
"react-toastify": "^10.0.6",
"starknetkit": "2.6.1",
"vite": "^6.0.11",
"vite-plugin-environment": "^1.1.3",
"vite-tsconfig-paths": "^5.1.4",
"web-vitals": "^2.1.4",
"zustand": "^5.0.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "jest",
"start": "vite",
"build": "vite build",
"lint": "eslint .",
"format": "prettier --check . --write",
"eject": "react-scripts eject"
"preview": "vite preview",
"test": "jest",
"format": "prettier --check . --write"
},
"options": {
"allowedHosts": ["localhost", ".localhost"],
"allowedHosts": [
"localhost",
".localhost"
],
"proxy": "http://localhost:8000"
},
"browserslist": {
Expand All @@ -46,12 +57,9 @@
]
},
"devDependencies": {
"@babel/preset-env": "^7.26.0",
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
"@tanstack/eslint-plugin-query": "^5.60.1",
"@testing-library/jest-dom": "^6.6.2",
"@types/jest": "^29.5.14",
"babel-jest": "^29.7.0",
"eslint": "^8.57.1",
"eslint-config-prettier": "^9.1.0",
"eslint-config-react-app": "^7.0.1",
Expand All @@ -60,6 +68,7 @@
"globals": "^15.11.0",
"jest": "^27.5.1",
"prettier": "^3.3.3",
"starknet": "^6.11.0"
"starknet": "^6.11.0",
"vite-plugin-svgr": "^4.3.0"
}
}
8 changes: 4 additions & 4 deletions frontend/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import Stake from './pages/stake/Stake';
import { TELEGRAM_BOT_LINK } from './utils/constants';
import { useCheckMobile } from './hooks/useCheckMobile';
import PositionHistory from './pages/position-history/PositionHistory';
import WithdrawAll from 'pages/spotnet/dashboard/withdraw-all/WithdrawAll';
import { DefiSpringPage } from 'pages/spotnet/defi-spring/DefiSpring';
import { AddDeposit } from 'pages/add-deposit/AddDeposit';
import WithdrawAll from './pages/spotnet/dashboard/withdraw-all/WithdrawAll';
import { DefiSpringPage } from './pages/spotnet/defi-spring/DefiSpring';
import { AddDeposit } from './pages/add-deposit/AddDeposit';

function App() {
const { setWalletId, removeWalletId } = useWalletStore();
Expand All @@ -34,7 +34,7 @@ function App() {
const [isMobileRestrictionModalOpen, setisMobileRestrictionModalOpen] = useState(true);
const isMobile = useCheckMobile();

const disableDesktopOnMobile = process.env.REACT_APP_DISABLE_DESKTOP_ON_MOBILE !== 'false';
const disableDesktopOnMobile = process.env.VITE_APP_DISABLE_DESKTOP_ON_MOBILE !== 'false';

const connectWalletMutation = useConnectWallet(setWalletId);

Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/dashboard/borrow/Borrow.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from 'react';
import './borrow.css';
import { ReactComponent as BorrowIcon } from 'assets/icons/borrow_dynamic.svg';
import BorrowIcon from '../../../assets/icons/borrow_dynamic.svg?react';

function Borrow({ data }) {
return (
<div className="tab-content">
<div className="borrow-tab-content">
<div className="balance-info">
<div className="currency-info">
{React.createElement(data[1]?.currencyIcon || BorrowIcon, {
Expand Down
1 change: 0 additions & 1 deletion frontend/src/components/dashboard/borrow/borrow.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
}

.currency-info {
margin-top: 1rem;
display: flex;
align-items: center;
}
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/components/dashboard/collateral/Collateral.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React from 'react';
import './collateral.css';
import { ReactComponent as CollateralIcon } from 'assets/icons/collateral_dynamic.svg';
import CollateralIcon from '../../../assets/icons/collateral_dynamic.svg?react';
import { TrendingDown, TrendingUp } from 'lucide-react';

function Collateral({ data, startSum, currentSum, getCurrentSumColor }) {
return (
<div className="tab-content">
<div className="collateral-tab-content">
<div className="balance-info">
<div className="currency-info">
{React.createElement(data[0]?.currencyIcon || CollateralIcon, {
Expand All @@ -26,7 +26,7 @@ function Collateral({ data, startSum, currentSum, getCurrentSumColor }) {
</span>
<span>
<span className="balance-label">Current sum: </span>
<span className={currentSum === 0 ? 'current-sum-green' : getCurrentSumColor()}>
<span className={currentSum >= 0 ? 'current-sum-green' : getCurrentSumColor()}>
<span className="currency-symbol">$</span>
{currentSum ? Number(currentSum).toFixed(8) : '0.00'}
{currentSum > startSum && currentSum !== 0 && <TrendingUp className="lucide-up-icon" />}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import './dashboardTabs.css';
import { ReactComponent as DepositIcon } from '../../../assets/icons/deposited_dynamic.svg';
import { ReactComponent as CollateralIcon } from '../../../assets/icons/collateral_dynamic.svg';
import { ReactComponent as BorrowIcon } from '../../../assets/icons/borrow_dynamic.svg';
import { DASHBOARD_TABS } from 'utils/constants';
import DepositIcon from '../../../assets/icons/deposited_dynamic.svg?react';
import CollateralIcon from '../../../assets/icons/collateral_dynamic.svg?react';
import BorrowIcon from '../../../assets/icons/borrow_dynamic.svg?react';
import { DASHBOARD_TABS } from '../../../utils/constants';

function DashboardTabs({ activeTab, switchTab }) {
const { COLLATERAL, BORROW, DEPOSITED } = DASHBOARD_TABS;
Expand Down
Loading
Loading