Skip to content

Commit

Permalink
refactor: remove some more unused files (#11772)
Browse files Browse the repository at this point in the history
* refactor: remove some more unused files

* fix: remove unused code

* fix: annoying checking for @masknet/shared-base
  • Loading branch information
swkatmask authored Sep 30, 2024
1 parent 0f388d6 commit 153a169
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 385 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from '@mui/material'
import { useRedPacketTrans } from '../locales/index.js'
import { makeStyles } from '@masknet/theme'
import { useCallback, useMemo, useState } from 'react'
import { useCallback, useState } from 'react'
import { Icons, type GeneratedIcon } from '@masknet/icons'
import { RequirementType, type FireflyRedpacketSettings } from '../types.js'
import { EMPTY_LIST, NetworkPluginID, PluginID } from '@masknet/shared-base'
Expand All @@ -22,7 +22,7 @@ import { useChainContext } from '@masknet/web3-hooks-base'
import { Trans } from 'react-i18next'
import { getEnumAsArray } from '@masknet/kit'

const useStyles = makeStyles<{ isFirefly: boolean }>()((theme, { isFirefly }) => ({
const useStyles = makeStyles()((theme) => ({
container: {
padding: theme.spacing(2),
minHeight: 460,
Expand All @@ -34,14 +34,14 @@ const useStyles = makeStyles<{ isFirefly: boolean }>()((theme, { isFirefly }) =>
rowGap: theme.spacing(1),
},
icon: {
color: isFirefly ? 'var(--color-light-main)' : theme.palette.maskColor.main,
color: 'var(--color-light-main)',
minWidth: 20,
width: 20,
height: 20,
marginRight: theme.spacing(1),
},
title: {
color: isFirefly ? 'var(--color-light-main)' : theme.palette.maskColor.main,
color: 'var(--color-light-main)',
fontSize: 16,
fontWeight: 700,
lineHeight: '22px',
Expand Down Expand Up @@ -88,7 +88,7 @@ const useStyles = makeStyles<{ isFirefly: boolean }>()((theme, { isFirefly }) =>
},
collectionName: {
fontSize: 15,
color: isFirefly ? 'var(--color-light-main)' : theme.palette.maskColor.main,
color: 'var(--color-light-main)',
lineHeight: '20px',
fontWeight: 700,
},
Expand All @@ -104,7 +104,6 @@ const useStyles = makeStyles<{ isFirefly: boolean }>()((theme, { isFirefly }) =>

interface ClaimRequirementsDialogProps {
onNext: (settings: FireflyRedpacketSettings) => void
isFirefly: boolean
origin?: RequirementType[]
}

Expand All @@ -128,10 +127,10 @@ export function ClaimRequirementsDialog(props: ClaimRequirementsDialogProps) {
const t = useRedPacketTrans()
const [selectedRules, setSelectedRules] = useState(props.origin ?? [RequirementType.Follow])
const [selectedCollection, setSelectedCollection] = useState<NonFungibleCollection<ChainId, SchemaType>>()
const { classes } = useStyles({ isFirefly: props.isFirefly })
const { classes } = useStyles()
const { chainId } = useChainContext<NetworkPluginID.PLUGIN_EVM>()

const hasNFTHolder = useMemo(() => selectedRules.includes(RequirementType.NFTHolder), [selectedRules])
const hasNFTHolder = selectedRules.includes(RequirementType.NFTHolder)

const handleClick = useCallback(() => {
SelectNonFungibleContractModal.open({
Expand All @@ -156,9 +155,7 @@ export function ClaimRequirementsDialog(props: ClaimRequirementsDialogProps) {
})
}, [chainId])

const disabled = useMemo(() => {
return selectedRules.includes(RequirementType.NFTHolder) && !selectedCollection
}, [selectedRules, selectedCollection])
const disabled = selectedRules.includes(RequirementType.NFTHolder) && !selectedCollection

return (
<>
Expand Down
65 changes: 19 additions & 46 deletions packages/plugins/RedPacket/src/SiteAdaptor/RedPacketDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { useRedPacketTrans } from '../locales/index.js'
import { reduceUselessPayloadInfo } from './utils/reduceUselessPayloadInfo.js'
import { RedPacketMetaKey } from '../constants.js'
import type { RedPacketSettings } from './hooks/useCreateCallback.js'
import { RedPacketConfirmDialog } from './RedPacketConfirmDialog.js'
import { RedPacketERC20Form } from './RedPacketERC20Form.js'
import { RedPacketERC721Form } from './RedPacketERC721Form.js'
import { openComposition } from './openComposition.js'
Expand All @@ -30,7 +29,6 @@ import { ClaimRequirementsDialog } from './ClaimRequirementsDialog.js'
import { ClaimRequirementsRuleDialog } from './ClaimRequirementsRuleDialog.js'
import type { FireflyContext, FireflyRedpacketSettings } from '../types.js'
import { FireflyRedpacketConfirmDialog } from './FireflyRedpacketConfirmDialog.js'
import { RedPacketPast } from './RedPacketPast.js'
import { CompositionTypeContext } from './RedPacketInjection.js'

const useStyles = makeStyles<{ scrollY: boolean; isDim: boolean }>()((theme, { isDim, scrollY }) => {
Expand Down Expand Up @@ -77,7 +75,7 @@ interface RedPacketDialogProps {
onClose: () => void
isOpenFromApplicationBoard?: boolean
source?: PluginID
fireflyContext?: FireflyContext
fireflyContext: FireflyContext
}

export default function RedPacketDialog(props: RedPacketDialogProps) {
Expand Down Expand Up @@ -120,8 +118,6 @@ export default function RedPacketDialog(props: RedPacketDialogProps) {
const [openSelectNFTDialog, setOpenSelectNFTDialog] = useState(false)
// #endregion

const isFirefly = !!props.fireflyContext

const handleClose = useCallback(() => {
setStep(CreateRedPacketPageStep.NewRedPacketPage)
setSettings(undefined)
Expand Down Expand Up @@ -161,10 +157,6 @@ export default function RedPacketDialog(props: RedPacketDialogProps) {
}
}

if (!isFirefly && senderName) {
payload.sender.name === senderName
}

openComposition(RedPacketMetaKey, reduceUselessPayloadInfo(payload), compositionType, {
payloadImage,
claimRequirements,
Expand All @@ -177,8 +169,7 @@ export default function RedPacketDialog(props: RedPacketDialogProps) {

const onBack = useCallback(() => {
if (step === CreateRedPacketPageStep.ConfirmPage) {
if (isFirefly) setStep(CreateRedPacketPageStep.ClaimRequirementsPage)
else setStep(CreateRedPacketPageStep.NewRedPacketPage)
setStep(CreateRedPacketPageStep.ClaimRequirementsPage)
}
if (step === CreateRedPacketPageStep.ClaimRequirementsPage) {
setStep(CreateRedPacketPageStep.NewRedPacketPage)
Expand All @@ -189,16 +180,12 @@ export default function RedPacketDialog(props: RedPacketDialogProps) {
CrossIsolationMessages.events.smartPayDialogEvent.sendToAll({ open: true })
}
}
}, [step, props.source === PluginID.SmartPay, handleClose, isFirefly])
}, [step, props.source === PluginID.SmartPay, handleClose])
const isCreateStep = step === CreateRedPacketPageStep.NewRedPacketPage
const onNext = useCallback(() => {
if (!isCreateStep) return
if (isFirefly) {
setStep(CreateRedPacketPageStep.ClaimRequirementsPage)
} else {
setStep(CreateRedPacketPageStep.ConfirmPage)
}
}, [isCreateStep, isFirefly])
setStep(CreateRedPacketPageStep.ClaimRequirementsPage)
}, [isCreateStep])
const onDialogClose = useCallback(() => {
if (openSelectNFTDialog) return setOpenSelectNFTDialog(false)
if (openNFTConfirmDialog) return setOpenNFTConfirmDialog(false)
Expand Down Expand Up @@ -290,26 +277,26 @@ export default function RedPacketDialog(props: RedPacketDialogProps) {
}, [])

return (
<TabContext value={showHistory && isFirefly ? currentHistoryTab : currentTab}>
<TabContext value={showHistory ? currentHistoryTab : currentTab}>
<InjectedDialog
isOpenFromApplicationBoard={props.isOpenFromApplicationBoard}
open={props.open}
title={title}
titleTail={titleTail}
titleTabs={
step === CreateRedPacketPageStep.NewRedPacketPage && !openNFTConfirmDialog && !showDetails ?
showHistory && isFirefly ?
showHistory ?
<MaskTabList variant="base" onChange={onChangeHistoryTab} aria-label="Redpacket">
<Tab label={t.claimed_tab_title()} value={historyTabs.claimed} />
<Tab label={t.sent_tab_title()} value={historyTabs.sent} />
</MaskTabList>
: <MaskTabList variant="base" onChange={onChange} aria-label="Redpacket">
<Tab label={t.erc20_tab_title()} value={tabs.tokens} />
<Tab
className={isFirefly ? classes.disabledTab : undefined}
className={classes.disabledTab}
label={t.nfts()}
value={tabs.collectibles}
disabled={isFirefly}
disabled
/>
</MaskTabList>

Expand All @@ -321,7 +308,8 @@ export default function RedPacketDialog(props: RedPacketDialogProps) {
step === CreateRedPacketPageStep.NewRedPacketPage &&
!openNFTConfirmDialog &&
!openSelectNFTDialog &&
((!showHistory && !showDetails) || !isFirefly)
!showHistory &&
!showDetails
) ?
<div className={classes.abstractTabWrapper}>
<NetworkTab
Expand Down Expand Up @@ -355,7 +343,6 @@ export default function RedPacketDialog(props: RedPacketDialogProps) {
expectedChainId={chainId}
origin={settings}
gasOption={gasOption}
isFirefly={isFirefly}
onClose={handleClose}
onNext={onNext}
onChange={_onChange}
Expand All @@ -379,9 +366,7 @@ export default function RedPacketDialog(props: RedPacketDialogProps) {
</TabPanel>
</div>
{showHistory && !showDetails ?
isFirefly ?
<FireflyRedPacketPast tabs={historyTabs} handleOpenDetails={handleOpenDetails} />
: <RedPacketPast tabs={tabs} onSelect={onCreateOrSelect} onClose={handleClose} />
<FireflyRedPacketPast tabs={historyTabs} handleOpenDetails={handleOpenDetails} />
: null}

{showDetails ?
Expand All @@ -393,31 +378,19 @@ export default function RedPacketDialog(props: RedPacketDialogProps) {
: null}

{step === CreateRedPacketPageStep.ConfirmPage && settings ?
isFirefly && props.fireflyContext ?
<FireflyRedpacketConfirmDialog
onClose={handleClose}
onCreated={handleCreated}
fireflyContext={props.fireflyContext}
fireflySettings={fireflyRpSettings}
settings={settings}
/>
: <RedPacketConfirmDialog
expectedChainId={chainId}
onClose={handleClose}
onBack={onBack}
onCreated={handleCreated}
settings={settings}
gasOption={gasOption}
onGasOptionChange={handleGasSettingChange}
/>

<FireflyRedpacketConfirmDialog
onClose={handleClose}
onCreated={handleCreated}
fireflyContext={props.fireflyContext}
fireflySettings={fireflyRpSettings}
settings={settings}
/>
: null}
{step === CreateRedPacketPageStep.ClaimRequirementsPage ?
<>
<ClaimRequirementsDialog
origin={fireflyRpSettings?.requirements}
onNext={handleClaimRequirementsNext}
isFirefly={isFirefly}
/>
<ClaimRequirementsRuleDialog open={showClaimRule} onClose={() => setShowClaimRule(false)} />
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ interface RedPacketFormProps {
setERC721DialogHeight?: (height: number) => void
gasOption?: GasConfig
expectedChainId: ChainId
isFirefly?: boolean
origin?: RedPacketSettings
onClose: () => void
onNext: () => void
Expand All @@ -102,7 +101,7 @@ interface RedPacketFormProps {
}

export function RedPacketERC20Form(props: RedPacketFormProps) {
const { origin, expectedChainId, isFirefly, gasOption, onChange, onNext, onGasOptionChange, onChainChange } = props
const { origin, expectedChainId, gasOption, onChange, onNext, onGasOptionChange, onChainChange } = props
const t = useRedPacketTrans()
const { classes } = useStyles()
const theme = useTheme()
Expand Down Expand Up @@ -360,7 +359,7 @@ export function RedPacketERC20Form(props: RedPacketFormProps) {
placeholder={t.blessing_words()}
value={message}
inputProps={{
maxLength: isFirefly ? 40 : 100,
maxLength: 40,
}}
/>
</Box>
Expand All @@ -386,7 +385,7 @@ export function RedPacketERC20Form(props: RedPacketFormProps) {
expectedPluginID={NetworkPluginID.PLUGIN_EVM}
expectedChainId={chainId}
actualPluginID={pluginID}
disableSwitchAccount={isFirefly}>
disableSwitchAccount>
<EthereumERC20TokenApprovedBoundary
amount={totalAmount.toFixed()}
balance={balance}
Expand All @@ -408,7 +407,7 @@ export function RedPacketERC20Form(props: RedPacketFormProps) {
<WalletConnectedBoundary
noGasText={t.no_enough_gas_fees()}
expectedChainId={chainId}
hideRiskWarningConfirmed={isFirefly}>
hideRiskWarningConfirmed>
<ActionButton
size="medium"
className={classes.button}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function RedPacketInjection() {
setOpen(false)
}, [])

if (!open) return null
if (!open || !fireflyContext) return null
return (
<EVMWeb3ContextProvider>
<CompositionTypeContext.Provider value={compositionType}>
Expand Down
Loading

0 comments on commit 153a169

Please sign in to comment.