Skip to content

Commit

Permalink
wallet sidebar: add ongoing task card
Browse files Browse the repository at this point in the history
  • Loading branch information
sehyunc committed Nov 17, 2024
1 parent be356ae commit 7618a6f
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/components/wallet-sidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ConnectWalletMenuItem } from "@/app/components/wallet-sidebar/connect-w
import { PWADialog } from "@/app/components/wallet-sidebar/pwa-dialog"
import { RecentFillsMenuItem } from "@/app/components/wallet-sidebar/recent-fills-menu-item"
import { RenegadeWalletActionsDropdown } from "@/app/components/wallet-sidebar/renegade-wallet-actions-dropdown"
import { RunningTaskCard } from "@/app/components/wallet-sidebar/running-task-card"
import { SolanaWalletActionsDropdown } from "@/app/components/wallet-sidebar/solana-wallet-actions-dropdown"
import { ConnectContent } from "@/app/components/wallet-sidebar/solana/connect-content"
import { WalletButton } from "@/app/components/wallet-sidebar/wallet-button"
Expand Down Expand Up @@ -88,6 +89,7 @@ export function WalletSidebar({
</SidebarMenu>
</SidebarGroup>
<SidebarGroup className="mt-auto">
<RunningTaskCard />
<SidebarGroupLabel>Bridge & Deposit</SidebarGroupLabel>
{solanaWallet.isConnected ? (
<WalletButton
Expand Down
67 changes: 67 additions & 0 deletions app/components/wallet-sidebar/running-task-card.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { useEffect, useState } from "react"

import { Task, useTaskHistoryWebSocket } from "@renegade-fi/react"

import {
Card,
CardDescription,
CardHeader,
CardTitle,
} from "@/components/ui/card"

import {
generateCompletionToastMessage,
generateStartToastMessage,
} from "@/lib/constants/task"

export function RunningTaskCard() {
const [visibleTask, setVisibleTask] = useState<Task | null>(null)
useTaskHistoryWebSocket({
onUpdate(task) {
if (task.state !== "Queued") {
setVisibleTask(task)
}
},
})

useEffect(() => {
if (!visibleTask) return

if (visibleTask.state === "Completed" || visibleTask.state === "Failed") {
const timer = setTimeout(() => {
setVisibleTask(null)
}, 60000)

return () => clearTimeout(timer)
}
}, [visibleTask])

if (!visibleTask) return null

const status = visibleTask.state
const isRunning = status !== "Completed" && status !== "Failed"
const description = isRunning
? generateStartToastMessage(visibleTask)
: generateCompletionToastMessage(visibleTask)

return (
<div className="p-1">
<Card className="rounded-none shadow-none">
<form>
<CardHeader className="p-3">
<CardTitle className="text-sm font-normal">
{isRunning ? (
<span className="inline-flex animate-text-gradient bg-gradient-to-r from-[#ACACAC] via-[#363636] to-[#ACACAC] bg-[200%_auto] bg-clip-text text-transparent">
{status}
</span>
) : (
<span>{status}</span>
)}
</CardTitle>
<CardDescription>{description}</CardDescription>
</CardHeader>
</form>
</Card>
</div>
)
}
13 changes: 13 additions & 0 deletions tailwind.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,13 @@ const config = {
},
green: {
price: "#43e043",
400: "#4ade80",
500: "#22c55e",
},
red: {
price: "#e04343",
400: "#f87171",
500: "#ef4444",
},
yellow: "hsl(var(--chart-yellow))",
blue: "hsl(var(--chart-blue))",
Expand Down Expand Up @@ -156,6 +160,14 @@ const config = {
opacity: "1",
},
},
"text-gradient": {
from: {
backgroundPosition: "200% center",
},
to: {
backgroundPosition: "0% center",
},
},
},
animation: {
"accordion-down": "accordion-down 0.2s ease-out",
Expand All @@ -165,6 +177,7 @@ const config = {
"shimmer-button": "shimmer-button 45s ease infinite",
marquee: "marquee var(--duration) linear infinite",
ellipsis: "ellipsis 1.5s ease-in-out infinite",
"text-gradient": "text-gradient 1.3s linear infinite",
},
},
},
Expand Down

0 comments on commit 7618a6f

Please sign in to comment.