Add more Nostr settings
This commit is contained in:
parent
2ed559aa84
commit
ee4d6d88c7
7 changed files with 68 additions and 9 deletions
|
@ -41,4 +41,41 @@ const isValidNostrRelay = async (url: string): Promise<boolean> => {
|
|||
}
|
||||
};
|
||||
|
||||
export { isValidNpub, isValidNostrRelay };
|
||||
/**
|
||||
* Validates if the given parameter is a valid hex public key.
|
||||
* @param pubkey - The public key to validate.
|
||||
* @returns A boolean indicating if the public key is valid.
|
||||
*/
|
||||
const isValidHexPubKey = (pubkey: string): boolean => {
|
||||
return /^[0-9a-f]{64}$/i.test(pubkey);
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks if a parameter is a valid pubkey or npub and converts npub to pubkey.
|
||||
* @param input - The input string to check and convert.
|
||||
* @returns The pubkey if valid, otherwise null.
|
||||
*/
|
||||
|
||||
const getPubKey = (input: string): string | null => {
|
||||
try {
|
||||
// If input is a valid hex public key
|
||||
if (isValidHexPubKey(input)) {
|
||||
return input;
|
||||
}
|
||||
|
||||
// Try to decode the input as npub
|
||||
const { type, data } = nip19.decode(input);
|
||||
|
||||
// Check if the decoded type is 'npub' and the data length is 64 characters (32 bytes in hex)
|
||||
if (type === 'npub' && data.length === 64) {
|
||||
return data;
|
||||
}
|
||||
|
||||
return null;
|
||||
} catch (e) {
|
||||
// If any error is thrown, the input is not valid
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
export { isValidNpub, isValidNostrRelay, isValidHexPubKey, getPubKey };
|
||||
|
|
|
@ -36,7 +36,8 @@
|
|||
"flFlashOnUpd": "Displaybeleuchting bei neuem Block",
|
||||
"mempoolInstanceHelpText": "Nur wirksam, wenn die BTClock-Datenquelle deaktiviert ist. \nZur Anwendung ist ein Neustart erforderlich.",
|
||||
"luxLightToggle": "Automatisches Umschalten des Frontlichts bei Lux",
|
||||
"wpTimeout": "WiFi-Konfigurationsportal timeout"
|
||||
"wpTimeout": "WiFi-Konfigurationsportal timeout",
|
||||
"useNostr": "Nostr-Datenquelle verwenden"
|
||||
},
|
||||
"control": {
|
||||
"systemInfo": "Systeminfo",
|
||||
|
|
|
@ -38,7 +38,8 @@
|
|||
"luxLightToggle": "Auto toggle frontlight at lux",
|
||||
"wpTimeout": "WiFi-config portal timeout",
|
||||
"nostrPubKey": "Nostr source pubkey",
|
||||
"nostrRelay": "Nostr Relay"
|
||||
"nostrRelay": "Nostr Relay",
|
||||
"useNostr": "Use Nostr datasource"
|
||||
},
|
||||
"control": {
|
||||
"systemInfo": "System info",
|
||||
|
|
|
@ -35,7 +35,8 @@
|
|||
"flFlashOnUpd": "Luz de la pantalla parpadea con un nuevo bloque",
|
||||
"mempoolInstanceHelpText": "Solo es efectivo cuando la fuente de datos BTClock está deshabilitada. \nEs necesario reiniciar para aplicar.",
|
||||
"luxLightToggle": "Cambio automático de luz frontal en lux",
|
||||
"wpTimeout": "Portal de configuración WiFi timeout"
|
||||
"wpTimeout": "Portal de configuración WiFi timeout",
|
||||
"useNostr": "Utilice la fuente de datos Nostr"
|
||||
},
|
||||
"control": {
|
||||
"turnOff": "Apagar",
|
||||
|
|
|
@ -36,7 +36,8 @@
|
|||
"flFlashOnUpd": "Knipper displaylicht bij nieuw blok",
|
||||
"mempoolInstanceHelpText": "Alleen effectief als de BTClock-gegevensbron is uitgeschakeld. \nOm toe te passen is een herstart nodig.",
|
||||
"luxLightToggle": "Schakelen displaylicht op lux",
|
||||
"wpTimeout": "WiFi-config-portal timeout"
|
||||
"wpTimeout": "WiFi-config-portal timeout",
|
||||
"useNostr": "Gebruik Nostr-gegevensbron"
|
||||
},
|
||||
"control": {
|
||||
"systemInfo": "Systeeminformatie",
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<script lang="ts">
|
||||
import { isValidNpub, isValidNostrRelay } from '$lib';
|
||||
import { isValidNostrRelay, getPubKey, isValidHexPubKey } from '$lib';
|
||||
import { PUBLIC_BASE_URL } from '$lib/config';
|
||||
import { uiSettings } from '$lib/uiSettings';
|
||||
import { createEventDispatcher } from 'svelte';
|
||||
|
@ -84,6 +84,10 @@
|
|||
validNostrRelay = await isValidNostrRelay($settings.nostrRelay);
|
||||
};
|
||||
|
||||
const checkValidNostrPubkey = () => {
|
||||
$settings.nostrPubKey = getPubKey($settings.nostrPubKey);
|
||||
};
|
||||
|
||||
const onFlBrightnessChange = async () => {
|
||||
await fetch(`${PUBLIC_BASE_URL}/api/frontlight/brightness/${$settings.flMaxBrightness}`, {
|
||||
method: 'GET',
|
||||
|
@ -279,7 +283,7 @@
|
|||
</Col>
|
||||
</Row>
|
||||
{/if}
|
||||
{#if $settings.nostrPubKey}
|
||||
{#if $settings.useNostr}
|
||||
<Row>
|
||||
<Label md={6} for="nostrPubKey" size={$uiSettings.inputSize}
|
||||
>{$_('section.settings.nostrPubKey')}</Label
|
||||
|
@ -290,7 +294,8 @@
|
|||
bind:value={$settings.nostrPubKey}
|
||||
name="nostrPubKey"
|
||||
id="nostrPubKey"
|
||||
invalid={!isValidNpub($settings.nostrPubKey)}
|
||||
on:change={checkValidNostrPubkey}
|
||||
invalid={!isValidHexPubKey($settings.nostrPubKey)}
|
||||
bsSize={$uiSettings.inputSize}
|
||||
></Input>
|
||||
</Col>
|
||||
|
@ -504,6 +509,17 @@
|
|||
label="{$_('section.settings.ownDataSource')} ({$_('restartRequired')})"
|
||||
/>
|
||||
</Col>
|
||||
{#if $settings.nostrRelay}
|
||||
<Col md="6">
|
||||
<Input
|
||||
id="useNostr"
|
||||
bind:checked={$settings.useNostr}
|
||||
type="switch"
|
||||
bsSize={$uiSettings.inputSize}
|
||||
label="{$_('section.settings.useNostr')} ({$_('restartRequired')})"
|
||||
/>
|
||||
</Col>
|
||||
{/if}
|
||||
{#if $settings.hasFrontlight}
|
||||
<Col md="6">
|
||||
<Input
|
||||
|
|
|
@ -165,7 +165,9 @@
|
|||
{$_('section.status.uptime')}: {toUptimestring($status.espUptime)}
|
||||
<br />
|
||||
<p>
|
||||
{#if !$settings.ownDataSource}
|
||||
{#if $settings.useNostr}
|
||||
<span>Nostr connection status not available yet.</span>
|
||||
{:else if !$settings.ownDataSource}
|
||||
{$_('section.status.wsPriceConnection')}:
|
||||
<span>
|
||||
{#if $status.connectionStatus && $status.connectionStatus.price}
|
||||
|
|
Loading…
Reference in a new issue