useBunkerStore: fix parsing of saved connections
This commit is contained in:
parent
4d99a6d4f6
commit
df9cc19714
|
@ -1,4 +1,3 @@
|
||||||
import { NSchema as n } from '@nostrify/nostrify';
|
|
||||||
import { produce } from 'immer';
|
import { produce } from 'immer';
|
||||||
import { nip19 } from 'nostr-tools';
|
import { nip19 } from 'nostr-tools';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
@ -28,7 +27,7 @@ const connectionSchema = z.object({
|
||||||
pubkey: z.string(),
|
pubkey: z.string(),
|
||||||
accessToken: z.string(),
|
accessToken: z.string(),
|
||||||
authorizedPubkey: z.string(),
|
authorizedPubkey: z.string(),
|
||||||
bunkerSeckey: n.bech32('nsec'),
|
bunkerSeckey: z.custom<Uint8Array>((value) => value instanceof Uint8Array),
|
||||||
});
|
});
|
||||||
|
|
||||||
interface BunkerState {
|
interface BunkerState {
|
||||||
|
@ -63,10 +62,12 @@ export const useBunkerStore = create<BunkerState>()(
|
||||||
name: 'soapbox:bunker',
|
name: 'soapbox:bunker',
|
||||||
storage: {
|
storage: {
|
||||||
getItem(name) {
|
getItem(name) {
|
||||||
|
const value = localStorage.getItem(name);
|
||||||
|
|
||||||
const connections = jsonSchema(nsecReviver)
|
const connections = jsonSchema(nsecReviver)
|
||||||
.pipe(filteredArray(connectionSchema))
|
.pipe(filteredArray(connectionSchema))
|
||||||
.catch([])
|
.catch([])
|
||||||
.parse(localStorage.getItem(name));
|
.parse(value);
|
||||||
|
|
||||||
return { state: { connections } };
|
return { state: { connections } };
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue