mirror of
https://github.com/pezkuwichain/pwap.git
synced 2026-07-31 09:05:40 +00:00
971df8edba
- Remove all 3rd party parachain configurations from endpoints: - productionRelayPolkadot.ts: Keep only system parachains - productionRelayDicle.ts: Keep only system parachains - testingRelayZagros.ts: Keep only system parachains - testingRelayTeyrChain.ts: Keep only system parachains - Update domain references: - polkadot.js.org → pezkuwichain.app - wiki.polkadot.network → wiki.pezkuwichain.io - dotapps.io → pezkuwichain.app - statement.polkadot.network → docs.pezkuwichain.io/statement - support.polkadot.network → docs.pezkuwichain.io - Update repository references: - github.com/pezkuwi-js/apps → github.com/pezkuwichain/pwap - Rename system parachains to Pezkuwi ecosystem: - PolkadotAssetHub → PezkuwiAssetHub - polkadotBridgeHub → pezkuwiBridgeHub - polkadotCollectives → pezkuwiCollectives - polkadotCoretime → pezkuwiCoretime - polkadotPeople → pezkuwiPeople - Update network name in claims utility: - Polkadot → Pezkuwi
55 lines
1.5 KiB
TypeScript
55 lines
1.5 KiB
TypeScript
// Copyright 2017-2026 @pezkuwi/react-hooks authors & contributors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
import type React from 'react';
|
|
|
|
import { useEffect, useState } from 'react';
|
|
import store from 'store';
|
|
|
|
import { isBoolean } from '@pezkuwi/util';
|
|
|
|
type Flags = Record<string, boolean>;
|
|
|
|
type Setters<T extends Flags> = Record<keyof T, (value: boolean) => void>;
|
|
|
|
type State<T extends Flags> = [T, Setters<T>];
|
|
|
|
function getInitial <T extends Flags> (storageKey: string, initial: T): T {
|
|
const saved = store.get(`flags:${storageKey}`, {}) as T;
|
|
|
|
return Object.keys(initial).reduce((result, key: keyof T): T => {
|
|
if (isBoolean(saved[key])) {
|
|
result[key] = saved[key];
|
|
}
|
|
|
|
return result;
|
|
}, { ...initial });
|
|
}
|
|
|
|
function getSetters <T extends Flags> (flags: T, setFlags: React.Dispatch<React.SetStateAction<T>>): Setters<T> {
|
|
const setFlag = (key: keyof T) =>
|
|
(value: boolean) =>
|
|
setFlags((state) => ({ ...state, [key]: value }));
|
|
|
|
return Object.keys(flags).reduce((setters, key: keyof T): Setters<T> => {
|
|
setters[key] = setFlag(key);
|
|
|
|
return setters;
|
|
}, {} as Setters<T>);
|
|
}
|
|
|
|
// TODO Uses generics, we cannot use createNameHook as of yet
|
|
export function useSavedFlags <T extends Flags> (storageKey: string, initial: T): State<T> {
|
|
const [flags, setFlags] = useState(() => getInitial(storageKey, initial));
|
|
const [setters] = useState(() => getSetters(initial, setFlags));
|
|
|
|
useEffect(
|
|
(): void => {
|
|
store.set(`flags:${storageKey}`, flags);
|
|
},
|
|
[flags, storageKey]
|
|
);
|
|
|
|
return [flags, setters];
|
|
}
|