Skip to content

Commit 2f6b1df

Browse files
authored
[FIL-837] Add countdown and change default allocation type (#195)
* Add countdown and set contract allocation type as default
1 parent 2332dce commit 2f6b1df

File tree

3 files changed

+79
-9
lines changed

3 files changed

+79
-9
lines changed

src/components/Countdown.tsx

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import React, { useState, useEffect } from 'react'
2+
3+
interface TimeLeft {
4+
days?: string
5+
hours?: string
6+
minutes?: string
7+
seconds?: string
8+
}
9+
10+
const Countdown: React.FC = () => {
11+
const calculateTimeLeft = (): TimeLeft => {
12+
const targetDate = new Date(new Date().getFullYear(), 5, 1) // June 1st
13+
const now = new Date()
14+
const difference = targetDate.getTime() - now.getTime()
15+
16+
let timeLeft: TimeLeft = {}
17+
18+
if (difference > 0) {
19+
timeLeft = {
20+
days: Math.floor(difference / (1000 * 60 * 60 * 24))
21+
.toString()
22+
.padStart(2, '0'),
23+
hours: Math.floor(
24+
(difference % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60),
25+
)
26+
.toString()
27+
.padStart(2, '0'),
28+
minutes: Math.floor((difference % (1000 * 60 * 60)) / (1000 * 60))
29+
.toString()
30+
.padStart(2, '0'),
31+
}
32+
}
33+
34+
return timeLeft
35+
}
36+
37+
const [timeLeft, setTimeLeft] = useState<TimeLeft>(calculateTimeLeft())
38+
39+
useEffect(() => {
40+
const timer = setInterval(() => {
41+
setTimeLeft(calculateTimeLeft())
42+
}, 1000)
43+
44+
return () => {
45+
clearInterval(timer)
46+
}
47+
}, [])
48+
49+
if (timeLeft.minutes === undefined) {
50+
return null
51+
}
52+
53+
return (
54+
<div className="px-6">
55+
<p
56+
className="cursor-default"
57+
title="Using Client smart contract is available only for new applications. Select Contract as allocation type to start using it"
58+
>
59+
Direct allocation of DataCap will be deprecated in{' '}
60+
<span className="whitespace-nowrap">
61+
{timeLeft.days}d {timeLeft.hours}h {timeLeft.minutes}m
62+
</span>{' '}
63+
(June 1). Start using the Client smart contract today.
64+
</p>
65+
</div>
66+
)
67+
}
68+
69+
export default Countdown

src/components/DatacapAmountModel.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ import { Button } from '@/components/ui/button'
2020
import { AllocationUnit, type Allocation, type Application } from '@/type'
2121
import { type ReactNode, useState } from 'react'
2222
import { bytesToiB } from '@/lib/utils'
23+
import Countdown from './Countdown'
2324

24-
type AllocationType = 'contract' | 'directly'
25+
type AllocationType = 'directly' | 'contract'
2526

2627
interface AllocationConfig {
2728
isDialogOpen: boolean
@@ -78,6 +79,7 @@ const DatacapAmountModal = ({
7879
return (
7980
<Dialog open={allocationConfig.isDialogOpen} onClose={onClose} fullWidth>
8081
<DialogTitle>{title}</DialogTitle>
82+
<Countdown />
8183
<DialogContent>
8284
{(isApiCalling || isWalletConnecting) && (
8385
<div className="fixed inset-0 flex items-center justify-center z-50 bg-black bg-opacity-50">
@@ -123,14 +125,14 @@ const DatacapAmountModal = ({
123125
}}
124126
>
125127
<FormControlLabel
126-
value="directly"
128+
value={'contract'}
127129
control={<Radio />}
128-
label="Directly"
130+
label={'Contract'}
129131
/>
130132
<FormControlLabel
131-
value={'contract'}
133+
value="directly"
132134
control={<Radio />}
133-
label={'Contract'}
135+
label="Directly"
134136
/>
135137
</RadioGroup>
136138
</FormControl>

src/components/cards/AppInfoCard.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ const AppInfoCard: React.FC<ComponentProps> = ({
148148
isDialogOpen: boolean
149149
}>({
150150
amount: '',
151-
allocationType: 'directly',
151+
allocationType: 'contract',
152152
unit: AllocationUnit.GIB,
153153
isDialogOpen: false,
154154
})
@@ -613,7 +613,7 @@ const AppInfoCard: React.FC<ComponentProps> = ({
613613
isDialogOpen: false,
614614
amount: prev.amount || '0',
615615
unit: prev.unit || AllocationUnit.GIB,
616-
allocationType: 'directly',
616+
allocationType: 'contract',
617617
}))
618618
return
619619
}
@@ -723,7 +723,7 @@ const AppInfoCard: React.FC<ComponentProps> = ({
723723
)
724724

725725
setAllocationAmountConfig(() => ({
726-
allocationType: 'directly',
726+
allocationType: 'contract',
727727
amount,
728728
isDialogOpen: false,
729729
unit: unit as AllocationUnit,
@@ -1036,7 +1036,6 @@ const AppInfoCard: React.FC<ComponentProps> = ({
10361036
</CardContent>
10371037
</div>
10381038
) : null}
1039-
10401039
<CardContent>
10411040
{isProgressBarVisible && (
10421041
<ProgressBar

0 commit comments

Comments
 (0)