Skip to content

Commit 37a7008

Browse files
authored
fix: bugfix for redpacket history (#12049)
1 parent b3af073 commit 37a7008

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

packages/plugins/RedPacket/src/SiteAdaptor/hooks/useCreateRedPacketReceipt.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ export function useCreateRedPacketReceipt(txHashOrAccountId: string, chainId: Ch
5555
const result = await getRedpacket(txHashOrAccountId)
5656

5757
return {
58-
// id: result.
5958
id: txHashOrAccountId,
6059
creation_time: result.createTime.toString(),
6160
creator: result.creator.toBase58(),

packages/plugins/RedPacket/src/SiteAdaptor/hooks/useRedPacketHistory.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ export function useRedPacketHistory(address: string, historyType: FireflyRedPack
1515
select(data) {
1616
return data.pages.flatMap((x) => x.data)
1717
},
18+
gcTime: 0,
1819
})
1920
}

packages/plugins/RedPacket/src/SiteAdaptor/hooks/useRefundCallback.tsx

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import { refundSplToken } from '../helpers/refundSplToken.js'
1212
import { queryClient } from '@masknet/shared-base-ui'
1313
import { useCustomSnackbar } from '@masknet/theme'
1414
import { Trans } from '@lingui/react/macro'
15+
import { FireflyRedPacketAPI } from '@masknet/web3-providers/types'
16+
import { produce } from 'immer'
1517

1618
export 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
3941
export 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

Comments
 (0)