diff --git a/package-lock.json b/package-lock.json
index f5270b3..3eea841 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -44,6 +44,7 @@
"eslint": "^8.56.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.5",
+ "prettier": "3.2.5",
"ts-css-modules-vite-plugin": "1.0.20",
"typescript": "^5.2.2",
"vite": "^5.1.4"
@@ -4300,6 +4301,21 @@
"node": ">= 0.8.0"
}
},
+ "node_modules/prettier": {
+ "version": "3.2.5",
+ "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.2.5.tgz",
+ "integrity": "sha512-3/GWa9aOC0YeD7LUfvOG2NiDyhOWRvt1k+rcKhOuYnMY24iiCphgneUfJDyFXd6rZCAnuLBv6UeAULtrhT/F4A==",
+ "dev": true,
+ "bin": {
+ "prettier": "bin/prettier.cjs"
+ },
+ "engines": {
+ "node": ">=14"
+ },
+ "funding": {
+ "url": "https://github.com/prettier/prettier?sponsor=1"
+ }
+ },
"node_modules/pretty-bytes": {
"version": "6.1.1",
"resolved": "https://registry.npmjs.org/pretty-bytes/-/pretty-bytes-6.1.1.tgz",
diff --git a/package.json b/package.json
index 0eca093..fcc2c1c 100644
--- a/package.json
+++ b/package.json
@@ -9,8 +9,8 @@
"build": "tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"lint:fix": "eslint . --fix --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
- "formatter:check": "npx prettier --check \"src/**/*.{ts,tsx,js,jsx,html,css,sass,less,yml,md,graphql}\"",
- "formatter:fix": "npx prettier --write \"src/**/*.{ts,tsx,js,jsx,html,css,sass,less,yml,md,graphql}\"",
+ "formatter:check": "prettier --check \"src/**/*.{ts,tsx,js,jsx,html,css,sass,less,yml,md,graphql}\"",
+ "formatter:fix": "prettier --write \"src/**/*.{ts,tsx,js,jsx,html,css,sass,less,yml,md,graphql}\"",
"preview": "vite preview"
},
"dependencies": {
@@ -50,6 +50,7 @@
"eslint": "^8.56.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.5",
+ "prettier": "3.2.5",
"ts-css-modules-vite-plugin": "1.0.20",
"typescript": "^5.2.2",
"vite": "^5.1.4"
diff --git a/src/components/AppBar/AppBar.tsx b/src/components/AppBar/AppBar.tsx
index af03c5c..ce5eacb 100644
--- a/src/components/AppBar/AppBar.tsx
+++ b/src/components/AppBar/AppBar.tsx
@@ -43,12 +43,14 @@ export const AppBar = () => {
useEffect(() => {
if (metadataState) {
if (metadataState.content) {
- const { picture, display_name, name } = JSON.parse(metadataState.content)
-
+ const { picture, display_name, name } = JSON.parse(
+ metadataState.content
+ )
+
if (picture) {
setUserAvatar(picture)
}
-
+
setUsername(shorten(display_name || name || '', 7))
} else {
setUserAvatar('')
@@ -84,9 +86,7 @@ export const AppBar = () => {
})
)
- dispatch(
- setMetadataEvent(metadataController.getEmptyMetadataEvent())
- )
+ dispatch(setMetadataEvent(metadataController.getEmptyMetadataEvent()))
// clear authToken saved in local storage
clearAuthToken()
diff --git a/src/components/username.tsx b/src/components/username.tsx
index 928d0c6..ff93494 100644
--- a/src/components/username.tsx
+++ b/src/components/username.tsx
@@ -1,6 +1,9 @@
-import { Typography, IconButton } from '@mui/material'
+import { Typography, IconButton, Box, useTheme } from '@mui/material'
import { useSelector } from 'react-redux'
import { State } from '../store/rootReducer'
+import { hexToNpub } from '../utils'
+import { Link } from 'react-router-dom'
+import { getProfileRoute } from '../routes'
type Props = {
username: string
@@ -44,3 +47,47 @@ const Username = ({ username, avatarContent, handleClick }: Props) => {
}
export default Username
+
+type UserProps = {
+ pubkey: string
+ name: string
+ image?: string
+}
+
+/**
+ * This component will be used for the displaying username and profile picture.
+ * If image is not available, robohash image will be displayed
+ */
+export const UserComponent = ({ pubkey, name, image }: UserProps) => {
+ const theme = useTheme()
+
+ const npub = hexToNpub(pubkey)
+ const roboImage = `https://robohash.org/${npub}.png?set=set3`
+
+ return (
+
+
+
+
+ {name}
+
+
+
+ )
+}
diff --git a/src/layouts/Main.tsx b/src/layouts/Main.tsx
index e258e36..e1d6f48 100644
--- a/src/layouts/Main.tsx
+++ b/src/layouts/Main.tsx
@@ -5,7 +5,12 @@ import { useDispatch } from 'react-redux'
import { Outlet } from 'react-router-dom'
import { AppBar } from '../components/AppBar/AppBar'
import { restoreState, setAuthState, setMetadataEvent } from '../store/actions'
-import { clearAuthToken, clearState, loadState, saveNsecBunkerDelegatedKey } from '../utils'
+import {
+ clearAuthToken,
+ clearState,
+ loadState,
+ saveNsecBunkerDelegatedKey
+} from '../utils'
import { LoadingSpinner } from '../components/LoadingSpinner'
import { Dispatch } from '../store/store'
import { MetadataController, NostrController } from '../controllers'
@@ -29,9 +34,7 @@ export const MainLayout = () => {
})
)
- dispatch(
- setMetadataEvent(metadataController.getEmptyMetadataEvent())
- )
+ dispatch(setMetadataEvent(metadataController.getEmptyMetadataEvent()))
// clear authToken saved in local storage
clearAuthToken()
diff --git a/src/pages/create/index.tsx b/src/pages/create/index.tsx
index 764bff6..78f604a 100644
--- a/src/pages/create/index.tsx
+++ b/src/pages/create/index.tsx
@@ -18,20 +18,24 @@ import {
Tooltip,
Typography
} from '@mui/material'
+import JSZip from 'jszip'
import { MuiFileInput } from 'mui-file-input'
import { useEffect, useState } from 'react'
-import { Link, useNavigate } from 'react-router-dom'
+import { useSelector } from 'react-redux'
+import { useNavigate } from 'react-router-dom'
+import { toast } from 'react-toastify'
import { LoadingSpinner } from '../../components/LoadingSpinner'
+import { UserComponent } from '../../components/username'
import { MetadataController, NostrController } from '../../controllers'
-import { appPrivateRoutes, getProfileRoute } from '../../routes'
-import { ProfileMetadata, User, UserRole } from '../../types'
+import { appPrivateRoutes } from '../../routes'
+import { State } from '../../store/rootReducer'
+import { Meta, ProfileMetadata, User, UserRole } from '../../types'
import {
encryptArrayBuffer,
generateEncryptionKey,
getHash,
- getRoboHashPicture,
hexToNpub,
- pubToHex,
+ npubToHex,
queryNip05,
sendDM,
shorten,
@@ -39,10 +43,6 @@ import {
uploadToFileStorage
} from '../../utils'
import styles from './style.module.scss'
-import { toast } from 'react-toastify'
-import JSZip from 'jszip'
-import { useSelector } from 'react-redux'
-import { State } from '../../store/rootReducer'
export const CreatePage = () => {
const navigate = useNavigate()
@@ -109,7 +109,7 @@ export const CreatePage = () => {
}
if (userInput.startsWith('npub')) {
- const pubkey = await pubToHex(userInput)
+ const pubkey = npubToHex(userInput)
if (pubkey) {
addUser(pubkey)
setUserInput('')
@@ -246,13 +246,13 @@ export const CreatePage = () => {
if (!signedEvent) return
// create content for meta file
- const meta = {
- signers: signers.map((signer) => signer.pubkey),
- viewers: viewers.map((viewer) => viewer.pubkey),
+ const meta: Meta = {
+ signers: signers.map((signer) => hexToNpub(signer.pubkey)),
+ viewers: viewers.map((viewer) => hexToNpub(viewer.pubkey)),
fileHashes,
- submittedBy: usersPubkey,
+ submittedBy: hexToNpub(usersPubkey!),
signedEvents: {
- [signedEvent.pubkey]: JSON.stringify(signedEvent, null, 2)
+ [hexToNpub(signedEvent.pubkey)]: JSON.stringify(signedEvent, null, 2)
}
}
@@ -489,15 +489,6 @@ const DisplayUser = ({
})
}, [users])
- /**
- * Use robohash if any of the users images fail to load
- * @param event img tag onError event
- * @param pubkey of the user
- */
- const imageLoadError = (event: any, pubkey: string) => {
- event.target.src = getRoboHashPicture(pubkey)
- }
-
return (
@@ -511,31 +502,18 @@ const DisplayUser = ({
{users.map((user, index) => {
const userMeta = metadata[user.pubkey]
- const npub = hexToNpub(user.pubkey)
- const roboUrl = `https://robohash.org/${npub}.png?set=set3`
return (
-
- {imageLoadError(event, user.pubkey)}}
- src={userMeta?.picture || roboUrl}
- alt="Profile Image"
- className="profile-image"
- style={{
- borderWidth: '3px',
- borderStyle: 'solid',
- borderColor: `#${user.pubkey.substring(0, 6)}`
- }}
- />
-
-
- {userMeta?.display_name ||
- userMeta?.name ||
- shorten(npub)}
-
-
-
+