Skip to content
This repository was archived by the owner on Dec 24, 2025. It is now read-only.

Commit 1a83951

Browse files
committed
added cleanup expired proposals
1 parent 1aa85a4 commit 1a83951

6 files changed

Lines changed: 119 additions & 0 deletions

File tree

src/components/admin/AirdropAdmin.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,15 @@ export function AirdropAdmin() {
5555
isLoading,
5656
tgeStatus,
5757
initiateTGE,
58+
cleanupExpiredProposals,
5859
} = useAdminContract()
5960

6061
const [isCreatingCap, setIsCreatingCap] = useState(false)
6162
const [isAddingWallet, setIsAddingWallet] = useState(false)
6263
const [isApproving, setIsApproving] = useState(false)
6364
const [isExecuting, setIsExecuting] = useState(false)
6465
const [isSettingTGE, setIsSettingTGE] = useState(false)
66+
const [isCleaning, setIsCleaning] = useState(false)
6567

6668
const handleCreateCap = async () => {
6769
try {
@@ -174,6 +176,18 @@ export function AirdropAdmin() {
174176
}
175177
}
176178

179+
const handleCleanupExpiredProposals = async () => {
180+
try {
181+
setError(null)
182+
setIsCleaning(true)
183+
await cleanupExpiredProposals(10)
184+
} catch (error: any) {
185+
setError(error.message)
186+
} finally {
187+
setIsCleaning(false)
188+
}
189+
}
190+
177191
const renderVestingCapTable = () => {
178192
if (isLoading) {
179193
return <CircularProgress />
@@ -599,6 +613,14 @@ export function AirdropAdmin() {
599613
</TableBody>
600614
</Table>
601615
</TableContainer>
616+
<Button
617+
variant="contained"
618+
onClick={handleCleanupExpiredProposals}
619+
disabled={isCleaning}
620+
sx={{ mt: 2 }}
621+
>
622+
{isCleaning ? <CircularProgress size={24} /> : 'Cleanup Expired Proposals'}
623+
</Button>
602624
</AccordionDetails>
603625
</Accordion>
604626
</Box>

src/components/admin/TestnetMiningAdmin.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,15 @@ export function TestnetMiningAdmin() {
5555
isLoading,
5656
tgeStatus,
5757
initiateTGE,
58+
cleanupExpiredProposals,
5859
} = useAdminContract()
5960

6061
const [isCreatingCap, setIsCreatingCap] = useState(false)
6162
const [isAddingWallet, setIsAddingWallet] = useState(false)
6263
const [isApproving, setIsApproving] = useState(false)
6364
const [isExecuting, setIsExecuting] = useState(false)
6465
const [isSettingTGE, setIsSettingTGE] = useState(false)
66+
const [isCleaning, setIsCleaning] = useState(false)
6567

6668
const handleCreateCap = async () => {
6769
try {
@@ -174,6 +176,18 @@ export function TestnetMiningAdmin() {
174176
}
175177
}
176178

179+
const handleCleanupExpiredProposals = async () => {
180+
try {
181+
setError(null)
182+
setIsCleaning(true)
183+
await cleanupExpiredProposals(10)
184+
} catch (error: any) {
185+
setError(error.message)
186+
} finally {
187+
setIsCleaning(false)
188+
}
189+
}
190+
177191
const renderVestingCapTable = () => {
178192
if (isLoading) {
179193
return <CircularProgress />
@@ -599,6 +613,14 @@ export function TestnetMiningAdmin() {
599613
</TableBody>
600614
</Table>
601615
</TableContainer>
616+
<Button
617+
variant="contained"
618+
onClick={handleCleanupExpiredProposals}
619+
disabled={isCleaning}
620+
sx={{ mt: 2 }}
621+
>
622+
{isCleaning ? <CircularProgress size={24} /> : 'Cleanup Expired Proposals'}
623+
</Button>
602624
</AccordionDetails>
603625
</Accordion>
604626
</Box>

src/components/admin/TokenAdmin.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,14 @@ function ConnectedView({ error, setError, formData, setFormData, handlers, state
750750
</TableBody>
751751
</Table>
752752
</TableContainer>
753+
<Button
754+
variant="contained"
755+
onClick={handlers.handleCleanupExpiredProposals}
756+
disabled={states.isCleaning}
757+
sx={{ mt: 2 }}
758+
>
759+
{states.isCleaning ? <CircularProgress size={24} /> : 'Cleanup Expired Proposals'}
760+
</Button>
753761
</AccordionDetails>
754762
</Accordion>
755763
</Grid>
@@ -803,6 +811,7 @@ export function TokenAdmin() {
803811
nonceEvents,
804812
bridgeOpEvents,
805813
transferFromContract,
814+
cleanupExpiredProposals,
806815
} = useAdminContract()
807816

808817
const [isAddingToWhitelist, setIsAddingToWhitelist] = useState(false)
@@ -814,6 +823,7 @@ export function TokenAdmin() {
814823
const [isWhitelisting, setIsWhitelisting] = useState(false)
815824
const [isSettingNonce, setIsSettingNonce] = useState(false)
816825
const [isTransferring, setIsTransferring] = useState(false)
826+
const [isCleaning, setIsCleaning] = useState(false)
817827
const [whitelistedAddresses, setWhitelistedAddresses] = useState<string[]>([]);
818828

819829
// Add this effect to fetch whitelisted addresses when component mounts
@@ -991,6 +1001,18 @@ export function TokenAdmin() {
9911001
}
9921002
}
9931003

1004+
const handleCleanupExpiredProposals = async () => {
1005+
try {
1006+
setError(null)
1007+
setIsCleaning(true)
1008+
await cleanupExpiredProposals(10)
1009+
} catch (error: any) {
1010+
setError(error.message)
1011+
} finally {
1012+
setIsCleaning(false)
1013+
}
1014+
}
1015+
9941016
const handlers = {
9951017
handleAddToWhitelist,
9961018
handleSetTransactionLimit,
@@ -1003,6 +1025,7 @@ export function TokenAdmin() {
10031025
handleSetBridgeOpNonce,
10041026
handleBridgeOp,
10051027
handleTransfer,
1028+
handleCleanupExpiredProposals,
10061029
}
10071030

10081031
const states = {
@@ -1016,6 +1039,7 @@ export function TokenAdmin() {
10161039
isSettingNonce,
10171040
isBridgeOp,
10181041
isTransferring,
1042+
isCleaning,
10191043
}
10201044

10211045
const data = {

src/components/admin/VestingAdmin.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,15 @@ export function VestingAdmin() {
5555
isLoading,
5656
tgeStatus,
5757
initiateTGE,
58+
cleanupExpiredProposals,
5859
} = useAdminContract()
5960

6061
const [isCreatingCap, setIsCreatingCap] = useState(false)
6162
const [isAddingWallet, setIsAddingWallet] = useState(false)
6263
const [isApproving, setIsApproving] = useState(false)
6364
const [isExecuting, setIsExecuting] = useState(false)
6465
const [isSettingTGE, setIsSettingTGE] = useState(false)
66+
const [isCleaning, setIsCleaning] = useState(false)
6567

6668
const handleCreateCap = async () => {
6769
try {
@@ -174,6 +176,18 @@ export function VestingAdmin() {
174176
}
175177
}
176178

179+
const handleCleanupExpiredProposals = async () => {
180+
try {
181+
setError(null)
182+
setIsCleaning(true)
183+
await cleanupExpiredProposals(10)
184+
} catch (error: any) {
185+
setError(error.message)
186+
} finally {
187+
setIsCleaning(false)
188+
}
189+
}
190+
177191
const renderVestingCapTable = () => {
178192
if (isLoading) {
179193
return <CircularProgress />
@@ -599,6 +613,14 @@ export function VestingAdmin() {
599613
</TableBody>
600614
</Table>
601615
</TableContainer>
616+
<Button
617+
variant="contained"
618+
onClick={handleCleanupExpiredProposals}
619+
disabled={isCleaning}
620+
sx={{ mt: 2 }}
621+
>
622+
{isCleaning ? <CircularProgress size={24} /> : 'Cleanup Expired Proposals'}
623+
</Button>
602624
</AccordionDetails>
603625
</Accordion>
604626
</Box>

src/config/abis.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,13 @@ export const GOVERNANCE_ABI = [
361361
name: "ProposalExecuted",
362362
type: "event"
363363
},
364+
{
365+
inputs: [{ type: "uint256", name: "maxProposalsToCheck" }],
366+
name: "cleanupExpiredProposals",
367+
outputs: [],
368+
stateMutability: "nonpayable",
369+
type: "function"
370+
},
364371
] as const;
365372

366373
// Common Contract ABI used across multiple contracts

src/hooks/useAdminContract.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,6 +1258,27 @@ export function useAdminContract() {
12581258
}
12591259
}
12601260

1261+
const cleanupExpiredProposals = async (maxProposalsToCheck: number) => {
1262+
if (!contractAddress) throw new Error('Contract address not found');
1263+
if (!userAddress) throw new Error('Please connect your wallet');
1264+
1265+
try {
1266+
const { request } = await publicClient.simulateContract({
1267+
address: contractAddress,
1268+
abi: contractAbi,
1269+
functionName: 'cleanupExpiredProposals',
1270+
args: [BigInt(maxProposalsToCheck)],
1271+
account: userAddress,
1272+
});
1273+
1274+
const hash = await writeContractAsync(request);
1275+
return hash;
1276+
} catch (error: any) {
1277+
console.error('Error cleaning up expired proposals:', error);
1278+
throw error;
1279+
}
1280+
};
1281+
12611282
return {
12621283
whitelistInfo,
12631284
whitelistedAddresses,
@@ -1294,5 +1315,6 @@ export function useAdminContract() {
12941315
handleSetRoleQuorum,
12951316
checkRoleConfig,
12961317
roleConfigs,
1318+
cleanupExpiredProposals,
12971319
}
12981320
}

0 commit comments

Comments
 (0)