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
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const ContactsTable = memo<ContactsTableProps>(({ network }) => {
value.map<RelationProfile>((profile) => ({
favorite: profile.favor === RelationFavor.COLLECTED,
name: profile.nickname || profile.identifier.userId || '',
fingerprint: profile.fingerprint,
fingerprint: profile.linkedPersona?.rawPublicKey,
identifier: profile.identifier,
avatar: profile.avatar,
})),
Expand Down
2 changes: 1 addition & 1 deletion packages/mask/background/services/__utils__/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function toProfileInformation(profiles: ProfileRecord[]) {
result.push({
identifier: profile.identifier,
nickname: profile.nickname,
fingerprint: profile.linkedPersona?.rawPublicKey,
linkedPersona: profile.linkedPersona,
})
}

Expand Down
12 changes: 11 additions & 1 deletion packages/mask/src/components/DataSource/useActivatedUI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { activatedSocialNetworkUI, globalUIState } from '../../social-network'
import { Subscription, useSubscription } from 'use-subscription'
import type { IdentityResolved } from '@masknet/plugin-infra'
import { isEqual } from 'lodash-unified'
import { useAsync } from 'react-use'
import Services from '../../extension/service'

const default_ = new ValueRef<IdentityResolved>({}, isEqual)
export function useLastRecognizedIdentity() {
Expand All @@ -17,11 +19,19 @@ export function useCurrentVisitingIdentity() {
}
export function useCurrentIdentity(): {
identifier: ProfileIdentifier
linkedPersona?: { nickname?: string; identifier: PersonaIdentifier; fingerprint?: string }
linkedPersona?: PersonaIdentifier
} | null {
return useSubscription(CurrentIdentitySubscription)
}

export function useCurrentLinkedPersona() {
const currentIdentity = useSubscription(CurrentIdentitySubscription)
return useAsync(async () => {
if (!currentIdentity?.linkedPersona) return
return Services.Identity.queryPersona(currentIdentity.linkedPersona)
}, [currentIdentity?.linkedPersona])
}

const CurrentIdentitySubscription: Subscription<ProfileInformation> = {
getCurrentValue() {
const all = globalUIState.profiles.value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const ProfileInList = memo<ProfileInListProps>((props) => {
secondary: classes.overflow,
}}
primary={name}
secondary={props.item.fingerprint?.toLowerCase()}
secondary={props.item.linkedPersona?.rawPublicKey?.toLowerCase()}
/>
</ListItemButton>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function SelectProfileUI(props: SelectProfileUIProps) {
if (search === '') return true
return (
!!x.identifier.userId.toLowerCase().match(search.toLowerCase()) ||
!!x.fingerprint?.toLowerCase().match(search.toLowerCase()) ||
!!x.linkedPersona?.rawPublicKey?.toLowerCase().match(search.toLowerCase()) ||
!!(x.nickname || '').toLowerCase().match(search.toLowerCase())
)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function ProfileInList(props: ProfileInListProps) {
const classes = useStylesExtends(useStyle(), props)
const profile = props.item
const name = profile.nickname || profile.identifier.userId
const secondary = profile.fingerprint?.toLowerCase()
const secondary = profile.linkedPersona?.rawPublicKey?.toLowerCase()
const onClick = useCallback((ev: React.MouseEvent<HTMLDivElement>) => props.onChange(ev, !props.checked), [props])
return (
<ListItemButton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Web3Utils from 'web3-utils'
import { DialogContent } from '@mui/material'
import { makeStyles } from '@masknet/theme'
import { useI18N } from '../../../utils'
import { useCurrentIdentity } from '../../../components/DataSource/useActivatedUI'
import { useCurrentIdentity, useCurrentLinkedPersona } from '../../../components/DataSource/useActivatedUI'
import { useRemoteControlledDialog } from '@masknet/shared-base-ui'
import { InjectedDialog, InjectedDialogProps } from '@masknet/shared'
import { ITO_MetaKey_2, MSG_DELIMITER } from '../constants'
Expand Down Expand Up @@ -145,7 +145,10 @@ export function CompositionDialog(props: CompositionDialogProps) {
const state = useState<DialogTabs>(DialogTabs.create)

const currentIdentity = useCurrentIdentity()
const senderName = currentIdentity?.identifier.userId ?? currentIdentity?.linkedPersona?.nickname ?? 'Unknown User'

const { value: linkedPersona } = useCurrentLinkedPersona()

const senderName = currentIdentity?.identifier.userId ?? linkedPersona?.nickname ?? 'Unknown User'
const onCreateOrSelect = useCallback(
async (payload: JSON_PayloadInMask) => {
if (!payload.password) {
Expand Down
7 changes: 5 additions & 2 deletions packages/mask/src/plugins/ITO/SNSAdaptor/CreateForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import formatDateTime from 'date-fns/format'
import { ChangeEvent, useCallback, useEffect, useMemo, useState } from 'react'
import { v4 as uuid } from 'uuid'
import Web3Utils from 'web3-utils'
import { useCurrentIdentity } from '../../../components/DataSource/useActivatedUI'
import { useCurrentIdentity, useCurrentLinkedPersona } from '../../../components/DataSource/useActivatedUI'
import ActionButton from '../../../extension/options-page/DashboardComponents/ActionButton'
import { sliceTextByUILength, useI18N } from '../../../utils'
import { DateTimePanel } from '../../../web3/UI/DateTimePanel'
Expand Down Expand Up @@ -130,7 +130,10 @@ export function CreateForm(props: CreateFormProps) {
const { ITO2_CONTRACT_ADDRESS, DEFAULT_QUALIFICATION2_ADDRESS } = useITOConstants()

const currentIdentity = useCurrentIdentity()
const senderName = currentIdentity?.identifier.userId ?? currentIdentity?.linkedPersona?.nickname ?? 'Unknown User'

const { value: linkedPersona } = useCurrentLinkedPersona()

const senderName = currentIdentity?.identifier.userId ?? linkedPersona?.nickname ?? 'Unknown User'

const [message, setMessage] = useState(origin?.title ?? '')
const [totalOfPerWallet, setTotalOfPerWallet] = useState(
Expand Down
18 changes: 15 additions & 3 deletions packages/mask/src/plugins/Polls/SNSAdaptor/PollsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@ import addDate from 'date-fns/add'
import { InjectedDialog } from '@masknet/shared'
import { useI18N } from '../../../utils'
import AbstractTab, { AbstractTabProps } from '../../../components/shared/AbstractTab'
import { useCurrentIdentity } from '../../../components/DataSource/useActivatedUI'
import { useCurrentIdentity, useCurrentLinkedPersona } from '../../../components/DataSource/useActivatedUI'
import type { PollGunDB } from '../Services'
import { PollCardUI } from './Polls'
import type { PollMetaData } from '../types'
import { PLUGIN_META_KEY } from '../constants'
import { PluginPollRPC } from '../messages'
import { useCompositionContext } from '@masknet/plugin-infra/content-script'
import { useAsync } from 'react-use'
import Services from '../../../extension/service'
import { head } from 'lodash-unified'

const useNewPollStyles = makeStyles()((theme) => ({
menuPaper: {
Expand Down Expand Up @@ -259,8 +262,17 @@ export default function PollsDialog(props: PollsDialogProps) {
props.onClose()
}

const senderName = useCurrentIdentity()?.linkedPersona?.nickname
const senderFingerprint = useCurrentIdentity()?.linkedPersona?.fingerprint
const currentIdentity = useCurrentIdentity()
const { value: linkedPersona } = useCurrentLinkedPersona()
const { value: currentProfile } = useAsync(async () => {
if (!currentIdentity?.linkedPersona || !currentIdentity.identifier) return
const profilesInformation = await Services.Identity.queryProfilesInformation([currentIdentity?.identifier])

return head(profilesInformation)
}, [currentIdentity])

const senderName = linkedPersona?.nickname
const senderFingerprint = currentProfile?.linkedPersona?.rawPublicKey

const tabProps: AbstractTabProps = {
tabs: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import { DialogContent } from '@mui/material'
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
import Web3Utils from 'web3-utils'
import { useCurrentIdentity } from '../../../components/DataSource/useActivatedUI'
import { useCurrentIdentity, useCurrentLinkedPersona } from '../../../components/DataSource/useActivatedUI'
import AbstractTab, { AbstractTabProps } from '../../../components/shared/AbstractTab'
import Services from '../../../extension/service'
import { useI18N } from '../../../utils'
Expand Down Expand Up @@ -93,7 +93,10 @@ export default function RedPacketDialog(props: RedPacketDialogProps) {
const { address: publicKey, privateKey } = useMemo(() => web3.eth.accounts.create(), [])

const currentIdentity = useCurrentIdentity()
const senderName = currentIdentity?.identifier.userId ?? currentIdentity?.linkedPersona?.nickname

const { value: linkedPersona } = useCurrentLinkedPersona()

const senderName = currentIdentity?.identifier.userId ?? linkedPersona?.nickname
const { closeDialog: closeApplicationBoardDialog } = useRemoteControlledDialog(
WalletMessages.events.ApplicationDialogUpdated,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import BigNumber from 'bignumber.js'
import { omit } from 'lodash-unified'
import { ChangeEvent, useCallback, useEffect, useMemo, useRef, useState } from 'react'
import { usePickToken } from '@masknet/shared'
import { useCurrentIdentity } from '../../../components/DataSource/useActivatedUI'
import { useCurrentIdentity, useCurrentLinkedPersona } from '../../../components/DataSource/useActivatedUI'
import ActionButton from '../../../extension/options-page/DashboardComponents/ActionButton'
import { useI18N } from '../../../utils'
import { EthereumERC20TokenApprovedBoundary } from '../../../web3/UI/EthereumERC20TokenApprovedBoundary'
Expand Down Expand Up @@ -107,7 +107,10 @@ export function RedPacketERC20Form(props: RedPacketFormProps) {
const [isRandom, setRandom] = useState(origin?.isRandom ? 1 : 0)
const [message, setMessage] = useState(origin?.message || t('plugin_red_packet_best_wishes'))
const currentIdentity = useCurrentIdentity()
const senderName = currentIdentity?.identifier.userId ?? currentIdentity?.linkedPersona?.nickname ?? 'Unknown User'

const { value: linkedPersona } = useCurrentLinkedPersona()

const senderName = currentIdentity?.identifier.userId ?? linkedPersona?.nickname ?? 'Unknown User'

// shares
const [shares, setShares] = useState<number | ''>(origin?.shares || RED_PACKET_DEFAULT_SHARES)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { NftRedPacketHistoryList } from './NftRedPacketHistoryList'
import type { NftRedPacketHistory, RedPacketJSONPayload } from '../types'
import { RedPacketNftMetaKey } from '../constants'
import { useCompositionContext } from '@masknet/plugin-infra/content-script'
import { useCurrentIdentity } from '../../../components/DataSource/useActivatedUI'
import { useCurrentIdentity, useCurrentLinkedPersona } from '../../../components/DataSource/useActivatedUI'
import type { ERC721ContractDetailed } from '@masknet/web3-shared-evm'

enum RpTypeTabs {
Expand Down Expand Up @@ -64,7 +64,10 @@ export function RedPacketPast({ onSelect, onClose }: Props) {
const chainId = useChainId()

const currentIdentity = useCurrentIdentity()
const senderName = currentIdentity?.identifier.userId ?? currentIdentity?.linkedPersona?.nickname ?? 'Unknown User'

const { value: linkedPersona } = useCurrentLinkedPersona()

const senderName = currentIdentity?.identifier.userId ?? linkedPersona?.nickname ?? 'Unknown User'
const { attachMetadata } = useCompositionContext()
const handleSendNftRedpacket = useCallback(
(history: NftRedPacketHistory, contractDetailed: ERC721ContractDetailed) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import { useCompositionContext } from '@masknet/plugin-infra/content-script'
import { RedPacketNftMetaKey } from '../constants'
import { WalletMessages } from '../../Wallet/messages'
import { RedPacketRPC } from '../messages'
import { useAsync } from 'react-use'
import Services from '../../../extension/service'

const useStyles = makeStyles()((theme) => ({
root: {
Expand Down Expand Up @@ -169,7 +171,13 @@ export function RedpacketNftConfirmDialog(props: RedpacketNftConfirmDialogProps)
const { address: publicKey, privateKey } = useMemo(() => web3.eth.accounts.create(), [])
const duration = 60 * 60 * 24
const currentIdentity = useCurrentIdentity()
const senderName = currentIdentity?.identifier.userId ?? currentIdentity?.linkedPersona?.nickname ?? 'Unknown User'

const { value: linkedPersona } = useAsync(async () => {
if (!currentIdentity?.linkedPersona) return
return Services.Identity.queryPersona(currentIdentity.linkedPersona)
}, [currentIdentity?.linkedPersona])

const senderName = currentIdentity?.identifier.userId ?? linkedPersona?.nickname ?? 'Unknown User'
const tokenIdList = tokenList.map((value) => value.tokenId)
const [createState, createCallback, resetCallback] = useCreateNftRedpacketCallback(
duration,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function getProfileIdentifierAtFacebook(links: link[] | link, allowCollec
if (allowCollectInfo && image.getAttribute('aria-label') === nickname && nickname) {
Services.Identity.updateProfileInfo(identifier, { nickname, avatarURL: image.src })
if (currentProfile?.linkedPersona) {
Services.Identity.createNewRelation(identifier, currentProfile.linkedPersona.identifier)
Services.Identity.createNewRelation(identifier, currentProfile.linkedPersona)
}
}
} catch {}
Expand All @@ -49,7 +49,7 @@ export function getProfileIdentifierAtFacebook(links: link[] | link, allowCollec
if (allowCollectInfo && avatar) {
Services.Identity.updateProfileInfo(identifier, { nickname, avatarURL: image.src })
if (currentProfile?.linkedPersona) {
Services.Identity.createNewRelation(identifier, currentProfile.linkedPersona.identifier)
Services.Identity.createNewRelation(identifier, currentProfile.linkedPersona)
}
}
} catch {}
Expand All @@ -59,7 +59,7 @@ export function getProfileIdentifierAtFacebook(links: link[] | link, allowCollec
if (allowCollectInfo && avatar) {
Services.Identity.updateProfileInfo(identifier, { nickname, avatarURL: avatar })
if (currentProfile?.linkedPersona) {
Services.Identity.createNewRelation(identifier, currentProfile.linkedPersona.identifier)
Services.Identity.createNewRelation(identifier, currentProfile.linkedPersona)
}
}
} catch {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function collectPostsMindsInner(store: Next.CollectingCapabilities.PostsProvider
avatarURL: avatar,
})
if (currentProfile?.linkedPersona)
Services.Identity.createNewRelation(postBy, currentProfile.linkedPersona.identifier)
Services.Identity.createNewRelation(postBy, currentProfile.linkedPersona)
}
// decode steganographic image
// don't add await on this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function registerPostCollectorInner(
avatarURL: info.avatarURL.getCurrentValue()?.toString(),
})
if (currentProfile?.linkedPersona) {
Services.Identity.createNewRelation(profileIdentifier, currentProfile.linkedPersona.identifier)
Services.Identity.createNewRelation(profileIdentifier, currentProfile.linkedPersona)
}
},
(info: PostInfo) => info.author.getCurrentValue(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export const ifUsingMask = memoizePromise(
async (pid: ProfileIdentifier | null) => {
if (!pid) throw new Error()
const p = await Services.Identity.queryProfilesInformation([pid])
if (!p[0].fingerprint) throw new Error()
if (!p[0].linkedPersona?.rawPublicKey) throw new Error()
},
(x) => x,
)
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const useInjectedDialogClassesOverwriteTwitter = makeStyles()((theme) => {
display: 'grid',
gridTemplateColumns: 'repeat(3, 1fr)',
alignItems: 'center',
padding: '17px 16px',
padding: 16,
position: 'relative',
background: theme.palette.background.modalTitle,
borderBottom: 'none',
Expand Down
2 changes: 1 addition & 1 deletion packages/mask/src/social-network-adaptor/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function getCurrentSNSNetwork(current: SocialNetwork.Base['networkIdentif
export function getCurrentIdentifier():
| {
identifier: ProfileIdentifier
linkedPersona?: { identifier: PersonaIdentifier }
linkedPersona?: PersonaIdentifier
}
| undefined {
const current = activatedSocialNetworkUI.collecting.identityProvider?.recognized.value
Expand Down
9 changes: 6 additions & 3 deletions packages/mask/src/social-network/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
} from '@masknet/shared-base'
import { Environment, assertNotEnvironment, ValueRef } from '@dimensiondev/holoflows-kit'
import { IdentityResolved, startPluginSNSAdaptor } from '@masknet/plugin-infra/content-script'
import { getCurrentSNSNetwork } from '../social-network-adaptor/utils'
import { getCurrentIdentifier, getCurrentSNSNetwork } from '../social-network-adaptor/utils'
import { createPluginHost } from '../plugin-infra/host'
import { definedSocialNetworkUIs } from './define'
import { setupShadowRootPortal, MaskMessages } from '../utils'
Expand Down Expand Up @@ -109,8 +109,11 @@ export async function activateSocialNetworkUIInner(ui_deferred: SocialNetworkUI.

// Update user avatar
ui.collecting.currentVisitingIdentityProvider?.recognized.addListener((ref) => {
if (ref.avatar && ref.identifier) {
Services.Identity.updateProfileInfo(ref.identifier, { avatarURL: ref.avatar })
if (!(ref.avatar && ref.identifier)) return
Services.Identity.updateProfileInfo(ref.identifier, { avatarURL: ref.avatar, nickname: ref.nickname })
const currentProfile = getCurrentIdentifier()
if (currentProfile?.linkedPersona) {
Services.Identity.createNewRelation(ref.identifier, currentProfile.linkedPersona)
}
})

Expand Down
2 changes: 1 addition & 1 deletion packages/shared-base/src/Persona/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface ProfileInformation {
nickname?: string
avatar?: string
identifier: ProfileIdentifier
fingerprint?: string
linkedPersona?: PersonaIdentifier
}

export enum RelationFavor {
Expand Down