diff --git a/app/hooks/use-nostr-profile.ts b/app/hooks/use-nostr-profile.ts index 7d0e861da..d8680e0d1 100644 --- a/app/hooks/use-nostr-profile.ts +++ b/app/hooks/use-nostr-profile.ts @@ -219,6 +219,7 @@ const useNostrProfile = () => { [ "wss://relay.damus.io", "wss://relay.primal.net", + "wss://nos.lol", "wss://relay.islandbitcoin.com", ], 0, @@ -451,52 +452,6 @@ const useNostrProfile = () => { throw new Error("Failed to publish profile to any relays") } - console.log(`\n✨ Profile update completed with ${successCount} successful publishes`) - - // Background retry for remaining failed relays - if (failedRelays.length > 0) { - console.log( - `ā° Scheduling background retry for ${failedRelays.length} failed relays in 5 seconds...`, - ) - setTimeout(() => { - console.log("šŸ”„ Starting background retry for failed relays...") - retryFailedRelays(signedKind0Event, failedRelays) - }, 5000) - } - - // Verify profile propagation after 3 seconds - if (successfulRelays.length > 0) { - setTimeout(async () => { - console.log("\nšŸ” Starting profile propagation verification...") - - // Use the new verification helper - const verifyRelays = [ - "wss://relay.flashapp.me", - "wss://relay.islandbitcoin.com", - "wss://relay.damus.io", - "wss://relay.primal.net", - ] - - const verification = await verifyEventOnRelays( - pool, - signedKind0Event.id, - verifyRelays, - 0, // kind-0 for profile - ) - - if (verification.found) { - console.log( - `āœ… Profile verified on ${verification.foundOnRelays.length} critical relays`, - ) - console.log("Profile available on:", verification.foundOnRelays.join(", ")) - } else { - console.log( - "āš ļø WARNING: Profile verification failed - not found on any critical relay", - ) - } - }, 3000) - } - return { successCount, totalRelays: publicRelays.length, successfulRelays } } diff --git a/app/screens/authentication-screen/username-set.tsx b/app/screens/authentication-screen/username-set.tsx index f84896b17..6518c67f8 100644 --- a/app/screens/authentication-screen/username-set.tsx +++ b/app/screens/authentication-screen/username-set.tsx @@ -8,7 +8,6 @@ import { PrimaryBtn } from "@app/components/buttons" import { Screen } from "@app/components/screen" // hooks -import useNostrProfile from "@app/hooks/use-nostr-profile" import { useI18nContext } from "@app/i18n/i18n-react" import useLogout from "@app/hooks/use-logout" import { useAppConfig } from "@app/hooks" @@ -43,13 +42,12 @@ export const UsernameSet: React.FC = ({ navigation, route }) => { const { LL } = useI18nContext() const { colors } = useTheme().theme const styles = useStyles() - - const { updateNostrProfile } = useNostrProfile() const { logout } = useLogout() const { userProfileEvent } = useChatContext() const [error, setError] = useState() const [lnAddress, setLnAddress] = useState("") + const [isSubmitting, setIsSubmitting] = useState(false) const [updateUsername, { loading }] = useUserUpdateUsernameMutation({ update: (cache, { data }) => { @@ -78,6 +76,8 @@ export const UsernameSet: React.FC = ({ navigation, route }) => { }) const onSetLightningAddress = async () => { + setIsSubmitting(true) + setError(undefined) const validationResult = validateLightningAddress(lnAddress) if (!validationResult.valid) { setError(validationResult.error) @@ -102,26 +102,16 @@ export const UsernameSet: React.FC = ({ navigation, route }) => { console.log("No existing profile found or failed to parse") } } - - // Merge with new username data - updateNostrProfile({ - content: { - ...existingProfile, - name: lnAddress, - username: lnAddress, - lud16: `${lnAddress}@${lnAddressHostname}`, - nip05: `${lnAddress}@${lnAddressHostname}`, - }, - }) if ((data?.userUpdateUsername?.errors ?? []).length > 0) { if (data?.userUpdateUsername?.errors[0]?.code === "USERNAME_ERROR") { setError(SetAddressError.ADDRESS_UNAVAILABLE) } else { setError(SetAddressError.UNKNOWN_ERROR) } + setIsSubmitting(false) return } - + setIsSubmitting(false) dispatch(updateUserData({ username: lnAddress })) navigation.reset({ index: 0, @@ -178,6 +168,7 @@ export const UsernameSet: React.FC = ({ navigation, route }) => { = ({ navigation, route }) => { {errorMessage && } { if (isGenerating) return setIsGenerating(true) setProgressMessage("Creating Nostr profile...") - let newSecret = await saveNewNostrKey((message) => { - setProgressMessage(message) - }) + let newSecret = await saveNewNostrKey( + (message) => { + setProgressMessage(message) + }, + { + name: dataAuthed?.me?.username, + username: dataAuthed?.me?.username, + lud16: `${dataAuthed?.me?.username}@${lnDomain}`, + nip05: `${dataAuthed?.me?.username}@${lnDomain}`, + }, + ) setSecretKey(newSecret) setIsGenerating(false) setProgressMessage("") @@ -151,7 +159,9 @@ export const NostrSettingsScreen = () => { style={{ marginRight: 10, opacity: isGenerating ? 0.5 : 1 }} /> - {isGenerating ? progressMessage || LL.Nostr.creatingProfile() : LL.Nostr.createNewProfile()} + {isGenerating + ? progressMessage || LL.Nostr.creatingProfile() + : LL.Nostr.createNewProfile()} diff --git a/app/utils/nostr/publish-helpers.ts b/app/utils/nostr/publish-helpers.ts index 87f75c83f..8c0b263dd 100644 --- a/app/utils/nostr/publish-helpers.ts +++ b/app/utils/nostr/publish-helpers.ts @@ -8,7 +8,7 @@ export async function publishEventToRelays( pool: SimplePool, event: Event, relays: string[], - eventLabel: string = "Event" + eventLabel: string = "Event", ): Promise<{ successCount: number failedCount: number @@ -117,17 +117,22 @@ export async function verifyEventOnRelays( pool: SimplePool, eventId: string, relays: string[], - eventKind?: number + eventKind?: number, ): Promise<{ found: boolean foundOnRelays: string[] missingFromRelays: string[] + event: Event | null }> { - console.log(`\nšŸ” Verifying ${eventKind === 0 ? "profile" : "event"} ${eventId} on ${relays.length} relays...`) + console.log( + `\nšŸ” Verifying ${eventKind === 0 ? "profile" : "event"} ${eventId} on ${ + relays.length + } relays...`, + ) const foundOnRelays: string[] = [] const missingFromRelays: string[] = [] - + let event: Event | null = null const verifyPromises = relays.map(async (relay) => { try { const filter: any = { ids: [eventId] } @@ -135,9 +140,9 @@ export async function verifyEventOnRelays( filter.kinds = [eventKind] } - const event = await pool.get([relay], filter) - - if (event && event.id === eventId) { + const eventFound = await pool.get([relay], filter) + event = eventFound + if (eventFound && eventFound.id === eventId) { console.log(` āœ… Found on ${relay}`) foundOnRelays.push(relay) } else { @@ -156,6 +161,7 @@ export async function verifyEventOnRelays( found: foundOnRelays.length > 0, foundOnRelays, missingFromRelays, + event, } console.log(`\nšŸ“Š Verification Summary:`) @@ -171,10 +177,7 @@ export async function verifyEventOnRelays( * Gets the best relays for publishing based on purpose */ export function getPublishingRelays(purpose: "profile" | "note" | "general"): string[] { - const coreRelays = [ - "wss://relay.flashapp.me", - "wss://relay.islandbitcoin.com", - ] + const coreRelays = ["wss://relay.flashapp.me", "wss://relay.islandbitcoin.com"] const majorPublicRelays = [ "wss://relay.damus.io", @@ -182,15 +185,9 @@ export function getPublishingRelays(purpose: "profile" | "note" | "general"): st "wss://relay.snort.social", ] - const profileRelays = [ - "wss://purplepag.es", - "wss://relay.nostr.band", - ] + const profileRelays = ["wss://purplepag.es", "wss://relay.nostr.band"] - const noteRelays = [ - "wss://relay.current.fyi", - "wss://relay.nostrplebs.com", - ] + const noteRelays = ["wss://relay.current.fyi", "wss://relay.nostrplebs.com"] switch (purpose) { case "profile": @@ -201,4 +198,4 @@ export function getPublishingRelays(purpose: "profile" | "note" | "general"): st default: return [...coreRelays, ...majorPublicRelays] } -} \ No newline at end of file +}