diff --git a/packages/maskbook/src/plugin-infra/register.ts b/packages/maskbook/src/plugin-infra/register.ts index 6649c4c3c8ba..a350b9fd307b 100644 --- a/packages/maskbook/src/plugin-infra/register.ts +++ b/packages/maskbook/src/plugin-infra/register.ts @@ -3,4 +3,5 @@ import '@dimensiondev/plugin-example' import '../plugins/RedPacket' +import '../plugins/Snapshot' import '../plugins/External' diff --git a/packages/maskbook/src/plugins/Collectible/UI/Collectible.tsx b/packages/maskbook/src/plugins/Collectible/UI/Collectible.tsx index ce769acce2e7..6ceb8abf3b78 100644 --- a/packages/maskbook/src/plugins/Collectible/UI/Collectible.tsx +++ b/packages/maskbook/src/plugins/Collectible/UI/Collectible.tsx @@ -33,7 +33,7 @@ import { currentCollectibleProviderSettings } from '../settings' import { FootnoteMenu, FootnoteMenuOption } from '../../Trader/UI/trader/FootnoteMenu' import { MaskbookTextIcon } from '../../../resources/MaskbookIcon' import { resolveAssetLinkOnOpenSea, resolveCollectibleProviderName } from '../pipes' -import { Markdown } from '../../Snapshot/UI/Markdown' +import { Markdown } from '../../Snapshot/SNSAdaptor/Markdown' import { ActionBar } from './ActionBar' import { useChainId } from '@dimensiondev/web3-shared' import { getEnumAsArray } from '@dimensiondev/maskbook-shared' diff --git a/packages/maskbook/src/plugins/Collectible/UI/TokenTab.tsx b/packages/maskbook/src/plugins/Collectible/UI/TokenTab.tsx index dddba161f86e..54a4a2b1a09e 100644 --- a/packages/maskbook/src/plugins/Collectible/UI/TokenTab.tsx +++ b/packages/maskbook/src/plugins/Collectible/UI/TokenTab.tsx @@ -4,7 +4,7 @@ import { CollectibleTab } from './CollectibleTab' import { CollectibleState } from '../hooks/useCollectibleState' import { FormattedAddress } from '@dimensiondev/maskbook-shared' import { resolveAddressLinkOnExplorer, getChainName, ChainId, useChainId } from '@dimensiondev/web3-shared' -import { Markdown } from '../../Snapshot/UI/Markdown' +import { Markdown } from '../../Snapshot/SNSAdaptor/Markdown' import { Account } from './Account' import { resolveTraitLinkOnOpenSea } from '../pipes' diff --git a/packages/maskbook/src/plugins/PluginSerivce.ts b/packages/maskbook/src/plugins/PluginSerivce.ts index 435b7b6dd609..522b70e62ca9 100644 --- a/packages/maskbook/src/plugins/PluginSerivce.ts +++ b/packages/maskbook/src/plugins/PluginSerivce.ts @@ -19,5 +19,4 @@ import './Polls/utils' import './ITO/messages' import './Airdrop/messages' import './Collectible/messages' -import './Snapshot/messages' import './dHEDGE/messages' diff --git a/packages/maskbook/src/plugins/PluginUI.ts b/packages/maskbook/src/plugins/PluginUI.ts index c9bef1e72ae6..d49e2af77c59 100644 --- a/packages/maskbook/src/plugins/PluginUI.ts +++ b/packages/maskbook/src/plugins/PluginUI.ts @@ -21,7 +21,6 @@ import { AirdropPluginDefine } from './Airdrop/define' import { CollectiblesPluginDefine } from './Collectible/define' import { sideEffect } from '../utils/side-effects' import { VCentPluginDefine } from './VCent/define' -import { SnapShotPluginDefine } from './Snapshot/define' import { DHedgePluginDefine } from './dHEDGE/define' sideEffect.then(() => { @@ -36,7 +35,6 @@ sideEffect.then(() => { if (Flags.trader_enabled) plugins.add(TraderPluginDefine) if (Flags.transak_enabled) plugins.add(TransakPluginDefine) if (Flags.airdrop_enabled) plugins.add(AirdropPluginDefine) - if (Flags.snapshot_enabled) plugins.add(SnapShotPluginDefine) if (Flags.collectibles_enabled) plugins.add(CollectiblesPluginDefine) if (Flags.dhedge_enabled) plugins.add(DHedgePluginDefine) if (process.env.STORYBOOK) plugins.add(StorybookPluginDefine) diff --git a/packages/maskbook/src/plugins/RedPacket/messages.ts b/packages/maskbook/src/plugins/RedPacket/messages.ts index dd1f3824a8c9..5e3e8d1f476a 100644 --- a/packages/maskbook/src/plugins/RedPacket/messages.ts +++ b/packages/maskbook/src/plugins/RedPacket/messages.ts @@ -1,13 +1,15 @@ import { RedPacketPluginID } from './constants' import { createPluginMessage } from '../utils/createPluginMessage' import { createPluginRPC } from '../utils/createPluginRPC' +import type { WebExtensionMessage } from '@dimensiondev/holoflows-kit' export interface RedPacketMessages { redPacketUpdated: void _: unknown } if (import.meta.webpackHot) import.meta.webpackHot.accept() -export const RedPacketMessage = createPluginMessage(RedPacketPluginID) +export const RedPacketMessage: WebExtensionMessage = + createPluginMessage(RedPacketPluginID) export const RedPacketRPC = createPluginRPC( RedPacketPluginID, () => import('./Worker/services'), diff --git a/packages/maskbook/src/plugins/Snapshot/UI/InformationCard.tsx b/packages/maskbook/src/plugins/Snapshot/SNSAdaptor/InformationCard.tsx similarity index 98% rename from packages/maskbook/src/plugins/Snapshot/UI/InformationCard.tsx rename to packages/maskbook/src/plugins/Snapshot/SNSAdaptor/InformationCard.tsx index 5f3cc3836a34..82afe0663017 100644 --- a/packages/maskbook/src/plugins/Snapshot/UI/InformationCard.tsx +++ b/packages/maskbook/src/plugins/Snapshot/SNSAdaptor/InformationCard.tsx @@ -13,7 +13,7 @@ import { TokenIcon } from '../../../extension/options-page/DashboardComponents/T import { useI18N } from '../../../utils' import { EthereumBlockie } from '../../../web3/UI/EthereumBlockie' import { SnapshotContext } from '../context' -import { useProposal } from '../hooks/useProposal' +import { useProposal } from './hooks/useProposal' import { SnapshotCard } from './SnapshotCard' export interface InformationCardProps {} diff --git a/packages/maskbook/src/plugins/Snapshot/UI/LoadingCard.tsx b/packages/maskbook/src/plugins/Snapshot/SNSAdaptor/LoadingCard.tsx similarity index 100% rename from packages/maskbook/src/plugins/Snapshot/UI/LoadingCard.tsx rename to packages/maskbook/src/plugins/Snapshot/SNSAdaptor/LoadingCard.tsx diff --git a/packages/maskbook/src/plugins/Snapshot/UI/LoadingFailCard.tsx b/packages/maskbook/src/plugins/Snapshot/SNSAdaptor/LoadingFailCard.tsx similarity index 100% rename from packages/maskbook/src/plugins/Snapshot/UI/LoadingFailCard.tsx rename to packages/maskbook/src/plugins/Snapshot/SNSAdaptor/LoadingFailCard.tsx diff --git a/packages/maskbook/src/plugins/Snapshot/UI/Markdown.tsx b/packages/maskbook/src/plugins/Snapshot/SNSAdaptor/Markdown.tsx similarity index 94% rename from packages/maskbook/src/plugins/Snapshot/UI/Markdown.tsx rename to packages/maskbook/src/plugins/Snapshot/SNSAdaptor/Markdown.tsx index e27813577337..7abb84d100cd 100644 --- a/packages/maskbook/src/plugins/Snapshot/UI/Markdown.tsx +++ b/packages/maskbook/src/plugins/Snapshot/SNSAdaptor/Markdown.tsx @@ -1,6 +1,6 @@ import { makeStyles } from '@material-ui/core' import { useStylesExtends } from '../../../components/custom-ui-helper' -import { useRemarkable } from '../hooks/useRemarkable' +import { useRemarkable } from './hooks/useRemarkable' const useStyles = makeStyles((theme) => ({ root: { diff --git a/packages/maskbook/src/plugins/Snapshot/UI/PostInspector.tsx b/packages/maskbook/src/plugins/Snapshot/SNSAdaptor/PostInspector.tsx similarity index 85% rename from packages/maskbook/src/plugins/Snapshot/UI/PostInspector.tsx rename to packages/maskbook/src/plugins/Snapshot/SNSAdaptor/PostInspector.tsx index a5f1eec8b00b..604c39338e35 100644 --- a/packages/maskbook/src/plugins/Snapshot/UI/PostInspector.tsx +++ b/packages/maskbook/src/plugins/Snapshot/SNSAdaptor/PostInspector.tsx @@ -1,8 +1,8 @@ import { SnapshotContext } from '../context' -import { getProposalIdentifier } from '../helpers' +import { getProposalIdentifier } from './helpers' import { Snapshot } from './Snapshot' import { LoadingFailCard } from './LoadingFailCard' -import { useRetry } from '../hooks/useRetry' +import { useRetry } from './hooks/useRetry' export interface PostInspectorProps { url: string diff --git a/packages/maskbook/src/plugins/Snapshot/UI/ProgressTab.tsx b/packages/maskbook/src/plugins/Snapshot/SNSAdaptor/ProgressTab.tsx similarity index 100% rename from packages/maskbook/src/plugins/Snapshot/UI/ProgressTab.tsx rename to packages/maskbook/src/plugins/Snapshot/SNSAdaptor/ProgressTab.tsx diff --git a/packages/maskbook/src/plugins/Snapshot/UI/ProposalTab.tsx b/packages/maskbook/src/plugins/Snapshot/SNSAdaptor/ProposalTab.tsx similarity index 91% rename from packages/maskbook/src/plugins/Snapshot/UI/ProposalTab.tsx rename to packages/maskbook/src/plugins/Snapshot/SNSAdaptor/ProposalTab.tsx index 08dfd83e2c31..e8cdbc607e88 100644 --- a/packages/maskbook/src/plugins/Snapshot/UI/ProposalTab.tsx +++ b/packages/maskbook/src/plugins/Snapshot/SNSAdaptor/ProposalTab.tsx @@ -1,6 +1,6 @@ import { useContext } from 'react' import { VotingCard } from './VotingCard' -import { useProposal } from '../hooks/useProposal' +import { useProposal } from './hooks/useProposal' import { SnapshotTab } from './SnapshotTab' import { ReadMeCard } from './ReadmeCard' import { SnapshotContext } from '../context' diff --git a/packages/maskbook/src/plugins/Snapshot/UI/ReadmeCard.tsx b/packages/maskbook/src/plugins/Snapshot/SNSAdaptor/ReadmeCard.tsx similarity index 71% rename from packages/maskbook/src/plugins/Snapshot/UI/ReadmeCard.tsx rename to packages/maskbook/src/plugins/Snapshot/SNSAdaptor/ReadmeCard.tsx index 2e5d2abe55de..64b684e177cf 100644 --- a/packages/maskbook/src/plugins/Snapshot/UI/ReadmeCard.tsx +++ b/packages/maskbook/src/plugins/Snapshot/SNSAdaptor/ReadmeCard.tsx @@ -1,13 +1,8 @@ import { useContext } from 'react' -import { makeStyles } from '@material-ui/core' import { Markdown } from './Markdown' -import { useProposal } from '../hooks/useProposal' +import { useProposal } from './hooks/useProposal' import { SnapshotContext } from '../context' -const useStyles = makeStyles((theme) => { - return {} -}) - export interface ReadMeCardProps {} export function ReadMeCard(props: ReadMeCardProps) { diff --git a/packages/maskbook/src/plugins/Snapshot/UI/ResultCard.tsx b/packages/maskbook/src/plugins/Snapshot/SNSAdaptor/ResultCard.tsx similarity index 94% rename from packages/maskbook/src/plugins/Snapshot/UI/ResultCard.tsx rename to packages/maskbook/src/plugins/Snapshot/SNSAdaptor/ResultCard.tsx index 4c8286633a79..1e83e71cedab 100644 --- a/packages/maskbook/src/plugins/Snapshot/UI/ResultCard.tsx +++ b/packages/maskbook/src/plugins/Snapshot/SNSAdaptor/ResultCard.tsx @@ -4,12 +4,12 @@ import { makeStyles, Box, List, ListItem, Typography, LinearProgress, withStyles import { ShadowRootTooltip, useI18N } from '../../../utils' import millify from 'millify' import { SnapshotContext } from '../context' -import { useProposal } from '../hooks/useProposal' -import { useVotes } from '../hooks/useVotes' -import { useResults } from '../hooks/useResults' +import { useProposal } from './hooks/useProposal' +import { useVotes } from './hooks/useVotes' +import { useResults } from './hooks/useResults' import { SnapshotCard } from './SnapshotCard' import { parse } from 'json2csv' -import { useRetry } from '../hooks/useRetry' +import { useRetry } from './hooks/useRetry' import { LoadingFailCard } from './LoadingFailCard' import { LoadingCard } from './LoadingCard' @@ -76,10 +76,10 @@ function Content() { const classes = useStyles() const { t } = useI18N() const listRef = useRef([]) - const [tooltipVisibles, setTooltipVisibles] = useState(new Array(results.length).fill(false)) + const [tooltipsVisible, setTooltipsVisible] = useState(new Array(results.length).fill(false)) useEffect(() => { - setTooltipVisibles(listRef.current.map((element) => (element.offsetWidth === choiceMaxWidth ? true : false))) + setTooltipsVisible(listRef.current.map((element) => (element.offsetWidth === choiceMaxWidth ? true : false))) }, []) const dataForCsv = useMemo( @@ -109,7 +109,7 @@ function Content() { }} title={{result.choice}} placement="top" - disableHoverListener={!tooltipVisibles[i]} + disableHoverListener={!tooltipsVisible[i]} arrow> { diff --git a/packages/maskbook/src/plugins/Snapshot/UI/Snapshot.tsx b/packages/maskbook/src/plugins/Snapshot/SNSAdaptor/Snapshot.tsx similarity index 98% rename from packages/maskbook/src/plugins/Snapshot/UI/Snapshot.tsx rename to packages/maskbook/src/plugins/Snapshot/SNSAdaptor/Snapshot.tsx index f01a5a120ff1..9203db3354d0 100644 --- a/packages/maskbook/src/plugins/Snapshot/UI/Snapshot.tsx +++ b/packages/maskbook/src/plugins/Snapshot/SNSAdaptor/Snapshot.tsx @@ -1,7 +1,7 @@ import { useState, useContext } from 'react' import { makeStyles, Box, Card, CardHeader, CardContent, Typography, Tab, Tabs, Chip, Paper } from '@material-ui/core' import { SnapshotContext } from '../context' -import { useProposal } from '../hooks/useProposal' +import { useProposal } from './hooks/useProposal' import { ProposalTab } from './ProposalTab' import { ProgressTab } from './ProgressTab' diff --git a/packages/maskbook/src/plugins/Snapshot/UI/SnapshotCard.tsx b/packages/maskbook/src/plugins/Snapshot/SNSAdaptor/SnapshotCard.tsx similarity index 95% rename from packages/maskbook/src/plugins/Snapshot/UI/SnapshotCard.tsx rename to packages/maskbook/src/plugins/Snapshot/SNSAdaptor/SnapshotCard.tsx index 99e02db19946..143f1d0790ee 100644 --- a/packages/maskbook/src/plugins/Snapshot/UI/SnapshotCard.tsx +++ b/packages/maskbook/src/plugins/Snapshot/SNSAdaptor/SnapshotCard.tsx @@ -1,5 +1,4 @@ import { Card, makeStyles, CardContent, CardHeader, Typography } from '@material-ui/core' -import { useI18N } from '../../../utils' const useStyles = makeStyles((theme) => { return { @@ -40,7 +39,6 @@ export interface SnapshotCardProps { export function SnapshotCard(props: SnapshotCardProps) { const { title, children } = props - const { t } = useI18N() const classes = useStyles() return ( diff --git a/packages/maskbook/src/plugins/Snapshot/UI/SnapshotTab.tsx b/packages/maskbook/src/plugins/Snapshot/SNSAdaptor/SnapshotTab.tsx similarity index 100% rename from packages/maskbook/src/plugins/Snapshot/UI/SnapshotTab.tsx rename to packages/maskbook/src/plugins/Snapshot/SNSAdaptor/SnapshotTab.tsx diff --git a/packages/maskbook/src/plugins/Snapshot/UI/Vote.tsx b/packages/maskbook/src/plugins/Snapshot/SNSAdaptor/Vote.tsx similarity index 88% rename from packages/maskbook/src/plugins/Snapshot/UI/Vote.tsx rename to packages/maskbook/src/plugins/Snapshot/SNSAdaptor/Vote.tsx index d5133abe9593..fce12e3c606e 100644 --- a/packages/maskbook/src/plugins/Snapshot/UI/Vote.tsx +++ b/packages/maskbook/src/plugins/Snapshot/SNSAdaptor/Vote.tsx @@ -2,7 +2,7 @@ import { useBlockie } from '@dimensiondev/web3-shared' import { Avatar, Box, makeStyles } from '@material-ui/core' import type { VoteItem as VoteType } from '../types' -const useStlyes = makeStyles(() => ({ +const useStyles = makeStyles(() => ({ avatar: { width: 16, height: 16, @@ -14,7 +14,7 @@ export interface VoteProps { } export function Vote(props: VoteProps) { - const classes = useStlyes() + const classes = useStyles() const blockie = useBlockie(props.vote.address) return ( diff --git a/packages/maskbook/src/plugins/Snapshot/UI/VoteConfirmDialog.tsx b/packages/maskbook/src/plugins/Snapshot/SNSAdaptor/VoteConfirmDialog.tsx similarity index 100% rename from packages/maskbook/src/plugins/Snapshot/UI/VoteConfirmDialog.tsx rename to packages/maskbook/src/plugins/Snapshot/SNSAdaptor/VoteConfirmDialog.tsx diff --git a/packages/maskbook/src/plugins/Snapshot/UI/VotesCard.tsx b/packages/maskbook/src/plugins/Snapshot/SNSAdaptor/VotesCard.tsx similarity index 98% rename from packages/maskbook/src/plugins/Snapshot/UI/VotesCard.tsx rename to packages/maskbook/src/plugins/Snapshot/SNSAdaptor/VotesCard.tsx index aa899b2958d9..8ed1df2cef58 100644 --- a/packages/maskbook/src/plugins/Snapshot/UI/VotesCard.tsx +++ b/packages/maskbook/src/plugins/Snapshot/SNSAdaptor/VotesCard.tsx @@ -7,8 +7,8 @@ import { useContext } from 'react' import { useI18N } from '../../../utils' import { EthereumBlockie } from '../../../web3/UI/EthereumBlockie' import { SnapshotContext } from '../context' -import { useRetry } from '../hooks/useRetry' -import { useVotes } from '../hooks/useVotes' +import { useRetry } from './hooks/useRetry' +import { useVotes } from './hooks/useVotes' import type { VoteItem } from '../types' import { LoadingCard } from './LoadingCard' import { LoadingFailCard } from './LoadingFailCard' diff --git a/packages/maskbook/src/plugins/Snapshot/UI/VotingCard.tsx b/packages/maskbook/src/plugins/Snapshot/SNSAdaptor/VotingCard.tsx similarity index 96% rename from packages/maskbook/src/plugins/Snapshot/UI/VotingCard.tsx rename to packages/maskbook/src/plugins/Snapshot/SNSAdaptor/VotingCard.tsx index 4baa967c39b8..3d60581c5746 100644 --- a/packages/maskbook/src/plugins/Snapshot/UI/VotingCard.tsx +++ b/packages/maskbook/src/plugins/Snapshot/SNSAdaptor/VotingCard.tsx @@ -6,12 +6,12 @@ import { SnapshotContext } from '../context' import { useAccount } from '@dimensiondev/web3-shared' import { PluginSnapshotRPC } from '../messages' import { SnapshotCard } from './SnapshotCard' -import { useProposal } from '../hooks/useProposal' -import { usePower } from '../hooks/usePower' +import { useProposal } from './hooks/useProposal' +import { usePower } from './hooks/usePower' import { EthereumWalletConnectedBoundary } from '../../../web3/UI/EthereumWalletConnectedBoundary' import { VoteConfirmDialog } from './VoteConfirmDialog' import { useSnackbarCallback } from '../../../extension/options-page/DashboardDialogs/Base' -import { useRetry } from '../hooks/useRetry' +import { useRetry } from './hooks/useRetry' const useStyles = makeStyles((theme) => { return { diff --git a/packages/maskbook/src/plugins/Snapshot/helpers.ts b/packages/maskbook/src/plugins/Snapshot/SNSAdaptor/helpers.ts similarity index 80% rename from packages/maskbook/src/plugins/Snapshot/helpers.ts rename to packages/maskbook/src/plugins/Snapshot/SNSAdaptor/helpers.ts index 81271bef0738..67cc0766d059 100644 --- a/packages/maskbook/src/plugins/Snapshot/helpers.ts +++ b/packages/maskbook/src/plugins/Snapshot/SNSAdaptor/helpers.ts @@ -1,4 +1,4 @@ -import type { ProposalIdentifier } from './types' +import type { ProposalIdentifier } from '../types' export function getProposalIdentifier(url: string): ProposalIdentifier { const parsedURL = new URL(url) diff --git a/packages/maskbook/src/plugins/Snapshot/hooks/usePower.ts b/packages/maskbook/src/plugins/Snapshot/SNSAdaptor/hooks/usePower.ts similarity index 85% rename from packages/maskbook/src/plugins/Snapshot/hooks/usePower.ts rename to packages/maskbook/src/plugins/Snapshot/SNSAdaptor/hooks/usePower.ts index 12abb7285eb5..3fdb41e09c45 100644 --- a/packages/maskbook/src/plugins/Snapshot/hooks/usePower.ts +++ b/packages/maskbook/src/plugins/Snapshot/SNSAdaptor/hooks/usePower.ts @@ -1,7 +1,7 @@ import { useAsyncRetry } from 'react-use' import { useAccount, useBlockNumber } from '@dimensiondev/web3-shared' -import { PluginSnapshotRPC } from '../messages' -import type { ProposalIdentifier } from '../types' +import { PluginSnapshotRPC } from '../../messages' +import type { ProposalIdentifier } from '../../types' import { useProposal } from './useProposal' export function usePower(identifier: ProposalIdentifier) { diff --git a/packages/maskbook/src/plugins/Snapshot/hooks/useProposal.ts b/packages/maskbook/src/plugins/Snapshot/SNSAdaptor/hooks/useProposal.ts similarity index 83% rename from packages/maskbook/src/plugins/Snapshot/hooks/useProposal.ts rename to packages/maskbook/src/plugins/Snapshot/SNSAdaptor/hooks/useProposal.ts index b6fde505875b..fa5c346014d7 100644 --- a/packages/maskbook/src/plugins/Snapshot/hooks/useProposal.ts +++ b/packages/maskbook/src/plugins/Snapshot/SNSAdaptor/hooks/useProposal.ts @@ -1,6 +1,6 @@ -import { PluginSnapshotRPC } from '../messages' -import type { Proposal, ProposalMessage } from '../types' -import { useSuspense } from '../../../utils/hooks/useSuspense' +import { PluginSnapshotRPC } from '../../messages' +import type { Proposal, ProposalMessage } from '../../types' +import { useSuspense } from '../../../../utils/hooks/useSuspense' const cache = new Map] | [1, { proposal: Proposal; message: ProposalMessage }] | [2, Error]>() export function proposalRetry() { @@ -23,7 +23,7 @@ async function Suspender(id: string) { proposal.isStart = now > message.payload.start * 1000 proposal.isEnd = now > message.payload.end * 1000 - proposal.status = !proposal.isStart ? 'Pending' : proposal.isEnd ? 'Close' : 'Active' + proposal.status = !proposal.isStart ? 'Pending' : proposal.isEnd ? 'Closed' : 'Active' proposal.authorName = profiles[0]?.name proposal.authorAvatar = profiles[0]?.image return { proposal, message } diff --git a/packages/maskbook/src/plugins/Snapshot/hooks/useRemarkable.ts b/packages/maskbook/src/plugins/Snapshot/SNSAdaptor/hooks/useRemarkable.ts similarity index 100% rename from packages/maskbook/src/plugins/Snapshot/hooks/useRemarkable.ts rename to packages/maskbook/src/plugins/Snapshot/SNSAdaptor/hooks/useRemarkable.ts diff --git a/packages/maskbook/src/plugins/Snapshot/hooks/useResults.ts b/packages/maskbook/src/plugins/Snapshot/SNSAdaptor/hooks/useResults.ts similarity index 96% rename from packages/maskbook/src/plugins/Snapshot/hooks/useResults.ts rename to packages/maskbook/src/plugins/Snapshot/SNSAdaptor/hooks/useResults.ts index 16a080e853ca..78ae24cd9beb 100644 --- a/packages/maskbook/src/plugins/Snapshot/hooks/useResults.ts +++ b/packages/maskbook/src/plugins/Snapshot/SNSAdaptor/hooks/useResults.ts @@ -1,5 +1,5 @@ -import type { ProposalIdentifier, ProposalResult, VoteItemList } from '../types' -import { useSuspense } from '../../../utils/hooks/useSuspense' +import type { ProposalIdentifier, ProposalResult, VoteItemList } from '../../types' +import { useSuspense } from '../../../../utils/hooks/useSuspense' import { useProposal } from './useProposal' import { useVotes } from './useVotes' diff --git a/packages/maskbook/src/plugins/Snapshot/hooks/useRetry.ts b/packages/maskbook/src/plugins/Snapshot/SNSAdaptor/hooks/useRetry.ts similarity index 71% rename from packages/maskbook/src/plugins/Snapshot/hooks/useRetry.ts rename to packages/maskbook/src/plugins/Snapshot/SNSAdaptor/hooks/useRetry.ts index 00c251698d5f..74f01ae7ccdf 100644 --- a/packages/maskbook/src/plugins/Snapshot/hooks/useRetry.ts +++ b/packages/maskbook/src/plugins/Snapshot/SNSAdaptor/hooks/useRetry.ts @@ -1,7 +1,7 @@ import { useCallback } from 'react' import { useUpdate } from 'react-use' -import { votesRetry } from '../hooks/useVotes' -import { resultsRetry } from '../hooks/useResults' +import { votesRetry } from './useVotes' +import { resultsRetry } from './useResults' export function useRetry() { const forceUpdate = useUpdate() diff --git a/packages/maskbook/src/plugins/Snapshot/hooks/useVotes.ts b/packages/maskbook/src/plugins/Snapshot/SNSAdaptor/hooks/useVotes.ts similarity index 94% rename from packages/maskbook/src/plugins/Snapshot/hooks/useVotes.ts rename to packages/maskbook/src/plugins/Snapshot/SNSAdaptor/hooks/useVotes.ts index ae845e4c1a27..b45f54e01f5b 100644 --- a/packages/maskbook/src/plugins/Snapshot/hooks/useVotes.ts +++ b/packages/maskbook/src/plugins/Snapshot/SNSAdaptor/hooks/useVotes.ts @@ -1,6 +1,6 @@ -import { PluginSnapshotRPC } from '../messages' -import type { VoteItemList, ProposalIdentifier, VoteItem } from '../types' -import { useSuspense } from '../../../utils/hooks/useSuspense' +import { PluginSnapshotRPC } from '../../messages' +import type { VoteItemList, ProposalIdentifier, VoteItem } from '../../types' +import { useSuspense } from '../../../../utils/hooks/useSuspense' import { useProposal } from './useProposal' import { useBlockNumber } from '@dimensiondev/web3-shared' diff --git a/packages/maskbook/src/plugins/Snapshot/define.tsx b/packages/maskbook/src/plugins/Snapshot/SNSAdaptor/index.tsx similarity index 65% rename from packages/maskbook/src/plugins/Snapshot/define.tsx rename to packages/maskbook/src/plugins/Snapshot/SNSAdaptor/index.tsx index b6dee47a62f6..a936eacd4f23 100644 --- a/packages/maskbook/src/plugins/Snapshot/define.tsx +++ b/packages/maskbook/src/plugins/Snapshot/SNSAdaptor/index.tsx @@ -1,12 +1,12 @@ +import type { Plugin } from '@dimensiondev/mask-plugin-infra' +import { base } from '../base' import { useMemo, Suspense } from 'react' import { Skeleton, makeStyles } from '@material-ui/core' -import { PluginConfig, PluginScope, PluginStage } from '../types' -import { SNAPSHOT_PLUGIN_NAME, SNAPSHOT_PLUGIN_ID } from './constants' -import MaskbookPluginWrapper from '../MaskbookPluginWrapper' -import { PostInspector } from './UI/PostInspector' -import { usePostInfoDetails } from '../../components/DataSource/usePostInfo' -import { extractTextFromTypedMessage } from '../../protocols/typed-message' -import { parseURL } from '../../utils/utils' +import MaskbookPluginWrapper from '../../MaskbookPluginWrapper' +import { PostInspector } from './PostInspector' +import { usePostInfoDetails } from '../../../components/DataSource/usePostInfo' +import { extractTextFromTypedMessage } from '../../../protocols/typed-message' +import { parseURL } from '@dimensiondev/maskbook-shared' const useStyles = makeStyles((theme) => { return { @@ -22,31 +22,6 @@ const useStyles = makeStyles((theme) => { const isSnaphotURL = (x: string): boolean => /^https:\/\/(?:www.)?snapshot.(org|page)\/#\/(.*?)\/proposal\/[A-Za-z0-9]+$/.test(x) -export const SnapShotPluginDefine: PluginConfig = { - id: SNAPSHOT_PLUGIN_ID, - pluginName: SNAPSHOT_PLUGIN_NAME, - identifier: SNAPSHOT_PLUGIN_ID, - pluginIcon: '📷', - pluginDescription: 'A plugin for https://snapshot.org/', - stage: PluginStage.Production, - scope: PluginScope.Public, - successDecryptionInspector: function Component(props): JSX.Element | null { - const text = useMemo(() => extractTextFromTypedMessage(props.message), [props.message]) - const link = useMemo(() => parseURL(text.val || ''), [text.val]).find(isSnaphotURL) - if (!text.ok) return null - if (!link) return null - return - }, - postInspector: function Component(): JSX.Element | null { - const link = usePostInfoDetails - .postMetadataMentionedLinks() - .concat(usePostInfoDetails.postMentionedLinks()) - .find(isSnaphotURL) - if (!link) return null - return - }, -} - function Renderer({ url }: { url: string }) { const classes = useStyles() return ( @@ -66,3 +41,25 @@ function Renderer({ url }: { url: string }) { ) } + +const sns: Plugin.SNSAdaptor.Definition = { + ...base, + init(signal) {}, + DecryptedInspector: function Component(props): JSX.Element | null { + const text = useMemo(() => extractTextFromTypedMessage(props.message), [props.message]) + const link = useMemo(() => parseURL(text.val || ''), [text.val]).find(isSnaphotURL) + if (!text.ok) return null + if (!link) return null + return + }, + PostInspector: function Component(): JSX.Element | null { + const link = usePostInfoDetails + .postMetadataMentionedLinks() + .concat(usePostInfoDetails.postMentionedLinks()) + .find(isSnaphotURL) + if (!link) return null + return + }, +} + +export default sns diff --git a/packages/maskbook/src/plugins/Snapshot/UI/StatusChip.tsx b/packages/maskbook/src/plugins/Snapshot/UI/StatusChip.tsx deleted file mode 100644 index f8c2879e082c..000000000000 --- a/packages/maskbook/src/plugins/Snapshot/UI/StatusChip.tsx +++ /dev/null @@ -1,3 +0,0 @@ -export interface StatusChipProps {} - -export function StatusChip(props: StatusChipProps) {} diff --git a/packages/maskbook/src/plugins/Snapshot/apis/index.ts b/packages/maskbook/src/plugins/Snapshot/Worker/apis/index.ts similarity index 95% rename from packages/maskbook/src/plugins/Snapshot/apis/index.ts rename to packages/maskbook/src/plugins/Snapshot/Worker/apis/index.ts index ca9583b2913e..7aca6dc4d5d4 100644 --- a/packages/maskbook/src/plugins/Snapshot/apis/index.ts +++ b/packages/maskbook/src/plugins/Snapshot/Worker/apis/index.ts @@ -1,7 +1,7 @@ import ss from '@snapshot-labs/snapshot.js' import { ChainId } from '@dimensiondev/web3-shared' -import type { VoteItemList, Proposal, Profile3Box, ProposalMessage, ProposalIdentifier, VoteSuccess } from '../types' -import Services from '../../../extension/service' +import type { VoteItemList, Proposal, Profile3Box, ProposalMessage, ProposalIdentifier, VoteSuccess } from '../../types' +import Services from '../../../../extension/service' export async function fetchProposal(id: string) { const response = await fetch(`https://ipfs.io/ipfs/${id}`, { diff --git a/packages/maskbook/src/plugins/Snapshot/Worker/index.ts b/packages/maskbook/src/plugins/Snapshot/Worker/index.ts new file mode 100644 index 000000000000..4838783d7aa5 --- /dev/null +++ b/packages/maskbook/src/plugins/Snapshot/Worker/index.ts @@ -0,0 +1,9 @@ +import type { Plugin } from '@dimensiondev/mask-plugin-infra' +import { base } from '../base' +import '../messages' + +const worker: Plugin.Worker.Definition = { + ...base, + init(signal) {}, +} +export default worker diff --git a/packages/maskbook/src/plugins/Snapshot/services.ts b/packages/maskbook/src/plugins/Snapshot/Worker/services.ts similarity index 100% rename from packages/maskbook/src/plugins/Snapshot/services.ts rename to packages/maskbook/src/plugins/Snapshot/Worker/services.ts diff --git a/packages/maskbook/src/plugins/Snapshot/base.ts b/packages/maskbook/src/plugins/Snapshot/base.ts new file mode 100644 index 000000000000..41f2a1edd4c0 --- /dev/null +++ b/packages/maskbook/src/plugins/Snapshot/base.ts @@ -0,0 +1,17 @@ +import type { Plugin } from '@dimensiondev/mask-plugin-infra' +import { SNAPSHOT_PLUGIN_ID } from './constants' + +export const base: Plugin.Shared.Definition = { + ID: SNAPSHOT_PLUGIN_ID, + icon: '📷', + name: { fallback: 'Snapshot' }, + description: { + fallback: 'A plugin for https://snapshot.org/', + }, + publisher: { name: { fallback: 'Mask Network' }, link: 'https://mask.io/' }, + enableRequirement: { + architecture: { app: true, web: true }, + networks: { type: 'opt-out', networks: {} }, + target: 'stable', + }, +} diff --git a/packages/maskbook/src/plugins/Snapshot/index.ts b/packages/maskbook/src/plugins/Snapshot/index.ts new file mode 100644 index 000000000000..69a353f163b6 --- /dev/null +++ b/packages/maskbook/src/plugins/Snapshot/index.ts @@ -0,0 +1,17 @@ +import { registerPlugin } from '@dimensiondev/mask-plugin-infra' +import { base } from './base' + +registerPlugin({ + ...base, + SNSAdaptor: { + load: () => import('./SNSAdaptor'), + hotModuleReload: (hot) => + import.meta.webpackHot && + import.meta.webpackHot.accept('./SNSAdaptor/index', () => hot(import('./SNSAdaptor'))), + }, + Worker: { + load: () => import('./Worker'), + hotModuleReload: (hot) => + import.meta.webpackHot && import.meta.webpackHot.accept('./Worker/index', () => hot(import('./Worker'))), + }, +}) diff --git a/packages/maskbook/src/plugins/Snapshot/messages.ts b/packages/maskbook/src/plugins/Snapshot/messages.ts index bfd7d57d52ee..030570dc0418 100644 --- a/packages/maskbook/src/plugins/Snapshot/messages.ts +++ b/packages/maskbook/src/plugins/Snapshot/messages.ts @@ -18,10 +18,11 @@ interface SnapshotMessages { voteConfirmDialogUpdated: VoteConfirmDialogEvent } +if (import.meta.webpackHot) import.meta.webpackHot.accept() export const PluginSnapshotMessages: WebExtensionMessage = createPluginMessage(SNAPSHOT_PLUGIN_ID) export const PluginSnapshotRPC = createPluginRPC( SNAPSHOT_PLUGIN_ID, - () => import('./services'), + () => import('./Worker/services'), PluginSnapshotMessages.events.rpc, )