react/src/hooks/usePricing
dependabot[bot] 9d2c0f3c63
Bump prettier from 2.2.1 to 2.3.0 (#307)
* Bump prettier from 2.2.1 to 2.3.0

Bumps [prettier](https://github.com/prettier/prettier) from 2.2.1 to 2.3.0.
- [Release notes](https://github.com/prettier/prettier/releases)
- [Changelog](https://github.com/prettier/prettier/blob/main/CHANGELOG.md)
- [Commits](https://github.com/prettier/prettier/compare/2.2.1...2.3.0)

Signed-off-by: dependabot[bot] <support@github.com>

* prettier updates

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Matthias Kretschmann <m@kretschmann.io>
2021-05-25 09:48:08 +02:00
..
PriceOptions.ts update to new ocean.js 2020-10-26 16:36:35 +02:00
README.md docs updates 2020-10-19 13:18:18 +02:00
index.ts move to usePricing 2020-10-19 02:47:12 -07:00
usePricing.ts Bump prettier from 2.2.1 to 2.3.0 (#307) 2021-05-25 09:48:08 +02:00

README.md

usePricing

Hook with helper utilities to create fixed price exchanges or liquidity pools for your data set, mint datatokens, and buy and sell datatokens.

Usage

import React from 'react'
import { useOcean, useCreatePricing } from '@oceanprotocol/react'
import { Metadata, DDO } from '@oceanprotocol/lib'

export default function MyComponent({ ddo }: { ddo: DDO }) {
  const { accountId } = useOcean()

  // Pricing helpers
  const {
    createPricing,
    buyDT,
    sellDT,
    pricingStepText,
    pricingError
  } = usePricing(ddo)

  const priceOptions = {
    price: 10,
    dtAmount: 10,
    type: 'fixed',
    weightOnDataToken: '',
    swapFee: ''
  }

  async function handleCreatePricing() {
    await createPricing(priceOptions)
  }

  async function handleMint() {
    await mint('1')
  }
  async function handleBuyDT() {
    await buyDT('1')
  }
  async function handleSellDT() {
    await sellDT('1')
  }

  return (
    <div>
      <h1>Post for sale</h1>

      <p>Your account: {accountId}</p>
      <button onClick={handleMint}>Mint DT</button>
      <button onClick={handleCreatePricing}>Post for sale</button>
      <button onClick={handleBuyDT}>Buy DT</button>
      <button onClick={handleSellDT}>Sell DT</button>
    </div>
  )
}