Skip to content

[FIL-837] Add countdown and change default allocation type #195

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
merged 2 commits into from
May 8, 2025
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
78 changes: 78 additions & 0 deletions src/components/Countdown.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import React, { useState, useEffect } from 'react'

interface TimeLeft {
days?: string
hours?: string
minutes?: string
seconds?: string
}

const Countdown: React.FC = () => {
const calculateTimeLeft = (): TimeLeft => {
const targetDate = new Date(new Date().getFullYear(), 5, 1) // June 1st
const now = new Date()
const difference = targetDate.getTime() - now.getTime()

let timeLeft: TimeLeft = {}

if (difference > 0) {
timeLeft = {
days: Math.floor(difference / (1000 * 60 * 60 * 24))
.toString()
.padStart(2, '0'),
hours: Math.floor(
(difference % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60),
)
.toString()
.padStart(2, '0'),
minutes: Math.floor((difference % (1000 * 60 * 60)) / (1000 * 60))
.toString()
.padStart(2, '0'),
seconds: Math.floor((difference % (1000 * 60)) / 1000)
.toString()
.padStart(2, '0'),
}
}

return timeLeft
}

const [timeLeft, setTimeLeft] = useState<TimeLeft>(calculateTimeLeft())
const [isMounted, setIsMounted] = useState(false)

useEffect(() => {
setIsMounted(true)
const timer = setInterval(() => {
setTimeLeft(calculateTimeLeft())
}, 1000)

return () => {
clearInterval(timer)
}
}, [])

if (!isMounted) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Any reason to do that?

return null
}

if (timeLeft.seconds === undefined) {
return null
}

return (
<div className="px-6 pb-6">
<p
className="cursor-default"
title="Using Client smart contract is available only for new applications. Select Contract as allocation type to start using it"
>
Direct client allocation will be deprecated in{' '}
<span className="inline-block text-center" style={{ width: '90px' }}>
{timeLeft.days}:{timeLeft.hours}:{timeLeft.minutes}:{timeLeft.seconds}
</span>
. Start using the Client smart contract today.
Copy link
Collaborator

@kacperzuk-neti kacperzuk-neti May 8, 2025

Choose a reason for hiding this comment

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

Suggested change
Direct client allocation will be deprecated in{' '}
<span className="inline-block text-center" style={{ width: '90px' }}>
{timeLeft.days}:{timeLeft.hours}:{timeLeft.minutes}:{timeLeft.seconds}
</span>
. Start using the Client smart contract today.
Direct allocation of DataCap will be deprecated in{' '}
<span class="whitespace-nowrap">{timeLeft.days} days</span> (June 1). Start using the Client smart contract today.

Reasons:

  1. Numbers in countdown are confusing. 24:10:24:02? Users will need to guess what it means
  2. Some (me :D) will prefer explicit date.
  3. Direct client allocation sounds confusing. We're not allocating clients, we're allocating datacap.
  4. Why the fixed width and inline-block and text-center? I assume it was to prevent breaking the text over new line. whitespace-nowrap seems better for that purpose. If the reason was different please explain.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We need to add a link to instruction/more in-depth explanation.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The link to the instructions will be added once the instructions are ready.

</p>
</div>
)
}

export default Countdown
10 changes: 5 additions & 5 deletions src/components/DatacapAmountModel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { AllocationUnit, type Allocation, type Application } from '@/type'
import { type ReactNode, useState } from 'react'
import { bytesToiB } from '@/lib/utils'

type AllocationType = 'contract' | 'directly'
type AllocationType = 'directly' | 'contract'

interface AllocationConfig {
isDialogOpen: boolean
Expand Down Expand Up @@ -123,14 +123,14 @@ const DatacapAmountModal = ({
}}
>
<FormControlLabel
value="directly"
value={'contract'}
control={<Radio />}
label="Directly"
label={'Contract'}
/>
<FormControlLabel
value={'contract'}
value="directly"
control={<Radio />}
label={'Contract'}
label="Directly"
/>
</RadioGroup>
</FormControl>
Expand Down
9 changes: 5 additions & 4 deletions src/components/cards/AppInfoCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import {
DialogTitle as DialogTitlePrimitive,
DialogTrigger,
} from '@/components/ui/Dialog'
import Countdown from '../Countdown'
interface ComponentProps {
initialApplication: Application
repo: string
Expand Down Expand Up @@ -148,7 +149,7 @@ const AppInfoCard: React.FC<ComponentProps> = ({
isDialogOpen: boolean
}>({
amount: '',
allocationType: 'directly',
allocationType: 'contract',
unit: AllocationUnit.GIB,
isDialogOpen: false,
})
Expand Down Expand Up @@ -613,7 +614,7 @@ const AppInfoCard: React.FC<ComponentProps> = ({
isDialogOpen: false,
amount: prev.amount || '0',
unit: prev.unit || AllocationUnit.GIB,
allocationType: 'directly',
allocationType: 'contract',
}))
return
}
Expand Down Expand Up @@ -723,7 +724,7 @@ const AppInfoCard: React.FC<ComponentProps> = ({
)

setAllocationAmountConfig(() => ({
allocationType: 'directly',
allocationType: 'contract',
amount,
isDialogOpen: false,
unit: unit as AllocationUnit,
Expand Down Expand Up @@ -1036,7 +1037,6 @@ const AppInfoCard: React.FC<ComponentProps> = ({
</CardContent>
</div>
) : null}

<CardContent>
{isProgressBarVisible && (
<ProgressBar
Expand All @@ -1046,6 +1046,7 @@ const AppInfoCard: React.FC<ComponentProps> = ({
/>
)}
</CardContent>
<Countdown />
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's move it to the modal where allocator chooses contract vs direct.

<div>
<CardFooter className="flex flex-row items-center border-t pt-4 pb-2 mt-4 justify-between gap-3">
<div className="flex gap-2 pb-4">
Expand Down