@@ -44,10 +44,16 @@ import { useActiveAccount, useActiveWalletChain } from "thirdweb/react";
4444import { upload } from "thirdweb/storage" ;
4545import { isZkSyncChain } from "thirdweb/utils" ;
4646import { FormHelperText , FormLabel , Text } from "tw-components" ;
47+ import {
48+ LAST_USED_PROJECT_ID ,
49+ LAST_USED_TEAM_ID ,
50+ } from "../../../app/team/[team_slug]/[project_slug]/components/SaveLastUsedProject" ;
4751import { useAddContractToProject } from "../../../app/team/[team_slug]/[project_slug]/hooks/project-contracts" ;
4852import { useCustomFactoryAbi , useFunctionParamsFromABI } from "../hooks" ;
4953import {
5054 AddToProjectCardUI ,
55+ type MinimalProject ,
56+ type MinimalTeam ,
5157 type MinimalTeamsAndProjects ,
5258} from "./add-to-project-card" ;
5359import { Fieldset } from "./common" ;
@@ -151,9 +157,42 @@ export const CustomContractForm: React.FC<CustomContractFormProps> = ({
151157 const thirdwebClient = useThirdwebClient ( jwt ) ;
152158
153159 const [ isImportEnabled , setIsImportEnabled ] = useState ( true ) ;
154- const [ importSelection , setImportSelection ] = useState ( {
155- team : teamsAndProjects [ 0 ] ?. team ,
156- project : teamsAndProjects [ 0 ] ?. projects [ 0 ] ,
160+
161+ const [ importSelection , setImportSelection ] = useState < {
162+ team : MinimalTeam | undefined ;
163+ project : MinimalProject | undefined ;
164+ } > ( ( ) => {
165+ const defaultSelection = {
166+ team : teamsAndProjects [ 0 ] ?. team ,
167+ project : teamsAndProjects [ 0 ] ?. projects [ 0 ] ,
168+ } ;
169+
170+ try {
171+ const lastUsedTeamSlug = localStorage . getItem ( LAST_USED_TEAM_ID ) ;
172+ const lastUsedProjectSlug = localStorage . getItem ( LAST_USED_PROJECT_ID ) ;
173+
174+ if ( ! lastUsedTeamSlug || ! lastUsedProjectSlug ) {
175+ return defaultSelection ;
176+ }
177+
178+ const teamWithProjects = teamsAndProjects . find (
179+ ( t ) => t . team . id === lastUsedTeamSlug ,
180+ ) ;
181+ const project = teamWithProjects ?. projects . find (
182+ ( p ) => p . id === lastUsedProjectSlug ,
183+ ) ;
184+
185+ if ( teamWithProjects && project ) {
186+ return {
187+ team : teamWithProjects . team ,
188+ project,
189+ } ;
190+ }
191+ } catch {
192+ // ignore localStorage errors
193+ }
194+
195+ return defaultSelection ;
157196 } ) ;
158197
159198 const activeAccount = useActiveAccount ( ) ;
0 commit comments