2020-10-14 13:55:18 +02:00
|
|
|
# `usePricing`
|
2020-10-14 10:11:49 +02:00
|
|
|
|
|
|
|
Post asset for sale by creating liquidity pools or fixed rate exchange
|
2020-10-14 13:55:18 +02:00
|
|
|
Buy DT
|
|
|
|
Sell DT
|
2020-10-14 10:11:49 +02:00
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
|
|
|
```tsx
|
|
|
|
import React from 'react'
|
|
|
|
import { useOcean, usePostforSale } from '@oceanprotocol/react'
|
|
|
|
import { Metadata } from '@oceanprotocol/lib'
|
|
|
|
|
|
|
|
export default function MyComponent() {
|
|
|
|
const { accountId } = useOcean()
|
|
|
|
|
|
|
|
// Publish helpers
|
2020-10-14 13:55:18 +02:00
|
|
|
const { createPricing, buyDT, sellDT } = usePricing()
|
2020-10-14 10:11:49 +02:00
|
|
|
|
|
|
|
const priceOptions = {
|
|
|
|
price: 10,
|
|
|
|
dtAmount: 10,
|
|
|
|
type: 'fixed',
|
|
|
|
weightOnDataToken: '',
|
|
|
|
swapFee: ''
|
|
|
|
}
|
|
|
|
|
2020-10-14 13:55:18 +02:00
|
|
|
async function handleCreatePricing() {
|
2020-10-14 10:11:49 +02:00
|
|
|
const ddo = await createPricing(dataTokenAddress, priceOptions)
|
|
|
|
}
|
|
|
|
|
2020-10-14 13:55:18 +02:00
|
|
|
async function handleBuyDT() {
|
|
|
|
const ddo = await buyDT(dataTokenAddress, 1)
|
|
|
|
}
|
|
|
|
async function handleSellDT() {
|
|
|
|
const ddo = await sellDT(dataTokenAddress, 1)
|
|
|
|
}
|
|
|
|
|
2020-10-14 10:11:49 +02:00
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<h1>Post for sale</h1>
|
|
|
|
|
|
|
|
<p>Your account: {accountId}</p>
|
2020-10-14 13:55:18 +02:00
|
|
|
<button onClick={handleCreatePricing}>Post for sale</button>
|
|
|
|
<button onClick={handleBuyDT}>Buy DT</button>
|
|
|
|
<button onClick={handleSellDT}>Sell DT</button>
|
2020-10-14 10:11:49 +02:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
```
|