@@ -6,7 +6,8 @@ import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs";
66import { SafeTx } from "@/core/safe-tx" ;
77import { useCurrentTransactions } from "@/hooks/use-current-transactions" ;
88import { useSafeParams } from "@/hooks/use-safe-params" ;
9- import { useMemo , useState } from "react" ;
9+ import { useRouter , useSearchParams } from "next/navigation" ;
10+ import { useEffect , useMemo , useState } from "react" ;
1011import { Address } from "viem" ;
1112import { getReportRef } from "../../utils/get-report" ;
1213import { TimelockTxStatus } from "../../utils/tx-status" ;
@@ -21,13 +22,26 @@ interface SafeViewProps {
2122export type TabType = "queue" | "execute" | "history" ;
2223
2324export function SafeView ( { safeAddress } : SafeViewProps ) {
24- const [ activeTab , setActiveTab ] = useState < TabType > ( "queue" ) ;
25+ const router = useRouter ( ) ;
26+ const searchParams = useSearchParams ( ) ;
27+ const [ activeTab , setActiveTab ] = useState < TabType > ( ) ;
28+
29+ useEffect ( ( ) => {
30+ if ( activeTab === undefined ) {
31+ const tab = searchParams . get ( "tab" ) as TabType ;
32+ setActiveTab (
33+ tab && [ "queue" , "execute" , "history" ] . includes ( tab ) ? tab : "queue"
34+ ) ;
35+ }
36+ } , [ searchParams , activeTab ] ) ;
2537
2638 const { txs, governor, isLoading, error } =
2739 useCurrentTransactions ( safeAddress ) ;
2840 const { threshold, nonce } = useSafeParams ( safeAddress ) ;
2941
3042 const txsToShow = useMemo ( ( ) => {
43+ if ( ! activeTab ) return [ ] ;
44+
3145 return ( txs || [ ] ) . filter ( ( t ) => {
3246 if ( activeTab === "queue" ) {
3347 return t . nonce >= ( nonce ?? 0n ) ;
@@ -49,6 +63,10 @@ export function SafeView({ safeAddress }: SafeViewProps) {
4963 return < div > Error: { error . message } </ div > ;
5064 }
5165
66+ if ( ! activeTab ) {
67+ return null ;
68+ }
69+
5270 return (
5371 < PageLayout
5472 title = { "Transactions" }
@@ -79,7 +97,10 @@ export function SafeView({ safeAddress }: SafeViewProps) {
7997 < div className = "p-4" >
8098 < Tabs
8199 value = { activeTab }
82- onValueChange = { ( value ) => setActiveTab ( value as TabType ) }
100+ onValueChange = { ( value ) => {
101+ setActiveTab ( value as TabType ) ;
102+ router . replace ( `?tab=${ value } ` ) ;
103+ } }
83104 className = "w-full"
84105 >
85106 < TabsList >
0 commit comments