Skip to content

Commit

Permalink
fix: bugfix for redpacket history (#12049)
Browse files Browse the repository at this point in the history
  • Loading branch information
nuanyang233 authored Jan 21, 2025
1 parent b3af073 commit 37a7008
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ export function useCreateRedPacketReceipt(txHashOrAccountId: string, chainId: Ch
const result = await getRedpacket(txHashOrAccountId)

return {
// id: result.
id: txHashOrAccountId,
creation_time: result.createTime.toString(),
creator: result.creator.toBase58(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ export function useRedPacketHistory(address: string, historyType: FireflyRedPack
select(data) {
return data.pages.flatMap((x) => x.data)
},
gcTime: 0,
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { refundSplToken } from '../helpers/refundSplToken.js'
import { queryClient } from '@masknet/shared-base-ui'
import { useCustomSnackbar } from '@masknet/theme'
import { Trans } from '@lingui/react/macro'
import { FireflyRedPacketAPI } from '@masknet/web3-providers/types'
import { produce } from 'immer'

export function useRefundCallback(version: number, from: string, id?: string, expectedChainId?: ChainId) {
const { chainId } = useChainContext<NetworkPluginID.PLUGIN_EVM>({ chainId: expectedChainId })
Expand Down Expand Up @@ -39,6 +41,7 @@ export function useRefundCallback(version: number, from: string, id?: string, ex
export function useSolanaRefundCallback(rpid: string) {
const { showSnackbar } = useCustomSnackbar()
const [isRefunded, setIsRefunded] = useState(false)
const { account } = useChainContext()
const [state, refundCallback] = useAsyncFn(async () => {
try {
if (!rpid) throw new Error('Failed to resolve redpacket id')
Expand All @@ -59,9 +62,25 @@ export function useSolanaRefundCallback(rpid: string) {
})
}

queryClient.invalidateQueries({
queryKey: ['redpacket', 'history'],
})
queryClient.setQueriesData<{ pages: Array<{ data: FireflyRedPacketAPI.RedPacketSentInfo[] }> }>(
{
queryKey: ['redpacket', 'history', account, FireflyRedPacketAPI.ActionType.Send],
},
(old) => {
if (!old) return old

return produce(old, (draft) => {
for (const page of draft.pages) {
if (!page) continue
for (const record of page.data) {
if (record.redpacket_id !== rpid) continue
record.redpacket_status = FireflyRedPacketAPI.RedPacketStatus.Refund
}
}
})
},
)

setIsRefunded(true)
showSnackbar(<Trans>Refund Successfully</Trans>, { variant: 'success' })
} catch (error) {
Expand All @@ -70,7 +89,7 @@ export function useSolanaRefundCallback(rpid: string) {
}
throw error
}
}, [rpid])
}, [rpid, account])

return [state, isRefunded, refundCallback] as const
}

0 comments on commit 37a7008

Please sign in to comment.