44 */
55
66import { useEffect , useRef , useState , useCallback } from 'react' ;
7- import { Paper , Box } from '@mui/material' ;
7+ import { Paper , Box , Collapse , Alert } from '@mui/material' ;
88import SwapVertIcon from '@mui/icons-material/SwapVert' ;
99import { SwapBox } from './SwapBox' ;
1010import { SwapProgress } from './SwapProgress' ;
1111import { ExchangeRateDisplay } from './ExchangeRateDisplay' ;
1212import { SwapButton } from './SwapButton' ;
1313import { SwapErrorAlert } from './SwapErrorAlert' ;
14+ import { SubscriptionStatusBadge } from './SubscriptionStatusBadge' ;
15+ import { SponsorshipToggle } from './SponsorshipToggle' ;
1416import { useContracts } from '../../contexts/contracts' ;
1517import { useWallet } from '../../contexts/wallet' ;
1618import { useOnboarding } from '../../contexts/onboarding' ;
1719import { useSwap } from '../../contexts/swap' ;
20+ import { useSubscriptionStatus } from '../../hooks/useSubscriptionStatus' ;
1821import type { Balances } from '../../types' ;
1922
2023export function SwapContainer ( ) {
2124 const { isLoadingContracts, fetchBalances } = useContracts ( ) ;
22- const { currentAddress } = useWallet ( ) ;
25+ const { currentAddress, isUsingEmbeddedWallet } = useWallet ( ) ;
2326 const {
2427 status : onboardingStatus ,
2528 startOnboarding,
2629 isDripping,
30+ dripPhase,
2731 dripError,
2832 dismissDripError,
2933 } = useOnboarding ( ) ;
@@ -39,12 +43,31 @@ export function SwapContainer() {
3943 isSwapping,
4044 phase : swapPhase ,
4145 error : swapError ,
46+ bypassSponsorship,
47+ setBypassSponsorship,
4248 setFromAmount,
4349 setToAmount,
4450 executeSwap,
4551 dismissError : dismissSwapError ,
4652 } = useSwap ( ) ;
4753
54+ const subscriptionStatus = useSubscriptionStatus ( isSwapping ) ;
55+ const isBlocked = subscriptionStatus . kind === 'full' || subscriptionStatus . kind === 'depleted' ;
56+
57+ // Drip success banner
58+ const [ showDripSuccess , setShowDripSuccess ] = useState ( false ) ;
59+ const dripSuccessTimerRef = useRef < ReturnType < typeof setTimeout > | null > ( null ) ;
60+
61+ useEffect ( ( ) => {
62+ if ( dripPhase === 'success' ) {
63+ setShowDripSuccess ( true ) ;
64+ dripSuccessTimerRef . current = setTimeout ( ( ) => setShowDripSuccess ( false ) , 10000 ) ;
65+ }
66+ return ( ) => {
67+ if ( dripSuccessTimerRef . current ) clearTimeout ( dripSuccessTimerRef . current ) ;
68+ } ;
69+ } , [ dripPhase ] ) ;
70+
4871 // Local balance state
4972 const [ balances , setBalances ] = useState < Balances > ( { gregoCoin : null , gregoCoinPremium : null } ) ;
5073 const [ isLoadingBalances , setIsLoadingBalances ] = useState ( false ) ;
@@ -102,12 +125,10 @@ export function SwapContainer() {
102125 } , [ swapError , dripError ] ) ;
103126
104127 const handleSwapClick = ( ) => {
105- // Check if user needs onboarding
128+ setShowDripSuccess ( false ) ;
106129 if ( ! isOnboarded ) {
107- // Start onboarding - user initiated a swap transaction
108130 startOnboarding ( true ) ;
109131 } else {
110- // Already onboarded, execute swap directly
111132 executeSwap ( ) ;
112133 }
113134 } ;
@@ -215,16 +236,42 @@ export function SwapContainer() {
215236 { /* Exchange Rate Info */ }
216237 < ExchangeRateDisplay exchangeRate = { exchangeRate } isLoadingRate = { isLoadingRate } />
217238
239+ { /* Drip success banner */ }
240+ < Collapse in = { showDripSuccess } timeout = { { enter : 300 , exit : 600 } } >
241+ < Alert
242+ severity = "success"
243+ onClose = { ( ) => setShowDripSuccess ( false ) }
244+ sx = { {
245+ mt : 2 ,
246+ backgroundColor : 'rgba(212, 255, 40, 0.08)' ,
247+ border : '1px solid rgba(212, 255, 40, 0.3)' ,
248+ color : '#D4FF28' ,
249+ '& .MuiAlert-icon' : { color : '#D4FF28' } ,
250+ '& .MuiIconButton-root' : { color : '#D4FF28' } ,
251+ } }
252+ >
253+ GregoCoin received — you're ready to swap!
254+ </ Alert >
255+ </ Collapse >
256+
218257 { /* Swap Button or Progress */ }
219258 { isSwapping ? (
220259 < SwapProgress />
221260 ) : (
222- < SwapButton
223- onClick = { handleSwapClick }
224- disabled = { ! canSwap || isDripping }
225- contractsLoading = { isLoadingContracts }
226- hasAmount = { ! ! fromAmount && parseFloat ( fromAmount ) > 0 }
227- />
261+ < >
262+ < SwapButton
263+ onClick = { handleSwapClick }
264+ disabled = { ! canSwap || isDripping || isBlocked }
265+ contractsLoading = { isLoadingContracts }
266+ hasAmount = { ! ! fromAmount && parseFloat ( fromAmount ) > 0 }
267+ subscriptionStatus = { subscriptionStatus }
268+ />
269+ { ! isUsingEmbeddedWallet && subscriptionStatus . kind !== 'no_fpc' ? (
270+ < SponsorshipToggle status = { subscriptionStatus } value = { bypassSponsorship } onChange = { setBypassSponsorship } />
271+ ) : (
272+ < SubscriptionStatusBadge status = { subscriptionStatus } />
273+ ) }
274+ </ >
228275 ) }
229276
230277 { /* Error Display */ }
0 commit comments