@@ -10,14 +10,17 @@ import {
1010 Flex ,
1111 Grid ,
1212 Button ,
13- Badge
13+ Badge ,
14+ Center ,
15+ Spinner
1416} from '@chakra-ui/react' ;
15- import { UsdCurrencyAmount } from 'src/shared' ;
17+ import { UsdCurrencyAmount , Network } from 'src/shared' ;
18+ import { useWebhooksQuery } from '../../webhooks/model/queries' ;
1619import { WebhookTiers , calculateExpectedPrice } from '../utils/calculating' ;
1720
18- export const PricingDiagram = ( ) => {
21+ export const PricingDiagram : FC < { isDisabled ?: boolean } > = ( { isDisabled = false } ) => {
1922 return (
20- < Grid gap = { 3 } >
23+ < Grid gap = { 3 } opacity = { isDisabled ? 0.6 : 1 } >
2124 < Box >
2225 < Text textStyle = "label2" pb = { 2 } fontWeight = { 600 } >
2326 Subscribed accounts
@@ -120,7 +123,7 @@ export const PricingDiagram = () => {
120123 ) ;
121124} ;
122125
123- export const WebhooksPricingCalculator = ( ) => {
126+ export const WebhooksPricingCalculator : FC < { isDisabled ?: boolean } > = ( { isDisabled = false } ) => {
124127 const [ accounts , setAccounts ] = useState < number | null > ( null ) ;
125128 const [ messages , setMessages ] = useState < number | null > ( null ) ;
126129
@@ -136,7 +139,7 @@ export const WebhooksPricingCalculator = () => {
136139
137140 const currentPrice = new UsdCurrencyAmount ( calculateExpectedPrice ( accounts , messages ) ) ;
138141 return (
139- < Card w = "100%" >
142+ < Card flexDir = "column" display = "flex" w = "100%" opacity = { isDisabled ? 0.6 : 1 } >
140143 < CardHeader >
141144 < Text textStyle = "text.label2" fontWeight = { 600 } >
142145 Pricing Calculator
@@ -146,14 +149,16 @@ export const WebhooksPricingCalculator = () => {
146149 < Input
147150 bg = "white"
148151 border = "1px solid #83898F52"
149- onChange = { e => parseIntInput ( e , setAccounts ) }
152+ isDisabled = { isDisabled }
153+ onChange = { e => ! isDisabled && parseIntInput ( e , setAccounts ) }
150154 placeholder = "Subscribed accounts"
151155 value = { accounts ?? '' }
152156 />
153157 < Input
154158 bg = "white"
155159 border = "1px solid #83898F52"
156- onChange = { e => parseIntInput ( e , setMessages ) }
160+ isDisabled = { isDisabled }
161+ onChange = { e => ! isDisabled && parseIntInput ( e , setMessages ) }
157162 placeholder = "Number of messages sent"
158163 value = { messages ?? '' }
159164 />
@@ -170,28 +175,41 @@ export const WebhooksPricingCalculator = () => {
170175 ) ;
171176} ;
172177
173- export const WebhooksPricingSection : FC < { hideActivation ?: boolean } > = ( {
174- hideActivation = false
175- } ) => {
178+ export const WebhooksPricingSection : FC = ( ) => {
176179 const navigate = useNavigate ( ) ;
180+ const { data : webhooks = [ ] , isLoading, error } = useWebhooksQuery ( Network . MAINNET ) ;
177181
178- const handleActivateWebhooks = ( ) => {
182+ const isWebhooksUnavailable = Boolean ( error ) ;
183+ const isWebhooksInactive = webhooks . length === 0 && ! isLoading && ! isWebhooksUnavailable ;
184+
185+ const handleTryWebhooks = ( ) => {
179186 navigate ( '../webhooks' ) ;
180187 } ;
181188
189+ // Loading state
190+ if ( isLoading ) {
191+ return (
192+ < Center py = "8" >
193+ < Spinner />
194+ </ Center >
195+ ) ;
196+ }
197+
182198 return (
183199 < Box >
200+ { /* Header with Inactive badge */ }
184201 < Flex align = "baseline" gap = "3" mb = "4" >
185202 < Text textStyle = "h4" fontWeight = { 600 } >
186203 Webhooks
187204 </ Text >
188- { ! hideActivation && (
205+ { isWebhooksInactive && (
189206 < Badge fontSize = "xs" colorScheme = "gray" >
190207 Inactive
191208 </ Badge >
192209 ) }
193210 </ Flex >
194211
212+ { /* Main content: Pricing diagram and calculator */ }
195213 < Flex align = "flex-start" wrap = "wrap" gap = "6" >
196214 < Box flex = "3 1 300px" minW = "300px" >
197215 < Text textStyle = "body2" mb = "3" color = "text.secondary" >
@@ -202,9 +220,9 @@ export const WebhooksPricingSection: FC<{ hideActivation?: boolean }> = ({
202220 </ Box >
203221 < Box flex = "1 1 308px" minW = "280px" >
204222 < WebhooksPricingCalculator />
205- { ! hideActivation && (
206- < Button w = "100%" mt = "4" onClick = { handleActivateWebhooks } variant = "primary" >
207- Activate Webhooks
223+ { isWebhooksInactive && (
224+ < Button w = "100%" mt = "4" onClick = { handleTryWebhooks } variant = "primary" >
225+ Try Webhooks
208226 </ Button >
209227 ) }
210228 </ Box >
0 commit comments