@@ -4,11 +4,12 @@ import React, {
4
4
useEffect ,
5
5
useState ,
6
6
} from "react" ;
7
- import styles from "../../styles/components/registerV2 .module.css" ;
7
+ import styles from "../../styles/components/registerV3 .module.css" ;
8
8
import { gweiToEth , numberToFixedString } from "../../utils/feltService" ;
9
9
import { CurrencyType } from "../../utils/constants" ;
10
10
import CurrencyDropdown from "./currencyDropdown" ;
11
11
import { Skeleton } from "@mui/material" ;
12
+ import ArrowRightIcon from "../UI/iconsComponents/icons/arrowRightIcon" ;
12
13
13
14
type RegisterSummaryProps = {
14
15
duration : number ;
@@ -22,6 +23,9 @@ type RegisterSummaryProps = {
22
23
displayedCurrency : CurrencyType ;
23
24
onCurrencySwitch : ( type : CurrencyType ) => void ;
24
25
loadingPrice ?: boolean ;
26
+ isUpselled ?: boolean ;
27
+ discountedPrice ?: string ; // price the user will pay after discount
28
+ discountedDuration ?: number ; // years the user will have the domain for after discount
25
29
} ;
26
30
27
31
const RegisterSummary : FunctionComponent < RegisterSummaryProps > = ( {
@@ -36,6 +40,9 @@ const RegisterSummary: FunctionComponent<RegisterSummaryProps> = ({
36
40
displayedCurrency,
37
41
onCurrencySwitch,
38
42
loadingPrice,
43
+ isUpselled = false ,
44
+ discountedPrice,
45
+ discountedDuration,
39
46
} ) => {
40
47
const [ ethUsdPrice , setEthUsdPrice ] = useState < string > ( "0" ) ; // price of 1ETH in USD
41
48
const [ usdRegistrationPrice , setUsdRegistrationPrice ] = useState < string > ( "0" ) ;
@@ -56,19 +63,42 @@ const RegisterSummary: FunctionComponent<RegisterSummaryProps> = ({
56
63
function computeUsdPrice ( ) {
57
64
if ( ethUsdPrice ) {
58
65
return (
59
- Number ( ethUsdPrice ) * Number ( gweiToEth ( ethRegistrationPrice ) )
66
+ Number ( ethUsdPrice ) *
67
+ Number ( gweiToEth ( ethRegistrationPrice ) ) *
68
+ duration
60
69
) . toFixed ( 2 ) ;
61
70
}
62
71
return "0" ;
63
72
}
64
73
65
74
setUsdRegistrationPrice ( computeUsdPrice ( ) ) ;
66
- } , [ ethRegistrationPrice , ethUsdPrice ] ) ;
75
+ } , [ ethRegistrationPrice , ethUsdPrice , duration ] ) ;
67
76
68
77
function displayPrice ( priceToPay : string , salesTaxInfo : string ) : ReactNode {
69
78
return (
70
79
< div className = "flex items-center justify-center" >
71
- < span className = { styles . price } > { priceToPay } </ span >
80
+ < span className = { styles . price } >
81
+ { priceToPay } { displayedCurrency } { recurrence }
82
+ </ span >
83
+ { isSwissResident ? (
84
+ < p className = { styles . legend } > { salesTaxInfo } </ p >
85
+ ) : null }
86
+ </ div >
87
+ ) ;
88
+ }
89
+
90
+ function displayDiscountedPrice (
91
+ price : string ,
92
+ priceDiscounted : string ,
93
+ salesTaxInfo : string
94
+ ) : ReactNode {
95
+ return (
96
+ < div className = "flex items-center justify-center" >
97
+ < span className = { styles . priceCrossed } > { price } </ span >
98
+ < ArrowRightIcon width = "25" color = "#454545" />
99
+ < span className = { styles . price } >
100
+ { priceDiscounted } { displayedCurrency } { recurrence } 🔥
101
+ </ span >
72
102
{ isSwissResident ? (
73
103
< p className = { styles . legend } > { salesTaxInfo } </ p >
74
104
) : null }
@@ -87,24 +117,34 @@ const RegisterSummary: FunctionComponent<RegisterSummaryProps> = ({
87
117
) } $ worth of ${ displayedCurrency } for Swiss VAT)`
88
118
: "" ;
89
119
120
+ if ( isUpselled && discountedPrice ) {
121
+ return displayDiscountedPrice (
122
+ numberToFixedString ( Number ( gweiToEth ( registrationPrice ) ) , 3 ) ,
123
+ numberToFixedString ( Number ( gweiToEth ( discountedPrice ) ) , 3 ) ,
124
+ salesTaxInfo
125
+ ) ;
126
+ }
90
127
return displayPrice (
91
- numberToFixedString ( Number ( gweiToEth ( registrationPrice ) ) , 3 )
92
- . concat ( ` ${ displayedCurrency } ` )
93
- . concat ( recurrence ) ,
128
+ numberToFixedString ( Number ( gweiToEth ( registrationPrice ) ) , 3 ) ,
94
129
salesTaxInfo
95
130
) ;
96
131
}
97
132
133
+ function getMessage ( ) {
134
+ if ( customMessage ) return customMessage ;
135
+ else {
136
+ return `${ gweiToEth ( ethRegistrationPrice ) } ETH x ${
137
+ isUpselled ? discountedDuration : duration
138
+ } ${ isUpselled || duration > 1 ? "years" : "year" } `;
139
+ }
140
+ }
141
+
98
142
return (
99
143
< div className = { styles . pricesSummary } >
100
144
< div className = { styles . totalDue } >
101
145
< h4 className = { styles . totalDueTitle } > Total due:</ h4 >
102
146
< div className = { styles . priceContainer } >
103
- < p className = { styles . legend } >
104
- { customMessage
105
- ? customMessage
106
- : `For ${ duration } ${ duration === 1 ? "year" : "years" } ` }
107
- </ p >
147
+ < p className = { styles . legend } > { getMessage ( ) } </ p >
108
148
{ loadingPrice ? (
109
149
< Skeleton variant = "text" width = "150px" height = "24px" />
110
150
) : (
0 commit comments