From a1eacd47c517ef1f1b652e88641e1b6ddf9ce4a6 Mon Sep 17 00:00:00 2001 From: zhouhanseng Date: Mon, 7 Feb 2022 19:36:13 +0800 Subject: [PATCH 01/12] chore: dao id list from mask configuration --- .../InjectedComponents/ProfileTabContent.tsx | 12 +++++-- packages/plugin-infra/src/hooks/index.ts | 1 + .../src/hooks/useDaoTabTwitterIdList.ts | 32 +++++++++++++++++++ packages/plugin-infra/src/types.ts | 6 +++- packages/plugins/DAO/src/SNSAdaptor/index.tsx | 8 +++-- packages/plugins/DAO/src/constants.ts | 18 ----------- 6 files changed, 53 insertions(+), 24 deletions(-) create mode 100644 packages/plugin-infra/src/hooks/useDaoTabTwitterIdList.ts diff --git a/packages/mask/src/components/InjectedComponents/ProfileTabContent.tsx b/packages/mask/src/components/InjectedComponents/ProfileTabContent.tsx index e941b0e44853..ce908752ab2b 100644 --- a/packages/mask/src/components/InjectedComponents/ProfileTabContent.tsx +++ b/packages/mask/src/components/InjectedComponents/ProfileTabContent.tsx @@ -4,7 +4,14 @@ import { first } from 'lodash-unified' import { Box, CircularProgress } from '@mui/material' import { makeStyles, useStylesExtends } from '@masknet/theme' import { useAddressNames } from '@masknet/web3-shared-evm' -import { createInjectHooksRenderer, useActivatedPluginsSNSAdaptor, Plugin, PluginId } from '@masknet/plugin-infra' +import { + createInjectHooksRenderer, + useActivatedPluginsSNSAdaptor, + useDaoTabTwitterIdList, + DEFAULT_SUPPORTED_TWITTER_IDS, + Plugin, + PluginId, +} from '@masknet/plugin-infra' import { PageTab } from '../InjectedComponents/PageTab' import { useLocationChange } from '../../utils/hooks/useLocationChange' import { MaskMessages, useI18N } from '../../utils' @@ -48,9 +55,10 @@ export function ProfileTabContent(props: ProfileTabContentProps) { const identity = useCurrentVisitingIdentity() const { value: addressNames, loading: loadingAddressNames } = useAddressNames(identity) + const { value: daoTabTwitterIdList = DEFAULT_SUPPORTED_TWITTER_IDS } = useDaoTabTwitterIdList() const tabs = useActivatedPluginsSNSAdaptor('any') .flatMap((x) => x.ProfileTabs?.map((y) => ({ ...y, pluginID: x.ID })) ?? []) - .filter((z) => z.Utils?.shouldDisplay?.(identity, addressNames) ?? true) + .filter((z) => z.Utils?.shouldDisplay?.(identity, addressNames, daoTabTwitterIdList) ?? true) .sort((a, z) => { // order those tabs from next id first if (a.pluginID === PluginId.NextID) return -1 diff --git a/packages/plugin-infra/src/hooks/index.ts b/packages/plugin-infra/src/hooks/index.ts index e18c0691aa98..e7eacf360463 100644 --- a/packages/plugin-infra/src/hooks/index.ts +++ b/packages/plugin-infra/src/hooks/index.ts @@ -4,3 +4,4 @@ export * from './useActivatedPluginWeb3State' export * from './useAllPluginsWeb3State' export * from './useLookupDomain' export * from './useReverseAddress' +export * from './useDaoTabTwitterIdList' diff --git a/packages/plugin-infra/src/hooks/useDaoTabTwitterIdList.ts b/packages/plugin-infra/src/hooks/useDaoTabTwitterIdList.ts new file mode 100644 index 000000000000..5d3d8b71b0c0 --- /dev/null +++ b/packages/plugin-infra/src/hooks/useDaoTabTwitterIdList.ts @@ -0,0 +1,32 @@ +import { useAsync } from 'react-use' + +const WEB3_DAO_TAB_TWITTER_ID_LIST_API = 'https://configuration.r2d2.to/twitter-supported-id-list.json' + +export const DEFAULT_SUPPORTED_TWITTER_IDS = [ + 'ConstitutionDAO', + 'juiceboxETH', + /* cspell:disable-next-line */ + 'AssangeDAO', + 'OfficialMoonDAO', + 'TheSpiceDAO', + /* cspell:disable-next-line */ + 'sharkdao', + 'CrayonFinance', + 'merge_dao', + 'DAOTaiFung', + 'Tile_DAO', + /* cspell:disable-next-line */ + 'mountaindao', + 'OfficialMoonDAO', +] + +export function useDaoTabTwitterIdList() { + return useAsync(async () => { + try { + const response = await fetch(WEB3_DAO_TAB_TWITTER_ID_LIST_API) + return response.json() as Promise + } catch (error) { + return DEFAULT_SUPPORTED_TWITTER_IDS + } + }, []) +} diff --git a/packages/plugin-infra/src/types.ts b/packages/plugin-infra/src/types.ts index 949c384e29b6..719f9e3c3438 100644 --- a/packages/plugin-infra/src/types.ts +++ b/packages/plugin-infra/src/types.ts @@ -412,7 +412,11 @@ export namespace Plugin.SNSAdaptor { /** * If it returns false, this tab will not be displayed. */ - shouldDisplay?: (identity?: ProfileIdentity, addressNames?: ProfileAddress[]) => boolean + shouldDisplay?: ( + identity?: ProfileIdentity, + addressNames?: ProfileAddress[], + twitterSupportedList?: string[], + ) => boolean /** * Sort address name in expected order. diff --git a/packages/plugins/DAO/src/SNSAdaptor/index.tsx b/packages/plugins/DAO/src/SNSAdaptor/index.tsx index 43e2c41c27c6..bc037da536ac 100644 --- a/packages/plugins/DAO/src/SNSAdaptor/index.tsx +++ b/packages/plugins/DAO/src/SNSAdaptor/index.tsx @@ -1,6 +1,6 @@ import type { Plugin } from '@masknet/plugin-infra' import { base } from '../base' -import { PLUGIN_ID, SUPPORTED_TWITTER_IDS } from '../constants' +import { PLUGIN_ID } from '../constants' import { DAOPage } from '../components/DAOPage' const sns: Plugin.SNSAdaptor.Definition = { @@ -17,10 +17,12 @@ const sns: Plugin.SNSAdaptor.Definition = { }, }, Utils: { - shouldDisplay: (identity) => { + shouldDisplay: (identity, _addressNames, daoTabTwitterIdList) => { return ( !identity?.identifier.isUnknown && - SUPPORTED_TWITTER_IDS.some((x) => x.toLowerCase() === identity?.identifier.userId.toLowerCase()) + (daoTabTwitterIdList ?? []).some( + (x) => x.toLowerCase() === identity?.identifier.userId.toLowerCase(), + ) ) }, }, diff --git a/packages/plugins/DAO/src/constants.ts b/packages/plugins/DAO/src/constants.ts index b5e4c331dcab..b83ee33aa073 100644 --- a/packages/plugins/DAO/src/constants.ts +++ b/packages/plugins/DAO/src/constants.ts @@ -4,21 +4,3 @@ export const PLUGIN_ID = PluginId.DAO export const PLUGIN_META_KEY = `${PluginId.DAO}:1` export const PLUGIN_DESCRIPTION = 'The Web3 DAO based on JuiceBox.' export const PLUGIN_NAME = 'DAO' - -export const SUPPORTED_TWITTER_IDS = [ - 'ConstitutionDAO', - 'juiceboxETH', - 'AssangeDAO', - 'OfficialMoonDAO', - 'TheSpiceDAO', - /* cspell:disable-next-line */ - 'sharkdao', - 'CrayonFinance', - 'merge_dao', - /* cspell:disable-next-line */ - 'DAOTaiFung', - 'Tile_DAO', - /* cspell:disable-next-line */ - 'mountaindao', - 'OfficialMoonDAO', -] From 3bcc6be14165a1fc7bad7485f9d79be35c2ee1f1 Mon Sep 17 00:00:00 2001 From: zhouhanseng Date: Mon, 7 Feb 2022 20:14:10 +0800 Subject: [PATCH 02/12] fix: cspell --- packages/plugin-infra/src/hooks/useDaoTabTwitterIdList.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/plugin-infra/src/hooks/useDaoTabTwitterIdList.ts b/packages/plugin-infra/src/hooks/useDaoTabTwitterIdList.ts index 5d3d8b71b0c0..81a0574336d8 100644 --- a/packages/plugin-infra/src/hooks/useDaoTabTwitterIdList.ts +++ b/packages/plugin-infra/src/hooks/useDaoTabTwitterIdList.ts @@ -13,6 +13,7 @@ export const DEFAULT_SUPPORTED_TWITTER_IDS = [ 'sharkdao', 'CrayonFinance', 'merge_dao', + /* cspell:disable-next-line */ 'DAOTaiFung', 'Tile_DAO', /* cspell:disable-next-line */ From 6c7d7e63b0b1a7cf1b01b761421e552e284eb61e Mon Sep 17 00:00:00 2001 From: zhouhanseng Date: Tue, 8 Feb 2022 18:52:40 +0800 Subject: [PATCH 03/12] fix: collectible style --- .../mask/src/plugins/Collectible/SNSAdaptor/ArticleTab.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/mask/src/plugins/Collectible/SNSAdaptor/ArticleTab.tsx b/packages/mask/src/plugins/Collectible/SNSAdaptor/ArticleTab.tsx index b557f5a5e5f9..6bbb9a97454b 100644 --- a/packages/mask/src/plugins/Collectible/SNSAdaptor/ArticleTab.tsx +++ b/packages/mask/src/plugins/Collectible/SNSAdaptor/ArticleTab.tsx @@ -38,6 +38,10 @@ const useStyles = makeStyles()((theme) => ({ width: 36, height: 36, }, + iframe: { + minWidth: 300, + minHeight: 300, + }, })) export interface ArticleTabProps {} From 9b1642ce9fd71eda3c6a8f4838b5a238c22c0ea7 Mon Sep 17 00:00:00 2001 From: zhouhanseng Date: Tue, 8 Feb 2022 18:56:28 +0800 Subject: [PATCH 04/12] chore: cspell --- packages/plugin-infra/src/hooks/useDaoTabTwitterIdList.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/plugin-infra/src/hooks/useDaoTabTwitterIdList.ts b/packages/plugin-infra/src/hooks/useDaoTabTwitterIdList.ts index 81a0574336d8..f417e2d55256 100644 --- a/packages/plugin-infra/src/hooks/useDaoTabTwitterIdList.ts +++ b/packages/plugin-infra/src/hooks/useDaoTabTwitterIdList.ts @@ -2,24 +2,22 @@ import { useAsync } from 'react-use' const WEB3_DAO_TAB_TWITTER_ID_LIST_API = 'https://configuration.r2d2.to/twitter-supported-id-list.json' +// cspell:disable export const DEFAULT_SUPPORTED_TWITTER_IDS = [ 'ConstitutionDAO', 'juiceboxETH', - /* cspell:disable-next-line */ 'AssangeDAO', 'OfficialMoonDAO', 'TheSpiceDAO', - /* cspell:disable-next-line */ 'sharkdao', 'CrayonFinance', 'merge_dao', - /* cspell:disable-next-line */ 'DAOTaiFung', 'Tile_DAO', - /* cspell:disable-next-line */ 'mountaindao', 'OfficialMoonDAO', ] +// cspell:enable export function useDaoTabTwitterIdList() { return useAsync(async () => { From d5e1dcbca6c214a64cbd019d5945972a5fe053d9 Mon Sep 17 00:00:00 2001 From: zhouhanseng Date: Wed, 9 Feb 2022 10:37:22 +0800 Subject: [PATCH 05/12] chore: add loaded message --- packages/shared/src/UI/components/AssetPlayer/index.tsx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/shared/src/UI/components/AssetPlayer/index.tsx b/packages/shared/src/UI/components/AssetPlayer/index.tsx index 840d114df82f..08ce050d74b1 100644 --- a/packages/shared/src/UI/components/AssetPlayer/index.tsx +++ b/packages/shared/src/UI/components/AssetPlayer/index.tsx @@ -146,6 +146,12 @@ export const AssetPlayer = memo((props) => { } }, [playerState, ref.current]) + useEffect(() => { + if (playerState === AssetPlayerState.NORMAL) { + ref.current?.iFrameResizer.sendMessage({ loaded: true }) + } + }, [playerState, ref.current]) + const IframeResizerMemo = useMemo( () => hidden ? null : ( From 410796c20022f5a4fa1e03b34d0dfb4f6de0f28b Mon Sep 17 00:00:00 2001 From: zhouhanseng Date: Wed, 9 Feb 2022 10:45:13 +0800 Subject: [PATCH 06/12] chore: reply code review --- .../InjectedComponents/ProfileTabContent.tsx | 10 ++-------- packages/mask/src/utils/hooks/index.ts | 1 + .../src/utils}/hooks/useDaoTabTwitterIdList.ts | 0 packages/plugin-infra/src/hooks/index.ts | 1 - 4 files changed, 3 insertions(+), 9 deletions(-) rename packages/{plugin-infra/src => mask/src/utils}/hooks/useDaoTabTwitterIdList.ts (100%) diff --git a/packages/mask/src/components/InjectedComponents/ProfileTabContent.tsx b/packages/mask/src/components/InjectedComponents/ProfileTabContent.tsx index ce908752ab2b..b0a4939e85f3 100644 --- a/packages/mask/src/components/InjectedComponents/ProfileTabContent.tsx +++ b/packages/mask/src/components/InjectedComponents/ProfileTabContent.tsx @@ -4,16 +4,10 @@ import { first } from 'lodash-unified' import { Box, CircularProgress } from '@mui/material' import { makeStyles, useStylesExtends } from '@masknet/theme' import { useAddressNames } from '@masknet/web3-shared-evm' -import { - createInjectHooksRenderer, - useActivatedPluginsSNSAdaptor, - useDaoTabTwitterIdList, - DEFAULT_SUPPORTED_TWITTER_IDS, - Plugin, - PluginId, -} from '@masknet/plugin-infra' +import { createInjectHooksRenderer, useActivatedPluginsSNSAdaptor, Plugin, PluginId } from '@masknet/plugin-infra' import { PageTab } from '../InjectedComponents/PageTab' import { useLocationChange } from '../../utils/hooks/useLocationChange' +import { useDaoTabTwitterIdList, DEFAULT_SUPPORTED_TWITTER_IDS } from '../../utils/hooks/useDaoTabTwitterIdList' import { MaskMessages, useI18N } from '../../utils' import { useCurrentVisitingIdentity } from '../DataSource/useActivatedUI' diff --git a/packages/mask/src/utils/hooks/index.ts b/packages/mask/src/utils/hooks/index.ts index 5d302e13ece0..501bb283e3a8 100644 --- a/packages/mask/src/utils/hooks/index.ts +++ b/packages/mask/src/utils/hooks/index.ts @@ -4,3 +4,4 @@ export * from './useMenu' export * from './useQueryNavigatorPermission' export * from './useSettingSwitcher' export * from './useSuspense' +export * from './useDaoTabTwitterIdList' diff --git a/packages/plugin-infra/src/hooks/useDaoTabTwitterIdList.ts b/packages/mask/src/utils/hooks/useDaoTabTwitterIdList.ts similarity index 100% rename from packages/plugin-infra/src/hooks/useDaoTabTwitterIdList.ts rename to packages/mask/src/utils/hooks/useDaoTabTwitterIdList.ts diff --git a/packages/plugin-infra/src/hooks/index.ts b/packages/plugin-infra/src/hooks/index.ts index e7eacf360463..e18c0691aa98 100644 --- a/packages/plugin-infra/src/hooks/index.ts +++ b/packages/plugin-infra/src/hooks/index.ts @@ -4,4 +4,3 @@ export * from './useActivatedPluginWeb3State' export * from './useAllPluginsWeb3State' export * from './useLookupDomain' export * from './useReverseAddress' -export * from './useDaoTabTwitterIdList' From cf8ea4ab1efd6e1d0963366d80d829dfe828040d Mon Sep 17 00:00:00 2001 From: zhouhanseng Date: Wed, 9 Feb 2022 16:39:37 +0800 Subject: [PATCH 07/12] chore: plugin infra sns netural --- packages/plugin-infra/src/types.ts | 6 +----- packages/plugins/DAO/src/SNSAdaptor/index.tsx | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/packages/plugin-infra/src/types.ts b/packages/plugin-infra/src/types.ts index 719f9e3c3438..f9388c066d0e 100644 --- a/packages/plugin-infra/src/types.ts +++ b/packages/plugin-infra/src/types.ts @@ -412,11 +412,7 @@ export namespace Plugin.SNSAdaptor { /** * If it returns false, this tab will not be displayed. */ - shouldDisplay?: ( - identity?: ProfileIdentity, - addressNames?: ProfileAddress[], - twitterSupportedList?: string[], - ) => boolean + shouldDisplay?(identity?: ProfileIdentity, addressNames?: ProfileAddress[], extraInfo?: any): boolean /** * Sort address name in expected order. diff --git a/packages/plugins/DAO/src/SNSAdaptor/index.tsx b/packages/plugins/DAO/src/SNSAdaptor/index.tsx index bc037da536ac..1bed27ce9f27 100644 --- a/packages/plugins/DAO/src/SNSAdaptor/index.tsx +++ b/packages/plugins/DAO/src/SNSAdaptor/index.tsx @@ -17,7 +17,7 @@ const sns: Plugin.SNSAdaptor.Definition = { }, }, Utils: { - shouldDisplay: (identity, _addressNames, daoTabTwitterIdList) => { + shouldDisplay: (identity, _addressNames, daoTabTwitterIdList: string[]) => { return ( !identity?.identifier.isUnknown && (daoTabTwitterIdList ?? []).some( From 9007e437bf889b8bd9f0c384f951130868ea9627 Mon Sep 17 00:00:00 2001 From: zhouhanseng Date: Thu, 10 Feb 2022 22:01:37 +0800 Subject: [PATCH 08/12] chore: reply code review --- .../components/InjectedComponents/ProfileTabContent.tsx | 8 +++++++- packages/plugin-infra/src/types.ts | 6 +++++- packages/plugins/DAO/src/SNSAdaptor/index.tsx | 6 +++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/packages/mask/src/components/InjectedComponents/ProfileTabContent.tsx b/packages/mask/src/components/InjectedComponents/ProfileTabContent.tsx index b0a4939e85f3..f59871100c83 100644 --- a/packages/mask/src/components/InjectedComponents/ProfileTabContent.tsx +++ b/packages/mask/src/components/InjectedComponents/ProfileTabContent.tsx @@ -52,7 +52,13 @@ export function ProfileTabContent(props: ProfileTabContentProps) { const { value: daoTabTwitterIdList = DEFAULT_SUPPORTED_TWITTER_IDS } = useDaoTabTwitterIdList() const tabs = useActivatedPluginsSNSAdaptor('any') .flatMap((x) => x.ProfileTabs?.map((y) => ({ ...y, pluginID: x.ID })) ?? []) - .filter((z) => z.Utils?.shouldDisplay?.(identity, addressNames, daoTabTwitterIdList) ?? true) + .filter( + (z) => + z.Utils?.shouldDisplay?.(identity, addressNames, { + type: 'daoTabTwitterIdList', + items: daoTabTwitterIdList, + }) ?? true, + ) .sort((a, z) => { // order those tabs from next id first if (a.pluginID === PluginId.NextID) return -1 diff --git a/packages/plugin-infra/src/types.ts b/packages/plugin-infra/src/types.ts index f9388c066d0e..f06464fe06a6 100644 --- a/packages/plugin-infra/src/types.ts +++ b/packages/plugin-infra/src/types.ts @@ -412,7 +412,11 @@ export namespace Plugin.SNSAdaptor { /** * If it returns false, this tab will not be displayed. */ - shouldDisplay?(identity?: ProfileIdentity, addressNames?: ProfileAddress[], extraInfo?: any): boolean + shouldDisplay?( + identity?: ProfileIdentity, + addressNames?: ProfileAddress[], + extraInfo?: { type: 'daoTabTwitterIdList'; items: string[] }, + ): boolean /** * Sort address name in expected order. diff --git a/packages/plugins/DAO/src/SNSAdaptor/index.tsx b/packages/plugins/DAO/src/SNSAdaptor/index.tsx index 1bed27ce9f27..4fb7f22bfed5 100644 --- a/packages/plugins/DAO/src/SNSAdaptor/index.tsx +++ b/packages/plugins/DAO/src/SNSAdaptor/index.tsx @@ -17,7 +17,11 @@ const sns: Plugin.SNSAdaptor.Definition = { }, }, Utils: { - shouldDisplay: (identity, _addressNames, daoTabTwitterIdList: string[]) => { + shouldDisplay: (identity, _addressNames, extraData) => { + const { items: daoTabTwitterIdList } = extraData as { + type: 'daoTabTwitterIdList' + items: string[] + } return ( !identity?.identifier.isUnknown && (daoTabTwitterIdList ?? []).some( From 5138d79731ac29063683d14cdc9d08cd44d039e5 Mon Sep 17 00:00:00 2001 From: zhouhanseng Date: Fri, 11 Feb 2022 13:46:24 +0800 Subject: [PATCH 09/12] chore: reply code review --- packages/mask/src/utils/hooks/useDaoTabTwitterIdList.ts | 3 +++ packages/plugins/DAO/src/SNSAdaptor/index.tsx | 1 + 2 files changed, 4 insertions(+) diff --git a/packages/mask/src/utils/hooks/useDaoTabTwitterIdList.ts b/packages/mask/src/utils/hooks/useDaoTabTwitterIdList.ts index f417e2d55256..59f4a11cbea4 100644 --- a/packages/mask/src/utils/hooks/useDaoTabTwitterIdList.ts +++ b/packages/mask/src/utils/hooks/useDaoTabTwitterIdList.ts @@ -1,4 +1,6 @@ import { useAsync } from 'react-use' +import { activatedSocialNetworkUI } from '../../social-network' +import { isTwitter } from '../../social-network-adaptor/twitter.com/base' const WEB3_DAO_TAB_TWITTER_ID_LIST_API = 'https://configuration.r2d2.to/twitter-supported-id-list.json' @@ -22,6 +24,7 @@ export const DEFAULT_SUPPORTED_TWITTER_IDS = [ export function useDaoTabTwitterIdList() { return useAsync(async () => { try { + if (!isTwitter(activatedSocialNetworkUI)) return [] const response = await fetch(WEB3_DAO_TAB_TWITTER_ID_LIST_API) return response.json() as Promise } catch (error) { diff --git a/packages/plugins/DAO/src/SNSAdaptor/index.tsx b/packages/plugins/DAO/src/SNSAdaptor/index.tsx index 4fb7f22bfed5..29f8a5024712 100644 --- a/packages/plugins/DAO/src/SNSAdaptor/index.tsx +++ b/packages/plugins/DAO/src/SNSAdaptor/index.tsx @@ -18,6 +18,7 @@ const sns: Plugin.SNSAdaptor.Definition = { }, Utils: { shouldDisplay: (identity, _addressNames, extraData) => { + if (extraData?.type !== 'daoTabTwitterIdList') return false const { items: daoTabTwitterIdList } = extraData as { type: 'daoTabTwitterIdList' items: string[] From 3624ac58227be65cb8184338ada81b93577d58d3 Mon Sep 17 00:00:00 2001 From: Jack Works Date: Fri, 11 Feb 2022 15:18:29 +0800 Subject: [PATCH 10/12] Update packages/plugins/DAO/src/SNSAdaptor/index.tsx --- packages/plugins/DAO/src/SNSAdaptor/index.tsx | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/plugins/DAO/src/SNSAdaptor/index.tsx b/packages/plugins/DAO/src/SNSAdaptor/index.tsx index 29f8a5024712..02e6b480c619 100644 --- a/packages/plugins/DAO/src/SNSAdaptor/index.tsx +++ b/packages/plugins/DAO/src/SNSAdaptor/index.tsx @@ -19,10 +19,7 @@ const sns: Plugin.SNSAdaptor.Definition = { Utils: { shouldDisplay: (identity, _addressNames, extraData) => { if (extraData?.type !== 'daoTabTwitterIdList') return false - const { items: daoTabTwitterIdList } = extraData as { - type: 'daoTabTwitterIdList' - items: string[] - } + const { items: daoTabTwitterIdList } = extraData return ( !identity?.identifier.isUnknown && (daoTabTwitterIdList ?? []).some( From 9aa27aa3b85332d545e0db45cba454852744f9c2 Mon Sep 17 00:00:00 2001 From: zhouhanseng Date: Mon, 14 Feb 2022 17:51:03 +0800 Subject: [PATCH 11/12] chore: reply code review --- packages/mask/src/utils/hooks/useDaoTabTwitterIdList.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/mask/src/utils/hooks/useDaoTabTwitterIdList.ts b/packages/mask/src/utils/hooks/useDaoTabTwitterIdList.ts index 59f4a11cbea4..cd88d0d870aa 100644 --- a/packages/mask/src/utils/hooks/useDaoTabTwitterIdList.ts +++ b/packages/mask/src/utils/hooks/useDaoTabTwitterIdList.ts @@ -1,6 +1,7 @@ import { useAsync } from 'react-use' import { activatedSocialNetworkUI } from '../../social-network' import { isTwitter } from '../../social-network-adaptor/twitter.com/base' +import { union } from 'lodash-unified' const WEB3_DAO_TAB_TWITTER_ID_LIST_API = 'https://configuration.r2d2.to/twitter-supported-id-list.json' @@ -26,7 +27,8 @@ export function useDaoTabTwitterIdList() { try { if (!isTwitter(activatedSocialNetworkUI)) return [] const response = await fetch(WEB3_DAO_TAB_TWITTER_ID_LIST_API) - return response.json() as Promise + const result: string[] = await response.json() + return union(result, DEFAULT_SUPPORTED_TWITTER_IDS) } catch (error) { return DEFAULT_SUPPORTED_TWITTER_IDS } From d6db2b0e47a7a27af48a69843e691757850512c5 Mon Sep 17 00:00:00 2001 From: zhouhanseng Date: Wed, 23 Feb 2022 14:12:29 +0800 Subject: [PATCH 12/12] chore: use mask configuration client --- packages/configuration/src/index.ts | 6 ++-- .../InjectedComponents/ProfileTabContent.tsx | 10 +----- packages/mask/src/utils/hooks/index.ts | 1 - .../src/utils/hooks/useDaoTabTwitterIdList.ts | 36 ------------------- packages/plugin-infra/src/types.ts | 6 +--- packages/plugins/DAO/package.json | 1 + packages/plugins/DAO/src/SNSAdaptor/index.tsx | 28 +++++++++++++-- packages/plugins/DAO/tsconfig.json | 3 +- pnpm-lock.yaml | 8 +++-- 9 files changed, 38 insertions(+), 61 deletions(-) delete mode 100644 packages/mask/src/utils/hooks/useDaoTabTwitterIdList.ts diff --git a/packages/configuration/src/index.ts b/packages/configuration/src/index.ts index 3b7ff75c8a2f..69c3e9e18294 100644 --- a/packages/configuration/src/index.ts +++ b/packages/configuration/src/index.ts @@ -26,10 +26,10 @@ class Configuration { const cache = new Map>() -export function create(name: string, initialData?: T) { - const url = urlcat(`${DEFAULT_HOST}', ':prefix.:name.json`, { +export function create(name: string, prefix?: string, initialData?: T) { + const url = urlcat(DEFAULT_HOST, prefix ? ':prefix.:name.json' : ':name.json', { name, - prefix: DEFAULT_PREFIX, + prefix: prefix ?? DEFAULT_PREFIX, }) if (!cache.has(url)) cache.set(url, new Configuration(url, initialData)) return cache.get(url) as Configuration diff --git a/packages/mask/src/components/InjectedComponents/ProfileTabContent.tsx b/packages/mask/src/components/InjectedComponents/ProfileTabContent.tsx index 0c6989868654..db0b21e9a617 100644 --- a/packages/mask/src/components/InjectedComponents/ProfileTabContent.tsx +++ b/packages/mask/src/components/InjectedComponents/ProfileTabContent.tsx @@ -7,7 +7,6 @@ import { useAddressNames } from '@masknet/web3-shared-evm' import { createInjectHooksRenderer, useActivatedPluginsSNSAdaptor, Plugin, PluginId } from '@masknet/plugin-infra' import { PageTab } from '../InjectedComponents/PageTab' import { useLocationChange } from '../../utils/hooks/useLocationChange' -import { useDaoTabTwitterIdList, DEFAULT_SUPPORTED_TWITTER_IDS } from '../../utils/hooks/useDaoTabTwitterIdList' import { MaskMessages, useI18N } from '../../utils' import { useCurrentVisitingIdentity } from '../DataSource/useActivatedUI' @@ -49,16 +48,9 @@ export function ProfileTabContent(props: ProfileTabContentProps) { const identity = useCurrentVisitingIdentity() const { value: addressNames = [], loading: loadingAddressNames } = useAddressNames(identity) - const { value: daoTabTwitterIdList = DEFAULT_SUPPORTED_TWITTER_IDS } = useDaoTabTwitterIdList() const tabs = useActivatedPluginsSNSAdaptor('any') .flatMap((x) => x.ProfileTabs?.map((y) => ({ ...y, pluginID: x.ID })) ?? []) - .filter( - (z) => - z.Utils?.shouldDisplay?.(identity, addressNames, { - type: 'daoTabTwitterIdList', - items: daoTabTwitterIdList, - }) ?? true, - ) + .filter((z) => z.Utils?.shouldDisplay?.(identity, addressNames) ?? true) .sort((a, z) => { // order those tabs from next id first if (a.pluginID === PluginId.NextID) return -1 diff --git a/packages/mask/src/utils/hooks/index.ts b/packages/mask/src/utils/hooks/index.ts index 501bb283e3a8..5d302e13ece0 100644 --- a/packages/mask/src/utils/hooks/index.ts +++ b/packages/mask/src/utils/hooks/index.ts @@ -4,4 +4,3 @@ export * from './useMenu' export * from './useQueryNavigatorPermission' export * from './useSettingSwitcher' export * from './useSuspense' -export * from './useDaoTabTwitterIdList' diff --git a/packages/mask/src/utils/hooks/useDaoTabTwitterIdList.ts b/packages/mask/src/utils/hooks/useDaoTabTwitterIdList.ts deleted file mode 100644 index cd88d0d870aa..000000000000 --- a/packages/mask/src/utils/hooks/useDaoTabTwitterIdList.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { useAsync } from 'react-use' -import { activatedSocialNetworkUI } from '../../social-network' -import { isTwitter } from '../../social-network-adaptor/twitter.com/base' -import { union } from 'lodash-unified' - -const WEB3_DAO_TAB_TWITTER_ID_LIST_API = 'https://configuration.r2d2.to/twitter-supported-id-list.json' - -// cspell:disable -export const DEFAULT_SUPPORTED_TWITTER_IDS = [ - 'ConstitutionDAO', - 'juiceboxETH', - 'AssangeDAO', - 'OfficialMoonDAO', - 'TheSpiceDAO', - 'sharkdao', - 'CrayonFinance', - 'merge_dao', - 'DAOTaiFung', - 'Tile_DAO', - 'mountaindao', - 'OfficialMoonDAO', -] -// cspell:enable - -export function useDaoTabTwitterIdList() { - return useAsync(async () => { - try { - if (!isTwitter(activatedSocialNetworkUI)) return [] - const response = await fetch(WEB3_DAO_TAB_TWITTER_ID_LIST_API) - const result: string[] = await response.json() - return union(result, DEFAULT_SUPPORTED_TWITTER_IDS) - } catch (error) { - return DEFAULT_SUPPORTED_TWITTER_IDS - } - }, []) -} diff --git a/packages/plugin-infra/src/types.ts b/packages/plugin-infra/src/types.ts index 14f19e2ae768..e0843945d151 100644 --- a/packages/plugin-infra/src/types.ts +++ b/packages/plugin-infra/src/types.ts @@ -412,11 +412,7 @@ export namespace Plugin.SNSAdaptor { /** * If it returns false, this tab will not be displayed. */ - shouldDisplay?( - identity?: ProfileIdentity, - addressNames?: ProfileAddress[], - extraInfo?: { type: 'daoTabTwitterIdList'; items: string[] }, - ): boolean + shouldDisplay?(identity?: ProfileIdentity, addressNames?: ProfileAddress[]): boolean /** * Sort address name in expected order. diff --git a/packages/plugins/DAO/package.json b/packages/plugins/DAO/package.json index 0739ec2ae698..df9ab11a71ec 100644 --- a/packages/plugins/DAO/package.json +++ b/packages/plugins/DAO/package.json @@ -8,6 +8,7 @@ "@masknet/plugin-infra": "workspace:*", "@masknet/shared": "workspace:*", "@masknet/shared-base": "workspace:*", + "@masknet/configuration": "workspace:*", "bignumber.js": "^9.0.2", "date-fns": "^2.28.0", "iframe-resizer-react": "^1.1.0", diff --git a/packages/plugins/DAO/src/SNSAdaptor/index.tsx b/packages/plugins/DAO/src/SNSAdaptor/index.tsx index 02e6b480c619..bdf0114e3dac 100644 --- a/packages/plugins/DAO/src/SNSAdaptor/index.tsx +++ b/packages/plugins/DAO/src/SNSAdaptor/index.tsx @@ -2,6 +2,24 @@ import type { Plugin } from '@masknet/plugin-infra' import { base } from '../base' import { PLUGIN_ID } from '../constants' import { DAOPage } from '../components/DAOPage' +import { create } from '@masknet/configuration' + +// cspell:disable +const DEFAULT_SUPPORTED_TWITTER_IDS = [ + 'ConstitutionDAO', + 'juiceboxETH', + 'AssangeDAO', + 'OfficialMoonDAO', + 'TheSpiceDAO', + 'sharkdao', + 'CrayonFinance', + 'merge_dao', + 'DAOTaiFung', + 'Tile_DAO', + 'mountaindao', + 'OfficialMoonDAO', +] +// cspell:enable const sns: Plugin.SNSAdaptor.Definition = { ...base, @@ -17,9 +35,13 @@ const sns: Plugin.SNSAdaptor.Definition = { }, }, Utils: { - shouldDisplay: (identity, _addressNames, extraData) => { - if (extraData?.type !== 'daoTabTwitterIdList') return false - const { items: daoTabTwitterIdList } = extraData + shouldDisplay: (identity, _addressNames) => { + const daoTabTwitterIdList = create( + 'twitter-supported-id-list', + '', + DEFAULT_SUPPORTED_TWITTER_IDS, + ).get() + return ( !identity?.identifier.isUnknown && (daoTabTwitterIdList ?? []).some( diff --git a/packages/plugins/DAO/tsconfig.json b/packages/plugins/DAO/tsconfig.json index 1b3fd3a09a2e..035bf8c892ae 100644 --- a/packages/plugins/DAO/tsconfig.json +++ b/packages/plugins/DAO/tsconfig.json @@ -13,6 +13,7 @@ { "path": "../../shared" }, { "path": "../../shared-base" }, { "path": "../../theme" }, - { "path": "../../web3-providers" } + { "path": "../../web3-providers" }, + { "path": "../../configuration" } ] } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5036f662449b..d67aaf5c1783 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -636,6 +636,7 @@ importers: packages/plugins/DAO: specifiers: + '@masknet/configuration': workspace:* '@masknet/icons': workspace:* '@masknet/plugin-infra': workspace:* '@masknet/shared': workspace:* @@ -646,6 +647,7 @@ importers: react-use: ^17.3.2 urlcat: ^2.0.4 dependencies: + '@masknet/configuration': link:../../configuration '@masknet/icons': link:../../icons '@masknet/plugin-infra': link:../../plugin-infra '@masknet/shared': link:../../shared @@ -10070,7 +10072,7 @@ packages: resolution: {integrity: sha512-oagLNqpfNv7CvmyMoexMDNyVDSiq1rya0AEUgcLlNHdHgNl6U/hi8xY370n5y+ZIFEXOx0J4B1qF2NDjMRxklA==} engines: {node: '>=6.0.0'} dependencies: - pvutils: 1.0.17 + pvutils: 1.1.2 dev: false /assert-plus/1.0.0: @@ -21155,8 +21157,8 @@ packages: tslib: 2.3.1 dev: false - /pvutils/1.0.17: - resolution: {integrity: sha512-wLHYUQxWaXVQvKnwIDWFVKDJku9XDCvyhhxoq8dc5MFdIlRenyPI9eSfEtcvgHgD7FlvCyGAlWgOzRnZD99GZQ==} + /pvutils/1.1.2: + resolution: {integrity: sha512-wlo0BUInyP+ZgBJHV8PnJW8S2HubdQfMMip8B9yXr9aFlauJFuF1jZ/RWFmzGYitC7GxkxqXdwbY9/R97v+Cqg==} engines: {node: '>=6.0.0'} dev: false