diff --git a/app.config.js b/app.config.js index 4d3c8f82a..756154b8f 100644 --- a/app.config.js +++ b/app.config.js @@ -3,9 +3,12 @@ module.exports = { process.env.METADATACACHE_URI || 'https://aquarius.mainnet.oceanprotocol.com', - // List of supported chainIds which metadata cache queries - // will return by default - chainIds: [1, 3, 4, 137, 1287], + // List of chainIds which metadata cache queries will return by default. + // This preselects the Chains user preferences. + chainIds: [1, 137], + + // List of all supported chainIds. Used to populate the Chains user preferences list. + chainIdsSupported: [1, 3, 4, 137, 1287], infuraProjectId: process.env.GATSBY_INFURA_PROJECT_ID || 'xxx', diff --git a/src/components/atoms/NetworkName.module.css b/src/components/atoms/NetworkName.module.css index 2f03f5ac4..13ff67afb 100644 --- a/src/components/atoms/NetworkName.module.css +++ b/src/components/atoms/NetworkName.module.css @@ -9,6 +9,6 @@ display: inline-block; width: 1.2em; height: 1.2em; - fill: var(--color-secondary); - margin-right: calc(var(--spacer) / 12); + fill: currentColor; + margin-right: calc(var(--spacer) / 8); } diff --git a/src/components/molecules/UserPreferences/Chain.module.css b/src/components/molecules/UserPreferences/Chain.module.css index 568fc76cb..10f587861 100644 --- a/src/components/molecules/UserPreferences/Chain.module.css +++ b/src/components/molecules/UserPreferences/Chain.module.css @@ -1,30 +1,37 @@ -.buttons { - composes: buttons from './Appearance.module.css'; +.chains { + composes: box from '../../atoms/Box.module.css'; + box-shadow: none; + padding: 0; } -.button { - composes: button from './Appearance.module.css'; +.radioWrap { + composes: radioWrap from '../../atoms/Input/InputElement.module.css'; + padding: calc(var(--spacer) / 6) calc(var(--spacer) / 3); + border-bottom: 1px solid var(--border-color); } -.button span { - display: block; - font-size: var(--font-size-small); - font-family: var(--font-family-base); +.radioWrap:last-child { + border-bottom: none; +} + +.input { + composes: checkbox from '../../atoms/Input/InputElement.module.css'; + vertical-align: baseline; + margin-right: calc(var(--spacer) / 3); + margin-top: 0; +} + +.radioLabel { + composes: radioLabel from '../../atoms/Input/InputElement.module.css'; font-weight: var(--font-weight-base); - margin-top: calc(var(--spacer) / 10); + display: flex; + align-items: center; + margin: 0; + padding: 0; + width: 100%; } -.selected { - composes: selected from './Appearance.module.css'; -} - -.chains div[class*='boxSelectionsWrapper'] { - display: grid; - gap: calc(var(--spacer) / 4); - grid-template-columns: repeat(auto-fit, minmax(6rem, 1fr)); - padding-bottom: calc(var(--spacer) / 8); -} - -.chains label[class*='boxSelection'] { - padding: calc(var(--spacer) / 3) calc(var(--spacer) / 4) !important; +.input:checked + span { + color: var(--font-color-text); + font-weight: var(--font-weight-bold); } diff --git a/src/components/molecules/UserPreferences/Chain.tsx b/src/components/molecules/UserPreferences/Chain.tsx index 628a25410..f3b1e5f46 100644 --- a/src/components/molecules/UserPreferences/Chain.tsx +++ b/src/components/molecules/UserPreferences/Chain.tsx @@ -1,59 +1,50 @@ -import { ConfigHelperConfig } from '@oceanprotocol/lib' -import React, { ReactElement, ChangeEvent } from 'react' -import { useOcean } from '../../../providers/Ocean' -import { getOceanConfig } from '../../../utils/ocean' -import FormHelp from '../../atoms/Input/Help' +import React, { ChangeEvent, ReactElement } from 'react' import Label from '../../atoms/Input/Label' -import BoxSelection, { BoxSelectionOption } from '../FormFields/BoxSelection' -import { ReactComponent as EthIcon } from '../../../images/eth.svg' -import { ReactComponent as PolygonIcon } from '../../../images/polygon.svg' -import { ReactComponent as MoonbeamIcon } from '../../../images/moonbeam.svg' +import { useUserPreferences } from '../../../providers/UserPreferences' +import { useSiteMetadata } from '../../../hooks/useSiteMetadata' +import NetworkName from '../../atoms/NetworkName' +import { removeItemFromArray } from '../../../utils' +import FormHelp from '../../atoms/Input/Help' import styles from './Chain.module.css' export default function Chain(): ReactElement { - const { config, connect } = useOcean() + const { appConfig } = useSiteMetadata() + const { chainIds, setChainIds } = useUserPreferences() - async function connectOcean(event: ChangeEvent) { - const config = getOceanConfig(event.target.value) - await connect(config) + function handleChainChanged(e: ChangeEvent) { + const { value } = e.target + + // storing all chainId everywhere as a number so convert from here + const valueAsNumber = Number(value) + + const newChainIds = chainIds.includes(valueAsNumber) + ? [...removeItemFromArray(chainIds, valueAsNumber)] + : [...chainIds, valueAsNumber] + setChainIds(newChainIds) } - function isNetworkSelected(oceanConfig: string) { - return (config as ConfigHelperConfig).network === oceanConfig - } - - const options: BoxSelectionOption[] = [ - { - name: 'mainnet', - checked: isNetworkSelected('mainnet'), - title: 'ETH', - text: 'Mainnet', - icon: - }, - { - name: 'polygon', - checked: isNetworkSelected('polygon'), - title: 'Polygon', - text: 'Mainnet', - icon: - }, - { - name: 'moonbeamalpha', - checked: isNetworkSelected('moonbeamalpha'), - title: 'Moonbase Alpha', - text: 'Testnet', - icon: - } - ] - return ( -
  • - - +
  • + +
    + {appConfig.chainIdsSupported.map((chainId) => ( +
    + +
    + ))} +
    + Switch the data source for the interface.
  • ) diff --git a/src/components/molecules/UserPreferences/Debug.tsx b/src/components/molecules/UserPreferences/Debug.tsx index 5aef8a52e..ce1630e07 100644 --- a/src/components/molecules/UserPreferences/Debug.tsx +++ b/src/components/molecules/UserPreferences/Debug.tsx @@ -1,23 +1,21 @@ import React, { ReactElement } from 'react' import { useUserPreferences } from '../../../providers/UserPreferences' -import FormHelp from '../../atoms/Input/Help' -import InputElement from '../../atoms/Input/InputElement' +import Input from '../../atoms/Input' export default function Debug(): ReactElement { const { debug, setDebug } = useUserPreferences() return (
  • - setDebug(!debug)} /> - - Show geeky information in some places, and in your console. -
  • ) } diff --git a/src/components/molecules/UserPreferences/index.module.css b/src/components/molecules/UserPreferences/index.module.css index 1adc1a58c..922dd6c25 100644 --- a/src/components/molecules/UserPreferences/index.module.css +++ b/src/components/molecules/UserPreferences/index.module.css @@ -40,16 +40,16 @@ max-width: 20rem; } -.preferencesDetails li > div, -.preferencesDetails li p { - margin: 0; +.preferencesDetails > li > div, +.preferencesDetails p:last-child { + margin-bottom: 0; } .preferencesDetails li p { margin-top: calc(var(--spacer) / 8); } -.preferencesDetails li { +.preferencesDetails > li { padding-top: calc(var(--spacer) / 3); padding-bottom: calc(var(--spacer) / 3); } diff --git a/src/components/molecules/UserPreferences/index.tsx b/src/components/molecules/UserPreferences/index.tsx index 1c5a1ae30..7c4c861b4 100644 --- a/src/components/molecules/UserPreferences/index.tsx +++ b/src/components/molecules/UserPreferences/index.tsx @@ -11,16 +11,16 @@ import { darkModeConfig } from '../../../../app.config' import Chain from './Chain' export default function UserPreferences(): ReactElement { - // Calling this here because is not mounted on first load + // Calling this here because