feat: initialize default configuration for new users
This commit is contained in:
@@ -22,7 +22,7 @@ export default function GenerateNewAccount({
|
|||||||
const [password, setPassword] = useState('')
|
const [password, setPassword] = useState('')
|
||||||
|
|
||||||
const handleLogin = () => {
|
const handleLogin = () => {
|
||||||
nsecLogin(nsec, password).then(() => onLoginSuccess())
|
nsecLogin(nsec, password, true).then(() => onLoginSuccess())
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -634,7 +634,7 @@ function buildReplaceableQTag(coordinate: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function buildRTag(url: string, scope: TMailboxRelayScope) {
|
function buildRTag(url: string, scope: TMailboxRelayScope) {
|
||||||
return scope === 'both' ? ['r', url, scope] : ['r', url]
|
return scope !== 'both' ? ['r', url, scope] : ['r', url]
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildTTag(hashtag: string) {
|
function buildTTag(hashtag: string) {
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
import LoginDialog from '@/components/LoginDialog'
|
import LoginDialog from '@/components/LoginDialog'
|
||||||
import { ApplicationDataKey, BIG_RELAY_URLS, ExtendedKind } from '@/constants'
|
import { ApplicationDataKey, BIG_RELAY_URLS, ExtendedKind } from '@/constants'
|
||||||
import { createSeenNotificationsAtDraftEvent } from '@/lib/draft-event'
|
import {
|
||||||
|
createFollowListDraftEvent,
|
||||||
|
createRelayListDraftEvent,
|
||||||
|
createSeenNotificationsAtDraftEvent
|
||||||
|
} from '@/lib/draft-event'
|
||||||
import { getLatestEvent, getReplaceableEventIdentifier } from '@/lib/event'
|
import { getLatestEvent, getReplaceableEventIdentifier } from '@/lib/event'
|
||||||
import { getProfileFromEvent, getRelayListFromEvent } from '@/lib/event-metadata'
|
import { getProfileFromEvent, getRelayListFromEvent } from '@/lib/event-metadata'
|
||||||
import { formatPubkey, isValidPubkey, pubkeyToNpub } from '@/lib/pubkey'
|
import { formatPubkey, isValidPubkey, pubkeyToNpub } from '@/lib/pubkey'
|
||||||
@@ -44,7 +48,7 @@ type TNostrContext = {
|
|||||||
nsec: string | null
|
nsec: string | null
|
||||||
ncryptsec: string | null
|
ncryptsec: string | null
|
||||||
switchAccount: (account: TAccountPointer | null) => Promise<void>
|
switchAccount: (account: TAccountPointer | null) => Promise<void>
|
||||||
nsecLogin: (nsec: string, password?: string) => Promise<string>
|
nsecLogin: (nsec: string, password?: string, needSetup?: boolean) => Promise<string>
|
||||||
ncryptsecLogin: (ncryptsec: string) => Promise<string>
|
ncryptsecLogin: (ncryptsec: string) => Promise<string>
|
||||||
nip07Login: () => Promise<string>
|
nip07Login: () => Promise<string>
|
||||||
bunkerLogin: (bunker: string) => Promise<string>
|
bunkerLogin: (bunker: string) => Promise<string>
|
||||||
@@ -375,7 +379,7 @@ export function NostrProvider({ children }: { children: React.ReactNode }) {
|
|||||||
await loginWithAccountPointer(act)
|
await loginWithAccountPointer(act)
|
||||||
}
|
}
|
||||||
|
|
||||||
const nsecLogin = async (nsecOrHex: string, password?: string) => {
|
const nsecLogin = async (nsecOrHex: string, password?: string, needSetup?: boolean) => {
|
||||||
const nsecSigner = new NsecSigner()
|
const nsecSigner = new NsecSigner()
|
||||||
let privkey: Uint8Array
|
let privkey: Uint8Array
|
||||||
if (nsecOrHex.startsWith('nsec')) {
|
if (nsecOrHex.startsWith('nsec')) {
|
||||||
@@ -392,9 +396,14 @@ export function NostrProvider({ children }: { children: React.ReactNode }) {
|
|||||||
const pubkey = nsecSigner.login(privkey)
|
const pubkey = nsecSigner.login(privkey)
|
||||||
if (password) {
|
if (password) {
|
||||||
const ncryptsec = nip49.encrypt(privkey, password)
|
const ncryptsec = nip49.encrypt(privkey, password)
|
||||||
return login(nsecSigner, { pubkey, signerType: 'ncryptsec', ncryptsec })
|
login(nsecSigner, { pubkey, signerType: 'ncryptsec', ncryptsec })
|
||||||
|
} else {
|
||||||
|
login(nsecSigner, { pubkey, signerType: 'nsec', nsec: nip19.nsecEncode(privkey) })
|
||||||
}
|
}
|
||||||
return login(nsecSigner, { pubkey, signerType: 'nsec', nsec: nip19.nsecEncode(privkey) })
|
if (needSetup) {
|
||||||
|
setupNewUser(nsecSigner)
|
||||||
|
}
|
||||||
|
return pubkey
|
||||||
}
|
}
|
||||||
|
|
||||||
const ncryptsecLogin = async (ncryptsec: string) => {
|
const ncryptsecLogin = async (ncryptsec: string) => {
|
||||||
@@ -526,6 +535,18 @@ export function NostrProvider({ children }: { children: React.ReactNode }) {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const setupNewUser = async (signer: ISigner) => {
|
||||||
|
await Promise.allSettled([
|
||||||
|
client.publishEvent(BIG_RELAY_URLS, await signer.signEvent(createFollowListDraftEvent([]))),
|
||||||
|
client.publishEvent(
|
||||||
|
BIG_RELAY_URLS,
|
||||||
|
await signer.signEvent(
|
||||||
|
createRelayListDraftEvent(BIG_RELAY_URLS.map((url) => ({ url, scope: 'both' })))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
const signEvent = async (draftEvent: TDraftEvent) => {
|
const signEvent = async (draftEvent: TDraftEvent) => {
|
||||||
const event = await signer?.signEvent(draftEvent)
|
const event = await signer?.signEvent(draftEvent)
|
||||||
if (!event) {
|
if (!event) {
|
||||||
|
|||||||
Reference in New Issue
Block a user