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

feat(frontend): add WithdrawAll component and route #409

Merged
merged 10 commits into from
Dec 21, 2024
2 changes: 2 additions & 0 deletions frontend/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ 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';
import WithdrawAll from 'pages/spotnet/dashboard/withdraw-all/WithdrawAll';


function App() {
Expand Down Expand Up @@ -110,6 +111,7 @@ function App() {
<Route path="/documentation" element={<Documentation />} />
<Route path="/position-history" element={<PositionHistory />} />
<Route path="/stake" element={<Stake />} />
<Route path="/dashboard/withdraw-all" element={<WithdrawAll />} />
</Routes>
</main>
<Footer />
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
--light-dark-background: #130713;
--text-gray: #798795;
--modal-border: #170f2e;
--warning-colour:rgba(255, 251, 0, 0.84);
--warning-colour-alt: rgb(70, 70, 1);
1nonlypiece marked this conversation as resolved.
Show resolved Hide resolved
}

body {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/forms/form.css
1nonlypiece marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ input[type='number'].error {
width: 198px;
height: 101px;
align-items: center;
border-radius: 900px;
border-radius: 16px;
border: 1px solid var(--light-purple);
justify-content: center;
background-color: var(--dark-purple);
Expand Down
70 changes: 70 additions & 0 deletions frontend/src/pages/spotnet/dashboard/withdraw-all/WithdrawAll.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import React, { useState } from 'react';
import BalanceCards from 'components/BalanceCards';
import { ReactComponent as ETH } from '../../../../assets/icons/ethereum.svg';
import { ReactComponent as USDC } from '../../../../assets/icons/borrow_usdc.svg';
import { ReactComponent as STRK } from '../../../../assets/icons/strk.svg';
import './withdraw_all.css';
import { useWalletStore } from 'stores/useWalletStore';
import Button from 'components/ui/Button/Button';
import { ReactComponent as AlertHexagon } from 'assets/icons/alert_hexagon.svg';
import { axiosInstance } from 'utils/axios';

const WithdrawAll = () => {
const { walletId } = useWalletStore();
const [balances, setBalances] = useState([
{ icon: <ETH />, title: 'ETH', balance: '0.00' },
{ icon: <USDC />, title: 'USDC', balance: '0.00' },
{ icon: <STRK />, title: 'STRK', balance: '0.00' },
]);
1nonlypiece marked this conversation as resolved.
Show resolved Hide resolved
const [loading, setLoading] = useState(false);
const [error, setError] = useState(null);

const handleWithdrawAll = async () => {
setLoading(true);
setError(null);

try {
const response = await axiosInstance.get(`/api/withdraw-all?wallet_id=${walletId}`);
console.log(response);
if (response.status === 200) {
console.log('Withdraw All operation completed successfully.');
} else {
console.log('Failed to complete the Withdraw All operation.');
}
} catch (error) {
console.error('Error during Withdraw All operation:', error);
setError('Something went wrong. Please try again.');
} finally {
setLoading(false);
}
};
whateverfw marked this conversation as resolved.
Show resolved Hide resolved

return (
<div className="withdrawall-wrapper">
<div className="withdrawall-container">
<BalanceCards balances={balances} setBalances={setBalances} walletId={walletId} />
1nonlypiece marked this conversation as resolved.
Show resolved Hide resolved
<div className="withdrawall-info-card">
1nonlypiece marked this conversation as resolved.
Show resolved Hide resolved
Clicking on the `Withdraw All` button means you are agreeing to close all positions and get all tokens
transferred to your wallet.
</div>
<Button
className="withdrawall-btn"
variant="secondary"
size="lg"
type="button"
onClick={handleWithdrawAll}
disabled={loading}
>
{loading ? 'Processing...' : 'Withdraw All'}
</Button>
{error && (
<div className="error-message">
Error: {error} <AlertHexagon className="form-alert-hex" />
</div>
)}
</div>
</div>
);
};

export default WithdrawAll;
198 changes: 198 additions & 0 deletions frontend/src/pages/spotnet/dashboard/withdraw-all/withdraw_all.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
body {
font-family:
'Rethink Sans',
-apple-system,
Roboto,
Helvetica,
sans-serif;
}
1nonlypiece marked this conversation as resolved.
Show resolved Hide resolved

.withdrawall-wrapper {
position: relative;
background: url('../../../../../public/Form-bg.png') no-repeat;
background-size: cover;
background-position: center left;
min-height: 100vh;
display: flex;
justify-content: center;
align-items: flex-start;
padding: 1rem 0;
}

.withdrawall-container {
display: flex;
flex-direction: column;
justify-content: center;
gap: 10px;
padding: 0 24px;
padding-top: 20px;
}

.withdrawall-content {
width: 642px;
gap: 24px;
border-radius: 8px;
padding: 1rem 0;
color: var(--second-primary);
text-align: center;
display: flex;
justify-content: center;
flex-direction: column;
align-items: center;
}

.withdrawall-info-card {
background: var(--warning-colour-alt);
border: 1px solid var(--warning-colour);
color: var(--second-primary);
text-align: center;
border-radius: 8px;
width: 642px;
height: 98px;
padding: 8px 16px;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
gap: 20px;
margin-top: 52px;
margin-bottom: 52px;
}
.withdrawall-btn {
border-radius: 4px;
}

.error-message {
padding: 10px;
border-radius: 5px;
background-color: var(--error-color);
font-size: 15px;
color: var(--black);
margin-bottom: 5px;
width: 100%;
display: flex;
justify-content: space-between;
}

@media (max-width: 768px) {
.withdrawall-wrapper {
padding: 1rem 0;
}

.withdrawall-container {
width: 100%;
max-width: 100%;
margin: 0 auto;
box-sizing: border-box;
}

.withdrawall-content {
width: 100%;
max-width: 100%;
padding: 0.5rem 0;
gap: 16px;
}

.withdrawall-btn {
border-radius: 8px;
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 55px;
}

.withdrawall-info-card {
height: 98px;
border-radius: 8px;
width: 100%;
margin-top: 52px;
margin-bottom: 52px;
}
}

@media (max-width: 550px) {
.withdrawall-wrapper {
background: url('../../../../../public/dashboardmobile.png') no-repeat;
background-size: cover;
background-position: 50% 40%;
height: 100%;
}
.withdrawall-content {
gap: 40px;
display: flex;
justify-content: center;
flex-direction: column;
align-items: center;
}
.withdrawall-info-container {
display: grid;
gap: 30px;
padding-bottom: 40px;
}
.withdrawall-info-container {
width: 100%;
}
.withdrawall-info-card {
padding: 16px 24px;
height: 128px;
font-size: medium;
width: 100%;
border-radius: 8px;
gap: 0;
}

.withdrawall-btn {
width: 100%;
}
}

@media (max-width: 480px) {
.withdrawall-info-container {
width: 100%;
}
.withdrawall-info-card {
font-size: x-small;
padding: 16px 24px;
width: 100%;
}

.withdrawall-btn {
width: 100%;
font-size: 14px;
height: 50px;
}

.tab {
padding: 6px 0px;
font-size: 12px;
}
}

@media (max-width: 400px) {
.withdrawall-info-container {
width: 100%;
}

.withdrawall-btn {
width: 100%;
height: 45px;
}

.withdrawall-info-card {
padding: 16px 24px;
width: 100%;
}
}

@media (max-width: 350px) {

.withdrawall-btn {
width: 100%;
height: 45px;
}

.withdrawall-info-card {
width: 100%;
}
}
Loading