Skip to content

Commit

Permalink
update confirm dialog, remove auto vote
Browse files Browse the repository at this point in the history
  • Loading branch information
vidvidvid committed Jan 8, 2025
1 parent ba635de commit a3a3e09
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 72 deletions.
16 changes: 0 additions & 16 deletions packages/ui/app/veion/governance/vote/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ const Vote: React.FC = () => {
const initialId = searchParams.get('id') || lockedData[0].id;

const [showPendingOnly, setShowPendingOnly] = useState<boolean>(false);
const [showAutoOnly, setShowAutoOnly] = useState<boolean>(false);
const { currentChain } = useVeIONContext();

const selectedData = useMemo(
() => lockedData.find((item) => item.id === initialId),
Expand Down Expand Up @@ -97,19 +95,6 @@ const Vote: React.FC = () => {
<CardHeader className="flex flex-col md:flex-row md:items-center md:justify-between">
<CardTitle>Emissions Management</CardTitle>
<div className="flex items-center space-x-2 mt-2 md:mt-0">
<label
htmlFor="pending-votes"
className="text-sm text-white/80"
>
Auto vote only
</label>
<Switch
id="pending-votes"
checked={showAutoOnly}
onCheckedChange={setShowAutoOnly}
className="data-[state=checked]:bg-green-500 "
aria-label="Toggle auto votes only"
/>
<label
htmlFor="pending-votes"
className="text-sm text-white/80 pl-4"
Expand All @@ -129,7 +114,6 @@ const Vote: React.FC = () => {
<EmissionsProvider>
<EmissionsManagement
tokenId={0}
showAutoOnly={showAutoOnly}
showPendingOnly={showPendingOnly}
/>
</EmissionsProvider>
Expand Down
20 changes: 1 addition & 19 deletions packages/ui/components/veion/EmissionsManagement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,13 @@ import TokenBalance from '../markets/Cells/TokenBalance';

interface EmissionsManagementTableProps {
tokenId: number;
showAutoOnly: boolean;
showPendingOnly: boolean;
}

type AssetTypeFilter = 'all' | 'supply' | 'borrow';

function EmissionsManagement({
tokenId,
showAutoOnly,
showPendingOnly
}: EmissionsManagementTableProps) {
const { currentChain } = useVeIONContext();
Expand Down Expand Up @@ -67,11 +65,6 @@ function EmissionsManagement({
return false;
}

// Filter for auto votes if showAutoOnly is true
if (showAutoOnly && !row.autoVote) {
return false;
}

// Filter for pending votes if showPendingOnly is true
if (showPendingOnly && row.voteValue !== '') {
return false;
Expand All @@ -87,7 +80,7 @@ function EmissionsManagement({

return true;
});
}, [marketRows, showAutoOnly, showPendingOnly, searchTerm, assetTypeFilter]);
}, [marketRows, showPendingOnly, searchTerm, assetTypeFilter]);

const columns = useMemo<EnhancedColumnDef<VoteMarketRow>[]>(
() => [
Expand Down Expand Up @@ -199,17 +192,6 @@ function EmissionsManagement({
isDisabled={isVoting}
/>
)
},
{
id: 'autoVote',
header: 'AUTO VOTE',
cell: ({ row }) => (
<Checkbox
checked={row.original.autoVote}
disabled={isVoting}
className="data-[state=checked]:bg-green-500"
/>
)
}
],
[isVoting]
Expand Down
21 changes: 1 addition & 20 deletions packages/ui/components/veion/EmissionsManagementFooter.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useState } from 'react';
import { Card } from '@ui/components/ui/card';
import { Checkbox } from '@ui/components/ui/checkbox';
import { useEmissionsContext } from '@ui/context/EmissionsManagementContext';
import VoteConfirmationDialog from './VoteConfirmationDialog';
import { MarketSide } from '@ui/hooks/veion/useVeIONVote';
Expand All @@ -15,7 +14,6 @@ function EmissionsManagementFooter({
isVoting = false
}: EmissionsManagementFooterProps) {
const { votes, resetVotes, marketRows } = useEmissionsContext();
const [autoRepeat, setAutoRepeat] = useState(false);
const [showConfirmation, setShowConfirmation] = useState(false);
const hasVotes = Object.keys(votes).length > 0;

Expand All @@ -28,7 +26,6 @@ function EmissionsManagementFooter({
marketAddress: row.marketAddress,
side: row.side,
voteValue: row.voteValue,
autoVote: row.autoVote,
asset: row.asset
};
}
Expand All @@ -40,15 +37,13 @@ function EmissionsManagementFooter({
marketAddress: `0x${string}`;
side: MarketSide;
voteValue: string;
autoVote: boolean;
asset: string;
}
>
);

const handleFullReset = () => {
resetVotes();
setAutoRepeat(false);
};

const handleVoteClick = () => {
Expand All @@ -65,21 +60,7 @@ function EmissionsManagementFooter({
return (
<>
<Card className="fixed bottom-4 left-4 right-4 p-4 bg-[#35363D] border-t border-white/10 z-10">
<div className="flex items-center justify-between max-w-7xl mx-auto">
<div className="flex items-center gap-4">
<Checkbox
id="auto-repeat"
checked={autoRepeat}
onCheckedChange={(checked) => setAutoRepeat(checked as boolean)}
disabled={isVoting}
/>
<label
htmlFor="auto-repeat"
className={`text-sm text-white/80 cursor-pointer ${isVoting ? 'opacity-50' : ''}`}
>
Auto-repeat this voting choice each future period
</label>
</div>
<div className="flex justify-end w-full">
<div className="flex items-center gap-4">
<button
onClick={handleFullReset}
Expand Down
42 changes: 29 additions & 13 deletions packages/ui/components/veion/VoteConfirmationDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
AlertDialogTitle
} from '@ui/components/ui/alert-dialog';
import { ScrollArea } from '@ui/components/ui/scroll-area';
import { Check, X } from 'lucide-react';
import { Info } from 'lucide-react';
import Image from 'next/image';
import { MarketSide } from '@ui/hooks/veion/useVeIONVote';

type VoteRecord = Record<
Expand All @@ -19,7 +20,6 @@ type VoteRecord = Record<
marketAddress: `0x${string}`;
side: MarketSide;
voteValue: string;
autoVote: boolean;
asset: string;
}
>;
Expand All @@ -44,7 +44,11 @@ const VoteConfirmationDialog: React.FC<VoteConfirmationDialogProps> = ({
return (
<AlertDialog
open={isOpen}
onOpenChange={onClose}
onOpenChange={(open) => {
if (!isVoting) {
onClose();
}
}}
>
<AlertDialogContent className="max-w-2xl">
<AlertDialogHeader>
Expand All @@ -54,7 +58,15 @@ const VoteConfirmationDialog: React.FC<VoteConfirmationDialogProps> = ({
</AlertDialogDescription>
</AlertDialogHeader>

<ScrollArea className="h-96 rounded-md border border-white/10 my-4">
<div className="flex items-center gap-2 p-4 rounded-lg bg-blue-500/10 border border-blue-500/20">
<Info className="h-4 w-4 text-blue-500" />
<p className="text-sm text-blue-100">
Your choices will automatically apply to future epochs unless
modified
</p>
</div>

<ScrollArea className="h-96 rounded-md border border-white/10">
<div className="p-4">
<div className="space-y-4">
{voteEntries.map(([key, vote]) => (
Expand All @@ -64,6 +76,13 @@ const VoteConfirmationDialog: React.FC<VoteConfirmationDialogProps> = ({
>
<div className="flex flex-col gap-1">
<div className="flex items-center gap-2">
<Image
src={`/img/symbols/32/color/${vote.asset.toLowerCase()}.png`}
alt={vote.asset}
width={24}
height={24}
className="rounded-full"
/>
<span className="text-sm font-medium text-white/90">
{vote.asset}
</span>
Expand All @@ -82,14 +101,6 @@ const VoteConfirmationDialog: React.FC<VoteConfirmationDialogProps> = ({
<span className="text-sm font-medium text-white/90">
{vote.voteValue}%
</span>
<div className="flex items-center gap-1 text-xs text-white/60">
Auto Vote:
{vote.autoVote ? (
<Check className="w-4 h-4 text-green-500" />
) : (
<X className="w-4 h-4 text-red-500" />
)}
</div>
</div>
</div>
</div>
Expand All @@ -99,7 +110,12 @@ const VoteConfirmationDialog: React.FC<VoteConfirmationDialogProps> = ({
</ScrollArea>

<AlertDialogFooter>
<AlertDialogCancel disabled={isVoting}>Cancel</AlertDialogCancel>
<AlertDialogCancel
disabled={isVoting}
className="hover:bg-gray-900"
>
Cancel
</AlertDialogCancel>
<AlertDialogAction
onClick={async (e) => {
e.preventDefault();
Expand Down
4 changes: 0 additions & 4 deletions packages/ui/context/EmissionsManagementContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ type MarketMetrics = {
percentage: string;
value: string;
};
autoVote: boolean;
voteValue: string;
};

Expand All @@ -53,7 +52,6 @@ export type VoteMarketRow = {
percentage: string;
value: string;
};
autoVote: boolean;
voteValue: string;
};

Expand Down Expand Up @@ -124,7 +122,6 @@ export const EmissionsProvider: React.FC<{
percentage: (Math.random() * 50).toFixed(2) + '%',
value: (Math.random() * 10000).toFixed(0)
},
autoVote: Math.random() > 0.5,
voteValue: ''
};

Expand All @@ -144,7 +141,6 @@ export const EmissionsProvider: React.FC<{
percentage: (Math.random() * 50).toFixed(2) + '%',
value: (Math.random() * 10000).toFixed(0)
},
autoVote: Math.random() > 0.5,
voteValue: ''
};

Expand Down

0 comments on commit a3a3e09

Please sign in to comment.