Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: bugfix for redpacket history #12049

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Loading