From ceba57c83409caf7a799169bba0018ee650a4dbd Mon Sep 17 00:00:00 2001 From: Filip-L Date: Mon, 5 May 2025 15:48:08 +0200 Subject: [PATCH 1/3] Add button to reopen decline application --- src/components/AllocatorBalance.tsx | 6 +- src/components/cards/AppInfoCard.tsx | 433 ++++++++++++++------------- src/hooks/useApplicationActions.ts | 32 ++ src/lib/apiClient.ts | 14 + src/lib/constants.ts | 1 + src/type.ts | 3 + 6 files changed, 283 insertions(+), 206 deletions(-) diff --git a/src/components/AllocatorBalance.tsx b/src/components/AllocatorBalance.tsx index 5b57869e..b96a4bad 100644 --- a/src/components/AllocatorBalance.tsx +++ b/src/components/AllocatorBalance.tsx @@ -85,7 +85,11 @@ const AllocatorBalance: React.FC = ({ owner, repo }) => { if (balance === null) return - return
Allocator's DataCap balance: {bytesToiB(balance)}
+ return ( +
+ Allocator's DataCap balance: {bytesToiB(balance)} +
+ ) } export default AllocatorBalance diff --git a/src/components/cards/AppInfoCard.tsx b/src/components/cards/AppInfoCard.tsx index e5dc6511..818836cc 100644 --- a/src/components/cards/AppInfoCard.tsx +++ b/src/components/cards/AppInfoCard.tsx @@ -90,6 +90,7 @@ const AppInfoCard: React.FC = ({ mutationTrigger, mutationTriggerSSA, mutationApproveChanges, + mutationReopenDeclineApplication, mutationProposal, mutationApproval, walletError, @@ -413,6 +414,10 @@ const AppInfoCard: React.FC = ({ setButtonText('Approve') break + case 'Declined': + setButtonText('Reopen declined application') + break + case 'Granted': setButtonText('') break @@ -532,6 +537,13 @@ const AppInfoCard: React.FC = ({ } } break + case 'Declined': + if (userName != null) { + await mutationReopenDeclineApplication.mutateAsync({ + userName, + }) + } + break default: throw new Error( `Invalid application state ${application.Lifecycle.State}`, @@ -1051,229 +1063,240 @@ const AppInfoCard: React.FC = ({
- {application?.Lifecycle?.Active && ( -
- {LDNActorType.Verifier === currentActorType && - walletConnected && - session?.data?.user?.name !== undefined && - application?.Lifecycle?.['On Chain Address'] && - application?.['Client Contract Address'] && - ['ReadyToSign', 'Granted'].includes( - application?.Lifecycle?.State, - ) && ( -
- -
- )} - - {!walletConnected && - currentActorType === LDNActorType.Verifier && - ![ - 'KYCRequested', - 'Submitted', - 'ChangesRequested', - 'AdditionalInfoRequired', - 'AdditionalInfoSubmitted', - ].includes(application?.Lifecycle?.State) && ( - + )} + + {LDNActorType.Verifier === currentActorType && + walletConnected && + session?.data?.user?.name !== undefined && + application?.Lifecycle?.['On Chain Address'] && + application?.['Client Contract Address'] && + ['ChangingSP'].includes(application?.Lifecycle?.State) && ( +
+ - )} - - {LDNActorType.Verifier === currentActorType && - walletConnected && - session?.data?.user?.name !== undefined && - application?.Lifecycle?.['On Chain Address'] && - application?.['Client Contract Address'] && - ['ChangingSP'].includes(application?.Lifecycle?.State) && ( -
- -
- )} - - {LDNActorType.Verifier === currentActorType && - (session?.data?.user?.name !== undefined && - application?.Lifecycle?.State !== 'Granted' ? ( - <> - {application?.Lifecycle?.State === 'Submitted' && ( -
- -
- )} - {application?.Lifecycle?.State === 'ReadyToSign' && ( -
+
+ )} + + {LDNActorType.Verifier === currentActorType && + (session?.data?.user?.name !== undefined && + application?.Lifecycle?.State !== 'Granted' ? ( + <> + {application?.Lifecycle?.State === 'Submitted' && ( +
+ +
+ )} + {application?.Lifecycle?.State === 'ReadyToSign' && ( +
+ +
+ )} + {buttonText && + (walletConnected || + [ + 'KYCRequested', + 'Submitted', + 'AdditionalInfoRequired', + 'AdditionalInfoSubmitted', + 'ChangesRequested', + 'Declined', + ].includes(application?.Lifecycle?.State)) && ( + <> + {[ + 'KYCRequested', + 'Submitted', + 'AdditionalInfoRequired', + 'AdditionalInfoSubmitted', + ].includes(application?.Lifecycle?.State) && ( + <> + + + )} -
+ )} - {buttonText && - (walletConnected || - [ - 'KYCRequested', - 'Submitted', - 'AdditionalInfoRequired', - 'AdditionalInfoSubmitted', - 'ChangesRequested', - ].includes(application?.Lifecycle?.State)) && ( - <> - {[ - 'KYCRequested', - 'Submitted', - 'AdditionalInfoRequired', - 'AdditionalInfoSubmitted', - ].includes(application?.Lifecycle?.State) && ( - <> - - - )} - - - )} - - ) : ( - progress > 75 && - remaining > 0 && ( + + ) : ( + progress > 75 && + remaining > 0 && ( + + ) + ))} + {currentActorType === LDNActorType.Verifier && + [ + 'KYCRequested', + 'Submitted', + 'AdditionalInfoRequired', + 'AdditionalInfoSubmitted', + 'Granted', + ].includes(application?.Lifecycle?.State) && ( + + - ) - ))} - {currentActorType === LDNActorType.Verifier && - [ - 'KYCRequested', - 'Submitted', - 'AdditionalInfoRequired', - 'AdditionalInfoSubmitted', - 'Granted', - ].includes(application?.Lifecycle?.State) && ( - - + + + + + Decline Application + + + This action will decline this application. + + + + + + + - - - - - Decline Application - - - This action will decline this application. - - - - - - - - - - - - )} -
- )} + + + + )} + + {LDNActorType.Verifier === currentActorType && + session?.data?.user?.name !== undefined && + application?.Lifecycle?.State === 'TotalDatacapReached' && ( + <> + + Update the "Total Requested Amount" field in the + associated GitHub issue to reopen this application. + + + )} {LDNActorType.Verifier === currentActorType || (session?.data?.user?.name === undefined && ( <> diff --git a/src/hooks/useApplicationActions.ts b/src/hooks/useApplicationActions.ts index 8129cf26..e4316f84 100644 --- a/src/hooks/useApplicationActions.ts +++ b/src/hooks/useApplicationActions.ts @@ -12,6 +12,7 @@ import { postRemoveAlloc, postRequestKyc, postRevertApplicationToReadyToSign, + reopenDeclineApplication, triggerSSA, } from '@/lib/apiClient' import { @@ -83,6 +84,12 @@ interface ApplicationActions { { userName: string }, unknown > + mutationReopenDeclineApplication: UseMutationResult< + Application | undefined, + unknown, + { userName: string }, + unknown + > mutationChangeAllowedSPs: UseMutationResult< Application | undefined, unknown, @@ -433,6 +440,30 @@ const useApplicationActions = ( }, ) + const mutationReopenDeclineApplication = useMutation< + Application | undefined, + unknown, + { userName: string }, + unknown + >( + async ({ userName }) => { + return await reopenDeclineApplication( + initialApplication.ID, + repo, + owner, + userName, + ) + }, + { + onSuccess: (data) => { + setApiCalling(false) + if (data != null) updateCache(data) + }, + onError: () => { + setApiCalling(false) + }, + }, + ) /** * Mutation function to handle the proposal of an application. * It makes an API call to propose the application and updates the cache on success. @@ -915,6 +946,7 @@ const useApplicationActions = ( mutationDecline, mutationTrigger, mutationApproveChanges, + mutationReopenDeclineApplication, mutationProposal, mutationApproval, walletError, diff --git a/src/lib/apiClient.ts b/src/lib/apiClient.ts index 8555643b..ca6ecbc0 100644 --- a/src/lib/apiClient.ts +++ b/src/lib/apiClient.ts @@ -291,6 +291,20 @@ export const triggerSSA = async ( ) return data } + +export const reopenDeclineApplication = async ( + id: string, + repo: string, + owner: string, + githubUsername: string, +): Promise => { + const { data } = await apiClient.post( + `verifier/application/reopen_declined_application`, + {}, + { params: { github_username: githubUsername, id, owner, repo } }, + ) + return data +} /** * Triggers a KYC request for an application. * @param id the application id diff --git a/src/lib/constants.ts b/src/lib/constants.ts index ac39c212..5d8cd9cf 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -15,6 +15,7 @@ export const stateColor = { KYCRequested: 'bg-lime-400 text-white', ChangingSP: 'bg-amber-400 text-white', Declined: 'bg-red-400 text-white', + TotalDatacapReached: 'bg-black text-white', } export const allocationActiveColor = { diff --git a/src/type.ts b/src/type.ts index 287c7ec7..fcc72942 100644 --- a/src/type.ts +++ b/src/type.ts @@ -66,6 +66,9 @@ export interface Lifecycle { | 'TotalDatacapReached' | 'Error' | 'ChangingSp' + | 'Declined' + | 'TotalDatacapReached' + 'Validated At': string 'Validated By': string Active: boolean From 8445c3db2e9a98b590ae73edcb9da527776ed27f Mon Sep 17 00:00:00 2001 From: Filip-L Date: Wed, 7 May 2025 12:08:16 +0200 Subject: [PATCH 2/3] Disable redirect after decline --- src/components/cards/AppInfoCard.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/cards/AppInfoCard.tsx b/src/components/cards/AppInfoCard.tsx index 818836cc..28c9b214 100644 --- a/src/components/cards/AppInfoCard.tsx +++ b/src/components/cards/AppInfoCard.tsx @@ -568,7 +568,6 @@ const AppInfoCard: React.FC = ({ handleMutationError(error as Error) } toast.success('Application declined successfully') - router.push(`/`) } const handleAdditionalInfoClose = async ( From d0b9b00b897b80236e950e3db58c84a87a06450c Mon Sep 17 00:00:00 2001 From: Filip-L Date: Thu, 8 May 2025 23:23:59 +0200 Subject: [PATCH 3/3] Changes after CR --- src/components/cards/AppInfoCard.tsx | 2 +- src/type.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/cards/AppInfoCard.tsx b/src/components/cards/AppInfoCard.tsx index 28c9b214..0f052170 100644 --- a/src/components/cards/AppInfoCard.tsx +++ b/src/components/cards/AppInfoCard.tsx @@ -1115,7 +1115,7 @@ const AppInfoCard: React.FC = ({ session?.data?.user?.name !== undefined && application?.Lifecycle?.['On Chain Address'] && application?.['Client Contract Address'] && - ['ChangingSP'].includes(application?.Lifecycle?.State) && ( + application?.Lifecycle?.State === 'ChangingSP' && (