-
Notifications
You must be signed in to change notification settings - Fork 306
/
index.tsx
179 lines (170 loc) · 7.26 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import { Trans } from 'react-i18next'
import { Icons } from '@masknet/icons'
import { Box } from '@mui/material'
import { extractTextFromTypedMessage } from '@masknet/typed-message'
import { useMountReport } from '@masknet/web3-telemetry/hooks'
import { Web3ContextProvider } from '@masknet/web3-hooks-base'
import { SearchResultType } from '@masknet/web3-shared-base'
import { NetworkPluginID, parseURLs, SocialAddressType } from '@masknet/shared-base'
import {
type Plugin,
usePostInfoDetails,
usePluginWrapper,
SNSAdaptorContext,
} from '@masknet/plugin-infra/content-script'
import { PostInspector } from './PostInspector.js'
import { base } from '../base.js'
import { getPayloadFromURLs } from '../helpers/index.js'
import { SharedContextSettings, setupContext } from '../context.js'
import { PLUGIN_ID, PLUGIN_NAME } from '../constants.js'
import { DialogInspector } from './DialogInspector.js'
import { CollectionList } from './List/CollectionList.js'
import { TelemetryAPI } from '@masknet/web3-providers/types'
import { UserAssetsProvider } from './Context/UserAssetsContext.js'
const TabConfig: Plugin.SNSAdaptor.ProfileTab = {
ID: `${PLUGIN_ID}_nfts`,
label: 'NFTs',
priority: 1,
UI: {
TabContent({ socialAccount, identity }) {
useMountReport(TelemetryAPI.EventID.AccessWeb3TabNFTsTab)
if (!socialAccount) return null
return (
<SNSAdaptorContext.Provider value={SharedContextSettings.value}>
<Web3ContextProvider value={{ pluginID: socialAccount.pluginID }}>
<UserAssetsProvider
pluginID={socialAccount.pluginID}
address={socialAccount.address}
userId={identity?.identifier?.userId!}
persona={identity?.publicKey!}>
<CollectionList socialAccount={socialAccount} />
</UserAssetsProvider>
</Web3ContextProvider>
</SNSAdaptorContext.Provider>
)
},
},
Utils: {
sorter: (a, z) => {
if (a.supportedAddressTypes?.includes(SocialAddressType.ENS)) return -1
if (z.supportedAddressTypes?.includes(SocialAddressType.ENS)) return 1
if (a.supportedAddressTypes?.includes(SocialAddressType.RSS3)) return -1
if (z.supportedAddressTypes?.includes(SocialAddressType.RSS3)) return 1
if (a.supportedAddressTypes?.includes(SocialAddressType.Address)) return -1
if (z.supportedAddressTypes?.includes(SocialAddressType.Address)) return 1
return 0
},
},
}
const sns: Plugin.SNSAdaptor.Definition = {
...base,
init(signal, context) {
setupContext(context)
SharedContextSettings.value = context
},
GlobalInjection() {
return (
<SNSAdaptorContext.Provider value={SharedContextSettings.value}>
<DialogInspector />
</SNSAdaptorContext.Provider>
)
},
PostInspector() {
const links = usePostInfoDetails.mentionedLinks()
const payload = getPayloadFromURLs(links)
usePluginWrapper(!!payload)
return payload ? <PostInspector payload={payload} /> : null
},
DecryptedInspector(props) {
const links = parseURLs(extractTextFromTypedMessage(props.message, { linkAsText: true }).unwrapOr(''))
const payload = getPayloadFromURLs(links)
usePluginWrapper(!!payload)
return payload ? <PostInspector payload={payload} /> : null
},
ProfileTabs: [TabConfig],
ProfileCardTabs: [
{
...TabConfig,
priority: 1,
UI: {
TabContent({ socialAccount, identity }) {
useMountReport(TelemetryAPI.EventID.AccessWeb3ProfileDialogNFTsTab)
if (!socialAccount) return null
return (
<SNSAdaptorContext.Provider value={SharedContextSettings.value}>
<Web3ContextProvider value={{ pluginID: socialAccount.pluginID }}>
<UserAssetsProvider
pluginID={socialAccount.pluginID}
address={socialAccount.address}
userId={identity?.identifier?.userId!}
persona={identity?.publicKey!}>
<CollectionList height={392} socialAccount={socialAccount} />
</UserAssetsProvider>
</Web3ContextProvider>
</SNSAdaptorContext.Provider>
)
},
},
Utils: {
...TabConfig.Utils,
shouldDisplay(identity, socialAccount) {
return socialAccount?.pluginID === NetworkPluginID.PLUGIN_EVM
},
},
},
],
SearchResultTabs: [
{
...TabConfig,
priority: 1,
UI: {
TabContent({ result }) {
const socialAccount = {
pluginID: NetworkPluginID.PLUGIN_EVM,
address: result.type === SearchResultType.Domain ? result.address ?? '' : result.keyword,
label:
result.type === SearchResultType.Domain
? result.keyword
: result.type === SearchResultType.EOA
? result.domain ?? ''
: '',
supportedAddressTypes: [SocialAddressType.ENS],
}
return (
<SNSAdaptorContext.Provider value={SharedContextSettings.value}>
<Box style={{ minHeight: 300 }}>
<Web3ContextProvider value={{ pluginID: result.pluginID }}>
<UserAssetsProvider pluginID={result.pluginID} address={socialAccount.address}>
<CollectionList height={479} socialAccount={socialAccount} />
</UserAssetsProvider>
</Web3ContextProvider>
</Box>
</SNSAdaptorContext.Provider>
)
},
},
Utils: {
...TabConfig.Utils,
shouldDisplay(result) {
return [SearchResultType.Domain, SearchResultType.EOA].includes(result.type)
},
},
},
],
ApplicationEntries: [
{
ApplicationEntryID: base.ID,
category: 'dapp',
description: <Trans i18nKey="plugin_collectibles_description" />,
name: <Trans i18nKey="plugin_collectibles_name" />,
icon: <Icons.Collectibles size={36} />,
marketListSortingPriority: 7,
tutorialLink: 'https://realmasknetwork.notion.site/c388746f11774ecfa17914c900d3ed97',
},
],
wrapperProps: {
title: PLUGIN_NAME,
icon: <Icons.ApplicationNFT size={24} />,
},
}
export default sns