Replace getAgent() with reading agent (#4243)

* Replace getAgent() with agent

* Replace {agent} with agent
This commit is contained in:
dan 2024-05-28 16:37:51 +01:00 committed by GitHub
parent 8a2f43c218
commit 9bd411c151
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
74 changed files with 400 additions and 438 deletions

View file

@ -27,7 +27,7 @@ export const snapPoints = ['90%']
export function Component() {
const pal = usePalette('default')
const {currentAccount} = useSession()
const {getAgent} = useAgent()
const agent = useAgent()
const {_} = useLingui()
const [stage, setStage] = useState<Stages>(Stages.InputEmail)
const [email, setEmail] = useState<string>(currentAccount?.email || '')
@ -45,12 +45,12 @@ export function Component() {
setError('')
setIsProcessing(true)
try {
const res = await getAgent().com.atproto.server.requestEmailUpdate()
const res = await agent.com.atproto.server.requestEmailUpdate()
if (res.data.tokenRequired) {
setStage(Stages.ConfirmCode)
} else {
await getAgent().com.atproto.server.updateEmail({email: email.trim()})
await getAgent().resumeSession(getAgent().session!)
await agent.com.atproto.server.updateEmail({email: email.trim()})
await agent.resumeSession(agent.session!)
Toast.show(_(msg`Email updated`))
setStage(Stages.Done)
}
@ -75,11 +75,11 @@ export function Component() {
setError('')
setIsProcessing(true)
try {
await getAgent().com.atproto.server.updateEmail({
await agent.com.atproto.server.updateEmail({
email: email.trim(),
token: confirmationCode.trim(),
})
await getAgent().resumeSession(getAgent().session!)
await agent.resumeSession(agent.session!)
Toast.show(_(msg`Email updated`))
setStage(Stages.Done)
} catch (e) {

View file

@ -35,12 +35,12 @@ export type Props = {onChanged: () => void}
export function Component(props: Props) {
const {currentAccount} = useSession()
const {getAgent} = useAgent()
const agent = useAgent()
const {
isLoading,
data: serviceInfo,
error: serviceInfoError,
} = useServiceQuery(getAgent().service.toString())
} = useServiceQuery(agent.service.toString())
return isLoading || !currentAccount ? (
<View style={{padding: 18}}>
@ -71,7 +71,7 @@ export function Inner({
const {closeModal} = useModalControls()
const {mutateAsync: updateHandle, isPending: isUpdateHandlePending} =
useUpdateHandleMutation()
const {getAgent} = useAgent()
const agent = useAgent()
const [error, setError] = useState<string>('')
@ -111,7 +111,7 @@ export function Inner({
await updateHandle({
handle: newHandle,
})
await getAgent().resumeSession(getAgent().session!)
await agent.resumeSession(agent.session!)
closeModal()
onChanged()
} catch (err: any) {
@ -129,7 +129,7 @@ export function Inner({
closeModal,
updateHandle,
serviceInfo,
getAgent,
agent,
])
// rendering

View file

@ -37,7 +37,7 @@ export const snapPoints = isAndroid ? ['90%'] : ['45%']
export function Component() {
const pal = usePalette('default')
const {currentAccount} = useSession()
const {getAgent} = useAgent()
const agent = useAgent()
const {_} = useLingui()
const [stage, setStage] = useState<Stages>(Stages.RequestCode)
const [isProcessing, setIsProcessing] = useState<boolean>(false)
@ -46,7 +46,6 @@ export function Component() {
const [error, setError] = useState<string>('')
const {isMobile} = useWebMediaQueries()
const {closeModal} = useModalControls()
const agent = getAgent()
const onRequestCode = async () => {
if (

View file

@ -62,7 +62,7 @@ export function Component({
const {_} = useLingui()
const listCreateMutation = useListCreateMutation()
const listMetadataMutation = useListMetadataMutation()
const {getAgent} = useAgent()
const agent = useAgent()
const activePurpose = useMemo(() => {
if (list?.purpose) {
@ -157,7 +157,7 @@ export function Component({
{cleanNewlines: true},
)
await richText.detectFacets(getAgent())
await richText.detectFacets(agent)
richText = shortenLinks(richText)
// filter out any mention facets that didn't map to a user
@ -229,7 +229,7 @@ export function Component({
listMetadataMutation,
listCreateMutation,
_,
getAgent,
agent,
])
return (

View file

@ -31,7 +31,7 @@ export function Component({}: {}) {
const pal = usePalette('default')
const theme = useTheme()
const {currentAccount} = useSession()
const {getAgent} = useAgent()
const agent = useAgent()
const {removeAccount} = useSessionApi()
const {_} = useLingui()
const {closeModal} = useModalControls()
@ -45,7 +45,7 @@ export function Component({}: {}) {
setError('')
setIsProcessing(true)
try {
await getAgent().com.atproto.server.requestAccountDelete()
await agent.com.atproto.server.requestAccountDelete()
setIsEmailSent(true)
} catch (e: any) {
setError(cleanError(e))
@ -63,7 +63,7 @@ export function Component({}: {}) {
try {
// inform chat service of intent to delete account
const {success} = await getAgent().api.chat.bsky.actor.deleteAccount(
const {success} = await agent.api.chat.bsky.actor.deleteAccount(
undefined,
{
headers: DM_SERVICE_HEADERS,
@ -72,7 +72,7 @@ export function Component({}: {}) {
if (!success) {
throw new Error('Failed to inform chat service of account deletion')
}
await getAgent().com.atproto.server.deleteAccount({
await agent.com.atproto.server.deleteAccount({
did: currentAccount.did,
password,
token,

View file

@ -41,7 +41,7 @@ export function Component({
onSuccess?: () => void
}) {
const pal = usePalette('default')
const {getAgent} = useAgent()
const agent = useAgent()
const {currentAccount} = useSession()
const {_} = useLingui()
const [stage, setStage] = useState<Stages>(
@ -64,7 +64,7 @@ export function Component({
setError('')
setIsProcessing(true)
try {
await getAgent().com.atproto.server.requestEmailConfirmation()
await agent.com.atproto.server.requestEmailConfirmation()
setStage(Stages.ConfirmCode)
} catch (e) {
setError(cleanError(String(e)))
@ -77,11 +77,11 @@ export function Component({
setError('')
setIsProcessing(true)
try {
await getAgent().com.atproto.server.confirmEmail({
await agent.com.atproto.server.confirmEmail({
email: (currentAccount?.email || '').trim(),
token: confirmationCode.trim(),
})
await getAgent().resumeSession(getAgent().session!)
await agent.resumeSession(agent.session!)
Toast.show(_(msg`Email verified`))
closeModal()
onSuccess?.()