Skip to content

Commit

Permalink
Merge branch 'main' into fix-reusable-sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
Dprof-in-tech authored Dec 19, 2024
2 parents 0d7d73c + 883c19b commit cc432f2
Show file tree
Hide file tree
Showing 52 changed files with 1,432 additions and 727 deletions.
1 change: 1 addition & 0 deletions frontend/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = {
},
moduleNameMapper: {
'\\.svg$': '<rootDir>/test/__mocks__/svgMock.js',
'\\.css$': '<rootDir>/test/__mocks__/styleMock.js',
'^src/(.*)$': ['<rootDir>/src/$1'],
},
transformIgnorePatterns: [
Expand Down
31 changes: 15 additions & 16 deletions frontend/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import { getTelegramUserWalletId } from 'services/telegram';
import Documentation from 'pages/spotnet/documentation/Documentation';
import Withdraw from 'pages/vault/withdraw/Withdraw';
import { useWalletStore } from 'stores/useWalletStore';
import { Notifier } from 'components/Notifier/Notifier';
import { Notifier, notify } from 'components/Notifier/Notifier';
import { useConnectWallet } from 'hooks/useConnectWallet';
import OverviewPage from 'pages/spotnet/overview/Overview';
import { ActionModal } from 'components/ui/ActionModal';
import Stake from 'pages/vault/stake/Stake';
import { TELEGRAM_BOT_LINK } from 'utils/constants';
import { useCheckMobile } from 'hooks/useCheckMobile';
import { notifyError } from 'utils/notification';
import PositionHistory from 'pages/spotnet/position_history/PositionHistory';


function App() {
Expand All @@ -34,7 +34,6 @@ function App() {

const connectWalletMutation = useConnectWallet(setWalletId);


const handleConnectWallet = () => {
connectWalletMutation.mutate();
};
Expand Down Expand Up @@ -65,14 +64,16 @@ function App() {

useEffect(() => {
if (window.Telegram?.WebApp?.initData) {
getTelegramUserWalletId(window.Telegram.WebApp.initDataUnsafe.user.id).then((linked_wallet_id) => {
setWalletId(linked_wallet_id);
window.Telegram.WebApp.ready();
}).catch((error) => {
console.error('Error getting Telegram user wallet ID:', error);
notifyError('Error loading wallet');
window.Telegram.WebApp.ready();
});
getTelegramUserWalletId(window.Telegram.WebApp.initDataUnsafe.user.id)
.then((linked_wallet_id) => {
setWalletId(linked_wallet_id);
window.Telegram.WebApp.ready();
})
.catch((error) => {
console.error('Error getting Telegram user wallet ID:', error);
notify('Error loading wallet', "error");
window.Telegram.WebApp.ready();
});
}
}, [window.Telegram?.WebApp?.initDataUnsafe]);

Expand All @@ -93,14 +94,11 @@ function App() {
/>,
document.body
)}
<Header
onConnectWallet={handleConnectWallet}
onLogout={handleLogoutModal}
/>
<Header onConnectWallet={handleConnectWallet} onLogout={handleLogoutModal} />
<main>
<Routes>
<Route index element={<SpotnetApp onConnectWallet={handleConnectWallet} onLogout={handleLogout} />} />
<Route
<Route
path="/login"
element={walletId ? <Navigate to="/" /> : <Login onConnectWallet={handleConnectWallet} />}
/>
Expand All @@ -109,6 +107,7 @@ function App() {
<Route path="/overview" element={<OverviewPage />} />
<Route path="/form" element={<Form />} />
<Route path="/documentation" element={<Documentation />} />
<Route path="/position-history" element={<PositionHistory />} />
<Route path="/stake" element={<Stake />} />
</Routes>
</main>
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/assets/icons/filter-horizontal.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions frontend/src/components/Card/card.css
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
.card {
width: 309px;
height: 101px;
background: var(--dark-background);
background: var(--bg);
border: 1px solid var(--light-purple);
border-radius: 900px;
border-radius: 12px;
padding-top: 4px;
padding-right: 24px;
padding-left: 24px;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/GasFee/GasFee.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import './gasfee.css';
export default function GasFee() {
return (
<div className="main-card-footer">
<div className="divider"></div>

<div className="gas-fee-container">
<div className="gas-fee-circle">
<SettingIcon className="gas-fee-icon" />
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/components/GasFee/gasfee.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
display: flex;
align-items: center;
justify-content: space-between;
padding: 0rem 3rem;
padding-bottom: 1rem;
}

.gas-fee-circle {
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/LendingForm.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React, { useCallback, useEffect, useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { getTokenBalances, sendTransaction } from 'services/wallet';
import { notifyError } from 'utils/notification';
import { axiosInstance } from 'utils/axios';
import Button from 'components/ui/Button/Button';
import { useWalletStore } from 'stores /useWalletStore';
import { notify } from './Notifier/Notifier';


const LendingForm = () => {
Expand All @@ -29,7 +29,7 @@ const navigate = useNavigate();
setBalances(tokenBalances);
} catch (error) {
console.error('Failed to fetch balances:', error);
notifyError('Failed to fetch token balances. Please try again.');
notify('Failed to fetch token balances. Please try again.', "error");
}
}, [walletId]);

Expand Down
3 changes: 1 addition & 2 deletions frontend/src/components/MultiplierSelector.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import './multiplier.css';
const MultiplierSelector = ({ setSelectedMultiplier, selectedToken }) => {
const minMultiplier = 1.1;

const { data, isLoading, error } = useMaxMultiplier();
const { data, isLoading } = useMaxMultiplier();
const [actualValue, setActualValue] = useState(minMultiplier);
const sliderRef = useRef(null);
const isDragging = useRef(false);
Expand Down Expand Up @@ -104,7 +104,6 @@ const MultiplierSelector = ({ setSelectedMultiplier, selectedToken }) => {
}, [maxMultiplier, actualValue, setSelectedMultiplier]);

if (isLoading) return <div className="slider-skeleton">Loading multiplier data...</div>;
if (error) return <div className="error-message">Error loading multiplier data: {error.message}</div>;

return (
<div className="multiplier-card">
Expand Down
19 changes: 16 additions & 3 deletions frontend/src/components/Notifier/Notifier.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,27 @@ import React from 'react';
import { ToastContainer, toast } from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';

const notify = (message) => toast(message);
const defaultStyles = {
success: { backgroundColor: 'green', color: 'white' },
error: { backgroundColor: 'red', color: 'white' },
warning: { backgroundColor: 'orange', color: 'white' },
info: { backgroundColor: 'blue', color: 'white' },
};

const ToastWithLink = (message, link, linkMessage) => (
<div>
<span>{message}</span> <a target='_blank' href={link}>{linkMessage}</a>
</div>
);

const notify = (message, type='info', autoClose=3000) => toast(message, { type, autoClose, style: defaultStyles[type] || defaultStyles.info });

const Notifier = () => {
return (
<div>
<ToastContainer />
<ToastContainer position='top-center' />
</div>
);
};

export { Notifier, notify };
export { Notifier, notify, ToastWithLink};
3 changes: 2 additions & 1 deletion frontend/src/components/SlideBarFour.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useState, useCallback, useMemo } from 'react';
import { useMaxMultiplier } from 'hooks/useMaxMultiplier';
import './slider-three.css';
import { notify } from 'components/Notifier/Notifier';

const StepSlider = ({ min = 0, max = 10, step = 1, defaultValue = 1, setSelectedMultiplier, selectedToken }) => {
const { data, isLoading, error } = useMaxMultiplier();
Expand Down Expand Up @@ -34,7 +35,7 @@ const StepSlider = ({ min = 0, max = 10, step = 1, defaultValue = 1, setSelected
}, [value, maxMultiplier, TOTAL_MARKS]);

if (isLoading) return <div className="slider-skeleton">Loading multiplier data...</div>;
if (error) return <div className="error-message">Error loading multiplier data: {error.message}</div>;
if (error) return notify(error.message, 'error');

const currentMark = getCurrentMark();

Expand Down
4 changes: 3 additions & 1 deletion frontend/src/components/StakeCard/metricCard.css
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
.stake-card {
width: 309px;

background: var(--header-button-bg);
border: var(--midnight-purple-border);
border-radius: 900px;
border-radius: 999px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;

}

.stake-card .img {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/WalletSection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const WalletSection = ({ onConnectWallet, onLogout }) => {
onLogout();
}}
>
Log out
Disconnect
</button>
</div>
)}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/collateral/Collateral.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function Collateral({ data, startSum, currentSum, getCurrentSumColor }) {
<span className="currency-name">{data[0]?.currencyName || 'N/A'}</span>
</div>
<span>
<span className="balance-label">Balance: </span>
<span className="balance-label">Position Balance: </span>
<span className="balance-value">{data[0]?.balance ? Number(data[0].balance).toFixed(8) : '0.00'}</span>
</span>
<span>
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/components/ui/Button/button.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
border: none;
cursor: pointer;
font-weight: 600;
border-radius: 900px;
border-radius: 8px;
transition: all 0.2s ease-in-out;
display: flex;
justify-content: center;
Expand Down Expand Up @@ -71,7 +71,7 @@
left: 0;
right: 0;
bottom: 0;
border-radius: 50px;
border-radius: 8px;
padding: 2px;
background: linear-gradient(90deg, #74d6fd 0%, #e01dee 100%);
-webkit-mask:
Expand Down Expand Up @@ -101,15 +101,15 @@

@media (max-width: 768px) {
.button {
border-radius: 16px;
border-radius: 8px;
}

.button--primary {
padding: 20px 12px;
}

.button--secondary::before {
border-radius: 16px;
border-radius: 8px;
}

.button--lg {
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
--gray: #83919f;
--dark-purple: #120721;
--light-blue: #74d5fd;
--status-opened: #1edc9e;
--status-closed: #433b5a;
--status-pending: #83919f;
--slider-gray: #393942;
--light-blue: #88b4fa;
--thumb-image: url('./assets/icons/slider-thumb.svg');
Expand All @@ -63,6 +66,7 @@
--dark-background: #130713;
--light-dark-background: #130713;
--text-gray: #798795;
--modal-border: #170f2e;
}

body {
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/hooks/useClosePosition.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useMutation, useQuery } from '@tanstack/react-query';
import { axiosInstance } from 'utils/axios';
import { closePosition } from 'services/transaction';
import { useWalletStore } from 'stores/useWalletStore';
import { notify } from 'components/Notifier/Notifier';

export const useClosePosition = () => {
const { walletId } = useWalletStore();
Expand All @@ -18,6 +19,7 @@ export const useClosePosition = () => {
},
onError: (error) => {
console.error('Error during closePositionEvent', error);
notify(`Error during closePositionEvent: ${error.message}`, 'error')
},
});
};
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/hooks/useConnectWallet.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useMutation } from '@tanstack/react-query';
import { notify } from 'components/Notifier/Notifier';
import { connectWallet, checkForCRMToken } from 'services/wallet';
import { notifyError } from 'utils/notification';

export const useConnectWallet = (setWalletId) => {
return useMutation({
Expand All @@ -22,7 +22,7 @@ export const useConnectWallet = (setWalletId) => {
},
onError: (error) => {
console.error('Wallet connection failed:', error);
notifyError('Failed to connect wallet. Please try again.');
notify('Failed to connect wallet. Please try again.', "error");
},
});
};
6 changes: 4 additions & 2 deletions frontend/src/hooks/useMaxMultiplier.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import { useQuery } from '@tanstack/react-query';
import { ONE_HOUR_IN_MILLISECONDS } from '../utils/constants';
import { axiosInstance } from 'utils/axios';
import { notify } from 'components/Notifier/Notifier';

export const useMaxMultiplier = () => {
const { data, isPending, error } = useQuery({
const { data, isPending } = useQuery({
queryKey: ['max-multiplier'],
queryFn: async () => {
const response = await axiosInstance.get(`/api/get-multipliers`);
return response.data.multipliers;
},
staleTime: ONE_HOUR_IN_MILLISECONDS,
refetchInterval: ONE_HOUR_IN_MILLISECONDS,
onError: (error) => notify(`Error using multiplier: ${error.message}`, 'error')
});

return { data, isLoading: isPending, error };
return { data, isLoading: isPending };
};
Loading

0 comments on commit cc432f2

Please sign in to comment.