1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-12-02 05:57:29 +01:00
🧜‍♀️ THE Data Market
Go to file
Norby a2fe2fdee0
Set, edit, and display timeout (#324)
* added timeout to publish asset

* add timeout to edit asses(wip)

* added timout to edit metadata form

* fixed wrong constant name

* fix options autosorting

Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro>

* Fixed autosorting in edit form

* Added "1 day" to timeout options

* Changed ternary operators to switch

* Feature/asset timeout (#325)

* Compute asset timeout

* Code styled

* Deleted unused import

* Display timeout for buy/download

* Switch case for timeout values

* Moved mapping function to /utils/metadata

* display timeout option not matching defined ones, map seconds to string

* handle update with no predefined timeout value, add weeks to map method

* Display timeout on button

* consume button text logic change

* whoops, revert wrong change

* small millisecondsToStr refactor

* copy tweaks

* template literal logic restore

* keep tweaking help text logic

* abstract into method
* change whole condition logic
* tweak hasDatatoken/hasPreviousOrder combination condition

* Unified seconds to string conversion methods

* getHelpText tweaks, small refactor

* copy editing, limit hardcoded timeout list

* fix mixup of map & filter

* use Timeout as label and be done with it

Co-authored-by: mihaisc <mihai.scarlat@smartcontrol.ro>
Co-authored-by: claudiaHash <49017601+claudiaHash@users.noreply.github.com>
Co-authored-by: Matthias Kretschmann <m@kretschmann.io>
Co-authored-by: Claudia Holhos <clawww1996@gmail.com>
2021-01-22 17:12:48 +01:00
.github Create codeql-analysis.yml (#321) 2021-01-20 14:57:14 +01:00
.storybook fix storybook typography display 2020-07-13 23:48:19 +02:00
content Set, edit, and display timeout (#324) 2021-01-22 17:12:48 +01:00
gatsby copy, move terms file 2020-07-17 15:16:00 +02:00
scripts Feature/s3 deploy (#243) 2020-11-12 19:20:52 +02:00
src Set, edit, and display timeout (#324) 2021-01-22 17:12:48 +01:00
tests/unit Set, edit, and display timeout (#324) 2021-01-22 17:12:48 +01:00
_redirects netlify rewrite rules (#244) 2020-11-12 15:15:41 +01:00
.env.example move analytics id to environment variable (#238) 2020-11-10 16:52:26 +01:00
.eslintrc add eslint-plugin-react-hooks 2020-09-16 11:08:35 +02:00
.gitignore Pool statistics from the graph (#288) 2021-01-21 16:02:48 +01:00
.prettierrc make Gatsby start 2020-06-30 13:32:16 +02:00
.travis.yml Pool statistics from the graph (#288) 2021-01-21 16:02:48 +01:00
apollo.config.js Pool statistics from the graph (#288) 2021-01-21 16:02:48 +01:00
app.config.js Handle price fetching better (#265) 2020-11-20 14:31:28 +01:00
gatsby-browser.js add providers with wrapRootElement 2020-07-01 18:57:10 +02:00
gatsby-config.js move analytics id to environment variable (#238) 2020-11-10 16:52:26 +01:00
gatsby-node.js Pool statistics from the graph (#288) 2021-01-21 16:02:48 +01:00
gatsby-ssr.js add providers with wrapRootElement 2020-07-01 18:57:10 +02:00
LICENSE first commit 2020-05-07 09:03:30 +03:00
package-lock.json bump ocean libraries, vulnerability bumps (#329) 2021-01-21 17:04:49 +01:00
package.json bump ocean libraries, vulnerability bumps (#329) 2021-01-21 17:04:49 +01:00
README.md Pool statistics from the graph (#288) 2021-01-21 16:02:48 +01:00
tsconfig.json disable baseUrl 2020-10-30 16:31:22 +01:00
vercel.json set Vercel rewrites 2020-09-14 16:44:10 +02:00

banner

Ocean Marketplace

Build Status Netlify Status Maintainability Test Coverage js oceanprotocol

Table of Contents

🏄 Get Started

The app is a React app built with Gatsby.js + TypeScript + CSS modules and will connect to Ocean components in Rinkeby by default.

To start local development:

git clone git@github.com:oceanprotocol/market.git
cd market

npm install
npm start

This will start the development server under http://localhost:8000.

To explore the generated GraphQL data structure fire up the accompanying GraphiQL IDE under http://localhost:8000/__graphql.

Local components with Barge

If you prefer to connect to locally running components instead of remote connections, you can spin up barge and use a local Ganache network in another terminal before running npm start:

git clone git@github.com:oceanprotocol/barge.git
cd barge

# startup with local Ganache node
./start_ocean.sh

Finally, set environment variables to use this local connection in .env in the app:

# modify env variables, Rinkeby is enabled by default when using those files
cp .env.example .env

🦑 Environment variables

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:

# modify env variables, Rinkeby is enabled by default when using those files
cp .env.example .env

🦀 Data Sources

All displayed data in the app is presented around the concept of one data set, which is a combination of:

  • metadata about a data set
  • the actual data set files
  • the datatoken which represents the data set
  • financial data connected to this datatoken, either a pool or a fixed rate exchange contract
  • calculations and conversions based on financial data
  • metadata about publishers

All this data then comes from multiple sources:

Aquarius

All initial data sets and their metadata (DDO) is retrieved client-side on run-time from the Aquarius instance for each network. All app calls to Aquarius are done with 2 internal methods which mimic the same methods in ocean.js, but allow us:

  • to cancel requests when components get unmounted in combination with axios
  • hit Aquarius as early as possible without relying on any ocean.js initialization

Aquarius runs Elasticsearch under the hood so its stored metadata can be queried with Elasticsearch queries like so:

import { QueryResult } from '@oceanprotocol/lib/dist/node/metadatacache/MetadataCache'
import { queryMetadata } from '../../utils/aquarius'

const queryLatest = {
  page: 1,
  offset: 9,
  query: {
    nativeSearch: 1,
    // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html
    query_string: { query: `-isInPurgatory:true` }
  },
  sort: { created: -1 }
}

function Component() {
  const { config } = useOcean()
  const [result, setResult] = useState<QueryResult>()

  useEffect(() => {
    if (!config?.metadataCacheUri) return
    const source = axios.CancelToken.source()

    async function init() {
      const result = await queryMetadata(
        query,
        config.metadataCacheUri,
        source.token
      )
      setResult(result)
    }
    init()

    return () => {
      source.cancel()
    }
  }, [config?.metadataCacheUri, query])

  return <div>{result}</div>
}

For components within a single data set view the useAsset() hook can be used, which in the background gets the respective metadata from Aquarius.

import { useAsset } from '../../../providers/Asset'

function Component() {
  const { ddo } = useAsset()
  return <div>{ddo}</div>
}

Ocean Protocol Subgraph

Most financial data in the market is retrieved with GraphQL from our own subgraph, rendered on top of the initial data coming from Aquarius.

The app has Apollo Client setup to query the respective subgraph based on network. In any component this client can be used like so:

import { gql, useQuery } from '@apollo/client'

const query = gql`
  query PoolLiquidity($id: ID!, $shareId: ID) {
    pool(id: $id) {
      id
      totalShares
    }
  }
`

function Component() {
  const { data } = useQuery(query, {}, pollInterval: 5000 })
  return <div>{data}</div>
}

3Box

Publishers can create a profile on 3Box Hub and when found, it will be displayed in the app.

For this our own 3box-proxy is used, within the app the utility method get3BoxProfile() can be used to get all info:

import get3BoxProfile from '../../../utils/profile'

function Component() {
  const [profile, setProfile] = useState<Profile>()

  useEffect(() => {
    if (!account) return
    const source = axios.CancelToken.source()

    async function get3Box() {
      const profile = await get3BoxProfile(account, source.token)
      if (!profile) return

      setProfile(profile)
    }
    get3Box()

    return () => {
      source.cancel()
    }
  }, [account])
  return (
    <div>
      {profile.emoji} {profile.name}
    </div>
  )
}

Purgatory

Based on list-purgatory some data sets get additional data. Within most components this can be done with the internal useAsset() hook which fetches data from the market-purgatory endpoint in the background.

import { useAsset } from '../../../providers/Asset'

function Component() {
  const { isInPurgatory, purgatoryData } = useAsset()
  return isInPurgatory ? <div>{purgatoryData.reason}</div> : null
}

🎨 Storybook

TODO: this is broken for most components. See https://github.com/oceanprotocol/market/issues/128

Storybook is set up for this project and is used for UI development of components. Stories are created inside src/components/ alongside each component in the form of ComponentName.stories.tsx.

To run the Storybook server, execute in your Terminal:

npm run storybook

This will launch the Storybook UI with all stories loaded under localhost:4000.

Code Style

For linting and auto-formatting you can use from the root of the project:

# lint all js with eslint
npm run lint

# auto format all js & css with prettier, taking all configs into account
npm run format

👩‍🔬 Testing

TODO: this is broken and never runs in CI. See https://github.com/oceanprotocol/market/issues/128

Test suite for unit tests is setup with Jest as a test runner and:

To run all linting and unit tests:

npm test

For local development, you can start the test runner in a watch mode.

npm run test:watch

For analyzing the generated JavaScript bundle sizes you can use:

npm run analyze

🛳 Production

To create a production build, run from the root of the project:

npm run build
# serve production build
npm run serve

⬆️ Deployment

Every branch or Pull Request is automatically deployed to multiple hosts for redundancy and emergency reasons:

A link to a deployment will appear under each Pull Request.

The latest deployment of the main branch is automatically aliased to market.oceanprotocol.com, where the deployment on Netlify is the current live deployment.

💖 Contributing

We welcome contributions in form of bug reports, feature requests, code changes, or documentation improvements. Have a look at our contribution documentation for instructions and workflows:

🏛 License

Copyright 2021 Ocean Protocol Foundation Ltd.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.