@@ -27,30 +27,36 @@ export const PayToLabel = () => {
27
27
const [ cart , setCart ] = useState < number > ( 0 ) ;
28
28
const [ isLoading , setIsLoading ] = useState ( true ) ;
29
29
30
- const calculateDiscount = ( cart : number , discountRate : number ) => ( discountRate * cart ) / 100 ;
31
-
32
30
useEffect ( ( ) => {
33
- if ( paymentDetails !== null ) {
34
- let cart = Number ( paymentDetails . usdcSize ) ;
35
- setCart ( cart ) ;
36
- setIsLoading ( false ) ;
37
- }
38
- } , [ paymentDetails ] ) ;
31
+ if ( paymentDetails ) {
32
+ console . log ( 'in effect' , paymentDetails , customerTier ) ;
33
+ let cartValue = Number ( paymentDetails . usdcSize ) ;
39
34
40
- useEffect ( ( ) => {
41
- if ( customerTier !== null && cart > 0 ) {
42
- setDiscount ( calculateDiscount ( cart , customerTier . discount ) ) ;
35
+ console . log ( 'cart value' , cartValue ) ;
36
+ setCart ( cartValue ) ;
37
+ if ( customerTier && cartValue > 0 ) {
38
+ setDiscount ( ( cartValue * customerTier . discount ) / 100 ) ;
39
+ console . log ( 'discoutn' , cartValue * customerTier . discount ) ;
40
+ }
41
+ setIsLoading ( false ) ;
43
42
}
44
- } , [ customerTier , cart ] ) ;
43
+ } , [ paymentDetails , customerTier ] ) ;
45
44
46
45
function calculateFinalAmount ( ) : number {
47
- if ( ! loyaltyDetails || ! customer || ! paymentDetails || ! customerTier ) {
48
- return 0 ;
46
+ if ( ! paymentDetails ) {
47
+ return - 1 ;
48
+ }
49
+ console . log ( 'final stats' , loyaltyDetails , customer , paymentDetails , customerTier ) ;
50
+ if ( ! loyaltyDetails || ! customer || ! customerTier ) {
51
+ console . log ( 'no loyalty details' , paymentDetails . usdcSize ) ;
52
+ return paymentDetails . usdcSize ;
49
53
}
50
54
51
55
if ( loyaltyDetails ?. loyaltyProgram === 'tiers' && customer . customerOwns ) {
56
+ console . log ( 'cart - disc f, ' , cart , discount ) ;
52
57
return cart - discount ;
53
58
} else {
59
+ console . log ( 'else' , paymentDetails . usdcSize ) ;
54
60
return paymentDetails . usdcSize ;
55
61
}
56
62
}
@@ -73,7 +79,7 @@ export const PayToLabel = () => {
73
79
< div className = "divider" />
74
80
</ div >
75
81
< CartAmountLoading />
76
- < DiscountAmountLoading />
82
+ { showTierDiscount && < DiscountAmountLoading /> }
77
83
< FeePriceDisplayLoading />
78
84
</ div >
79
85
) ;
0 commit comments