|
1 | 1 | import React, { useEffect, useState } from "react"; |
2 | | -import { Activity, AlertCircle, ShieldCheck, TrendingUp, Wallet as WalletIcon, Loader2, Info } from "./icons"; |
| 2 | +import { useSearchParams } from "react-router-dom"; |
| 3 | +import { |
| 4 | + Activity, |
| 5 | + AlertCircle, |
| 6 | + ShieldCheck, |
| 7 | + TrendingUp, |
| 8 | + Wallet as WalletIcon, |
| 9 | + Loader2, |
| 10 | + Info, |
| 11 | + Share2 |
| 12 | +} from "./icons"; |
3 | 13 | import Skeleton from "./Skeleton"; |
4 | 14 | import { useVault } from "../context/VaultContext"; |
5 | 15 | import ApiStatusBanner from "./ApiStatusBanner"; |
6 | 16 | import VaultPerformanceChart from "./VaultPerformanceChart"; |
7 | 17 | import { useToast } from "../context/ToastContext"; |
8 | 18 | import { Tabs, TabsContent, TabsList, TabsTrigger } from "./Tabs"; |
9 | | -import { FormField } from "../forms"; |
10 | | -import WithdrawalConfirmationModal from "./WithdrawalConfirmationModal"; |
11 | 19 | import { FormField, SubmitButton } from "../forms"; |
| 20 | +import WithdrawalConfirmationModal from "./WithdrawalConfirmationModal"; |
12 | 21 | import { useDepositMutation, useWithdrawMutation } from "../hooks/useVaultMutations"; |
13 | 22 | import TransactionStatus, { type ActionStatus } from "./TransactionStatus"; |
14 | 23 | import CopyButton from "./CopyButton"; |
15 | | -import { |
16 | | - useDepositMutation, |
17 | | - useWithdrawMutation, |
18 | | -} from "../hooks/useVaultMutations"; |
| 24 | +import { copyTextToClipboard } from "../lib/clipboard"; |
19 | 25 |
|
20 | 26 | interface VaultDashboardProps { |
21 | 27 | walletAddress: string | null; |
@@ -145,6 +151,19 @@ const VaultDashboard: React.FC<VaultDashboardProps> = ({ |
145 | 151 | const depositMutation = useDepositMutation(); |
146 | 152 | const withdrawMutation = useWithdrawMutation(); |
147 | 153 |
|
| 154 | + const [searchParams] = useSearchParams(); |
| 155 | + |
| 156 | + useEffect(() => { |
| 157 | + const amountParam = searchParams.get("amount"); |
| 158 | + if (amountParam) { |
| 159 | + const val = Number(amountParam); |
| 160 | + if (!Number.isNaN(val) && val > 0) { |
| 161 | + setAmount(val.toString()); |
| 162 | + setActiveTab("deposit"); |
| 163 | + } |
| 164 | + } |
| 165 | + }, [searchParams]); |
| 166 | + |
148 | 167 | useEffect(() => { |
149 | 168 | const handleTrigger = () => { |
150 | 169 | setActiveTab("deposit"); |
@@ -547,7 +566,41 @@ const VaultDashboard: React.FC<VaultDashboardProps> = ({ |
547 | 566 | /> |
548 | 567 |
|
549 | 568 | <div className="flex justify-between items-center" style={{ margin: "16px 0 24px" }}> |
550 | | - <span style={{ color: "var(--text-secondary)", fontSize: "0.85rem" }}>Asset: USDC</span> |
| 569 | + <div className="flex items-center gap-sm"> |
| 570 | + <span style={{ color: "var(--text-secondary)", fontSize: "0.85rem" }}>Asset: USDC</span> |
| 571 | + {tab === "deposit" && ( |
| 572 | + <> |
| 573 | + <div style={{ width: "1px", height: "14px", background: "var(--border-glass)", margin: "0 4px" }} /> |
| 574 | + <button |
| 575 | + type="button" |
| 576 | + className="btn-link flex items-center gap-xs" |
| 577 | + style={{ fontSize: "0.75rem", color: "var(--accent-cyan)", padding: 0 }} |
| 578 | + onClick={async () => { |
| 579 | + const baseUrl = window.location.origin + window.location.pathname; |
| 580 | + const shareUrl = amount && !isNaN(Number(amount)) && Number(amount) > 0 |
| 581 | + ? `${baseUrl}?amount=${amount}` |
| 582 | + : baseUrl; |
| 583 | + |
| 584 | + try { |
| 585 | + await copyTextToClipboard(shareUrl); |
| 586 | + toast.success({ |
| 587 | + title: "Link copied", |
| 588 | + description: "Shareable vault link is ready to paste." |
| 589 | + }); |
| 590 | + } catch (err) { |
| 591 | + toast.error({ |
| 592 | + title: "Copy failed", |
| 593 | + description: "Could not copy link to clipboard." |
| 594 | + }); |
| 595 | + } |
| 596 | + }} |
| 597 | + > |
| 598 | + <Share2 size={12} /> |
| 599 | + Share Link |
| 600 | + </button> |
| 601 | + </> |
| 602 | + )} |
| 603 | + </div> |
551 | 604 | <button |
552 | 605 | type="button" |
553 | 606 | className="btn-max" |
|
0 commit comments