Skip to content

Commit

Permalink
refactor: rename SocialNetwork to SiteAdaptor (#10332)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack-Works committed Aug 9, 2023
1 parent 8811c72 commit fb27a74
Show file tree
Hide file tree
Showing 267 changed files with 559 additions and 567 deletions.
4 changes: 2 additions & 2 deletions .i18n-codegen.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
}
},
{
"input": "./packages/mask/src/social-network-adaptor/twitter.com/locales/en-US.json",
"output": "./packages/mask/src/social-network-adaptor/twitter.com/locales/i18n_generated",
"input": "./packages/mask/src/site-adaptors/twitter.com/locales/en-US.json",
"output": "./packages/mask/src/site-adaptors/twitter.com/locales/i18n_generated",
"parser": { "type": "i18next", "contextSeparator": "$", "pluralSeparator": "_" },
"generator": {
"type": "i18next/react-hooks",
Expand Down
2 changes: 1 addition & 1 deletion packages/dashboard/src/pages/Personas/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ValueRef } from '@masknet/shared-base'
import { useValueRef } from '@masknet/shared-base-ui'
import { Services, Messages } from '../../API.js'

export type SocialNetwork = {
export interface SiteAdaptor {
networkIdentifier: string
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { isSameAddress } from '@masknet/web3-shared-base'
import { useDashboardI18N } from '../../../../locales/index.js'
import { PersonaContext } from '../../hooks/usePersonaContext.js'
import { RenameDialog } from '../RenameDialog/index.js'
import type { SocialNetwork } from '../../api.js'
import type { SiteAdaptor } from '../../api.js'
import { UploadAvatarDialog } from '../UploadAvatarDialog/index.js'
import { MaskAvatar } from '../../../../components/MaskAvatar/index.js'
import { LogoutPersonaDialog } from '../LogoutPersonaDialog/index.js'
Expand Down Expand Up @@ -61,8 +61,14 @@ const MenuText = styled('span')(`

export const PersonaRowCard = memo(() => {
const wallets = useWallets()
const { currentPersona, connectPersona, disconnectPersona, renamePersona, deleteBound, definedSocialNetworks } =
PersonaContext.useContainer()
const {
currentPersona,
connectPersona,
disconnectPersona,
renamePersona,
deleteBound,
definedSocialNetworkAdaptors,
} = PersonaContext.useContainer()

const { value: hasPaymentPassword = false } = useAsync(WalletServiceRef.value.hasPassword, [])
if (!currentPersona?.identifier.publicKeyAsHex) return null
Expand All @@ -80,7 +86,7 @@ export const PersonaRowCard = memo(() => {
onDisconnect={disconnectPersona}
onDeleteBound={deleteBound}
onRename={renamePersona}
definedSocialNetworks={definedSocialNetworks}
definedSocialNetworkAdaptors={definedSocialNetworkAdaptors}
/>
)
})
Expand All @@ -90,7 +96,7 @@ export interface PersonaRowCardUIProps {
address?: string
identifier: PersonaIdentifier
profiles: ProfileInformation[]
definedSocialNetworks: SocialNetwork[]
definedSocialNetworkAdaptors: SiteAdaptor[]
publicKey: string
hasSmartPay: boolean
hasPaymentPassword: boolean
Expand All @@ -117,7 +123,7 @@ export const PersonaRowCardUI = memo<PersonaRowCardUIProps>((props) => {
const { classes } = useStyles()
const { confirmPassword } = useContext(UserContext)

const { nickname, definedSocialNetworks, identifier, profiles, publicKey, address } = props
const { nickname, definedSocialNetworkAdaptors, identifier, profiles, publicKey, address } = props
const { onConnect, onDisconnect, onRename, onDeleteBound } = props
const { value: privateKey } = useExportPrivateKey(identifier)
const { value: words } = useExportMnemonicWords(identifier)
Expand Down Expand Up @@ -183,7 +189,7 @@ export const PersonaRowCardUI = memo<PersonaRowCardUIProps>((props) => {
</Typography>
</Box>
<Box>
{definedSocialNetworks.map(({ networkIdentifier }) => {
{definedSocialNetworkAdaptors.map(({ networkIdentifier }) => {
const currentNetworkProfiles = profiles.filter(
(x) => x.identifier.network === networkIdentifier,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
formatPersonaFingerprint,
} from '@masknet/shared-base'
import { PersonaContext } from '../../hooks/usePersonaContext.js'
import type { SocialNetwork } from '../../api.js'
import type { SiteAdaptor } from '../../api.js'
import { usePersonaProofs } from '@masknet/shared'

const useStyles = makeStyles()((theme) => ({
Expand Down Expand Up @@ -56,19 +56,19 @@ export interface PersonaCardProps {
}

export const PersonaCard = memo<PersonaCardProps>((props) => {
const { connectPersona, disconnectPersona, definedSocialNetworks } = PersonaContext.useContainer()
const { connectPersona, disconnectPersona, definedSocialNetworkAdaptors } = PersonaContext.useContainer()
return (
<PersonaCardUI
{...props}
onConnect={connectPersona}
onDisconnect={disconnectPersona}
definedSocialNetworks={definedSocialNetworks}
definedSocialNetworkAdaptors={definedSocialNetworkAdaptors}
/>
)
})

export interface PersonaCardUIProps extends PersonaCardProps {
definedSocialNetworks: SocialNetwork[]
definedSocialNetworkAdaptors: SiteAdaptor[]
onConnect: (
identifier: PersonaIdentifier,
networkIdentifier: string,
Expand All @@ -80,7 +80,7 @@ export interface PersonaCardUIProps extends PersonaCardProps {
}

export const PersonaCardUI = memo<PersonaCardUIProps>((props) => {
const { nickname, active = false, definedSocialNetworks, identifier, profiles, publicKey } = props
const { nickname, active = false, definedSocialNetworkAdaptors, identifier, profiles, publicKey } = props
const { onConnect, onDisconnect, onClick } = props
const { classes, cx } = useStyles()
const proofs = usePersonaProofs(publicKey)
Expand All @@ -97,7 +97,7 @@ export const PersonaCardUI = memo<PersonaCardUIProps>((props) => {
</Typography>
</div>
<div className={classes.content}>
{definedSocialNetworks.map(({ networkIdentifier }) => {
{definedSocialNetworkAdaptors.map(({ networkIdentifier }) => {
const currentNetworkProfiles = profiles.filter(
(x) => x.identifier.network === networkIdentifier,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import { Services } from '../../../API.js'
import {
useOwnedPersonas,
useSupportedSocialNetworkSites,
type SocialNetwork,
type SiteAdaptor,
useCurrentPersonaIdentifier,
} from '../api.js'
import { useCreatePersona } from './useCreatePersona.js'
import { useDeleteBound } from './useOperateBindingProof.js'

function usePersonaContext() {
const currentPersonaIdentifier = useCurrentPersonaIdentifier()
const definedSocialNetworks: SocialNetwork[] = useSupportedSocialNetworkSites()
const definedSocialNetworkAdaptors: SiteAdaptor[] = useSupportedSocialNetworkSites()
const personas = useOwnedPersonas()
const currentPersona = personas.find((x) => x.identifier === currentPersonaIdentifier)
const [open, setOpen] = useState(false)
Expand All @@ -34,7 +34,7 @@ function usePersonaContext() {
changeCurrentPersona,
deleteBound,
currentPersona,
definedSocialNetworks,
definedSocialNetworkAdaptors,
personas,
openProfilePage,
drawerOpen: open,
Expand Down
12 changes: 6 additions & 6 deletions packages/dashboard/src/pages/Personas/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function Personas() {
const t = useDashboardI18N()
const navigate = useNavigate()
const { showSnackbar } = useCustomSnackbar()
const { drawerOpen, toggleDrawer, personas, currentPersona, connectPersona, definedSocialNetworks } =
const { drawerOpen, toggleDrawer, personas, currentPersona, connectPersona, definedSocialNetworkAdaptors } =
PersonaContext.useContainer()

useEffect(() => {
Expand All @@ -51,12 +51,12 @@ function Personas() {
}, [personas])

const [activeTab, setActiveTab] = useState(
firstProfileNetwork(currentPersona) ?? definedSocialNetworks[0].networkIdentifier,
firstProfileNetwork(currentPersona) ?? definedSocialNetworkAdaptors[0].networkIdentifier,
)

useEffect(() => {
setActiveTab(firstProfileNetwork(currentPersona) ?? definedSocialNetworks[0].networkIdentifier)
}, [currentPersona, definedSocialNetworks])
setActiveTab(firstProfileNetwork(currentPersona) ?? definedSocialNetworkAdaptors[0].networkIdentifier)
}, [currentPersona, definedSocialNetworkAdaptors])

if (!personas.length) return null

Expand All @@ -79,7 +79,7 @@ function Personas() {
<ContentContainer style={{ display: 'flex', flexDirection: 'column' }}>
<TabContext value={activeTab}>
<Tabs value={activeTab ? activeTab : false} onChange={(event, tab) => setActiveTab(tab)}>
{definedSocialNetworks.map(({ networkIdentifier }) => (
{definedSocialNetworkAdaptors.map(({ networkIdentifier }) => (
<Tab
key={networkIdentifier}
value={networkIdentifier}
Expand All @@ -88,7 +88,7 @@ function Personas() {
/>
))}
</Tabs>
{definedSocialNetworks.map(({ networkIdentifier }) => {
{definedSocialNetworkAdaptors.map(({ networkIdentifier }) => {
if (!currentPersona) return null
const profile = currentPersona.linkedProfiles.find(
(x) => x.identifier.network === networkIdentifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { ActionCard } from '../../../components/ActionCard/index.js'
export function ConnectSocialMedia() {
const navigate = useNavigate()
const t = useDashboardI18N()
const { currentPersona, connectPersona, definedSocialNetworks } = PersonaContext.useContainer()
const { currentPersona, connectPersona, definedSocialNetworkAdaptors } = PersonaContext.useContainer()

const handleConnect = async (networkIdentifier: string) => {
if (currentPersona) {
Expand All @@ -44,7 +44,7 @@ export function ConnectSocialMedia() {
{t.go_back()}
</Button>
</Stack>
{definedSocialNetworks.map(({ networkIdentifier }) => (
{definedSocialNetworkAdaptors.map(({ networkIdentifier }) => (
<ActionCard
key={networkIdentifier}
title={t.create_account_connect_social_media({
Expand Down
2 changes: 1 addition & 1 deletion packages/encryption/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This package is designed with OCap and prepared to run under SES.

```plain
raw message (text or image)
|> Social Network decoding (socialNetworkID)
|> Network specific decoding (NetworkID)
|> Standard Decryption
```

Expand Down
2 changes: 1 addition & 1 deletion packages/encryption/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export {
appendEncryptionTarget,
} from './encryption/index.js'

export { encodeByNetwork, decodeByNetwork, TwitterDecoder } from './social-network-encode-decode/index.js'
export { encodeByNetwork, decodeByNetwork, TwitterDecoder } from './network-encoding/index.js'

export {
type DecodeImageOptions,
Expand Down
22 changes: 11 additions & 11 deletions packages/mask/background/services/crypto/decryption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ import {
} from '../../network/gun/encryption/queryPostKey.js'

export interface DecryptionContext {
currentSocialNetwork: EncryptPayloadNetwork
encryptPayloadNetwork: EncryptPayloadNetwork
currentProfile: ProfileIdentifier | null
authorHint: ProfileIdentifier | null
postURL: string | undefined
}
export type SocialNetworkEncodedPayload =
export type EncodedPayload =
| {
type: 'text'
text: string
Expand All @@ -66,13 +66,13 @@ const downloadImage = (url: string): Promise<ArrayBuffer> => fetch(url).then((x)
* @param encoded If the encoded content is a text, it should only contain 1 payload. Extra payload will be ignored.
* @param context
*/
export async function* decryptionWithSocialNetworkDecoding(
encoded: SocialNetworkEncodedPayload,
export async function* decryptWithDecoding(
encoded: EncodedPayload,
context: DecryptionContext,
): AsyncGenerator<DecryptProgress, void, undefined> {
let decoded: string | Uint8Array
if (encoded.type === 'text') {
decoded = decodeByNetwork(context.currentSocialNetwork, encoded.text)[0]
decoded = decodeByNetwork(context.encryptPayloadNetwork, encoded.text)[0]
} else {
if (!context.authorHint) {
return yield new DecryptError(DecryptErrorReasons.UnrecognizedAuthor, undefined)
Expand All @@ -82,7 +82,7 @@ export async function* decryptionWithSocialNetworkDecoding(
downloadImage,
})
if (typeof result === 'string') {
decoded = decodeByNetwork(context.currentSocialNetwork, result)[0]
decoded = decodeByNetwork(context.encryptPayloadNetwork, result)[0]
} else if (result === null) {
return yield new DecryptError(DecryptErrorReasons.NoPayloadFound, undefined)
} else {
Expand All @@ -99,7 +99,7 @@ async function* decryption(payload: string | Uint8Array, context: DecryptionCont
const parse = await parsePayload(payload)
if (parse.err) return null

const { currentSocialNetwork, postURL, currentProfile, authorHint } = context
const { encryptPayloadNetwork, postURL, currentProfile, authorHint } = context

// #region Identify the PostIdentifier
const iv = parse.val.encryption.unwrapOr(null)?.iv.unwrapOr(null)
Expand All @@ -119,7 +119,7 @@ async function* decryption(payload: string | Uint8Array, context: DecryptionCont
yield info
}
const id = new PostIVIdentifier(
encryptPayloadNetworkToDomain(currentSocialNetwork),
encryptPayloadNetworkToDomain(encryptPayloadNetwork),
encodeArrayBuffer(new Uint8Array(iv)),
)
// #endregion
Expand Down Expand Up @@ -174,7 +174,7 @@ async function* decryption(payload: string | Uint8Array, context: DecryptionCont
yield* GUN_queryPostKey_version37(
iv,
author,
context.currentSocialNetwork,
context.encryptPayloadNetwork,
signal || new AbortController().signal,
)
},
Expand All @@ -186,7 +186,7 @@ async function* decryption(payload: string | Uint8Array, context: DecryptionCont
-38,
iv,
author,
context.currentSocialNetwork,
context.encryptPayloadNetwork,
signal || new AbortController().signal,
)
},
Expand All @@ -198,7 +198,7 @@ async function* decryption(payload: string | Uint8Array, context: DecryptionCont
-39,
iv,
author,
context.currentSocialNetwork,
context.encryptPayloadNetwork,
signal || new AbortController().signal,
)
},
Expand Down
2 changes: 1 addition & 1 deletion packages/mask/background/services/crypto/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Encrypt & decrypt (decryptionWithSocialNetworkDecoding is a generator, not included.)
// Encrypt & decrypt (decryptWithDecoding is a generator, not included.)
export { encryptTo } from './encryption.js'
export { appendShareTarget } from './appendEncryption.js'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Run `npx gulp sync-languages` to regenerate.
export default {
'mask/shared-ui/locales/%locale%.json': 'mask',
'mask/src/social-network-adaptor/twitter.com/locales/%locale%.json': 'DO_NOT_USE',
'mask/src/site-adaptors/twitter.com/locales/%locale%.json': 'DO_NOT_USE',
'shared/src/locales/%locale%.json': 'shared',
'shared-base-ui/src/locales/%locale%.json': 'shareBase',
'dashboard/src/locales/%locale%.json': 'dashboard',
Expand Down
10 changes: 5 additions & 5 deletions packages/mask/background/services/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { GeneratorServices, Services } from './types.js'
// #endregion

// #region Setup GeneratorServices
import { decryptionWithSocialNetworkDecoding } from './crypto/decryption.js'
import { decryptWithDecoding } from './crypto/decryption.js'
assertEnvironment(Environment.ManifestBackground)

const debugMode = process.env.NODE_ENV === 'development'
Expand All @@ -32,7 +32,7 @@ if (import.meta.webpackHot) {
import.meta.webpackHot.accept(['./backup'], () => hmr.dispatchEvent(new Event('backup')))
import.meta.webpackHot.accept(['./helper'], () => hmr.dispatchEvent(new Event('helper')))
import.meta.webpackHot.accept(['./settings'], () => hmr.dispatchEvent(new Event('settings')))
import.meta.webpackHot.accept(['./site-adaptors'], () => hmr.dispatchEvent(new Event('socialNetwork')))
import.meta.webpackHot.accept(['./site-adaptors'], () => hmr.dispatchEvent(new Event('site-adaptors')))
import.meta.webpackHot.accept(['./third-party-plugins'], () => hmr.dispatchEvent(new Event('thirdPartyPlugin')))
}

Expand Down Expand Up @@ -67,12 +67,12 @@ function setup<K extends keyof Services>(key: K, implementation: () => Promise<S
}
{
const GeneratorService: GeneratorServices = {
decryption: decryptionWithSocialNetworkDecoding,
decrypt: decryptWithDecoding,
}
import.meta.webpackHot?.accept(['./crypto/decryption'], async () => {
GeneratorService.decryption = (
GeneratorService.decrypt = (
await import(/* webpackPreload: true */ './crypto/decryption.js')
).decryptionWithSocialNetworkDecoding
).decryptWithDecoding
})
const channel = message.events.GeneratorServices.bind(MessageTarget.Broadcast)

Expand Down
4 changes: 2 additions & 2 deletions packages/mask/background/services/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type * as Crypto from './crypto/index.js'
import type { decryptionWithSocialNetworkDecoding } from './crypto/decryption.js'
import type { decryptWithDecoding } from './crypto/decryption.js'
import type * as Helper from './helper/index.js'
import type * as Backup from './backup/index.js'
import type * as Identity from './identity/index.js'
Expand All @@ -24,5 +24,5 @@ export interface Services {
ThirdPartyPlugin: ThirdPartyPluginService
}
export type GeneratorServices = {
decryption: typeof decryptionWithSocialNetworkDecoding
decrypt: typeof decryptWithDecoding
}

0 comments on commit fb27a74

Please sign in to comment.