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

Implement FE of withdrawals #431

Draft
wants to merge 4 commits into
base: staging
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
23 changes: 3 additions & 20 deletions frontend/components/MainPage/sections/AddFundsSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ import {
Button,
Flex,
message,
Popover,
// QRCode,
Tooltip,
Typography,
} from 'antd';
import Link from 'next/link';
import { forwardRef, useCallback, useMemo, useRef, useState } from 'react';
import styled from 'styled-components';

import { UNICODE_SYMBOLS } from '@/constants/symbols';
import { COW_SWAP_GNOSIS_XDAI_OLAS_URL } from '@/constants/urls';
Expand All @@ -27,12 +25,6 @@ import { CardSection } from '../../styled/CardSection';

const { Text } = Typography;

const CustomizedCardSection = styled(CardSection)<{ border?: boolean }>`
> .ant-btn {
width: 50%;
}
`;

export const AddFundsSection = () => {
const fundSectionRef = useRef<HTMLDivElement>(null);
const [isAddFundsVisible, setIsAddFundsVisible] = useState(false);
Expand All @@ -47,25 +39,16 @@ export const AddFundsSection = () => {

return (
<>
<CustomizedCardSection gap={12} padding="24px">
<CardSection gap={12} padding="24px">
<Button
type="default"
size="large"
block
onClick={isAddFundsVisible ? closeAddFunds : addFunds}
>
{isAddFundsVisible ? 'Close instructions' : 'Add funds'}
</Button>

<Popover
placement="topRight"
trigger={['hover', 'click']}
content={<Text>Ability to withdraw is coming soon</Text>}
>
<Button type="default" size="large" disabled>
Withdraw
</Button>
</Popover>
</CustomizedCardSection>
</CardSection>

{isAddFundsVisible && <OpenAddFundsSection ref={fundSectionRef} />}
</>
Expand Down
102 changes: 102 additions & 0 deletions frontend/components/YourWalletPage/WithdrawFunds.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import { Button, Flex, Input, message, Modal, Typography } from 'antd';
import { isAddress } from 'ethers/lib/utils';
import React, { useCallback, useState } from 'react';

import { delayInSeconds } from '@/utils/delay';

import { CustomAlert } from '../Alert';

const { Text } = Typography;

export const WithdrawFunds = () => {
const [isModalVisible, setIsModalVisible] = useState(false);
const [amount, setAmount] = useState('');
const [isWithdrawalLoading, setIsWithdrawalLoading] = useState(false);

const showModal = useCallback(() => {
setIsModalVisible(true);
}, []);

const handleCancel = useCallback(() => {
setIsModalVisible(false);
setAmount('');
}, []);

const handleProceed = useCallback(async () => {
if (!amount) return;

const isValidAddress = isAddress(amount);
if (!isValidAddress) {
message.error('Please enter a valid address');
return;
}

message.loading('Withdrawal pending. It may take a few minutes.');

setIsWithdrawalLoading(true);
await delayInSeconds(2); // TODO: integrate with the backend
setIsWithdrawalLoading(false);

message.success('Transaction complete.');
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-fetch everything, including balances, wallet details, etc., to ensure it’s up-to-date.

}, [amount]);

return (
<>
<Button onClick={showModal} block style={{ fontSize: 14 }}>
Withdraw all funds
</Button>

<Modal
title="Withdraw Funds"
open={isModalVisible}
footer={null}
onCancel={handleCancel}
width={400}
destroyOnClose
>
<Flex vertical gap={16} style={{ marginTop: 12 }}>
<Text>
To proceed, enter the EVM-compatible wallet address where you’d like
to receive your funds. Funds will be sent on Gnosis Chain.
</Text>

<CustomAlert
type="warning"
showIcon
message={
<Text className="text-sm">
Ensure you have access to this wallet to avoid losing assets.
</Text>
}
/>

<Input
value={amount}
onChange={(e) => setAmount(e.target.value)}
placeholder="0x..."
size="small"
className="text-base"
style={{ padding: '6px 12px' }}
/>

<Button
disabled={!amount}
loading={isWithdrawalLoading}
onClick={handleProceed}
block
type="primary"
className="text-base"
>
Proceed
</Button>

<Text className="text-sm text-light">
After withdrawal, you won’t be able to run your agent until you fund
it with the required amounts again. Some funds may be locked in
prediction markets and cannot be withdrawn at this time.
</Text>
</Flex>
</Modal>
</>
);
};
10 changes: 9 additions & 1 deletion frontend/components/YourWalletPage/YourAgent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
SignerTitle,
XdaiTitle,
} from './Titles';
import { WithdrawFunds } from './WithdrawFunds';

const { Text, Paragraph } = Typography;

Expand Down Expand Up @@ -147,7 +148,7 @@ const ServiceAndNftDetails = () => {
);
};

export const YourAgentWallet = () => {
const YourAgentWalletBreakdown = () => {
const { isBalanceLoaded, agentSafeBalance, agentEoaBalance } = useBalance();
const {
availableRewardsForEpochEth,
Expand Down Expand Up @@ -232,3 +233,10 @@ export const YourAgentWallet = () => {
</Card>
);
};

export const YourAgentWallet = () => (
<>
<YourAgentWalletBreakdown />
<WithdrawFunds />
</>
);
Loading