commit c16a8022f22cf2cc40c33d34ce49bba0c63362d8
parent 0773a062ebd4dc3f9c1a2d6dc02de499a4a0836a
Author: Daniel D’Aquino <daniel@daquino.me>
Date: Wed, 30 Oct 2024 15:45:50 -0700
Merge pull request #30 from danieldaquino/notedeck#330-part-deux
Purple checkout flows without Damus iOS — Part deux
Diffstat:
4 files changed, 15 insertions(+), 6 deletions(-)
diff --git a/src/components/NostrProfile.tsx b/src/components/NostrProfile.tsx
@@ -4,21 +4,22 @@ import { nip19 } from "nostr-tools"
import { Profile } from "@/utils/PurpleUtils";
export interface NostrProfileProps {
- profile: Profile
+ pubkey: string
+ profile: Profile | null
profileHeader: React.ReactNode
profileFooter: React.ReactNode
}
export function NostrProfile(props: NostrProfileProps) {
const intl = useIntl()
- const { profile } = props
- const npub = nip19.npubEncode(profile.pubkey)
+ const { profile, pubkey } = props
+ const npub = nip19.npubEncode(pubkey)
return (<>
<div className="mt-2 mb-4 flex flex-col items-center">
{props.profileHeader}
<div className="mt-4 flex flex-col gap-1 items-center justify-center mb-4">
- <Image src={profile?.picture || ("https://robohash.org/" + (profile.pubkey))} width={64} height={64} className="rounded-full" alt={profile.name || intl.formatMessage({ id: "purple.profile.unknown-user", defaultMessage: "Generic user avatar" })} />
+ <Image src={profile?.picture || ("https://robohash.org/" + (pubkey))} width={64} height={64} className="rounded-full" alt={profile?.name || intl.formatMessage({ id: "purple.profile.unknown-user", defaultMessage: "Generic user avatar" })} />
<div className="text-purple-100/90 font-semibold text-lg">
{profile?.name || (npub.substring(0, 8) + ":" + npub.substring(npub.length - 8))}
</div>
diff --git a/src/components/NostrUserInput.tsx b/src/components/NostrUserInput.tsx
@@ -91,8 +91,9 @@ export function NostrUserInput(props: { pubkey: string | null, setPubkey: (pubke
</div>
</div>
)}
- {profile && (<>
+ {((profile || profile === null) && props.pubkey) && (<>
<NostrProfile
+ pubkey={props.pubkey}
profile={profile}
profileHeader={props.profileHeader}
profileFooter={props.profileFooter}
diff --git a/src/components/sections/PurpleCheckoutDetails/Step2UserVerification.tsx b/src/components/sections/PurpleCheckoutDetails/Step2UserVerification.tsx
@@ -120,8 +120,9 @@ export function Step2UserVerification(props: Step2UserVerificationProps) {
</TabsContent>
</Tabs>
}
- {step2Done && profile && <>
+ {step2Done && pubkey && (profile !== undefined) && <>
<NostrProfile
+ pubkey={pubkey}
profile={profile}
profileHeader={<>
<div className="text-purple-200/50 font-normal text-sm">
diff --git a/src/hooks/usePurpleLoginSession.ts b/src/hooks/usePurpleLoginSession.ts
@@ -27,6 +27,12 @@ export function usePurpleLoginSession(setError: (message: string) => void) {
'Authorization': 'Bearer ' + sessionToken
},
});
+
+ if (response.status === 401) {
+ setSessionToken(null);
+ setAccountInfo(null);
+ return;
+ }
if (!response.ok) {
setError("Failed to get account info from our servers. Please wait a few minutes and refresh the page. If the problem persists, please contact support.");