-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! fix: mf-6332 handle unsend redpacket
- Loading branch information
Showing
8 changed files
with
162 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 28 additions & 28 deletions
56
packages/plugins/RedPacket/src/SiteAdaptor/RedPacketDialog.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
packages/plugins/RedPacket/src/SiteAdaptor/hooks/useCreateRedPacketReceipt.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { NetworkPluginID } from '@masknet/shared-base' | ||
import REDPACKET_ABI from '@masknet/web3-contracts/abis/HappyRedPacketV4.json' | ||
import { useWeb3Connection } from '@masknet/web3-hooks-base' | ||
import { isSameAddress } from '@masknet/web3-shared-base' | ||
import { type ChainId, decodeEvents, useRedPacketConstants } from '@masknet/web3-shared-evm' | ||
import { useQuery } from '@tanstack/react-query' | ||
import type { AbiItem } from 'web3-utils' | ||
|
||
type CreationSuccessEventParams = { | ||
id: string | ||
/** seconds in string */ | ||
creation_time: string | ||
/** creator wallet address */ | ||
creator: string | ||
/** seconds in string */ | ||
duration: '86400' | ||
id: HexString | ||
Check failure on line 17 in packages/plugins/RedPacket/src/SiteAdaptor/hooks/useCreateRedPacketReceipt.ts GitHub Actions / type-check
Check failure on line 17 in packages/plugins/RedPacket/src/SiteAdaptor/hooks/useCreateRedPacketReceipt.ts GitHub Actions / type-check
|
||
ifrandom: boolean | ||
message: string | ||
/** creator's name */ | ||
name: string | ||
/** account in string*/ | ||
number: string | ||
token_address: HexString | ||
/** account in string*/ | ||
total: string | ||
} | ||
export function useCreateRedPacketReceipt(txHash: string, chainId: ChainId) { | ||
const { HAPPY_RED_PACKET_ADDRESS_V4 } = useRedPacketConstants(chainId) | ||
const Web3 = useWeb3Connection(NetworkPluginID.PLUGIN_EVM) | ||
|
||
return useQuery({ | ||
queryKey: ['redpacket', 'creation-success-params', chainId, txHash], | ||
queryFn: async () => { | ||
if (!txHash || !Web3) return null | ||
|
||
const receipt = await Web3.getTransactionReceipt(txHash, { chainId }) | ||
if (!receipt) return null | ||
|
||
const log = receipt.logs.find((log) => isSameAddress(log.address, HAPPY_RED_PACKET_ADDRESS_V4)) | ||
if (!log) return null | ||
|
||
const eventParams = decodeEvents(REDPACKET_ABI as AbiItem[], [log]) as unknown as { | ||
CreationSuccess: { | ||
returnValues: CreationSuccessEventParams | ||
} | ||
} | ||
|
||
const { returnValues } = eventParams.CreationSuccess | ||
console.log({ eventParams, returnValues, txHash }) | ||
|
||
return returnValues | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters