From 1de31e4eff5226bab07ef3a7c88de5cac9563586 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Wed, 8 Jul 2020 15:15:02 +0200 Subject: [PATCH] consolidate actual app config --- README.md | 2 +- app.config.js | 19 ++++++++++ gatsby-config.js | 13 +++---- gatsby-node.js | 1 - plugins/gatsby-source-ocean/gatsby-node.js | 5 ++- src/components/organisms/JobsList.tsx | 1 - src/components/templates/Search/utils.ts | 4 +-- src/config/ocean.ts | 41 ---------------------- src/helpers/wrapRootElement.tsx | 4 +-- src/pages/asset/index.tsx | 4 +-- src/utils/getAssetRating.ts | 4 +-- src/utils/getFromFaucet.ts | 4 +-- src/utils/rateAsset.ts | 4 +-- tsconfig.json | 5 +-- 14 files changed, 44 insertions(+), 67 deletions(-) create mode 100644 app.config.js delete mode 100644 src/config/ocean.ts diff --git a/README.md b/README.md index 708891d76..ff912d3d6 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,7 @@ Files under `/api` are isolated and not part of Gatsby. ## 🦑 Environment variables -The `./src/config/ocean.ts` file is setup to prioritize environment variables for setting each Ocean component endpoint. By setting environment variables, you can easily switch between Ocean networks the app connects to, without directly modifying `./src/config/ocean.ts`. +The `app.config.js` file is setup to prioritize environment variables for setting each Ocean component endpoint. By setting environment variables, you can easily switch between Ocean networks the app connects to, without directly modifying `app.config.js`. For local development, you can use a `.env` file: diff --git a/app.config.js b/app.config.js new file mode 100644 index 000000000..a2fed28ac --- /dev/null +++ b/app.config.js @@ -0,0 +1,19 @@ +module.exports = { + oceanConfig: { + nodeUri: process.env.NODE_URI || 'https://pacific.oceanprotocol.com', + aquariusUri: + process.env.AQUARIUS_URI || + 'https://aquarius.marketplace.oceanprotocol.com', + brizoUri: + process.env.BRIZO_URI || 'https://brizo.marketplace.oceanprotocol.com', + brizoAddress: + process.env.BRIZO_ADDRESS || '0x00c6A0BC5cD0078d6Cd0b659E8061B404cfa5704', + secretStoreUri: + process.env.SECRET_STORE_URI || 'https://secret-store.oceanprotocol.com', + faucetUri: process.env.FAUCET_URI || 'https://faucet.oceanprotocol.com', + ratingUri: + process.env.RATING_URI || + 'https://rating.pacific.marketplace.dev-ocean.com', + verbose: 3 + } +} diff --git a/gatsby-config.js b/gatsby-config.js index 4fb71a658..bc8218293 100644 --- a/gatsby-config.js +++ b/gatsby-config.js @@ -1,10 +1,11 @@ require('dotenv').config() -const siteConfig = require('./content/site.json') +const siteContent = require('./content/site.json') +const { oceanConfig } = require('./app.config') module.exports = { siteMetadata: { - ...siteConfig.site + ...siteContent.site }, plugins: [ { @@ -31,7 +32,7 @@ module.exports = { { resolve: 'gatsby-source-ocean', options: { - aquariusUri: 'https://aquarius.marketplace.oceanprotocol.com' + aquariusUri: oceanConfig.aquariusUri } }, { @@ -58,12 +59,12 @@ module.exports = { // https://www.gatsbyjs.org/packages/gatsby-plugin-manifest/#using-with-gatsby-plugin-offline resolve: 'gatsby-plugin-manifest', options: { - name: siteConfig.site.siteTitle, - short_name: siteConfig.site.siteTitle, + name: siteContent.site.siteTitle, + short_name: siteContent.site.siteTitle, start_url: '/', background_color: '#ffffff', theme_color: '#141414', - icon: siteConfig.site.siteIcon, + icon: siteContent.site.siteIcon, display: 'standalone', cache_busting_mode: 'none' } diff --git a/gatsby-node.js b/gatsby-node.js index 25ed34941..7980cf5fb 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -1,5 +1,4 @@ const path = require('path') -// const { config } = require('./src/config/ocean') exports.onCreateWebpackConfig = ({ actions }) => { actions.setWebpackConfig({ diff --git a/plugins/gatsby-source-ocean/gatsby-node.js b/plugins/gatsby-source-ocean/gatsby-node.js index d56c368ea..2ffd2a7b4 100644 --- a/plugins/gatsby-source-ocean/gatsby-node.js +++ b/plugins/gatsby-source-ocean/gatsby-node.js @@ -2,10 +2,9 @@ const axios = require('axios') exports.sourceNodes = async ( { actions, createNodeId, createContentDigest }, - pluginOptions + { aquariusUri } ) => { const { createNode } = actions - const { aquariusUri } = pluginOptions // Query for all assets to use in creating pages. const result = await axios(`${aquariusUri}/api/v1/aquarius/assets`) @@ -29,7 +28,7 @@ exports.sourceNodes = async ( internal: { type: 'OceanAsset', contentDigest: createContentDigest(metadata), - description: `All data sets queried from ${pluginOptions.aquariusUri}` + description: `All data sets queried from ${aquariusUri}` } } diff --git a/src/components/organisms/JobsList.tsx b/src/components/organisms/JobsList.tsx index 0a6c8d83a..b048e45ed 100644 --- a/src/components/organisms/JobsList.tsx +++ b/src/components/organisms/JobsList.tsx @@ -14,7 +14,6 @@ import Button from '../atoms/Button' import { MetaDataMain, Logger } from '@oceanprotocol/squid' import DateCell from '../atoms/Table/DateCell' import DdoLinkCell from '../atoms/Table/DdoLinkCell' -import { config } from '../../config/ocean' import shortid from 'shortid' import ActionsCell from '../atoms/Table/ActionsCell' import Tooltip from '../atoms/Tooltip' diff --git a/src/components/templates/Search/utils.ts b/src/components/templates/Search/utils.ts index a27b970ef..b42ae8b83 100644 --- a/src/components/templates/Search/utils.ts +++ b/src/components/templates/Search/utils.ts @@ -4,7 +4,7 @@ import { } from '@oceanprotocol/squid/dist/node/aquarius/Aquarius' import { priceQueryParamToWei } from '../../../utils' import { Aquarius, Logger } from '@oceanprotocol/squid' -import { config } from '../../../config/ocean' +import { oceanConfig } from '../../../../app.config' export function getSearchQuery( page?: string | string[], @@ -52,7 +52,7 @@ export async function getResults(params: any): Promise { ]) : undefined - const aquarius = new Aquarius(config.aquariusUri, Logger) + const aquarius = new Aquarius(oceanConfig.aquariusUri, Logger) const queryResult = await aquarius.queryMetadata( getSearchQuery(page, offset, text, tag, priceQuery) ) diff --git a/src/config/ocean.ts b/src/config/ocean.ts deleted file mode 100644 index 0011db5ba..000000000 --- a/src/config/ocean.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { Config } from '@oceanprotocol/squid' - -export enum OceanNetworkChainIds { - 'Pacific' = 846353, - 'Nile' = 8995, - 'Spree' = 8996 -} - -declare type OceanNetworks = - | OceanNetworkChainIds.Pacific - | OceanNetworkChainIds.Nile - | OceanNetworkChainIds.Spree - -export interface OceanConfig extends Config { - faucetUri: string - ratingUri: string -} - -export const config: OceanConfig = { - nodeUri: process.env.NODE_URI || 'https://pacific.oceanprotocol.com', - aquariusUri: - process.env.AQUARIUS_URI || - 'https://aquarius.marketplace.oceanprotocol.com', - brizoUri: - process.env.BRIZO_URI || 'https://brizo.marketplace.oceanprotocol.com', - brizoAddress: - process.env.BRIZO_ADDRESS || '0x00c6A0BC5cD0078d6Cd0b659E8061B404cfa5704', - secretStoreUri: - process.env.SECRET_STORE_URI || 'https://secret-store.oceanprotocol.com', - faucetUri: process.env.FAUCET_URI || 'https://faucet.oceanprotocol.com', - ratingUri: - process.env.RATING_URI || - 'https://rating.pacific.marketplace.dev-ocean.com', - verbose: 3 -} - -export const CHAIN_IDS: OceanNetworks[] = [ - OceanNetworkChainIds.Pacific, - OceanNetworkChainIds.Nile, - OceanNetworkChainIds.Spree -] diff --git a/src/helpers/wrapRootElement.tsx b/src/helpers/wrapRootElement.tsx index 58102cd01..6dab2a77f 100644 --- a/src/helpers/wrapRootElement.tsx +++ b/src/helpers/wrapRootElement.tsx @@ -1,6 +1,6 @@ import React, { ReactElement } from 'react' import { Web3Provider, OceanProvider, Config } from '@oceanprotocol/react' -import { config } from '../config/ocean' +import { oceanConfig } from '../../app.config' const wrapRootElement = ({ element @@ -8,7 +8,7 @@ const wrapRootElement = ({ element: ReactElement }): ReactElement => ( - {element} + {element} ) diff --git a/src/pages/asset/index.tsx b/src/pages/asset/index.tsx index b0196cafc..0b5f0d02b 100644 --- a/src/pages/asset/index.tsx +++ b/src/pages/asset/index.tsx @@ -5,7 +5,7 @@ import Layout from '../../components/Layout' import { PageProps } from 'gatsby' import { MetaDataMarket, ServiceMetaDataMarket } from '../../@types/MetaData' import { Aquarius, Logger } from '@oceanprotocol/squid' -import { config } from '../../config/ocean' +import { oceanConfig } from '../../../app.config' import { Alert } from '../../components/atoms/Alert' export default function AssetRoute(props: PageProps): ReactElement { @@ -18,7 +18,7 @@ export default function AssetRoute(props: PageProps): ReactElement { useEffect(() => { async function init() { try { - const aquarius = new Aquarius(config.aquariusUri, Logger) + const aquarius = new Aquarius(oceanConfig.aquariusUri, Logger) const ddo = await aquarius.retrieveDDO(did) if (!ddo) { diff --git a/src/utils/getAssetRating.ts b/src/utils/getAssetRating.ts index 437cb546d..e51a659ae 100644 --- a/src/utils/getAssetRating.ts +++ b/src/utils/getAssetRating.ts @@ -1,6 +1,6 @@ import axios from 'axios' import { DID } from '@oceanprotocol/squid' -import { config } from '../config/ocean' +import { oceanConfig } from '../../app.config' export declare type GetRatingResponse = { comment: string @@ -8,7 +8,7 @@ export declare type GetRatingResponse = { vote: number } -const url = config.ratingUri + '/api/v1/rating' +const url = oceanConfig.ratingUri + '/api/v1/rating' export default async function getAssetRating( did: DID | string, diff --git a/src/utils/getFromFaucet.ts b/src/utils/getFromFaucet.ts index 2dadd1f69..d98cfb0f9 100644 --- a/src/utils/getFromFaucet.ts +++ b/src/utils/getFromFaucet.ts @@ -1,5 +1,5 @@ import axios, { AxiosResponse } from 'axios' -import { config } from '../config/ocean' +import { oceanConfig } from '../../app.config' export interface FaucetResponse { success: boolean @@ -13,7 +13,7 @@ export default async function getFromFaucet( try { const response: AxiosResponse = await axios({ method: 'POST', - url: `${config.faucetUri}/faucet`, + url: `${oceanConfig.faucetUri}/faucet`, data: { address: account, agent: 'market' diff --git a/src/utils/rateAsset.ts b/src/utils/rateAsset.ts index bfd972e55..f4dc657ac 100644 --- a/src/utils/rateAsset.ts +++ b/src/utils/rateAsset.ts @@ -1,11 +1,11 @@ import axios, { AxiosResponse } from 'axios' import Web3 from 'web3' import { DID } from '@oceanprotocol/squid' -import { config } from '../config/ocean' +import { oceanConfig } from '../../app.config' export declare type RatingResponse = [string, number] -const url = config.ratingUri + '/api/v1/rating' +const url = oceanConfig.ratingUri + '/api/v1/rating' export function gethash(message: string) { let hex = '' diff --git a/tsconfig.json b/tsconfig.json index 3f2d62c42..b1de2a998 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -12,8 +12,9 @@ "noEmit": true, "sourceMap": true, "noImplicitAny": true, - "skipLibCheck": true + "skipLibCheck": true, + "allowJs": true }, "exclude": ["node_modules", "public", ".cache", "*.js"], - "include": ["./src/**/*", "./api/**/*", "./tests/**/*"] + "include": ["./src/**/*", "./api/**/*", "./tests/**/*", "./app.config.js"] }