1
0
mirror of https://github.com/oceanprotocol/commons.git synced 2023-03-15 18:03:00 +01:00

highly simplify Ocean URIs and env variables

This commit is contained in:
Matthias Kretschmann 2019-06-12 03:14:24 +02:00
parent 97618c2ef2
commit 4b919f2ee8
Signed by: m
GPG Key ID: 606EEEF3C479A91F
7 changed files with 62 additions and 134 deletions

View File

@ -3,46 +3,42 @@
# Commons will default connecting to Nile # Commons will default connecting to Nile
# #
#
# Connect to Nile
#
REACT_APP_NODE_URI="https://nile.dev-ocean.com"
REACT_APP_AQUARIUS_URI="https://nginx-aquarius.dev-ocean.com"
REACT_APP_BRIZO_URI="https://nginx-brizo.dev-ocean.com"
REACT_APP_SECRET_STORE_URI="https://secret-store.dev-ocean.com"
REACT_APP_FAUCET_URI="https://faucet.nile.dev-ocean.com"
REACT_APP_BRIZO_ADDRESS="0x4aaab179035dc57b35e2ce066919048686f82972"
# #
# Connect to Duero # Connect to Duero
# #
REACT_APP_NODE_HOST="duero.dev-ocean.com" # REACT_APP_NODE_URI="https://duero.dev-ocean.com"
REACT_APP_AQUARIUS_HOST="aquarius.duero.dev-ocean.com" # REACT_APP_AQUARIUS_URI="https://aquarius.duero.dev-ocean.com"
REACT_APP_BRIZO_HOST="brizo.duero.dev-ocean.com" # REACT_APP_BRIZO_URI="https://brizo.duero.dev-ocean.com"
REACT_APP_SECRET_STORE_HOST="secret-store.duero.dev-ocean.com" # REACT_APP_SECRET_STORE_URI="https://secret-store.duero.dev-ocean.com"
REACT_APP_FAUCET_HOST="faucet.duero.dev-ocean.com" # REACT_APP_FAUCET_URI="https://faucet.duero.dev-ocean.com"
REACT_APP_PARITY_HOST=$REACT_APP_NODE_HOST # REACT_APP_BRIZO_ADDRESS="0x9d4ed58293f71122ad6a733c1603927a150735d0"
REACT_APP_BRIZO_ADDRESS="0x9d4ed58293f71122ad6a733c1603927a150735d0"
# #
# Connect to Nile Commons instances # Connect to Nile Commons instances
# #
# REACT_APP_NODE_HOST="nile.dev-ocean.com" # REACT_APP_NODE_URI="https://nile.dev-ocean.com"
# REACT_APP_AQUARIUS_HOST="aquarius.marketplace.dev-ocean.com" # REACT_APP_AQUARIUS_URI="https://aquarius.marketplace.dev-ocean.com"
# REACT_APP_BRIZO_HOST="brizo.marketplace.dev-ocean.com" # REACT_APP_BRIZO_URI="https://brizo.marketplace.dev-ocean.com"
# REACT_APP_SECRET_STORE_HOST="secret-store.marketplace.dev-ocean.com" # REACT_APP_SECRET_STORE_URI="https://secret-store.marketplace.dev-ocean.com"
# REACT_APP_FAUCET_HOST="faucet.nile.dev-ocean.com" # REACT_APP_FAUCET_URI="https://faucet.nile.dev-ocean.com"
# REACT_APP_PARITY_HOST=$REACT_APP_NODE_HOST # REACT_APP_BRIZO_ADDRESS="0x4aaab179035dc57b35e2ce066919048686f82972"
# #
# Connect to Spree (local with Barge) # Connect to Spree (local with Barge)
# #
# REACT_APP_NODE_SCHEME="http" # REACT_APP_NODE_URI="htts://localhost:8545"
# REACT_APP_NODE_HOST="localhost" # REACT_APP_AQUARIUS_URI="http://aquarius:5000"
# REACT_APP_NODE_PORT=8545 # REACT_APP_BRIZO_URI="http://localhost:8030"
# REACT_APP_AQUARIUS_SCHEME="http" # REACT_APP_SECRET_STORE_URI="http://localhost:12001"
# REACT_APP_AQUARIUS_HOST="aquarius" # REACT_APP_FAUCET_URI="http://localhost:3001"
# REACT_APP_AQUARIUS_PORT=5000
# REACT_APP_BRIZO_SCHEME="http"
# REACT_APP_BRIZO_HOST="localhost"
# REACT_APP_BRIZO_PORT=8030
# REACT_APP_PARITY_SCHEME=$REACT_APP_NODE_SCHEME
# REACT_APP_PARITY_HOST=$REACT_APP_NODE_HOST
# REACT_APP_PARITY_PORT=$REACT_APP_NODE_PORT
# REACT_APP_SECRET_STORE_SCHEME="http"
# REACT_APP_SECRET_STORE_HOST="localhost"
# REACT_APP_SECRET_STORE_PORT=12001
# REACT_APP_FAUCET_SCHEME="http"
# REACT_APP_FAUCET_HOST="localhost"
# REACT_APP_FAUCET_PORT=3001
# REACT_APP_BRIZO_ADDRESS="0x00bd138abd70e2f00903268f3db08f2d25677c9e" # REACT_APP_BRIZO_ADDRESS="0x00bd138abd70e2f00903268f3db08f2d25677c9e"

View File

@ -118,11 +118,4 @@ describe('VersionNumbers', () => {
'Could not get version' 'Could not get version'
) )
}) })
it('minimal component versions in link title, prefixed with `v`', async () => {
const { getByTitle } = render(<VersionNumbers minimal />)
mockAxios.mockResponse(mockResponse)
expect(mockAxios.get).toHaveBeenCalled()
await waitForElement(() => getByTitle(/v6.6.6/))
})
}) })

View File

@ -5,17 +5,7 @@ import { version } from '../../../../package.json'
import { version as versionSquid } from '@oceanprotocol/squid/package.json' import { version as versionSquid } from '@oceanprotocol/squid/package.json'
import styles from './index.module.scss' import styles from './index.module.scss'
import { import { aquariusUri, brizoUri, faucetUri } from '../../../config'
aquariusHost,
aquariusPort,
aquariusScheme,
brizoHost,
brizoPort,
brizoScheme,
faucetHost,
faucetPort,
faucetScheme
} from '../../../config'
import VersionTable from './VersionTable' import VersionTable from './VersionTable'
import { isJsonString } from './utils' import { isJsonString } from './utils'
@ -116,18 +106,14 @@ export default class VersionNumbers extends PureComponent<
} }
private async setAquarius() { private async setAquarius() {
const aquarius = await this.getData( const aquarius = await this.getData(aquariusUri)
aquariusScheme,
aquariusHost,
aquariusPort
)
aquarius && aquarius &&
aquarius.version !== undefined && aquarius.version !== undefined &&
this.setState({ aquarius: { isLoading: false, ...aquarius } }) this.setState({ aquarius: { isLoading: false, ...aquarius } })
} }
private async setBrizoAndKeeper() { private async setBrizoAndKeeper() {
const brizo = await this.getData(brizoScheme, brizoHost, brizoPort) const brizo = await this.getData(brizoUri)
const keeperVersion = const keeperVersion =
brizo['keeper-version'] && brizo['keeper-version'].replace('v', '') brizo['keeper-version'] && brizo['keeper-version'].replace('v', '')
@ -153,7 +139,7 @@ export default class VersionNumbers extends PureComponent<
} }
private async setFaucet() { private async setFaucet() {
const faucet = await this.getData(faucetScheme, faucetHost, faucetPort) const faucet = await this.getData(faucetUri)
// backwards compatibility // backwards compatibility
isJsonString(faucet) === false && isJsonString(faucet) === false &&
@ -167,9 +153,9 @@ export default class VersionNumbers extends PureComponent<
this.setState({ faucet: { isLoading: false, ...faucet } }) this.setState({ faucet: { isLoading: false, ...faucet } })
} }
private async getData(scheme: string, host: string, port: number | string) { private async getData(uri: string) {
try { try {
const response = await axios.get(`${scheme}://${host}:${port}`, { const response = await axios.get(uri, {
headers: { Accept: 'application/json' }, headers: { Accept: 'application/json' },
cancelToken: this.signal.token cancelToken: this.signal.token
}) })

View File

@ -1,49 +1,29 @@
// //
// commons-server connection // commons-server connection
// //
export const serviceScheme = process.env.REACT_APP_SERVICE_SCHEME || 'http' export const serviceUri =
export const serviceHost = process.env.REACT_APP_SERVICE_HOST || 'localhost' process.env.REACT_APP_SERVICE_URI || 'http://localhost:4000'
export const servicePort = process.env.REACT_APP_SERVICE_PORT || 4000
// //
// OCEAN REMOTE CONNECTIONS // OCEAN REMOTE CONNECTIONS
// //
export const nodeScheme = process.env.REACT_APP_NODE_SCHEME || 'https' export const nodeUri =
export const nodeHost = process.env.REACT_APP_NODE_HOST || 'nile.dev-ocean.com' process.env.REACT_APP_NODE_URI || 'https://nile.dev-ocean.com'
export const nodePort = process.env.REACT_APP_NODE_PORT || 443 export const aquariusUri =
process.env.REACT_APP_AQUARIUS_URI || 'https://nginx-aquarius.dev-ocean.com'
export const aquariusScheme = process.env.REACT_APP_AQUARIUS_SCHEME || 'https' export const brizoUri =
export const aquariusHost = process.env.REACT_APP_BRIZO_URI || 'https://nginx-brizo.dev-ocean.com'
process.env.REACT_APP_AQUARIUS_HOST || 'nginx-aquarius.dev-ocean.com'
export const aquariusPort = process.env.REACT_APP_AQUARIUS_PORT || 443
export const brizoScheme = process.env.REACT_APP_BRIZO_SCHEME || 'https'
export const brizoHost =
process.env.REACT_APP_BRIZO_HOST || 'nginx-brizo.dev-ocean.com'
export const brizoPort = process.env.REACT_APP_BRIZO_PORT || 443
export const brizoAddress = export const brizoAddress =
process.env.REACT_APP_BRIZO_ADDRESS || process.env.REACT_APP_BRIZO_ADDRESS ||
'0x4aaab179035dc57b35e2ce066919048686f82972' '0x4aaab179035dc57b35e2ce066919048686f82972'
export const secretStoreUri =
export const parityScheme = process.env.REACT_APP_PARITY_SCHEME || 'https' process.env.REACT_APP_SECRET_STORE_URI ||
export const parityHost = 'https://secret-store.dev-ocean.com'
process.env.REACT_APP_PARITY_HOST || 'nile.dev-ocean.com' export const faucetUri =
export const parityPort = process.env.REACT_APP_PARITY_PORT || 443 process.env.REACT_APP_FAUCET_URI || 'https://faucet.nile.dev-ocean.com'
export const secretStoreScheme =
process.env.REACT_APP_SECRET_STORE_SCHEME || 'https'
export const secretStoreHost =
process.env.REACT_APP_SECRET_STORE_HOST || 'secret-store.dev-ocean.com'
export const secretStorePort = process.env.REACT_APP_SECRET_STORE_PORT || 443
export const faucetScheme = process.env.REACT_APP_FAUCET_SCHEME || 'https'
export const faucetHost =
process.env.REACT_APP_FAUCET_HOST || 'faucet.nile.dev-ocean.com'
export const faucetPort = process.env.REACT_APP_FAUCET_PORT || 443
export const verbose = true
// //
// APP CONFIG // APP CONFIG
// //
export const verbose = true
export const analyticsId = 'UA-60614729-11' export const analyticsId = 'UA-60614729-11'

View File

@ -3,7 +3,7 @@ import Web3 from 'web3'
import { Logger, Ocean, Account } from '@oceanprotocol/squid' import { Logger, Ocean, Account } from '@oceanprotocol/squid'
import { User } from '.' import { User } from '.'
import { provideOcean, requestFromFaucet, FaucetResponse } from '../ocean' import { provideOcean, requestFromFaucet, FaucetResponse } from '../ocean'
import { nodeHost, nodePort, nodeScheme } from '../config' import { nodeUri } from '../config'
import MarketProvider from './MarketProvider' import MarketProvider from './MarketProvider'
const POLL_ACCOUNTS = 1000 // every 1s const POLL_ACCOUNTS = 1000 // every 1s
@ -81,11 +81,7 @@ export default class UserProvider extends PureComponent<{}, UserProviderState> {
ocn: 0 ocn: 0
}, },
network: '', network: '',
web3: new Web3( web3: new Web3(new Web3.providers.HttpProvider(nodeUri)),
new Web3.providers.HttpProvider(
`${nodeScheme}://${nodeHost}:${nodePort}`
)
),
account: '', account: '',
ocean: {} as any, ocean: {} as any,
requestFromFaucet: () => requestFromFaucet(''), requestFromFaucet: () => requestFromFaucet(''),

View File

@ -2,42 +2,22 @@ import { Ocean, Logger } from '@oceanprotocol/squid'
import Web3 from 'web3' import Web3 from 'web3'
import { import {
aquariusHost, aquariusUri,
aquariusPort, brizoUri,
aquariusScheme,
brizoHost,
brizoPort,
brizoScheme,
brizoAddress, brizoAddress,
faucetHost, faucetUri,
faucetPort, nodeUri,
faucetScheme, secretStoreUri,
nodeHost,
nodePort,
nodeScheme,
parityHost,
parityPort,
parityScheme,
secretStoreHost,
secretStorePort,
secretStoreScheme,
verbose verbose
} from './config' } from './config'
export async function provideOcean(web3provider: Web3) { export async function provideOcean(web3provider: Web3) {
const nodeUri = `${nodeScheme}://${nodeHost}:${nodePort}`
const aquariusUri = `${aquariusScheme}://${aquariusHost}:${aquariusPort}`
const brizoUri = `${brizoScheme}://${brizoHost}:${brizoPort}`
const parityUri = `${parityScheme}://${parityHost}:${parityPort}`
const secretStoreUri = `${secretStoreScheme}://${secretStoreHost}:${secretStorePort}`
const config = { const config = {
web3provider, web3provider,
nodeUri, nodeUri,
aquariusUri, aquariusUri,
brizoUri, brizoUri,
brizoAddress, brizoAddress,
parityUri,
secretStoreUri, secretStoreUri,
verbose verbose
} }
@ -58,7 +38,7 @@ export interface FaucetResponse {
export async function requestFromFaucet(account: string) { export async function requestFromFaucet(account: string) {
try { try {
const url = `${faucetScheme}://${faucetHost}:${faucetPort}/faucet` const url = `${faucetUri}/faucet`
const response = await fetch(url, { const response = await fetch(url, {
method: 'POST', method: 'POST',
headers: { headers: {

View File

@ -6,7 +6,7 @@ import ItemForm from './ItemForm'
import Item from './Item' import Item from './Item'
import styles from './index.module.scss' import styles from './index.module.scss'
import { serviceHost, servicePort, serviceScheme } from '../../../config' import { serviceUri } from '../../../config'
import cleanupContentType from '../../../utils/cleanupContentType' import cleanupContentType from '../../../utils/cleanupContentType'
interface File { interface File {
@ -68,16 +68,13 @@ export default class Files extends PureComponent<FilesProps, FilesStates> {
} }
try { try {
const response = await fetch( const response = await fetch(`${serviceUri}/api/v1/urlcheck`, {
`${serviceScheme}://${serviceHost}:${servicePort}/api/v1/urlcheck`, method: 'POST',
{ body: JSON.stringify({ url: value }),
method: 'POST', headers: {
body: JSON.stringify({ url: value }), 'Content-Type': 'application/json'
headers: {
'Content-Type': 'application/json'
}
} }
) })
res = await response.json() res = await response.json()
file.contentLength = res.result.contentLength file.contentLength = res.result.contentLength
file.contentType = res.result.contentType file.contentType = res.result.contentType