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
3 changes: 2 additions & 1 deletion packages/maskbook/src/plugin-infra/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ import '@dimensiondev/plugin-example'
import '../plugins/RedPacket'
import '../plugins/Snapshot'
import '../plugins/Collectible'
// import '../plugins/NFT'
import '../plugins/External'
// import '../plugins/NFT'
// import '../plugins/Airdrop'
Comment thread
guanbinrui marked this conversation as resolved.
36 changes: 36 additions & 0 deletions packages/maskbook/src/plugins/Airdrop/SNSAdaptor/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import type { Plugin } from '@dimensiondev/mask-plugin-infra'
import MaskbookPluginWrapper from '../../MaskbookPluginWrapper'
import { base } from '../base'
import { AirdropMetadataReader } from '../helpers'
import { Airdrop } from './Airdrop'
import type { AirdropJSONPayload } from '../types'
import { PLUGIN_NAME, PLUGIN_META_KEY } from '../constants'
import { CompositionDialog } from './CompositionDialog'

const sns: Plugin.SNSAdaptor.Definition = {
...base,
init(signal) {},
DecryptedInspector: function Comp(props) {
const payload = AirdropMetadataReader(props.message.meta)
if (!payload.ok) return null
return (
<MaskbookPluginWrapper pluginName={PLUGIN_NAME}>
<Airdrop payload={payload.val} />
</MaskbookPluginWrapper>
)
},
CompositionDialogMetadataBadgeRender: new Map([
[
PLUGIN_META_KEY,
(payload: AirdropJSONPayload) => {
return PLUGIN_NAME
},
],
]),
CompositionDialogEntry: {
label: `🪂 ${PLUGIN_NAME}`,
dialog: CompositionDialog,
},
}

export default sns
9 changes: 9 additions & 0 deletions packages/maskbook/src/plugins/Airdrop/Worker/index.ts
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions packages/maskbook/src/plugins/Airdrop/base.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { Plugin } from '@dimensiondev/mask-plugin-infra'
import { PLUGIN_ID, PLUGIN_ICON, PLUGIN_NAME, PLUGIN_DESCRIPTION } from './constants'

export const base: Plugin.Shared.Definition = {
ID: PLUGIN_ID,
icon: PLUGIN_ICON,
name: { fallback: PLUGIN_NAME },
description: { fallback: PLUGIN_DESCRIPTION },
publisher: { name: { fallback: 'Mask Network' }, link: 'https://mask.io/' },
enableRequirement: {
architecture: { app: false, web: true },
networks: { type: 'opt-out', networks: {} },
target: 'insider',
Comment thread
guanbinrui marked this conversation as resolved.
},
}
7 changes: 5 additions & 2 deletions packages/maskbook/src/plugins/Airdrop/constants.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { ChainId } from '@dimensiondev/web3-shared'

export const AirdropMetaKey = 'com.maskbook.airdrop:1'
export const AirdropPluginID = 'com.maskbook.airdrop'
export const PLUGIN_META_KEY = 'com.maskbook.airdrop:1'
export const PLUGIN_ID = 'com.maskbook.airdrop'
export const PLUGIN_NAME = 'Airdrop'
export const PLUGIN_ICON = '🪂'
export const PLUGIN_DESCRIPTION = ''

export const AIRDROP_CONSTANTS = {
AIRDROP_CONTRACT_ADDRESS: {
Expand Down
46 changes: 0 additions & 46 deletions packages/maskbook/src/plugins/Airdrop/define.tsx

This file was deleted.

4 changes: 2 additions & 2 deletions packages/maskbook/src/plugins/Airdrop/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createTypedMessageMetadataReader, createRenderWithMetadata } from '../../protocols/typed-message/metadata'
import { AirdropMetaKey } from './constants'
import { PLUGIN_META_KEY } from './constants'
import type { AirdropJSONPayload } from './types'
import schema from './schema.json'

export const AirdropMetadataReader = createTypedMessageMetadataReader<AirdropJSONPayload>(AirdropMetaKey, schema)
export const AirdropMetadataReader = createTypedMessageMetadataReader<AirdropJSONPayload>(PLUGIN_META_KEY, schema)
export const renderWithAirdropMetadata = createRenderWithMetadata(AirdropMetadataReader)
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { useAsyncRetry } from 'react-use'
import { PluginAirdropRPC } from '../messages'
import { AirdropRPC } from '../messages'

export function useAirdropPacket(address: string) {
return useAsyncRetry(async () => {
if (!address) return
return PluginAirdropRPC.getMaskAirdropPacket(address)
return AirdropRPC.getMaskAirdropPacket(address)
}, [address])
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { EthereumAddress } from 'wallet.ts'
import { formatEthereumAddress, isGreaterThan, ONE } from '@dimensiondev/maskbook-shared'
import type { AirdropPacket } from '../apis'
import { useAirdropContract } from '../contracts/useAirdropContract'
import { PluginAirdropRPC } from '../messages'
import { AirdropRPC } from '../messages'

export enum CheckStateType {
UNKNOWN,
Expand Down Expand Up @@ -66,7 +66,7 @@ export function useCheckCallback() {
const address_ = formatEthereumAddress(checkAddress.trim())

// read airdrop packet
const packet = await PluginAirdropRPC.getMaskAirdropPacket(address_)
const packet = await AirdropRPC.getMaskAirdropPacket(address_)
if (!packet) {
setCheckState({
type: CheckStateType.FAILED,
Expand Down
15 changes: 15 additions & 0 deletions packages/maskbook/src/plugins/Airdrop/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { registerPlugin } from '@dimensiondev/mask-plugin-infra'
import { base } from './base'

registerPlugin({
...base,
SNSAdaptor: {
load: () => import('./SNSAdaptor'),
hotModuleReload: (hot) =>
import.meta.webpackHot?.accept('./SNSAdaptor/index', () => hot(import('./SNSAdaptor'))),
},
Worker: {
load: () => import('./Worker'),
hotModuleReload: (hot) => import.meta.webpackHot?.accept('./Worker/index', () => hot(import('./Worker'))),
},
})
11 changes: 8 additions & 3 deletions packages/maskbook/src/plugins/Airdrop/messages.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import type { WebExtensionMessage } from '@dimensiondev/holoflows-kit'
import { createPluginMessage } from '../utils/createPluginMessage'
import { createPluginRPC } from '../utils/createPluginRPC'
import { AirdropPluginID } from './constants'
import { PLUGIN_ID } from './constants'

export interface AirdropMessages {
_: unknown
}

if (import.meta.webpackHot) import.meta.webpackHot.accept()
export const AirdropMessage = createPluginMessage<{ _: unknown }>(AirdropPluginID)
export const PluginAirdropRPC = createPluginRPC(AirdropPluginID, () => import('./services'), AirdropMessage.events._)
export const AirdropMessage: WebExtensionMessage<AirdropMessages> = createPluginMessage<{ _: unknown }>(PLUGIN_ID)
export const AirdropRPC = createPluginRPC(PLUGIN_ID, () => import('./services'), AirdropMessage.events._)
6 changes: 2 additions & 4 deletions packages/maskbook/src/plugins/Collectible/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ registerPlugin({
SNSAdaptor: {
load: () => import('./SNSAdaptor'),
hotModuleReload: (hot) =>
import.meta.webpackHot &&
import.meta.webpackHot.accept('./SNSAdaptor/index', () => hot(import('./SNSAdaptor'))),
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'))),
hotModuleReload: (hot) => import.meta.webpackHot?.accept('./Worker/index', () => hot(import('./Worker'))),
},
})
2 changes: 0 additions & 2 deletions packages/maskbook/src/plugins/PluginUI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { FileServicePluginDefine } from './FileService/UI-define'
import { TraderPluginDefine } from './Trader/define'
import { TransakPluginDefine } from './Transak/define'
import { ITO_PluginDefine } from './ITO/define'
import { AirdropPluginDefine } from './Airdrop/define'
import { sideEffect } from '../utils/side-effects'
import { VCentPluginDefine } from './VCent/define'
import { DHedgePluginDefine } from './dHEDGE/define'
Expand All @@ -31,7 +30,6 @@ sideEffect.then(() => {
if (Flags.poll_enabled) plugins.add(PollsPluginDefine)
if (Flags.trader_enabled) plugins.add(TraderPluginDefine)
if (Flags.transak_enabled) plugins.add(TransakPluginDefine)
if (Flags.airdrop_enabled) plugins.add(AirdropPluginDefine)
if (Flags.dhedge_enabled) plugins.add(DHedgePluginDefine)
if (process.env.STORYBOOK) plugins.add(StorybookPluginDefine)
})
6 changes: 2 additions & 4 deletions packages/maskbook/src/plugins/RedPacket/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ registerPlugin({
SNSAdaptor: {
load: () => import('./SNSAdaptor'),
hotModuleReload: (hot) =>
import.meta.webpackHot &&
import.meta.webpackHot.accept('./SNSAdaptor/index', () => hot(import('./SNSAdaptor'))),
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'))),
hotModuleReload: (hot) => import.meta.webpackHot?.accept('./Worker/index', () => hot(import('./Worker'))),
},
})
6 changes: 2 additions & 4 deletions packages/maskbook/src/plugins/Snapshot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ registerPlugin({
SNSAdaptor: {
load: () => import('./SNSAdaptor'),
hotModuleReload: (hot) =>
import.meta.webpackHot &&
import.meta.webpackHot.accept('./SNSAdaptor/index', () => hot(import('./SNSAdaptor'))),
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'))),
hotModuleReload: (hot) => import.meta.webpackHot?.accept('./Worker/index', () => hot(import('./Worker'))),
},
})
2 changes: 0 additions & 2 deletions packages/maskbook/src/utils/flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ export const Flags = {
election2020_enabled: webOnly,
election2020_composition_dialog_enabled: false,
dhedge_enabled: webOnly,
airdrop_enabled: webOnly,
airdrop_composition_dialog_enabled: false,
snapshot_enabled: webOnly,
metamask_support_enabled: webOnly,
toolbar_enabled: webOnly,
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-infra/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export namespace Plugin {
* ```ts
* const loader = {
* load: () => import('./code'),
* hotModuleReload: hot => import.meta.webpackHot && import.meta.webpackHot.accept('./code', () => hot(import('./code')))
* hotModuleReload: hot => import.meta.webpackHot?.accept('./code', () => hot(import('./code')))
* }
* ```
*
Expand All @@ -31,7 +31,7 @@ export namespace Plugin {
/**
* This provides the functionality for hot module reload on the plugin.
* When the callback is called, the old instance of the plugin will be unloaded, then the new instance will be init.
* @example hotModuleReload: hot => import.meta.webpackHot && import.meta.webpackHot.accept('./path', () => hot(import('./path')))
* @example hotModuleReload: hot => import.meta.webpackHot?.accept('./path', () => hot(import('./path')))
*/
hotModuleReload(onHot: (hot: Promise<{ default: DeferredModule }>) => void): void
}
Expand Down
10 changes: 3 additions & 7 deletions packages/plugins/example/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,14 @@ registerPlugin({
SNSAdaptor: {
load: () => import('./SNSAdaptor'),
hotModuleReload: (hot) =>
import.meta.webpackHot &&
import.meta.webpackHot.accept('./SNSAdaptor/index', () => hot(import('./SNSAdaptor'))),
import.meta.webpackHot?.accept('./SNSAdaptor/index', () => hot(import('./SNSAdaptor'))),
Comment thread
Jack-Works marked this conversation as resolved.
},
Dashboard: {
load: () => import('./Dashboard'),
hotModuleReload: (hot) =>
import.meta.webpackHot &&
import.meta.webpackHot.accept('./Dashboard/index', () => hot(import('./Dashboard'))),
hotModuleReload: (hot) => import.meta.webpackHot?.accept('./Dashboard/index', () => hot(import('./Dashboard'))),
},
Worker: {
load: () => import('./Worker'),
hotModuleReload: (hot) =>
import.meta.webpackHot && import.meta.webpackHot.accept('./Worker/index', () => hot(import('./Worker'))),
hotModuleReload: (hot) => import.meta.webpackHot?.accept('./Worker/index', () => hot(import('./Worker'))),
},
})