feat: add confirmation prompt when publishing event signed by a different user

This commit is contained in:
codytseng
2025-05-12 22:37:30 +08:00
parent 41527b2813
commit 46b9f5625b
13 changed files with 60 additions and 17 deletions

View File

@@ -514,11 +514,30 @@ export function NostrProvider({ children }: { children: React.ReactNode }) {
}
const event = await signEvent(draftEvent)
const relays = specifiedRelayUrls?.length
? specifiedRelayUrls
: (relayList?.write.slice(0, 10) ?? [])
.concat(Array.from(new Set(additionalRelayUrls)) ?? [])
.concat(client.getCurrentRelayUrls())
if (event.pubkey !== account.pubkey) {
const eventAuthor = await client.fetchProfile(event.pubkey)
const result = confirm(
t(
'You are about to publish an event signed by [{{eventAuthorName}}]. You are currently logged in as [{{currentUsername}}]. Are you sure?',
{ eventAuthorName: eventAuthor?.username, currentUsername: profile?.username }
)
)
if (!result) {
throw new Error(t('Cancelled'))
}
}
let relays: string[]
if (specifiedRelayUrls?.length) {
relays = specifiedRelayUrls
} else {
const relayList = await client.fetchRelayList(event.pubkey)
relays = (relayList?.write.slice(0, 10) ?? [])
.concat(Array.from(new Set(additionalRelayUrls)) ?? [])
.concat(client.getCurrentRelayUrls())
}
if (!relays.length) {
relays.push(...BIG_RELAY_URLS)
}