@@ -12,6 +12,8 @@ import { refundSplToken } from '../helpers/refundSplToken.js'
1212import { queryClient } from '@masknet/shared-base-ui'
1313import { useCustomSnackbar } from '@masknet/theme'
1414import { Trans } from '@lingui/react/macro'
15+ import { FireflyRedPacketAPI } from '@masknet/web3-providers/types'
16+ import { produce } from 'immer'
1517
1618export function useRefundCallback ( version : number , from : string , id ?: string , expectedChainId ?: ChainId ) {
1719 const { chainId } = useChainContext < NetworkPluginID . PLUGIN_EVM > ( { chainId : expectedChainId } )
@@ -39,6 +41,7 @@ export function useRefundCallback(version: number, from: string, id?: string, ex
3941export function useSolanaRefundCallback ( rpid : string ) {
4042 const { showSnackbar } = useCustomSnackbar ( )
4143 const [ isRefunded , setIsRefunded ] = useState ( false )
44+ const { account } = useChainContext ( )
4245 const [ state , refundCallback ] = useAsyncFn ( async ( ) => {
4346 try {
4447 if ( ! rpid ) throw new Error ( 'Failed to resolve redpacket id' )
@@ -59,9 +62,25 @@ export function useSolanaRefundCallback(rpid: string) {
5962 } )
6063 }
6164
62- queryClient . invalidateQueries ( {
63- queryKey : [ 'redpacket' , 'history' ] ,
64- } )
65+ queryClient . setQueriesData < { pages : Array < { data : FireflyRedPacketAPI . RedPacketSentInfo [ ] } > } > (
66+ {
67+ queryKey : [ 'redpacket' , 'history' , account , FireflyRedPacketAPI . ActionType . Send ] ,
68+ } ,
69+ ( old ) => {
70+ if ( ! old ) return old
71+
72+ return produce ( old , ( draft ) => {
73+ for ( const page of draft . pages ) {
74+ if ( ! page ) continue
75+ for ( const record of page . data ) {
76+ if ( record . redpacket_id !== rpid ) continue
77+ record . redpacket_status = FireflyRedPacketAPI . RedPacketStatus . Refund
78+ }
79+ }
80+ } )
81+ } ,
82+ )
83+
6584 setIsRefunded ( true )
6685 showSnackbar ( < Trans > Refund Successfully</ Trans > , { variant : 'success' } )
6786 } catch ( error ) {
@@ -70,7 +89,7 @@ export function useSolanaRefundCallback(rpid: string) {
7089 }
7190 throw error
7291 }
73- } , [ rpid ] )
92+ } , [ rpid , account ] )
7493
7594 return [ state , isRefunded , refundCallback ] as const
7695}
0 commit comments