mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
capture chainIds in user preferences provider
This commit is contained in:
parent
796fc6be81
commit
15b036f462
@ -6,17 +6,20 @@ import React, {
|
|||||||
useState,
|
useState,
|
||||||
useEffect
|
useEffect
|
||||||
} from 'react'
|
} from 'react'
|
||||||
import { Logger, LogLevel, ConfigHelperConfig } from '@oceanprotocol/lib'
|
import { Logger, LogLevel } from '@oceanprotocol/lib'
|
||||||
import { useOcean } from './Ocean'
|
|
||||||
import { isBrowser } from '../utils'
|
import { isBrowser } from '../utils'
|
||||||
|
import { useSiteMetadata } from '../hooks/useSiteMetadata'
|
||||||
|
|
||||||
interface UserPreferencesValue {
|
interface UserPreferencesValue {
|
||||||
debug: boolean
|
debug: boolean
|
||||||
currency: string
|
currency: string
|
||||||
locale: string
|
locale: string
|
||||||
|
chainIds: number[]
|
||||||
bookmarks: {
|
bookmarks: {
|
||||||
[network: string]: string[]
|
[network: string]: string[]
|
||||||
}
|
}
|
||||||
|
addChainId: (chain: number) => void
|
||||||
|
removeChainId: (chain: number) => void
|
||||||
setDebug: (value: boolean) => void
|
setDebug: (value: boolean) => void
|
||||||
setCurrency: (value: string) => void
|
setCurrency: (value: string) => void
|
||||||
addBookmark: (did: string) => void
|
addBookmark: (did: string) => void
|
||||||
@ -45,8 +48,7 @@ function UserPreferencesProvider({
|
|||||||
}: {
|
}: {
|
||||||
children: ReactNode
|
children: ReactNode
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
// const { config } = useOcean()
|
const { appConfig } = useSiteMetadata()
|
||||||
// const networkName = (config as ConfigHelperConfig).network
|
|
||||||
const localStorage = getLocalStorage()
|
const localStorage = getLocalStorage()
|
||||||
|
|
||||||
// Set default values from localStorage
|
// Set default values from localStorage
|
||||||
@ -55,12 +57,13 @@ function UserPreferencesProvider({
|
|||||||
localStorage?.currency || 'EUR'
|
localStorage?.currency || 'EUR'
|
||||||
)
|
)
|
||||||
const [locale, setLocale] = useState<string>()
|
const [locale, setLocale] = useState<string>()
|
||||||
|
const [chainIds, setChainIds] = useState(appConfig.chainIds)
|
||||||
const [bookmarks, setBookmarks] = useState(localStorage?.bookmarks || {})
|
const [bookmarks, setBookmarks] = useState(localStorage?.bookmarks || {})
|
||||||
|
|
||||||
// Write values to localStorage on change
|
// Write values to localStorage on change
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setLocalStorage({ debug, currency, bookmarks })
|
setLocalStorage({ chainIds, debug, currency, bookmarks })
|
||||||
}, [debug, currency, bookmarks])
|
}, [chainIds, debug, currency, bookmarks])
|
||||||
|
|
||||||
// Set ocean.js log levels, default: Error
|
// Set ocean.js log levels, default: Error
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -75,6 +78,16 @@ function UserPreferencesProvider({
|
|||||||
setLocale(window.navigator.language)
|
setLocale(window.navigator.language)
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
function addChainId(chain: number): void {
|
||||||
|
const newChainIds = [...chainIds, chain]
|
||||||
|
setChainIds(newChainIds)
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeChainId(chain: number): void {
|
||||||
|
const newChainIds = chainIds.filter((chainId) => chainId !== chain)
|
||||||
|
setChainIds(newChainIds)
|
||||||
|
}
|
||||||
|
|
||||||
// function addBookmark(didToAdd: string): void {
|
// function addBookmark(didToAdd: string): void {
|
||||||
// const newPinned = {
|
// const newPinned = {
|
||||||
// ...bookmarks,
|
// ...bookmarks,
|
||||||
@ -107,7 +120,10 @@ function UserPreferencesProvider({
|
|||||||
debug,
|
debug,
|
||||||
currency,
|
currency,
|
||||||
locale,
|
locale,
|
||||||
|
chainIds,
|
||||||
bookmarks,
|
bookmarks,
|
||||||
|
addChainId,
|
||||||
|
removeChainId,
|
||||||
setDebug,
|
setDebug,
|
||||||
setCurrency
|
setCurrency
|
||||||
// addBookmark,
|
// addBookmark,
|
||||||
|
Loading…
Reference in New Issue
Block a user