11import { useEffect , useMemo , useRef , useState } from "react" ;
2- import { ConnectedClient } from "../common " ;
2+ import { Address } from "viem " ;
33import { twMerge } from "tailwind-merge" ;
4+ import { ConnectedClient } from "../common" ;
45import { usePrerequisites } from "./usePrerequisites" ;
56import { Wallet } from "./Wallet" ;
67import { Allowance } from "./quarry/Allowance" ;
78import { Session } from "./Session" ;
89import { Step } from "./common" ;
9- import { Address } from "viem" ;
1010import { useAccountModal } from "../useAccountModal" ;
1111import { useEntryKitConfig } from "../EntryKitConfigProvider" ;
1212import { getPaymaster } from "../getPaymaster" ;
1313import { GasBalance } from "./GasBalance" ;
14+ import { GasBalance as GasBalanceQuarry } from "./quarry/GasBalance" ;
1415
1516export type Props = {
1617 userClient : ConnectedClient ;
@@ -20,6 +21,7 @@ export type Props = {
2021export function ConnectedSteps ( { userClient, initialUserAddress } : Props ) {
2122 const { chain } = useEntryKitConfig ( ) ;
2223 const paymaster = getPaymaster ( chain ) ;
24+ const [ focusedId , setFocusedId ] = useState < string | null > ( null ) ;
2325
2426 const userAddress = userClient . account . address ;
2527 const { data : prerequisites , error : prerequisitesError } = usePrerequisites ( userAddress ) ;
@@ -47,7 +49,8 @@ export function ConnectedSteps({ userClient, initialUserAddress }: Props) {
4749 }
4850 } , [ closeAccountModal , isNewConnection , prerequisites ] ) ;
4951
50- const { sessionAddress, hasAllowance, isSpender, hasDelegation, hasGasBalance } = prerequisites ?? { } ;
52+ const { sessionAddress, hasAllowance, isSpender, hasDelegation, hasGasBalance, hasQuarryBalance } =
53+ prerequisites ?? { } ;
5154
5255 const steps = useMemo ( ( ) : readonly Step [ ] => {
5356 if ( ! userAddress ) {
@@ -77,11 +80,19 @@ export function ConnectedSteps({ userClient, initialUserAddress }: Props) {
7780 } ) ;
7881 }
7982 } else if ( paymaster . type === "quarry" ) {
80- steps . push ( {
81- id : "allowance" ,
82- isComplete : ! ! hasAllowance ,
83- content : ( props ) => < Allowance { ...props } userAddress = { userAddress } /> ,
84- } ) ;
83+ if ( paymaster . isGasPass ) {
84+ steps . push ( {
85+ id : "allowance" ,
86+ isComplete : ! ! hasAllowance ,
87+ content : ( props ) => < Allowance { ...props } userAddress = { userAddress } /> ,
88+ } ) ;
89+ } else {
90+ steps . push ( {
91+ id : "gasBalanceQuarry" ,
92+ isComplete : ! ! hasQuarryBalance ,
93+ content : ( props ) => < GasBalanceQuarry { ...props } userAddress = { userAddress } /> ,
94+ } ) ;
95+ }
8596 }
8697
8798 steps . push ( {
@@ -93,7 +104,17 @@ export function ConnectedSteps({ userClient, initialUserAddress }: Props) {
93104 } ) ;
94105
95106 return steps ;
96- } , [ hasAllowance , hasDelegation , hasGasBalance , isSpender , paymaster , sessionAddress , userAddress , userClient ] ) ;
107+ } , [
108+ hasAllowance ,
109+ hasDelegation ,
110+ hasGasBalance ,
111+ hasQuarryBalance ,
112+ isSpender ,
113+ paymaster ,
114+ sessionAddress ,
115+ userAddress ,
116+ userClient ,
117+ ] ) ;
97118
98119 const [ selectedStepId ] = useState < null | string > ( null ) ;
99120 const nextStep = steps . find ( ( step ) => step . content != null && ! step . isComplete ) ;
@@ -107,19 +128,35 @@ export function ConnectedSteps({ userClient, initialUserAddress }: Props) {
107128 return (
108129 < div
109130 className = { twMerge (
110- // steps.length === 2 ? "min-h-[22rem]" : "min-h-[26rem] ",
111- "px-8 flex flex-col divide-y divide-neutral-800",
131+ "px-8 flex flex-col ",
132+ focusedId && " divide-y divide-neutral-800",
112133 "animate-in animate-duration-300 fade-in slide-in-from-bottom-8" ,
113134 ) }
114135 >
115136 { steps . map ( ( step , i ) => {
116137 const isActive = step === activeStep ;
117138 const isExpanded = isActive || completedSteps . length === steps . length ;
118139 const isDisabled = ! step . isComplete && activeStepIndex !== - 1 && i > activeStepIndex ;
140+ const isFocused = focusedId === step . id ;
141+
142+ const content = step . content ( {
143+ isActive,
144+ isExpanded,
145+ isFocused,
146+ setFocused : ( focused : boolean ) => setFocusedId ( focused ? step . id : null ) ,
147+ } ) ;
148+
149+ if ( focusedId ) {
150+ if ( step . id === focusedId ) {
151+ return content ;
152+ }
153+ return null ;
154+ }
155+
119156 return (
120157 < div key = { step . id } className = { twMerge ( "py-8 flex flex-col justify-center" , isActive ? "flex-grow" : null ) } >
121158 < div className = { twMerge ( "flex flex-col" , isDisabled ? "opacity-30 pointer-events-none" : null ) } >
122- { step . content ( { isActive , isExpanded } ) }
159+ { content }
123160 </ div >
124161 </ div >
125162 ) ;
0 commit comments