-
Notifications
You must be signed in to change notification settings - Fork 306
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: bugfix for encrypted contacts (#10530)
* fix: self persona in search list * fix: mf-4981 * fix: remove profiles * perf: improve query profiles * fix: mf-5095 * fix: query client * chore: del console * chore: fix url * refactor: remove dead code. * chore: code review * fix: query client * chore: code review * chore: revert lock file * chore: code rewiew * fix: remove query client provider * fix: end loading * chore: code review * chore: code review --------- Co-authored-by: guanbinrui <52657989+guanbinrui@users.noreply.github.com>
- Loading branch information
1 parent
852d9dc
commit 265637c
Showing
14 changed files
with
229 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 11 additions & 2 deletions
13
packages/mask/background/services/identity/relation/update.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,16 @@ | ||
import type { PersonaIdentifier, ProfileIdentifier, RelationFavor } from '@masknet/shared-base' | ||
import { createRelationsTransaction, updateRelationDB } from '../../../database/persona/db.js' | ||
import { createRelationsTransaction, deletePersonaRelationDB, updateRelationDB } from '../../../database/persona/db.js' | ||
|
||
export async function updateRelation(profile: ProfileIdentifier, linked: PersonaIdentifier, favor: RelationFavor) { | ||
export async function updateRelation( | ||
profile: ProfileIdentifier | PersonaIdentifier, | ||
linked: PersonaIdentifier, | ||
favor: RelationFavor, | ||
) { | ||
const t = await createRelationsTransaction() | ||
await updateRelationDB({ profile, linked, favor }, t) | ||
} | ||
|
||
export async function deletePersonaRelation(persona: PersonaIdentifier, linked: PersonaIdentifier) { | ||
const t = await createRelationsTransaction() | ||
await deletePersonaRelationDB(persona, linked, t) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
packages/mask/src/extension/popups/hook/useFriendProfiles.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { | ||
type ECKeyIdentifier, | ||
type BindingProof, | ||
NextIDPlatform, | ||
type ProfileIdentifier, | ||
EMPTY_LIST, | ||
} from '@masknet/shared-base' | ||
import { useCurrentPersona } from '../../../components/DataSource/useCurrentPersona.js' | ||
import { useQuery } from '@tanstack/react-query' | ||
import { NextIDProof } from '@masknet/web3-providers' | ||
import { UnsupportedPlatforms, PlatformSort } from '../pages/Friends/common.js' | ||
|
||
export type Friend = { | ||
persona: ECKeyIdentifier | ||
profile?: ProfileIdentifier | ||
avatar?: string | ||
} | ||
|
||
export const profilesFilter = (x: BindingProof) => { | ||
return (x.platform === NextIDPlatform.ENS && x.name.endsWith('.eth')) || !UnsupportedPlatforms.includes(x.platform) | ||
} | ||
|
||
export function useFriendProfiles(seen: boolean, nextId?: string, twitterId?: string) { | ||
const currentPersona = useCurrentPersona() | ||
|
||
const { data: profiles } = useQuery( | ||
['profiles', currentPersona?.identifier.publicKeyAsHex, nextId], | ||
async () => { | ||
if (!nextId) return EMPTY_LIST | ||
try { | ||
return await NextIDProof.queryProfilesByPublicKey(nextId, 2) | ||
} catch (error) { | ||
return EMPTY_LIST | ||
} | ||
}, | ||
{ | ||
enabled: seen && !!nextId, | ||
}, | ||
) | ||
if (!profiles) return EMPTY_LIST | ||
if (profiles.length === 0) { | ||
if (twitterId) { | ||
return [ | ||
{ | ||
platform: NextIDPlatform.Twitter, | ||
identity: twitterId, | ||
is_valid: true, | ||
last_checked_at: '', | ||
name: twitterId, | ||
created_at: '', | ||
}, | ||
] | ||
} else { | ||
return EMPTY_LIST | ||
} | ||
} | ||
const filtered = profiles.filter(profilesFilter).sort((a, b) => PlatformSort[a.platform] - PlatformSort[b.platform]) | ||
return filtered | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.