11"use client" ;
22import type { Project } from "@/api/projects" ;
33import { CopyTextButton } from "@/components/ui/CopyTextButton" ;
4- import { Alert , AlertDescription , AlertTitle } from "@/components/ui/alert" ;
4+ import { } from "@/components/ui/alert" ;
55import { Button } from "@/components/ui/button" ;
6- import { Checkbox , CheckboxWithLabel } from "@/components/ui/checkbox" ;
6+ import { } from "@/components/ui/checkbox" ;
77import {
88 Dialog ,
99 DialogContent ,
@@ -12,7 +12,7 @@ import {
1212} from "@/components/ui/dialog" ;
1313import { Input } from "@/components/ui/input" ;
1414import { Skeleton } from "@/components/ui/skeleton" ;
15- import { useMutation , useQuery } from "@tanstack/react-query" ;
15+ import { useMutation , useQuery , useQueryClient } from "@tanstack/react-query" ;
1616import { listAccessTokens , revokeAccessToken } from "@thirdweb-dev/vault-sdk" ;
1717import { Loader2 , LockIcon , Trash2 } from "lucide-react" ;
1818import { useState } from "react" ;
@@ -31,8 +31,7 @@ export default function ListAccessTokens(props: {
3131 const [ typedAdminKey , setTypedAdminKey ] = useState ( "" ) ;
3232 const [ adminKey , setAdminKey ] = useState ( "" ) ;
3333 const [ deletingTokenId , setDeletingTokenId ] = useState < string | null > ( null ) ;
34- const [ newAccessToken , setNewAccessToken ] = useState < string | null > ( null ) ;
35- const [ keysConfirmed , setKeysConfirmed ] = useState ( false ) ;
34+ const queryClient = useQueryClient ( ) ;
3635 // TODO allow passing permissions to the access token
3736 const createAccessTokenMutation = useMutation ( {
3837 mutationFn : async ( args : { adminKey : string } ) => {
@@ -57,9 +56,10 @@ export default function ListAccessTokens(props: {
5756 onError : ( error ) => {
5857 toast . error ( error . message ) ;
5958 } ,
60- onSuccess : ( data ) => {
61- setNewAccessToken ( data . userAccessToken . accessToken ) ;
62- listAccessTokensQuery . refetch ( ) ;
59+ onSuccess : ( ) => {
60+ queryClient . invalidateQueries ( {
61+ queryKey : [ "list-access-tokens" ] ,
62+ } ) ;
6363 } ,
6464 } ) ;
6565
@@ -95,7 +95,9 @@ export default function ListAccessTokens(props: {
9595 setDeletingTokenId ( null ) ;
9696 } ,
9797 onSuccess : ( ) => {
98- listAccessTokensQuery . refetch ( ) ;
98+ queryClient . invalidateQueries ( {
99+ queryKey : [ "list-access-tokens" ] ,
100+ } ) ;
99101 setDeletingTokenId ( null ) ;
100102 } ,
101103 } ) ;
@@ -171,6 +173,9 @@ export default function ListAccessTokens(props: {
171173 setModalOpen ( true ) ;
172174 } else {
173175 setAdminKey ( "" ) ;
176+ queryClient . invalidateQueries ( {
177+ queryKey : [ "list-access-tokens" ] ,
178+ } ) ;
174179 }
175180 } }
176181 variant = { "primary" }
@@ -281,98 +286,47 @@ export default function ListAccessTokens(props: {
281286 < DialogHeader className = "px-6 pt-6" >
282287 < DialogTitle > Unlock Vault</ DialogTitle >
283288 </ DialogHeader >
284- { /* If new access token, show copy button */ }
285- { newAccessToken ? (
286- < div className = "flex flex-col gap-4" >
287- < div className = "flex flex-col gap-4 px-6 " >
288- < p className = "text-muted-foreground text-xs" >
289- Here's your new access token. Store it securely as it will
290- not be displayed again.
291- </ p >
292- < CopyTextButton
293- textToCopy = { newAccessToken }
294- className = "!h-auto w-full justify-between bg-background px-3 py-3 font-mono text-xs"
295- textToShow = { maskSecret ( newAccessToken ) }
296- copyIconPosition = "right"
297- tooltip = "Copy Vault Access Token"
298- />
299- < p className = "text-muted-foreground text-xs" >
300- This access token is used to sign transactions and messages
301- from your backend. Can be revoked and recreated with your
302- admin key.
303- </ p >
304- < Alert variant = "destructive" >
305- < AlertTitle > Secure your keys</ AlertTitle >
306- < AlertDescription >
307- These keys will not be displayed again. Store them
308- securely as they provide access to your server wallets.
309- </ AlertDescription >
310- < div className = "h-4" />
311- < CheckboxWithLabel className = "text-foreground" >
312- < Checkbox
313- checked = { keysConfirmed }
314- onCheckedChange = { ( v ) => setKeysConfirmed ( ! ! v ) }
315- />
316- I confirm that I've securely stored these keys
317- </ CheckboxWithLabel >
318- </ Alert >
319- </ div >
320- < div className = "flex justify-end gap-3 border-t bg-card px-6 py-4" >
321- < Button
322- onClick = { ( ) => {
323- setNewAccessToken ( null ) ;
324- setKeysConfirmed ( false ) ;
325- } }
326- disabled = { ! keysConfirmed }
327- variant = { "primary" }
328- >
329- Go Back
330- </ Button >
331- </ div >
332- </ div >
333- ) : (
334- < div className = "flex flex-col gap-4" >
335- < div className = "flex flex-col gap-4 px-6" >
336- < p className = "flex items-center gap-2 text-sm text-warning-text" >
337- < LockIcon className = "h-4 w-4" /> This action requires your
338- Vault admin key.
339- </ p >
340- < Input
341- type = "password"
342- placeholder = "sa_adm_ABCD_1234..."
343- value = { typedAdminKey }
344- onChange = { ( e ) => setTypedAdminKey ( e . target . value ) }
345- onKeyDown = { ( e ) => {
346- if ( e . key === "Enter" ) {
347- setAdminKey ( typedAdminKey ) ;
348- }
349- } }
350- />
351- </ div >
352- < div className = "flex justify-end gap-3 border-t bg-card px-6 py-4" >
353- < Button
354- variant = { "outline" }
355- onClick = { ( ) => {
356- setAdminKey ( "" ) ;
357- setTypedAdminKey ( "" ) ;
358- setModalOpen ( false ) ;
359- } }
360- >
361- Cancel
362- </ Button >
363- < Button
364- variant = { "primary" }
365- onClick = { ( ) => {
289+ < div className = "flex flex-col gap-4" >
290+ < div className = "flex flex-col gap-4 px-6" >
291+ < p className = "flex items-center gap-2 text-sm text-warning-text" >
292+ < LockIcon className = "h-4 w-4" /> This action requires your
293+ Vault admin key.
294+ </ p >
295+ < Input
296+ type = "password"
297+ placeholder = "sa_adm_ABCD_1234..."
298+ value = { typedAdminKey }
299+ onChange = { ( e ) => setTypedAdminKey ( e . target . value ) }
300+ onKeyDown = { ( e ) => {
301+ if ( e . key === "Enter" ) {
366302 setAdminKey ( typedAdminKey ) ;
367- handleCloseModal ( ) ;
368- } }
369- disabled = { ! typedAdminKey || listAccessTokensQuery . isLoading }
370- >
371- Unlock Vault
372- </ Button >
373- </ div >
303+ }
304+ } }
305+ />
374306 </ div >
375- ) }
307+ < div className = "flex justify-end gap-3 border-t bg-card px-6 py-4" >
308+ < Button
309+ variant = { "outline" }
310+ onClick = { ( ) => {
311+ setAdminKey ( "" ) ;
312+ setTypedAdminKey ( "" ) ;
313+ setModalOpen ( false ) ;
314+ } }
315+ >
316+ Cancel
317+ </ Button >
318+ < Button
319+ variant = { "primary" }
320+ onClick = { ( ) => {
321+ setAdminKey ( typedAdminKey ) ;
322+ handleCloseModal ( ) ;
323+ } }
324+ disabled = { ! typedAdminKey || listAccessTokensQuery . isLoading }
325+ >
326+ Unlock Vault
327+ </ Button >
328+ </ div >
329+ </ div >
376330 </ DialogContent >
377331 </ Dialog >
378332 </ div >
0 commit comments