fix closing modals & add loader on enabling back signing
This commit is contained in:
parent
eff6792d64
commit
2115ce340d
@ -70,6 +70,7 @@ function App() {
|
||||
}, [dispatch])
|
||||
|
||||
useEffect(() => {
|
||||
console.log('NDK is ' + isConnected)
|
||||
if (isConnected) {
|
||||
load()
|
||||
}
|
||||
|
@ -36,8 +36,9 @@ export const ModalConfirmConnect = () => {
|
||||
const { name, icon = '' } = triggerApp || {}
|
||||
const appName = name || getShortenNpub(appNpub)
|
||||
|
||||
const handleActionTypeChange = (_: any, value: ACTION_TYPE) => {
|
||||
setSelectedActionType(value)
|
||||
const handleActionTypeChange = (_: any, value: ACTION_TYPE | null) => {
|
||||
if (!value) return undefined
|
||||
return setSelectedActionType(value)
|
||||
}
|
||||
|
||||
const handleCloseModal = handleClose(
|
||||
@ -48,6 +49,13 @@ export const ModalConfirmConnect = () => {
|
||||
await swicCall('confirm', pendingReqId, false, false)
|
||||
},
|
||||
)
|
||||
const closeModalAfterRequest = handleClose(
|
||||
MODAL_PARAMS_KEYS.CONFIRM_CONNECT,
|
||||
(sp) => {
|
||||
sp.delete('appNpub')
|
||||
sp.delete('reqId')
|
||||
},
|
||||
)
|
||||
|
||||
async function confirmPending(
|
||||
id: string,
|
||||
@ -57,10 +65,7 @@ export const ModalConfirmConnect = () => {
|
||||
call(async () => {
|
||||
await swicCall('confirm', id, allow, remember)
|
||||
console.log('confirmed', id, allow, remember)
|
||||
})
|
||||
handleClose(MODAL_PARAMS_KEYS.CONFIRM_CONNECT, async (sp) => {
|
||||
sp.delete('appNpub')
|
||||
sp.delete('reqId')
|
||||
closeModalAfterRequest()
|
||||
})
|
||||
}
|
||||
|
||||
@ -122,9 +127,7 @@ export const ModalConfirmConnect = () => {
|
||||
</StyledButton>
|
||||
<StyledButton
|
||||
fullWidth
|
||||
onClick={() =>
|
||||
confirmPending(pendingReqId, true, false)
|
||||
}
|
||||
onClick={() => confirmPending(pendingReqId, true, true)}
|
||||
>
|
||||
Allow {selectedActionType} actions
|
||||
</StyledButton>
|
||||
|
@ -59,7 +59,6 @@ export const ModalConfirmEvent: FC<ModalConfirmEventProps> = ({
|
||||
const [searchParams] = useSearchParams()
|
||||
|
||||
const appNpub = searchParams.get('appNpub') || ''
|
||||
const pendingReqId = searchParams.get('reqId') || ''
|
||||
|
||||
const { npub = '' } = useParams<{ npub: string }>()
|
||||
const apps = useAppSelector((state) => selectAppsByNpub(state, npub))
|
||||
@ -84,8 +83,9 @@ export const ModalConfirmEvent: FC<ModalConfirmEventProps> = ({
|
||||
const { name, icon = '' } = triggerApp || {}
|
||||
const appName = name || getShortenNpub(appNpub)
|
||||
|
||||
const handleActionTypeChange = (_: any, value: ACTION_TYPE) => {
|
||||
setSelectedActionType(value)
|
||||
const handleActionTypeChange = (_: any, value: ACTION_TYPE | null) => {
|
||||
if (!value) return undefined
|
||||
return setSelectedActionType(value)
|
||||
}
|
||||
|
||||
const selectedPendingRequests = pendingRequests.filter((pr) => pr.checked)
|
||||
@ -101,7 +101,15 @@ export const ModalConfirmEvent: FC<ModalConfirmEventProps> = ({
|
||||
},
|
||||
)
|
||||
|
||||
async function confirmPending(id: string) {
|
||||
const closeModalAfterRequest = handleClose(
|
||||
MODAL_PARAMS_KEYS.CONFIRM_EVENT,
|
||||
(sp) => {
|
||||
sp.delete('appNpub')
|
||||
sp.delete('reqId')
|
||||
},
|
||||
)
|
||||
|
||||
async function confirmPending() {
|
||||
selectedPendingRequests.forEach((req) => {
|
||||
call(async () => {
|
||||
if (selectedActionType === ACTION_TYPE.ONCE) {
|
||||
@ -109,14 +117,10 @@ export const ModalConfirmEvent: FC<ModalConfirmEventProps> = ({
|
||||
} else {
|
||||
await swicCall('confirm', req.id, true, true)
|
||||
}
|
||||
console.log('confirmed', req.id, id, selectedActionType)
|
||||
console.log('confirmed', req.id, selectedActionType)
|
||||
})
|
||||
})
|
||||
|
||||
handleClose(MODAL_PARAMS_KEYS.CONFIRM_EVENT, (sp) => {
|
||||
sp.delete('appNpub')
|
||||
sp.delete('reqId')
|
||||
})
|
||||
closeModalAfterRequest()
|
||||
}
|
||||
|
||||
const handleChangeCheckbox = (reqId: string) => () => {
|
||||
@ -204,10 +208,7 @@ export const ModalConfirmEvent: FC<ModalConfirmEventProps> = ({
|
||||
>
|
||||
Cancel
|
||||
</StyledButton>
|
||||
<StyledButton
|
||||
fullWidth
|
||||
onClick={() => confirmPending(pendingReqId)}
|
||||
>
|
||||
<StyledButton fullWidth onClick={confirmPending}>
|
||||
Allow {ACTION_LABELS[selectedActionType]}
|
||||
</StyledButton>
|
||||
</Stack>
|
||||
|
@ -86,6 +86,7 @@ export const ModalSettings = () => {
|
||||
onChange={handlePasswordChange}
|
||||
value={enteredPassword}
|
||||
helperText={isPasswordInvalid ? 'Invalid password' : ''}
|
||||
placeholder='Enter a password'
|
||||
helperTextProps={{
|
||||
sx: {
|
||||
'&.helper_text': {
|
||||
|
@ -60,7 +60,7 @@ export async function swicCall(method: string, ...args: any[]) {
|
||||
method,
|
||||
args: [...args],
|
||||
}
|
||||
//console.log("sending to SW", msg)
|
||||
console.log('sending to SW', msg)
|
||||
swr.active.postMessage(msg)
|
||||
})
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import { askNotificationPermission, getShortenNpub } from '../../utils/helpers'
|
||||
import { useParams } from 'react-router-dom'
|
||||
import { fetchProfile } from '../../modules/nostr'
|
||||
import { nip19 } from 'nostr-tools'
|
||||
import { Badge, Box, Stack } from '@mui/material'
|
||||
import { Badge, Box, CircularProgress, Stack } from '@mui/material'
|
||||
import { StyledIconButton } from './styled'
|
||||
import { SettingsIcon, ShareIcon } from '@/assets'
|
||||
import { AppLink } from '@/shared/AppLink/AppLink'
|
||||
@ -56,6 +56,7 @@ const KeyPage = () => {
|
||||
const userNameWithPrefix = userName + '@nsec.app'
|
||||
|
||||
const [showWarning, setShowWarning] = useState(false)
|
||||
const [isLoading, setIsLoading] = useState(false)
|
||||
|
||||
const filteredApps = apps.filter((a) => a.npub === npub)
|
||||
const filteredPendingReqs = pending.filter((p) => p.npub === npub)
|
||||
@ -64,12 +65,15 @@ const KeyPage = () => {
|
||||
const npubConnectPerms = filteredPerms.filter(
|
||||
(perm) => perm.perm === 'connect',
|
||||
)
|
||||
const excludeConnectPeqs = filteredPendingReqs.filter(
|
||||
const excludeConnectPendings = filteredPendingReqs.filter(
|
||||
(pr) => pr.method !== 'connect',
|
||||
)
|
||||
const connectPendings = filteredPendingReqs.filter(
|
||||
(pr) => pr.method === 'connect',
|
||||
)
|
||||
|
||||
const prepareEventPendings = excludeConnectPeqs.reduce<IPendingsByAppNpub>(
|
||||
(acc, current) => {
|
||||
const prepareEventPendings =
|
||||
excludeConnectPendings.reduce<IPendingsByAppNpub>((acc, current) => {
|
||||
const isConnected = npubConnectPerms.some(
|
||||
(cp) => cp.appNpub === current.appNpub,
|
||||
)
|
||||
@ -83,9 +87,7 @@ const KeyPage = () => {
|
||||
acc[current.appNpub].pending.push(current)
|
||||
acc[current.appNpub].isConnected = isConnected
|
||||
return acc
|
||||
},
|
||||
{},
|
||||
)
|
||||
}, {})
|
||||
|
||||
const load = useCallback(async () => {
|
||||
try {
|
||||
@ -131,14 +133,17 @@ const KeyPage = () => {
|
||||
}, [checkBackgroundSigning])
|
||||
|
||||
const handleEnableBackground = async () => {
|
||||
await askNotificationPermission()
|
||||
try {
|
||||
setIsLoading(true)
|
||||
await askNotificationPermission()
|
||||
const r = await swicCall('enablePush')
|
||||
if (!r) return nofity(`Failed to enable push subscription`, 'error')
|
||||
nofity('Enabled!', 'success')
|
||||
checkBackgroundSigning()
|
||||
setIsLoading(false)
|
||||
} catch (e) {
|
||||
nofity(`Failed to enable push subscription`, 'error')
|
||||
setIsLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
@ -153,10 +158,6 @@ const KeyPage = () => {
|
||||
}
|
||||
}, [npub, pending.length])
|
||||
|
||||
const connectPendings = filteredPendingReqs.filter(
|
||||
(pr) => pr.method === 'connect',
|
||||
)
|
||||
|
||||
const handleOpenConfirmConnectModal = useCallback(() => {
|
||||
if (
|
||||
!filteredPendingReqs.length ||
|
||||
@ -261,9 +262,20 @@ const KeyPage = () => {
|
||||
<Stack gap={'1rem'} height={'100%'}>
|
||||
{showWarning && (
|
||||
<Warning
|
||||
message='Please enable push notifications'
|
||||
message={
|
||||
<Stack
|
||||
direction={'row'}
|
||||
alignItems={'center'}
|
||||
gap={'1rem'}
|
||||
>
|
||||
Please enable push notifications{' '}
|
||||
{isLoading ? (
|
||||
<CircularProgress size={'1.5rem'} />
|
||||
) : null}
|
||||
</Stack>
|
||||
}
|
||||
Icon={<GppMaybeIcon htmlColor='white' />}
|
||||
onClick={handleEnableBackground}
|
||||
onClick={isLoading ? undefined : handleEnableBackground}
|
||||
/>
|
||||
)}
|
||||
{renderUserValueSection(
|
||||
|
@ -10,23 +10,10 @@ export async function call(cb: () => any) {
|
||||
try {
|
||||
return await cb()
|
||||
} catch (e) {
|
||||
log(`Error: ${e}`)
|
||||
console.log(`Error: ${e}`)
|
||||
}
|
||||
}
|
||||
|
||||
// export const getDefaultUserName = (npub: string) => {
|
||||
// try {
|
||||
// const npubToken = npub.includes('#') ? npub.split('#')[0] : npub
|
||||
// const { type, data: pubkey } = nip19.decode(npubToken)
|
||||
// if (type !== 'npub') return ''
|
||||
|
||||
// return getShortenNpub(nip19.npubEncode(pubkey))
|
||||
// } catch (error) {
|
||||
// console.error(error)
|
||||
// return ''
|
||||
// }
|
||||
// }
|
||||
|
||||
export const getShortenNpub = (npub = '') => {
|
||||
return npub.substring(0, 10) + '...' + npub.slice(-6)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user