Skip to content

[FIL-146] Allow triggering refill even if less than 75% of the DataCap was used #197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 34 additions & 5 deletions src/components/DatacapAmountModel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ interface AllocationConfig {
amount: string
unit: AllocationUnit
allocationType?: AllocationType
earlyRefillComment?: string
}

interface DatacapAmountModalProps {
Expand All @@ -40,6 +41,7 @@ interface DatacapAmountModalProps {
application: Application
clientContractAddress?: string | null
remainingDatacap?: number | undefined
usedDatatapInPercentage: number
setAllocationConfig: (config: any) => void
onClose: () => void
onCancel: () => void
Expand All @@ -59,6 +61,7 @@ const DatacapAmountModal = ({
title,
clientContractAddress,
remainingDatacap,
usedDatatapInPercentage,
}: DatacapAmountModalProps): ReactNode => {
const [isFillRemainingDatacapChecked, setIsFillRemainingDatacapChecked] =
useState(false)
Expand Down Expand Up @@ -86,8 +89,8 @@ const DatacapAmountModal = ({
<Spinner />
</div>
)}
<div>
{remainingDatacap && (
{remainingDatacap && remainingDatacap > 0 ? (
<div>
<FormControlLabel
control={
<Checkbox
Expand All @@ -97,8 +100,8 @@ const DatacapAmountModal = ({
}
label={`Allocate the remaining requested DataCap: ${bytesToiB(remainingDatacap)}`}
/>
)}
</div>
</div>
) : null}
<div className="flex gap-3 items-center flex-col">
{clientContractAddress &&
clientContractAddress !== null &&
Expand Down Expand Up @@ -222,6 +225,25 @@ const DatacapAmountModal = ({
</Box>
</div>
</div>
{usedDatatapInPercentage < 75 &&
remainingDatacap &&
remainingDatacap > 0 ? (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Kinda redundant, the line above will already return false when coerced to boolean for remainingDatacap equal to 0

<div className="w-full">
<TextField
label="Reason for triggering a new allocation despite 75% of the previous one not being utilized."
multiline
rows={4}
variant="outlined"
fullWidth
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to useCallback

setAllocationConfig((prev: AllocationConfig) => ({
...prev,
earlyRefillComment: e.target.value.trim(),
}))
}}
/>
</div>
) : null}
</div>
</DialogContent>
<DialogActions
Expand All @@ -233,7 +255,14 @@ const DatacapAmountModal = ({
Cancel
</Button>
<Button
disabled={isApiCalling || !allocationConfig.amount}
disabled={
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be good idea to define a constant for readability reasons instead of inlining so many condition

isApiCalling ||
!allocationConfig.amount ||
allocationConfig.amount === '0' ||
(allocationConfig.earlyRefillComment !== undefined &&
allocationConfig.earlyRefillComment.length < 10 &&
usedDatatapInPercentage < 75)
}
onClick={onConfirm}
>
Submit
Expand Down
6 changes: 5 additions & 1 deletion src/components/cards/AppInfoCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ const AppInfoCard: React.FC<ComponentProps> = ({
unit: AllocationUnit
isDialogOpen: boolean
isFillRemainingDatacapChecked: boolean
earlyRefillComment?: string
}>({
amount: '0',
unit: AllocationUnit.GIB,
Expand Down Expand Up @@ -685,6 +686,7 @@ const AppInfoCard: React.FC<ComponentProps> = ({
userName,
amount: amountInBytes.toString(),
unit: 'B' as AllocationUnit,
earlyRefillComment: refillInfoParams.earlyRefillComment,
})
} catch (err) {
handleSSAError(err)
Expand Down Expand Up @@ -1216,12 +1218,12 @@ const AppInfoCard: React.FC<ComponentProps> = ({
)}
</>
) : (
progress > 75 &&
remaining > 0 && (
<Button
disabled={isApiCalling}
onClick={() => {
setRefillInfoParams((prev) => ({
...prev,
amount: prev.amount || '1',
unit: prev.unit || AllocationUnit.GIB,
isDialogOpen: true,
Expand Down Expand Up @@ -1316,6 +1318,7 @@ const AppInfoCard: React.FC<ComponentProps> = ({
isWalletConnecting={isWalletConnecting}
isApiCalling={isApiCalling}
remainingDatacap={remaining}
usedDatatapInPercentage={progress}
onClose={() => {
setRefillInfoParams((prev) => ({
...prev,
Expand Down Expand Up @@ -1408,6 +1411,7 @@ const AppInfoCard: React.FC<ComponentProps> = ({
? selectedAllocator?.client_contract_address
: null
}
usedDatatapInPercentage={progress}
/>
</>
)
Expand Down
17 changes: 14 additions & 3 deletions src/hooks/useApplicationActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ interface ApplicationActions {
mutationTriggerSSA: UseMutationResult<
Application | undefined,
unknown,
{ userName: string; amount: string; unit: AllocationUnit },
{
userName: string
amount: string
unit: AllocationUnit
earlyRefillComment?: string
},
unknown
>
mutationRequestInfo: UseMutationResult<
Expand Down Expand Up @@ -382,16 +387,22 @@ const useApplicationActions = (
const mutationTriggerSSA = useMutation<
Application | undefined,
Error,
{ userName: string; amount: string; unit: AllocationUnit }
{
userName: string
amount: string
unit: AllocationUnit
earlyRefillComment?: string
}
>(
async ({ userName, amount, unit }) => {
async ({ userName, amount, unit, earlyRefillComment }) => {
return await triggerSSA(
amount,
unit,
initialApplication.ID,
repo,
owner,
userName,
earlyRefillComment,
)
},
{
Expand Down
2 changes: 2 additions & 0 deletions src/lib/apiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,12 +280,14 @@ export const triggerSSA = async (
repo: string,
owner: string,
actor: string,
earlyRefillComment?: string,
): Promise<Application | undefined> => {
const { data } = await apiClient.post(
`verifier/application/trigger_ssa`,
{
amount,
amount_type: unit,
early_refill_comment: earlyRefillComment,
},
{ params: { repo, owner, id, github_username: actor } },
)
Expand Down