format code

This commit is contained in:
Bekbolsun
2024-02-19 19:35:12 +06:00
parent 13f9bb13fd
commit adbc7d455d
12 changed files with 37 additions and 61 deletions

View File

@@ -68,7 +68,6 @@ export const ModalAppDetails = () => {
if (isEmptyString(url)) return if (isEmptyString(url)) return
try { try {
const u = new URL(url) const u = new URL(url)
if (isEmptyString(name)) setDetails((prev) => ({ ...prev, name: u.hostname })) if (isEmptyString(name)) setDetails((prev) => ({ ...prev, name: u.hostname }))

View File

@@ -73,11 +73,11 @@ export const ModalConfirmConnect = () => {
useEffect(() => { useEffect(() => {
if (isModalOpened) { if (isModalOpened) {
if (isPopup) { if (isPopup) {
console.log("waiting for sw") console.log('waiting for sw')
// wait for SW to start // wait for SW to start
swicWaitStarted().then(() => { swicWaitStarted().then(() => {
// give it some time to load the pending reqs etc // give it some time to load the pending reqs etc
console.log("waiting for sw done") console.log('waiting for sw done')
setTimeout(() => setIsLoaded(true), 500) setTimeout(() => setIsLoaded(true), 500)
}) })
} else { } else {
@@ -123,7 +123,6 @@ export const ModalConfirmConnect = () => {
const options = { perms, appUrl } const options = { perms, appUrl }
await confirmPending(pendingReqId, true, true, options) await confirmPending(pendingReqId, true, true, options)
} else { } else {
try { try {
await askNotificationPermission() await askNotificationPermission()
const result = await swicCall('enablePush') const result = await swicCall('enablePush')

View File

@@ -1,4 +1,4 @@
import { Stack, StackProps, styled } from "@mui/material"; import { Stack, StackProps, styled } from '@mui/material'
export const StyledSettingContainer = styled((props: StackProps) => ( export const StyledSettingContainer = styled((props: StackProps) => (
<Stack gap={'0.75rem'} component={'form'} {...props} /> <Stack gap={'0.75rem'} component={'form'} {...props} />
@@ -7,4 +7,4 @@ export const StyledSettingContainer = styled((props: StackProps) => (
borderRadius: '1rem', borderRadius: '1rem',
background: theme.palette.background.default, background: theme.palette.background.default,
color: theme.palette.text.primary, color: theme.palette.text.primary,
})) }))

View File

@@ -60,10 +60,8 @@ export const ModalSignUp = () => {
try { try {
setIsLoading(true) setIsLoading(true)
const k: any = await swicCall('generateKey', name) const k: any = await swicCall('generateKey', name)
if (k.name) if (k.name) notify(`Account created for "${k.name}"`, 'success')
notify(`Account created for "${k.name}"`, 'success') else notify(`Failed to assign name "${name}", try again`, 'error')
else
notify(`Failed to assign name "${name}", try again`, 'error')
setIsLoading(false) setIsLoading(false)
setTimeout(() => { setTimeout(() => {
// give frontend time to read the new key first // give frontend time to read the new key first

View File

@@ -13,14 +13,8 @@ export const Warning: FC<WarningProps> = ({ hint, message, icon, ...restProps })
<StyledContainer {...restProps}> <StyledContainer {...restProps}>
{icon && <IconContainer>{icon}</IconContainer>} {icon && <IconContainer>{icon}</IconContainer>}
<Stack flex={1} direction={'column'} gap={'0.2rem'}> <Stack flex={1} direction={'column'} gap={'0.2rem'}>
<Typography noWrap> <Typography noWrap>{message}</Typography>
{message} {hint && <Typography>{hint}</Typography>}
</Typography>
{hint && (
<Typography>
{hint}
</Typography>
)}
</Stack> </Stack>
</StyledContainer> </StyledContainer>
) )

View File

@@ -4,28 +4,21 @@ import { Avatar, ListItemIcon, MenuItem, Typography } from '@mui/material'
import React, { FC } from 'react' import React, { FC } from 'react'
type ListItemProfileProps = { type ListItemProfileProps = {
onClickItem: () => void onClickItem: () => void
} & DbKey } & DbKey
export const ListItemProfile: FC<ListItemProfileProps> = ({ export const ListItemProfile: FC<ListItemProfileProps> = ({ onClickItem, npub }) => {
onClickItem, const { userName, userAvatar, avatarTitle } = useProfile(npub)
npub, return (
}) => { <MenuItem sx={{ gap: '0.5rem' }} onClick={onClickItem}>
const { userName, userAvatar, avatarTitle } = useProfile(npub) <ListItemIcon>
return ( <Avatar src={userAvatar} alt={userName} sx={{ width: 36, height: 36 }}>
<MenuItem sx={{ gap: '0.5rem' }} onClick={onClickItem}> {avatarTitle}
<ListItemIcon> </Avatar>
<Avatar </ListItemIcon>
src={userAvatar} <Typography variant="body2" noWrap>
alt={userName} {userName}
sx={{ width: 36, height: 36 }} </Typography>
> </MenuItem>
{avatarTitle} )
</Avatar>
</ListItemIcon>
<Typography variant='body2' noWrap>
{userName}
</Typography>
</MenuItem>
)
} }

View File

@@ -693,7 +693,7 @@ export class NoauthBackend {
} }
private getDecision(backend: Nip46Backend, req: DbPending): DECISION { private getDecision(backend: Nip46Backend, req: DbPending): DECISION {
if (!(req.method in backend.handlers)) return DECISION.IGNORE; if (!(req.method in backend.handlers)) return DECISION.IGNORE
const reqPerm = getReqPerm(req) const reqPerm = getReqPerm(req)
const appPerms = this.perms.filter((p) => p.npub === req.npub && p.appNpub === req.appNpub) const appPerms = this.perms.filter((p) => p.npub === req.npub && p.appNpub === req.appNpub)
@@ -1175,10 +1175,10 @@ export class NoauthBackend {
} }
private async transferName(npub: string, name: string, newNpub: string) { private async transferName(npub: string, name: string, newNpub: string) {
const key = this.enckeys.find(k => k.npub === npub) const key = this.enckeys.find((k) => k.npub === npub)
if (!key) throw new Error("Npub not found") if (!key) throw new Error('Npub not found')
if (!name) throw new Error("Empty name") if (!name) throw new Error('Empty name')
if (key.name !== name) throw new Error("Name changed, please reload") if (key.name !== name) throw new Error('Name changed, please reload')
await this.sendTransferNameToServer(npub, key.name, newNpub) await this.sendTransferNameToServer(npub, key.name, newNpub)
await dbi.editName(npub, '') await dbi.editName(npub, '')
key.name = '' key.name = ''

View File

@@ -43,7 +43,7 @@ export function isWeakPassphase(passphrase: string): boolean {
const compl = Math.pow(base, passphrase.length) const compl = Math.pow(base, passphrase.length)
const thresh = Math.pow(11, 14) const thresh = Math.pow(11, 14)
// console.log({ big, small, number, punct, base, compl, thresh }); // console.log({ big, small, number, punct, base, compl, thresh });
return compl < thresh; return compl < thresh
} }
export class Keys { export class Keys {

View File

@@ -20,8 +20,8 @@ export async function swicRegister() {
}, },
onUpdate() { onUpdate() {
// tell new SW that it should activate immediately // tell new SW that it should activate immediately
swr?.waiting?.postMessage({type: 'SKIP_WAITING'}) swr?.waiting?.postMessage({ type: 'SKIP_WAITING' })
} },
}) })
navigator.serviceWorker.ready.then(async (r) => { navigator.serviceWorker.ready.then(async (r) => {
@@ -33,8 +33,7 @@ export async function swicRegister() {
console.log('This page is not currently controlled by a service worker.') console.log('This page is not currently controlled by a service worker.')
} }
while (queue.length) while (queue.length) await queue.shift()!()
await (queue.shift()!)()
}) })
navigator.serviceWorker.addEventListener('message', (event) => { navigator.serviceWorker.addEventListener('message', (event) => {
@@ -43,11 +42,11 @@ export async function swicRegister() {
} }
export function swicWaitStarted() { export function swicWaitStarted() {
return new Promise<void>(ok => { return new Promise<void>((ok) => {
if (swr && swr.active) ok() if (swr && swr.active) ok()
else queue.push(ok) else queue.push(ok)
}) })
} }
function onMessage(data: any) { function onMessage(data: any) {
const { id, result, error } = data const { id, result, error } = data
@@ -78,7 +77,6 @@ export async function swicCall(method: string, ...args: any[]) {
nextReqId++ nextReqId++
return new Promise((ok, rej) => { return new Promise((ok, rej) => {
const call = async () => { const call = async () => {
if (!swr || !swr.active) { if (!swr || !swr.active) {
rej(new Error('No active service worker')) rej(new Error('No active service worker'))

View File

@@ -16,12 +16,7 @@ export const BackgroundSigningWarning: FC<BackgroundSigningWarningProps> = ({ is
Enable background service {isEnabling ? <CircularProgress size={'1.5rem'} /> : null} Enable background service {isEnabling ? <CircularProgress size={'1.5rem'} /> : null}
</Stack> </Stack>
} }
hint={ hint={<Typography variant="body2">Please allow notifications for background operation.</Typography>}
<Typography variant='body2'>
Please allow notifications
for background operation.
</Typography>
}
icon={<AutoModeOutlinedIcon htmlColor="white" />} icon={<AutoModeOutlinedIcon htmlColor="white" />}
onClick={isEnabling ? undefined : onEnableBackSigning} onClick={isEnabling ? undefined : onEnableBackSigning}
/> />

View File

@@ -16,7 +16,7 @@ export enum ACTION_TYPE {
} }
export const ACTIONS: { [type: string]: string } = { export const ACTIONS: { [type: string]: string } = {
basic: 'Basic permissions', basic: 'Basic permissions',
get_public_key: 'Get public key', get_public_key: 'Get public key',
sign_event: 'Sign event', sign_event: 'Sign event',
connect: 'Connect', connect: 'Connect',

View File

@@ -3,7 +3,7 @@ import { format } from 'date-fns'
export const formatTimestampDate = (timestamp: number) => { export const formatTimestampDate = (timestamp: number) => {
try { try {
const date = new Date(timestamp) const date = new Date(timestamp)
const formattedDate = format(date, "dd-MM-yyyy HH:mm") const formattedDate = format(date, 'dd-MM-yyyy HH:mm')
return formattedDate return formattedDate
} catch (error) { } catch (error) {
return '' return ''