Skip to content
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 @@ -9,6 +9,7 @@ import type { ChainId, SchemaType } from '@masknet/web3-shared-evm'
import { ClickAwayListener, InputBase, Typography, type PopperProps } from '@mui/material'
import { useState, type HTMLProps } from 'react'
import { ConditionType, useRedPacket } from '../contexts/RedPacketContext.js'
import { useRedPacketSupportedChains } from '../hooks/useRedPacketSupportedChains.js'

const useStyles = makeStyles()((theme) => {
return {
Expand Down Expand Up @@ -137,6 +138,7 @@ export function ConditionSettings(props: HTMLProps<HTMLDivElement>) {
useRedPacket()
const [anchorEl, setAnchorEl] = useState<HTMLElement | null>()
const { chainId } = useChainContext<NetworkPluginID.PLUGIN_EVM>()
const chains = useRedPacketSupportedChains()

return (
<ClickAwayListener onClickAway={() => setAnchorEl(null)}>
Expand Down Expand Up @@ -259,6 +261,7 @@ export function ConditionSettings(props: HTMLProps<HTMLDivElement>) {
selectedTokens: requiredTokens,
pluginID: NetworkPluginID.PLUGIN_EVM,
chainId,
chains,
multiple: true,
maxTokens: 4,
})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { NetworkPluginID } from '@masknet/shared-base'
import { useNetworks } from '@masknet/web3-hooks-base'
import type { ChainId } from '@masknet/web3-shared-evm'
import { useMemo } from 'react'
import { RED_PACKET_UNSUPPORTED_CHAINS } from '../../constants.js'

/** Chain ids offered in the red packet token pickers. */
export function useRedPacketSupportedChains(): ChainId[] {
const networks = useNetworks(NetworkPluginID.PLUGIN_EVM, true)
return useMemo(
() =>
networks
.map((network) => network.chainId)
.filter((chainId) => !RED_PACKET_UNSUPPORTED_CHAINS.includes(chainId)),
[networks],
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { PreviewRedPacket } from '../components/PreviewRedPacket.js'
import { useRedPacket } from '../contexts/RedPacketContext.js'
import { useCreateParams } from '../hooks/useCreateCallback.js'
import { useDefaultCreateGas } from '../hooks/useDefaultCreateGas.js'
import { useRedPacketSupportedChains } from '../hooks/useRedPacketSupportedChains.js'
import { ThemePicker } from '../components/ThemePicker.js'

const useStyles = makeStyles()((theme) => ({
Expand Down Expand Up @@ -168,6 +169,7 @@ export function CreateTokenRedPacket() {
// context
const { pluginID } = useEnvironmentContext()
const { HAPPY_RED_PACKET_ADDRESS_V4 } = useRedPacketConstants(chainId)
const chains = useRedPacketSupportedChains()

// #region select token
const nativeTokenPrice = useNativeTokenPrice(NetworkPluginID.PLUGIN_EVM, { chainId }).data || 0
Expand All @@ -178,13 +180,14 @@ export function CreateTokenRedPacket() {
selectedTokens: token ? [token] : [],
chainId,
pluginID: NetworkPluginID.PLUGIN_EVM,
chains,
})
if (!picked || Array.isArray(picked)) return
if (chainId !== picked.chainId) {
setChainId(picked.chainId as ChainId)
}
setToken(picked as FungibleToken<ChainId, SchemaType>)
}, [token?.address, chainId])
}, [token?.address, chainId, chains])
// #endregion

// shares
Expand Down
7 changes: 7 additions & 0 deletions packages/plugins/RedPacket/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { PluginID } from '@masknet/shared-base'
import { FireflyRedPacketAPI } from '@masknet/web3-providers/types'
import { ChainId } from '@masknet/web3-shared-evm'

/**
* !! This ID is used to identify the stored plugin data. Change it will cause data lost.
Expand All @@ -12,6 +13,12 @@ export const RED_PACKET_MAX_SHARES = 500
export const SOL_REDPACKET_MAX_SHARES = 200
export const SOL_REDPACKET_CREATE_DEFAULT_GAS = '10000000'
export const DEFAULT_DURATION = 60 * 60 * 24 // 24 hours
/**
* Chains hidden from the red packet token pickers.
* The Robinhood chain is not claimable yet (the backend does not support claiming),
* so creating a lucky drop there is disabled until it is.
*/
export const RED_PACKET_UNSUPPORTED_CHAINS = [ChainId.Robinhood]
export const enum RoutePaths {
Create = '/create',
CreateTokenRedPacket = '/create/token',
Expand Down
Loading