chore: replace the usage of ProfileMetadata with NDKUserProfile
All checks were successful
Open PR on Staging / audit_and_check (pull_request) Successful in 46s
All checks were successful
Open PR on Staging / audit_and_check (pull_request) Successful in 46s
This commit is contained in:
parent
01bb68d87b
commit
95f5398736
@ -37,30 +37,19 @@ export const AppBar = () => {
|
|||||||
const [anchorElUser, setAnchorElUser] = useState<null | HTMLElement>(null)
|
const [anchorElUser, setAnchorElUser] = useState<null | HTMLElement>(null)
|
||||||
|
|
||||||
const authState = useAppSelector((state) => state.auth)
|
const authState = useAppSelector((state) => state.auth)
|
||||||
const metadataState = useAppSelector((state) => state.metadata)
|
const userProfile = useAppSelector((state) => state.user.profile)
|
||||||
const userRobotImage = useAppSelector((state) => state.userRobotImage)
|
const userRobotImage = useAppSelector((state) => state.user.robotImage)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (metadataState) {
|
const npub = authState.usersPubkey ? hexToNpub(authState.usersPubkey) : ''
|
||||||
if (metadataState.content) {
|
if (userProfile) {
|
||||||
const profileMetadata = JSON.parse(metadataState.content)
|
setUserAvatar(userProfile.image || userRobotImage || '')
|
||||||
const { picture } = profileMetadata
|
setUsername(getProfileUsername(npub, userProfile))
|
||||||
|
} else {
|
||||||
if (picture || userRobotImage) {
|
setUserAvatar('')
|
||||||
setUserAvatar(picture || userRobotImage)
|
setUsername(getProfileUsername(npub))
|
||||||
}
|
|
||||||
|
|
||||||
const npub = authState.usersPubkey
|
|
||||||
? hexToNpub(authState.usersPubkey)
|
|
||||||
: ''
|
|
||||||
|
|
||||||
setUsername(getProfileUsername(npub, profileMetadata))
|
|
||||||
} else {
|
|
||||||
setUserAvatar(userRobotImage || '')
|
|
||||||
setUsername('')
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}, [metadataState, userRobotImage, authState.usersPubkey])
|
}, [userRobotImage, authState.usersPubkey, userProfile])
|
||||||
|
|
||||||
const handleOpenUserMenu = (event: React.MouseEvent<HTMLElement>) => {
|
const handleOpenUserMenu = (event: React.MouseEvent<HTMLElement>) => {
|
||||||
setAnchorElUser(event.currentTarget)
|
setAnchorElUser(event.currentTarget)
|
||||||
|
@ -679,7 +679,7 @@ export const DrawPDFFields = ({
|
|||||||
renderValue={(value) => (
|
renderValue={(value) => (
|
||||||
<Counterpart
|
<Counterpart
|
||||||
npub={value}
|
npub={value}
|
||||||
metadata={userProfiles}
|
userProfiles={userProfiles}
|
||||||
signers={signers}
|
signers={signers}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
@ -1,31 +1,32 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { ProfileMetadata, User } from '../../../types'
|
import { User } from '../../../types'
|
||||||
import _ from 'lodash'
|
import _ from 'lodash'
|
||||||
import { npubToHex, getProfileUsername } from '../../../utils'
|
import { npubToHex, getProfileUsername } from '../../../utils'
|
||||||
import { AvatarIconButton } from '../../UserAvatarIconButton'
|
import { AvatarIconButton } from '../../UserAvatarIconButton'
|
||||||
import styles from './Counterpart.module.scss'
|
import styles from './Counterpart.module.scss'
|
||||||
|
import { NDKUserProfile } from '@nostr-dev-kit/ndk'
|
||||||
|
|
||||||
interface CounterpartProps {
|
interface CounterpartProps {
|
||||||
npub: string
|
npub: string
|
||||||
metadata: {
|
userProfiles: {
|
||||||
[key: string]: ProfileMetadata
|
[key: string]: NDKUserProfile
|
||||||
}
|
}
|
||||||
signers: User[]
|
signers: User[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Counterpart = React.memo(
|
export const Counterpart = React.memo(
|
||||||
({ npub, metadata, signers }: CounterpartProps) => {
|
({ npub, userProfiles, signers }: CounterpartProps) => {
|
||||||
let displayValue = _.truncate(npub, { length: 16 })
|
let displayValue = _.truncate(npub, { length: 16 })
|
||||||
|
|
||||||
const signer = signers.find((u) => u.pubkey === npubToHex(npub))
|
const signer = signers.find((u) => u.pubkey === npubToHex(npub))
|
||||||
if (signer) {
|
if (signer) {
|
||||||
const signerMetadata = metadata[signer.pubkey]
|
const profile = userProfiles[signer.pubkey]
|
||||||
displayValue = getProfileUsername(npub, signerMetadata)
|
displayValue = getProfileUsername(npub, profile)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.counterpartSelectValue}>
|
<div className={styles.counterpartSelectValue}>
|
||||||
<AvatarIconButton
|
<AvatarIconButton
|
||||||
src={signerMetadata.picture}
|
src={profile.image}
|
||||||
hexKey={signer.pubkey || undefined}
|
hexKey={signer.pubkey || undefined}
|
||||||
sx={{
|
sx={{
|
||||||
padding: 0,
|
padding: 0,
|
||||||
|
@ -1,18 +1,17 @@
|
|||||||
import { Event, EventTemplate } from 'nostr-tools'
|
import { EventTemplate } from 'nostr-tools'
|
||||||
import { useCallback } from 'react'
|
import { useCallback } from 'react'
|
||||||
import { NostrController } from '../controllers'
|
import { NostrController } from '../controllers'
|
||||||
import { appPrivateRoutes } from '../routes'
|
import { appPrivateRoutes } from '../routes'
|
||||||
import {
|
import {
|
||||||
setAuthState,
|
setAuthState,
|
||||||
setMetadataEvent,
|
setRelayMapAction,
|
||||||
setRelayMapAction
|
setUserProfile
|
||||||
} from '../store/actions'
|
} from '../store/actions'
|
||||||
import {
|
import {
|
||||||
base64DecodeAuthToken,
|
base64DecodeAuthToken,
|
||||||
compareObjects,
|
compareObjects,
|
||||||
createAndSaveAuthToken,
|
createAndSaveAuthToken,
|
||||||
getAuthToken,
|
getAuthToken,
|
||||||
getEmptyMetadataEvent,
|
|
||||||
getRelayMapFromNDKRelayList,
|
getRelayMapFromNDKRelayList,
|
||||||
unixNow
|
unixNow
|
||||||
} from '../utils'
|
} from '../utils'
|
||||||
@ -62,20 +61,11 @@ export const useAuth = () => {
|
|||||||
*/
|
*/
|
||||||
const authAndGetMetadataAndRelaysMap = useCallback(
|
const authAndGetMetadataAndRelaysMap = useCallback(
|
||||||
async (pubkey: string) => {
|
async (pubkey: string) => {
|
||||||
const emptyMetadata = getEmptyMetadataEvent()
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const profile = await findMetadata(pubkey)
|
const profile = await findMetadata(pubkey)
|
||||||
|
dispatch(setUserProfile(profile))
|
||||||
if (profile && profile.profileEvent) {
|
|
||||||
const event: Event = JSON.parse(profile.profileEvent)
|
|
||||||
dispatch(setMetadataEvent(event))
|
|
||||||
} else {
|
|
||||||
dispatch(setMetadataEvent(emptyMetadata))
|
|
||||||
}
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.warn('Error occurred while finding metadata', err)
|
console.warn('Error occurred while finding metadata', err)
|
||||||
dispatch(setMetadataEvent(emptyMetadata))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const timestamp = unixNow()
|
const timestamp = unixNow()
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { useCallback, useEffect, useRef, useState } from 'react'
|
import { useCallback, useEffect, useRef, useState } from 'react'
|
||||||
import { Outlet, useNavigate, useSearchParams } from 'react-router-dom'
|
import { Outlet, useNavigate, useSearchParams } from 'react-router-dom'
|
||||||
|
|
||||||
import { Event, getPublicKey, nip19 } from 'nostr-tools'
|
import { getPublicKey, nip19 } from 'nostr-tools'
|
||||||
|
|
||||||
import { init as initNostrLogin } from 'nostr-login'
|
import { init as initNostrLogin } from 'nostr-login'
|
||||||
import { NostrLoginAuthOptions } from 'nostr-login/dist/types'
|
import { NostrLoginAuthOptions } from 'nostr-login/dist/types'
|
||||||
@ -22,14 +22,14 @@ import {
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
restoreState,
|
restoreState,
|
||||||
setMetadataEvent,
|
setUserProfile,
|
||||||
updateKeyPair,
|
updateKeyPair,
|
||||||
updateLoginMethod,
|
updateLoginMethod,
|
||||||
updateNostrLoginAuthMethod,
|
updateNostrLoginAuthMethod,
|
||||||
updateUserAppData
|
updateUserAppData,
|
||||||
|
setUserRobotImage
|
||||||
} from '../store/actions'
|
} from '../store/actions'
|
||||||
import { LoginMethod } from '../store/auth/types'
|
import { LoginMethod } from '../store/auth/types'
|
||||||
import { setUserRobotImage } from '../store/userRobotImage/action'
|
|
||||||
|
|
||||||
import { getRoboHashPicture, loadState } from '../utils'
|
import { getRoboHashPicture, loadState } from '../utils'
|
||||||
|
|
||||||
@ -165,17 +165,7 @@ export const MainLayout = () => {
|
|||||||
if (!loginMethod || !usersPubkey) return logout()
|
if (!loginMethod || !usersPubkey) return logout()
|
||||||
|
|
||||||
findMetadata(usersPubkey).then((profile) => {
|
findMetadata(usersPubkey).then((profile) => {
|
||||||
if (profile && profile.profileEvent) {
|
dispatch(setUserProfile(profile))
|
||||||
try {
|
|
||||||
const event: Event = JSON.parse(profile.profileEvent)
|
|
||||||
dispatch(setMetadataEvent(event))
|
|
||||||
} catch (error) {
|
|
||||||
console.error(
|
|
||||||
'An error occurred in parsing profile event from profile obj',
|
|
||||||
error
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
setIsLoading(false)
|
setIsLoading(false)
|
||||||
|
@ -17,8 +17,7 @@ store.subscribe(
|
|||||||
_.throttle(() => {
|
_.throttle(() => {
|
||||||
saveState({
|
saveState({
|
||||||
auth: store.getState().auth,
|
auth: store.getState().auth,
|
||||||
metadata: store.getState().metadata,
|
user: store.getState().user,
|
||||||
userRobotImage: store.getState().userRobotImage,
|
|
||||||
relays: store.getState().relays
|
relays: store.getState().relays
|
||||||
})
|
})
|
||||||
}, 1000)
|
}, 1000)
|
||||||
|
@ -1127,7 +1127,7 @@ export const CreatePage = () => {
|
|||||||
key={option.pubkey}
|
key={option.pubkey}
|
||||||
>
|
>
|
||||||
<AvatarIconButton
|
<AvatarIconButton
|
||||||
src={contentJson.picture}
|
src={contentJson.picture || contentJson.image}
|
||||||
hexKey={option.pubkey}
|
hexKey={option.pubkey}
|
||||||
color="inherit"
|
color="inherit"
|
||||||
sx={{
|
sx={{
|
||||||
|
@ -22,7 +22,7 @@ import {
|
|||||||
shorten
|
shorten
|
||||||
} from '../../utils'
|
} from '../../utils'
|
||||||
|
|
||||||
import { NDKEvent, NDKUserProfile, profileFromEvent } from '@nostr-dev-kit/ndk'
|
import { NDKUserProfile } from '@nostr-dev-kit/ndk'
|
||||||
import { useNDKContext } from '../../hooks'
|
import { useNDKContext } from '../../hooks'
|
||||||
import styles from './style.module.scss'
|
import styles from './style.module.scss'
|
||||||
|
|
||||||
@ -35,8 +35,8 @@ export const ProfilePage = () => {
|
|||||||
const [pubkey, setPubkey] = useState<string>()
|
const [pubkey, setPubkey] = useState<string>()
|
||||||
const [userProfile, setUserProfile] = useState<NDKUserProfile | null>(null)
|
const [userProfile, setUserProfile] = useState<NDKUserProfile | null>(null)
|
||||||
|
|
||||||
const userRobotImage = useAppSelector((state) => state.userRobotImage)
|
const userRobotImage = useAppSelector((state) => state.user.robotImage)
|
||||||
const metadataState = useAppSelector((state) => state.metadata)
|
const currentUserProfile = useAppSelector((state) => state.user.profile)
|
||||||
const { usersPubkey } = useAppSelector((state) => state.auth)
|
const { usersPubkey } = useAppSelector((state) => state.auth)
|
||||||
|
|
||||||
const [isUsersOwnProfile, setIsUsersOwnProfile] = useState(false)
|
const [isUsersOwnProfile, setIsUsersOwnProfile] = useState(false)
|
||||||
@ -58,12 +58,8 @@ export const ProfilePage = () => {
|
|||||||
}, [npub, usersPubkey])
|
}, [npub, usersPubkey])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isUsersOwnProfile && metadataState) {
|
if (isUsersOwnProfile && currentUserProfile) {
|
||||||
const ndkEvent = new NDKEvent(ndk, metadataState)
|
setUserProfile(currentUserProfile)
|
||||||
const profile = profileFromEvent(ndkEvent)
|
|
||||||
|
|
||||||
setUserProfile(profile)
|
|
||||||
|
|
||||||
setIsLoading(false)
|
setIsLoading(false)
|
||||||
|
|
||||||
return
|
return
|
||||||
@ -81,7 +77,7 @@ export const ProfilePage = () => {
|
|||||||
setIsLoading(false)
|
setIsLoading(false)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}, [ndk, isUsersOwnProfile, metadataState, pubkey, findMetadata])
|
}, [ndk, isUsersOwnProfile, currentUserProfile, pubkey, findMetadata])
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rendering text with button which copies the provided text
|
* Rendering text with button which copies the provided text
|
||||||
|
@ -17,12 +17,7 @@ import {
|
|||||||
Tooltip
|
Tooltip
|
||||||
} from '@mui/material'
|
} from '@mui/material'
|
||||||
|
|
||||||
import {
|
import { NDKEvent, NDKUserProfile, serializeProfile } from '@nostr-dev-kit/ndk'
|
||||||
NDKEvent,
|
|
||||||
NDKUserProfile,
|
|
||||||
profileFromEvent,
|
|
||||||
serializeProfile
|
|
||||||
} from '@nostr-dev-kit/ndk'
|
|
||||||
import { launch as launchNostrLoginDialog } from 'nostr-login'
|
import { launch as launchNostrLoginDialog } from 'nostr-login'
|
||||||
import { kinds, nip19, UnsignedEvent } from 'nostr-tools'
|
import { kinds, nip19, UnsignedEvent } from 'nostr-tools'
|
||||||
|
|
||||||
@ -37,7 +32,7 @@ import { Container } from '../../../components/Container'
|
|||||||
import { Footer } from '../../../components/Footer/Footer'
|
import { Footer } from '../../../components/Footer/Footer'
|
||||||
import { LoadingSpinner } from '../../../components/LoadingSpinner'
|
import { LoadingSpinner } from '../../../components/LoadingSpinner'
|
||||||
|
|
||||||
import { setMetadataEvent } from '../../../store/actions'
|
import { setUserProfile as updateUserProfile } from '../../../store/actions'
|
||||||
import { LoginMethod, NostrLoginAuthMethod } from '../../../store/auth/types'
|
import { LoginMethod, NostrLoginAuthMethod } from '../../../store/auth/types'
|
||||||
import { Dispatch } from '../../../store/store'
|
import { Dispatch } from '../../../store/store'
|
||||||
|
|
||||||
@ -52,8 +47,8 @@ export const ProfileSettingsPage = () => {
|
|||||||
const [pubkey, setPubkey] = useState<string>()
|
const [pubkey, setPubkey] = useState<string>()
|
||||||
const [userProfile, setUserProfile] = useState<NDKUserProfile | null>(null)
|
const [userProfile, setUserProfile] = useState<NDKUserProfile | null>(null)
|
||||||
|
|
||||||
const userRobotImage = useAppSelector((state) => state.userRobotImage)
|
const userRobotImage = useAppSelector((state) => state.user.robotImage)
|
||||||
const metadataState = useAppSelector((state) => state.metadata)
|
const currentUserProfile = useAppSelector((state) => state.user.profile)
|
||||||
const keys = useAppSelector((state) => state.auth?.keyPair)
|
const keys = useAppSelector((state) => state.auth?.keyPair)
|
||||||
const { usersPubkey, loginMethod, nostrLoginAuthMethod } = useAppSelector(
|
const { usersPubkey, loginMethod, nostrLoginAuthMethod } = useAppSelector(
|
||||||
(state) => state.auth
|
(state) => state.auth
|
||||||
@ -80,11 +75,8 @@ export const ProfileSettingsPage = () => {
|
|||||||
}, [npub, usersPubkey])
|
}, [npub, usersPubkey])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isUsersOwnProfile && metadataState) {
|
if (isUsersOwnProfile && currentUserProfile) {
|
||||||
const ndkEvent = new NDKEvent(ndk, metadataState)
|
setUserProfile(currentUserProfile)
|
||||||
const profile = profileFromEvent(ndkEvent)
|
|
||||||
|
|
||||||
setUserProfile(profile)
|
|
||||||
|
|
||||||
setIsLoading(false)
|
setIsLoading(false)
|
||||||
|
|
||||||
@ -103,7 +95,7 @@ export const ProfileSettingsPage = () => {
|
|||||||
setIsLoading(false)
|
setIsLoading(false)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}, [ndk, isUsersOwnProfile, metadataState, pubkey, findMetadata])
|
}, [ndk, isUsersOwnProfile, currentUserProfile, pubkey, findMetadata])
|
||||||
|
|
||||||
const editItem = (
|
const editItem = (
|
||||||
key: keyof NDKUserProfile,
|
key: keyof NDKUserProfile,
|
||||||
@ -208,7 +200,7 @@ export const ProfileSettingsPage = () => {
|
|||||||
)}`
|
)}`
|
||||||
)
|
)
|
||||||
|
|
||||||
dispatch(setMetadataEvent(signedEvent))
|
dispatch(updateUserProfile(userProfile))
|
||||||
}
|
}
|
||||||
|
|
||||||
setSavingProfileMetadata(false)
|
setSavingProfileMetadata(false)
|
||||||
@ -323,12 +315,12 @@ export const ProfileSettingsPage = () => {
|
|||||||
/>
|
/>
|
||||||
</ListItem>
|
</ListItem>
|
||||||
|
|
||||||
{editItem('picture', 'Picture URL', undefined, undefined, {
|
{editItem('image', 'Picture URL', undefined, undefined, {
|
||||||
endAdornment: isUsersOwnProfile ? robohashButton() : undefined
|
endAdornment: isUsersOwnProfile ? robohashButton() : undefined
|
||||||
})}
|
})}
|
||||||
|
|
||||||
{editItem('name', 'Username')}
|
{editItem('name', 'Username')}
|
||||||
{editItem('display_name', 'Display Name')}
|
{editItem('displayName', 'Display Name')}
|
||||||
{editItem('nip05', 'Nostr Address (nip05)')}
|
{editItem('nip05', 'Nostr Address (nip05)')}
|
||||||
{editItem('lud16', 'Lightning Address (lud16)')}
|
{editItem('lud16', 'Lightning Address (lud16)')}
|
||||||
{editItem('about', 'About', true, 4)}
|
{editItem('about', 'About', true, 4)}
|
||||||
|
@ -7,7 +7,7 @@ export const UPDATE_LOGIN_METHOD = 'UPDATE_LOGIN_METHOD'
|
|||||||
export const UPDATE_NOSTR_LOGIN_AUTH_METHOD = 'UPDATE_NOSTR_LOGIN_AUTH_METHOD'
|
export const UPDATE_NOSTR_LOGIN_AUTH_METHOD = 'UPDATE_NOSTR_LOGIN_AUTH_METHOD'
|
||||||
export const UPDATE_KEYPAIR = 'UPDATE_KEYPAIR'
|
export const UPDATE_KEYPAIR = 'UPDATE_KEYPAIR'
|
||||||
|
|
||||||
export const SET_METADATA_EVENT = 'SET_METADATA_EVENT'
|
export const SET_USER_PROFILE = 'SET_USER_PROFILE'
|
||||||
|
|
||||||
export const SET_USER_ROBOT_IMAGE = 'SET_USER_ROBOT_IMAGE'
|
export const SET_USER_ROBOT_IMAGE = 'SET_USER_ROBOT_IMAGE'
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ import * as ActionTypes from './actionTypes'
|
|||||||
import { State } from './rootReducer'
|
import { State } from './rootReducer'
|
||||||
|
|
||||||
export * from './auth/action'
|
export * from './auth/action'
|
||||||
export * from './metadata/action'
|
export * from './user/action'
|
||||||
export * from './relays/action'
|
export * from './relays/action'
|
||||||
export * from './userAppData/action'
|
export * from './userAppData/action'
|
||||||
|
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
import * as ActionTypes from '../actionTypes'
|
|
||||||
import { SetMetadataEvent } from './types'
|
|
||||||
import { Event } from 'nostr-tools'
|
|
||||||
|
|
||||||
export const setMetadataEvent = (payload: Event): SetMetadataEvent => ({
|
|
||||||
type: ActionTypes.SET_METADATA_EVENT,
|
|
||||||
payload
|
|
||||||
})
|
|
@ -1,25 +0,0 @@
|
|||||||
import * as ActionTypes from '../actionTypes'
|
|
||||||
import { MetadataDispatchTypes } from './types'
|
|
||||||
import { Event } from 'nostr-tools'
|
|
||||||
|
|
||||||
const initialState: Event | null = null
|
|
||||||
|
|
||||||
const reducer = (
|
|
||||||
state = initialState,
|
|
||||||
action: MetadataDispatchTypes
|
|
||||||
): Event | null => {
|
|
||||||
switch (action.type) {
|
|
||||||
case ActionTypes.SET_METADATA_EVENT:
|
|
||||||
return {
|
|
||||||
...action.payload
|
|
||||||
}
|
|
||||||
|
|
||||||
case ActionTypes.RESTORE_STATE:
|
|
||||||
return action.payload.metadata || initialState
|
|
||||||
|
|
||||||
default:
|
|
||||||
return state
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default reducer
|
|
@ -1,10 +0,0 @@
|
|||||||
import * as ActionTypes from '../actionTypes'
|
|
||||||
import { Event } from 'nostr-tools'
|
|
||||||
import { RestoreState } from '../actions'
|
|
||||||
|
|
||||||
export interface SetMetadataEvent {
|
|
||||||
type: typeof ActionTypes.SET_METADATA_EVENT
|
|
||||||
payload: Event
|
|
||||||
}
|
|
||||||
|
|
||||||
export type MetadataDispatchTypes = SetMetadataEvent | RestoreState
|
|
@ -1,37 +1,31 @@
|
|||||||
import { Event } from 'nostr-tools'
|
|
||||||
import { combineReducers } from 'redux'
|
import { combineReducers } from 'redux'
|
||||||
import { UserAppData } from '../types'
|
import { UserAppData } from '../types'
|
||||||
import * as ActionTypes from './actionTypes'
|
import * as ActionTypes from './actionTypes'
|
||||||
import authReducer from './auth/reducer'
|
import authReducer from './auth/reducer'
|
||||||
import { AuthDispatchTypes, AuthState } from './auth/types'
|
import { AuthDispatchTypes, AuthState } from './auth/types'
|
||||||
import metadataReducer from './metadata/reducer'
|
import userReducer from './user/reducer'
|
||||||
import relaysReducer from './relays/reducer'
|
import relaysReducer from './relays/reducer'
|
||||||
import { RelaysDispatchTypes, RelaysState } from './relays/types'
|
import { RelaysDispatchTypes, RelaysState } from './relays/types'
|
||||||
import UserAppDataReducer from './userAppData/reducer'
|
import UserAppDataReducer from './userAppData/reducer'
|
||||||
import userRobotImageReducer from './userRobotImage/reducer'
|
|
||||||
import { MetadataDispatchTypes } from './metadata/types'
|
|
||||||
import { UserAppDataDispatchTypes } from './userAppData/types'
|
import { UserAppDataDispatchTypes } from './userAppData/types'
|
||||||
import { UserRobotImageDispatchTypes } from './userRobotImage/types'
|
import { UserDispatchTypes, UserState } from './user/types'
|
||||||
|
|
||||||
export interface State {
|
export interface State {
|
||||||
auth: AuthState
|
auth: AuthState
|
||||||
metadata?: Event
|
user: UserState
|
||||||
userRobotImage?: string
|
|
||||||
relays: RelaysState
|
relays: RelaysState
|
||||||
userAppData?: UserAppData
|
userAppData?: UserAppData
|
||||||
}
|
}
|
||||||
|
|
||||||
type AppActions =
|
type AppActions =
|
||||||
| AuthDispatchTypes
|
| AuthDispatchTypes
|
||||||
| MetadataDispatchTypes
|
| UserDispatchTypes
|
||||||
| UserRobotImageDispatchTypes
|
|
||||||
| RelaysDispatchTypes
|
| RelaysDispatchTypes
|
||||||
| UserAppDataDispatchTypes
|
| UserAppDataDispatchTypes
|
||||||
|
|
||||||
export const appReducer = combineReducers({
|
export const appReducer = combineReducers({
|
||||||
auth: authReducer,
|
auth: authReducer,
|
||||||
metadata: metadataReducer,
|
user: userReducer,
|
||||||
userRobotImage: userRobotImageReducer,
|
|
||||||
relays: relaysReducer,
|
relays: relaysReducer,
|
||||||
userAppData: UserAppDataReducer
|
userAppData: UserAppDataReducer
|
||||||
})
|
})
|
||||||
|
17
src/store/user/action.ts
Normal file
17
src/store/user/action.ts
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import { NDKUserProfile } from '@nostr-dev-kit/ndk'
|
||||||
|
import * as ActionTypes from '../actionTypes'
|
||||||
|
import { SetUserProfile, SetUserRobotImage } from './types'
|
||||||
|
|
||||||
|
export const setUserRobotImage = (
|
||||||
|
payload: string | null
|
||||||
|
): SetUserRobotImage => ({
|
||||||
|
type: ActionTypes.SET_USER_ROBOT_IMAGE,
|
||||||
|
payload
|
||||||
|
})
|
||||||
|
|
||||||
|
export const setUserProfile = (
|
||||||
|
payload: NDKUserProfile | null
|
||||||
|
): SetUserProfile => ({
|
||||||
|
type: ActionTypes.SET_USER_PROFILE,
|
||||||
|
payload
|
||||||
|
})
|
34
src/store/user/reducer.ts
Normal file
34
src/store/user/reducer.ts
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
import * as ActionTypes from '../actionTypes'
|
||||||
|
import { UserDispatchTypes, UserState } from './types'
|
||||||
|
|
||||||
|
const initialState: UserState = {
|
||||||
|
robotImage: null,
|
||||||
|
profile: null
|
||||||
|
}
|
||||||
|
|
||||||
|
const reducer = (
|
||||||
|
state = initialState,
|
||||||
|
action: UserDispatchTypes
|
||||||
|
): UserState => {
|
||||||
|
switch (action.type) {
|
||||||
|
case ActionTypes.SET_USER_ROBOT_IMAGE:
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
robotImage: action.payload
|
||||||
|
}
|
||||||
|
|
||||||
|
case ActionTypes.SET_USER_PROFILE:
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
profile: action.payload
|
||||||
|
}
|
||||||
|
|
||||||
|
// case ActionTypes.RESTORE_STATE:
|
||||||
|
// return action.payload.
|
||||||
|
|
||||||
|
default:
|
||||||
|
return state
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default reducer
|
23
src/store/user/types.ts
Normal file
23
src/store/user/types.ts
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import { NDKUserProfile } from '@nostr-dev-kit/ndk'
|
||||||
|
import * as ActionTypes from '../actionTypes'
|
||||||
|
import { RestoreState } from '../actions'
|
||||||
|
|
||||||
|
export interface UserState {
|
||||||
|
robotImage: string | null
|
||||||
|
profile: NDKUserProfile | null
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SetUserRobotImage {
|
||||||
|
type: typeof ActionTypes.SET_USER_ROBOT_IMAGE
|
||||||
|
payload: string | null
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SetUserProfile {
|
||||||
|
type: typeof ActionTypes.SET_USER_PROFILE
|
||||||
|
payload: NDKUserProfile | null
|
||||||
|
}
|
||||||
|
|
||||||
|
export type UserDispatchTypes =
|
||||||
|
| SetUserRobotImage
|
||||||
|
| SetUserProfile
|
||||||
|
| RestoreState
|
@ -1,9 +0,0 @@
|
|||||||
import * as ActionTypes from '../actionTypes'
|
|
||||||
import { SetUserRobotImage } from './types'
|
|
||||||
|
|
||||||
export const setUserRobotImage = (
|
|
||||||
payload: string | null
|
|
||||||
): SetUserRobotImage => ({
|
|
||||||
type: ActionTypes.SET_USER_ROBOT_IMAGE,
|
|
||||||
payload
|
|
||||||
})
|
|
@ -1,22 +0,0 @@
|
|||||||
import * as ActionTypes from '../actionTypes'
|
|
||||||
import { UserRobotImageDispatchTypes } from './types'
|
|
||||||
|
|
||||||
const initialState: string | null = null
|
|
||||||
|
|
||||||
const reducer = (
|
|
||||||
state = initialState,
|
|
||||||
action: UserRobotImageDispatchTypes
|
|
||||||
): string | null | undefined => {
|
|
||||||
switch (action.type) {
|
|
||||||
case ActionTypes.SET_USER_ROBOT_IMAGE:
|
|
||||||
return action.payload
|
|
||||||
|
|
||||||
case ActionTypes.RESTORE_STATE:
|
|
||||||
return action.payload.userRobotImage || initialState
|
|
||||||
|
|
||||||
default:
|
|
||||||
return state
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default reducer
|
|
@ -1,9 +0,0 @@
|
|||||||
import * as ActionTypes from '../actionTypes'
|
|
||||||
import { RestoreState } from '../actions'
|
|
||||||
|
|
||||||
export interface SetUserRobotImage {
|
|
||||||
type: typeof ActionTypes.SET_USER_ROBOT_IMAGE
|
|
||||||
payload: string | null
|
|
||||||
}
|
|
||||||
|
|
||||||
export type UserRobotImageDispatchTypes = SetUserRobotImage | RestoreState
|
|
@ -1,7 +1,6 @@
|
|||||||
export * from './cache'
|
export * from './cache'
|
||||||
export * from './core'
|
export * from './core'
|
||||||
export * from './nostr'
|
export * from './nostr'
|
||||||
export * from './profile'
|
|
||||||
export * from './relay'
|
export * from './relay'
|
||||||
export * from './zip'
|
export * from './zip'
|
||||||
export * from './event'
|
export * from './event'
|
||||||
|
@ -1,12 +0,0 @@
|
|||||||
export interface ProfileMetadata {
|
|
||||||
name?: string
|
|
||||||
display_name?: string
|
|
||||||
/** @deprecated use name instead */
|
|
||||||
username?: string
|
|
||||||
picture?: string
|
|
||||||
banner?: string
|
|
||||||
about?: string
|
|
||||||
website?: string
|
|
||||||
nip05?: string
|
|
||||||
lud16?: string
|
|
||||||
}
|
|
@ -1,5 +1,5 @@
|
|||||||
import { hexToBytes } from '@noble/hashes/utils'
|
import { hexToBytes } from '@noble/hashes/utils'
|
||||||
import { NDKEvent } from '@nostr-dev-kit/ndk'
|
import { NDKEvent, NDKUserProfile } from '@nostr-dev-kit/ndk'
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
import { truncate } from 'lodash'
|
import { truncate } from 'lodash'
|
||||||
import {
|
import {
|
||||||
@ -18,7 +18,7 @@ import {
|
|||||||
import { toast } from 'react-toastify'
|
import { toast } from 'react-toastify'
|
||||||
import { NIP05_REGEX } from '../constants'
|
import { NIP05_REGEX } from '../constants'
|
||||||
import store from '../store/store'
|
import store from '../store/store'
|
||||||
import { Meta, ProfileMetadata, SignedEvent } from '../types'
|
import { Meta, SignedEvent } from '../types'
|
||||||
import { SIGIT_BLOSSOM } from './const.ts'
|
import { SIGIT_BLOSSOM } from './const.ts'
|
||||||
import { getHash } from './hash'
|
import { getHash } from './hash'
|
||||||
import { parseJson, removeLeadingSlash } from './string'
|
import { parseJson, removeLeadingSlash } from './string'
|
||||||
@ -497,9 +497,9 @@ export const getUserAppDataFromBlossom = async (
|
|||||||
*/
|
*/
|
||||||
export const getProfileUsername = (
|
export const getProfileUsername = (
|
||||||
npub: `npub1${string}` | string,
|
npub: `npub1${string}` | string,
|
||||||
profile?: ProfileMetadata // todo: use NDKUserProfile
|
profile?: NDKUserProfile
|
||||||
) =>
|
) =>
|
||||||
truncate(profile?.display_name || profile?.name || hexToNpub(npub), {
|
truncate(profile?.displayName || profile?.name || hexToNpub(npub), {
|
||||||
length: 16
|
length: 16
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user