Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: fw-496 a single account can only claim once from a redpacket (#…
…11495) * feat: fw-496 a single account can only claim once from a redpacket * fixup! feat: fw-496 a single account can only claim once from a redpacket * fix: claim platform
- Loading branch information
Showing
9 changed files
with
146 additions
and
11 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
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
40 changes: 40 additions & 0 deletions
40
packages/plugins/RedPacket/src/SiteAdaptor/hooks/useParseRedPacket.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,40 @@ | ||
import { useLastRecognizedIdentity, usePostInfoDetails } from '@masknet/plugin-infra/content-script' | ||
import { NetworkPluginID } from '@masknet/shared-base' | ||
import { useChainContext, useNetworkContext } from '@masknet/web3-hooks-base' | ||
import { FireflyRedPacket } from '@masknet/web3-providers' | ||
import type { FireflyRedPacketAPI } from '@masknet/web3-providers/types' | ||
import type { ChainId } from '@masknet/web3-shared-evm' | ||
import { useQuery, type UseQueryResult } from '@tanstack/react-query' | ||
|
||
type T = UseQueryResult | ||
/** | ||
* Parse RedPacket with post info | ||
*/ | ||
export function useParseRedPacket(chainId: ChainId) { | ||
const images = usePostInfoDetails.postMetadataImages() | ||
const { pluginID } = useNetworkContext() | ||
const { account } = useChainContext<NetworkPluginID.PLUGIN_EVM>({ | ||
chainId, | ||
account: pluginID === NetworkPluginID.PLUGIN_EVM ? undefined : '', | ||
}) | ||
const source = usePostInfoDetails.source() | ||
const me = useLastRecognizedIdentity() | ||
const myProfileId = me?.profileId | ||
|
||
const query = useQuery({ | ||
enabled: images.length > 0, | ||
queryKey: ['red-packet', 'parse', source, images[0], account], | ||
queryFn: async () => { | ||
const platform = source?.toLowerCase() as FireflyRedPacketAPI.PlatformType | ||
return FireflyRedPacket.parse({ | ||
image: { | ||
imageUrl: images[0], | ||
}, | ||
walletAddress: account, | ||
platform, | ||
profileId: myProfileId, | ||
}) | ||
}, | ||
}) | ||
return query.data | ||
} |
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
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