From 431a76ed0858a848a13231caa094e90140a3baf5 Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Tue, 10 Feb 2026 00:08:46 +0000 Subject: [PATCH] just yeet declaration for now --- src/screens/Profile/components/GermButton.tsx | 60 +++++++++++-------- 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/src/screens/Profile/components/GermButton.tsx b/src/screens/Profile/components/GermButton.tsx index 9f30013196..a70d427539 100644 --- a/src/screens/Profile/components/GermButton.tsx +++ b/src/screens/Profile/components/GermButton.tsx @@ -1,12 +1,18 @@ import {Platform, View} from 'react-native' import {Image} from 'expo-image' -import {type AppBskyActorDefs} from '@atproto/api' +import { + type AppBskyActorDefs, + type AppBskyActorGetProfile, + type AtpAgent, +} from '@atproto/api' import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' -import {useMutation} from '@tanstack/react-query' +import {useMutation, useQueryClient} from '@tanstack/react-query' +import {until} from '#/lib/async/until' import {isNetworkError} from '#/lib/strings/errors' import {logger} from '#/logger' +import {RQKEY} from '#/state/queries/profile' import {useAgent, useSession} from '#/state/session' import {atoms as a, useTheme, web} from '#/alf' import {Button, ButtonIcon, ButtonText} from '#/components/Button' @@ -79,37 +85,26 @@ function GermSelfButton({did}: {did: string}) { const selfExplanationDialogControl = Dialog.useDialogControl() const agent = useAgent() const t = useTheme() + const queryClient = useQueryClient() const {mutate, isPending} = useMutation({ onMutate: async () => { - const res = await agent.com.germnetwork.declaration.get({ + await agent.com.germnetwork.declaration.delete({ repo: did, rkey: 'self', }) - if (!res?.value) { - throw new Error('Failed to get self declaration') - } - - await agent.com.germnetwork.declaration.put( - { - repo: did, - rkey: 'self', - }, - { - ...res.value, - messageMe: { - ...res.value.messageMe, - // TODO: update types - // showButtonTo: 'none', - }, - }, - ) - - // TODO: await appview and revalidate profile + await whenAppViewReady(agent, did, res => !res.data.associated?.germ) }, onSuccess: () => { - Toast.show(_(msg`Germ DM link removed`)) + selfExplanationDialogControl.close(() => { + Toast.show( + _( + msg`Germ DM link disconnected. You can reconnect it at any time through the Germ app.`, + ), + ) + void queryClient.refetchQueries({queryKey: RQKEY(did)}) + }) }, onError: error => { Toast.show( @@ -169,14 +164,14 @@ function GermSelfButton({did}: {did: string}) { @@ -222,3 +217,16 @@ function platform() { return 'web' } } + +async function whenAppViewReady( + agent: AtpAgent, + actor: string, + fn: (res: AppBskyActorGetProfile.Response) => boolean, +) { + await until( + 5, // 5 tries + 1e3, // 1s delay between tries + fn, + () => agent.app.bsky.actor.getProfile({actor}), + ) +}