fix(marks): add default signer #207

Merged
enes merged 3 commits from 145-default-signer into 201-toolbox-update 2024-09-19 11:24:17 +00:00

View File

@ -37,6 +37,9 @@ interface Props {
export const DrawPDFFields = (props: Props) => {
const { selectedFiles, selectedTool, onDrawFieldsChange, users } = props
const signers = users.filter((u) => u.role === UserRole.signer)
const defaultSignerNpub = signers.length ? hexToNpub(signers[0].pubkey) : ''
const [lastSigner, setLastSigner] = useState(defaultSignerNpub)
const { to, from } = useScale()
const [sigitFiles, setSigitFiles] = useState<SigitFile[]>([])
@ -115,7 +118,7 @@ export const DrawPDFFields = (props: Props) => {
top: to(page.width, y),
width: event.pointerType === 'mouse' ? 0 : DEFAULT_START_SIZE.width,
height: event.pointerType === 'mouse' ? 0 : DEFAULT_START_SIZE.height,
counterpart: '',
counterpart: lastSigner,
type: selectedTool.identifier
}
@ -453,9 +456,15 @@ export const DrawPDFFields = (props: Props) => {
<FormControl fullWidth size="small">
<InputLabel id="counterparts">Counterpart</InputLabel>
<Select
value={drawnField.counterpart}
value={
drawnField.counterpart ||
lastSigner ||
defaultSignerNpub ||
''
}
onChange={(event) => {
drawnField.counterpart = event.target.value
setLastSigner(event.target.value)
refreshPdfFiles()
}}
labelId="counterparts"
@ -465,52 +474,47 @@ export const DrawPDFFields = (props: Props) => {
}}
renderValue={(value) => renderCounterpartValue(value)}
>
{users
.filter((u) => u.role === UserRole.signer)
.map((user, index) => {
const npub = hexToNpub(user.pubkey)
let displayValue = truncate(npub, {
length: 16
})
{signers.map((signer, index) => {
const npub = hexToNpub(signer.pubkey)
let displayValue = truncate(npub, {
length: 16
})
const metadata = props.metadata[user.pubkey]
const metadata = props.metadata[signer.pubkey]
if (metadata) {
displayValue = truncate(
metadata.name ||
metadata.display_name ||
metadata.username ||
npub,
{
length: 16
}
)
}
return (
<MenuItem
key={index}
value={hexToNpub(user.pubkey)}
>
<ListItemIcon>
<AvatarIconButton
src={metadata?.picture}
hexKey={user.pubkey}
aria-label={`account of user ${displayValue}`}
color="inherit"
sx={{
padding: 0,
'> img': {
width: '30px',
height: '30px'
}
}}
/>
</ListItemIcon>
<ListItemText>{displayValue}</ListItemText>
</MenuItem>
if (metadata) {
displayValue = truncate(
metadata.name ||
metadata.display_name ||
metadata.username ||
npub,
{
length: 16
}
)
})}
}
return (
<MenuItem key={index} value={npub}>
<ListItemIcon>
<AvatarIconButton
src={metadata?.picture}
hexKey={signer.pubkey}
aria-label={`account of user ${displayValue}`}
color="inherit"
sx={{
padding: 0,
'> img': {
width: '30px',
height: '30px'
}
}}
/>
</ListItemIcon>
<ListItemText>{displayValue}</ListItemText>
</MenuItem>
)
})}
</Select>
</FormControl>
</div>
@ -524,28 +528,28 @@ export const DrawPDFFields = (props: Props) => {
)
}
const renderCounterpartValue = (value: string) => {
const user = users.find((u) => u.pubkey === npubToHex(value))
if (user) {
let displayValue = truncate(value, {
length: 16
})
const metadata = props.metadata[user.pubkey]
const renderCounterpartValue = (npub: string) => {
let displayValue = truncate(npub, {
length: 16
})
const signer = signers.find((u) => u.pubkey === npubToHex(npub))
Review

Should this be turned into a utilitiy function, something like getDisplayName that can then be re-used wherever needed?

Should this be turned into a utilitiy function, something like `getDisplayName` that can then be re-used wherever needed?
Review

Yes, there are a few places where this shows up, there are also variation with truncate and shorten, I've opened up a new issue to check since I expect more places where it need fixing #205

Yes, there are a few places where this shows up, there are also variation with truncate and shorten, I've opened up a new issue to check since I expect more places where it need fixing https://git.nostrdev.com/sigit/sigit.io/issues/205
Review

I think it's a fairly minor refactor and can be done as part of the same PR

I think it's a fairly minor refactor and can be done as part of the same PR
Review

Okay, on it!

Okay, on it!
if (signer) {
const metadata = props.metadata[signer.pubkey]
if (metadata) {
displayValue = truncate(
metadata.name || metadata.display_name || metadata.username || value,
metadata.display_name || metadata.name || npub,
{
length: 16
}
)
}
return (
<>
<AvatarIconButton
src={props.metadata[user.pubkey]?.picture}
hexKey={npubToHex(user.pubkey) || undefined}
src={props.metadata[signer.pubkey]?.picture}
hexKey={signer.pubkey || undefined}
sx={{
padding: 0,
marginRight: '6px',
@ -560,7 +564,7 @@ export const DrawPDFFields = (props: Props) => {
)
}
return value
return displayValue
}
if (parsingPdf) {