Skip to content
This repository has been archived by the owner on Aug 3, 2021. It is now read-only.

Commit

Permalink
move to usePricing
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcos20 committed Oct 19, 2020
1 parent e39f414 commit 6e5ae7b
Show file tree
Hide file tree
Showing 16 changed files with 202 additions and 295 deletions.
4 changes: 2 additions & 2 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { AllDdos } from './AllDdos'
import { ConsumeDdo } from './ConsumeDdo'
import { NetworkMonitor } from './NetworkMonitor'
import { LogLevel } from '@oceanprotocol/lib/dist/node/utils'
import { Trade } from './Trade'
import { Pricing } from './Pricing'

const configRinkeby = new ConfigHelper().getConfig('rinkeby')
const providerOptions = {}
Expand Down Expand Up @@ -41,7 +41,7 @@ function App() {
<Publish />
</div>
<div>
<Trade />
<Pricing />
</div>
<div>
<ConsumeDdo />
Expand Down
57 changes: 57 additions & 0 deletions example/src/Pricing.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import React from 'react'
import { useOcean, usePricing } from '@oceanprotocol/react'
// import { useOcean, usePublish } from '@oceanprotocol/react'
import { DDO } from '@oceanprotocol/lib'
import { useState } from 'react'
import { Metadata } from '@oceanprotocol/lib/dist/node/ddo/interfaces/Metadata'

export function Trade() {
const { ocean, accountId } = useOcean()
const { createPricing,buyDT,sellDT,mint,pricingStep,pricingStepText,pricingIsLoading, pricingError} = usePricing()
const [datatoken, setDatatoken] = useState<string | undefined>()
const handleBuy = async () => {
const tx = await buyDT(datatoken,'1')
console.log(tx)
}
const handleSell = async () => {
const tx = await buyDT(datatoken,'1')
console.log(tx)
}
const handleChange = (e: any) => {
setDatatoken(e.target.value)
}
const handlePostForSale = async () => {
if(datatoken){
const priceOptions = {
price: 7,
dtAmount: 10,
type: 'fixed',
weightOnDataToken: '',
swapFee: ''
}
const tx = await createPricing(datatoken,priceOptions)
console.log(tx)
}
}
return (
<>
<div>Trade Datatoken</div>
<div>
Datatoken <input onChange={handleChange}></input>
</div>
<div>
<button onClick={handlePostForSale}>Post for sale</button>
</div>
<div>
<button onClick={handleBuy}>Buy 1 DT</button>
</div>
<div>
<button onClick={handleSell}>Sell 1 DT</button>
</div>
<div>
IsLoading: {pricingIsLoading.toString()} || Status: {pricingStepText}
</div>

</>
)
}
40 changes: 6 additions & 34 deletions example/src/Publish.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import React from 'react'
import { usePublish, useCreatePricing } from '@oceanprotocol/react'
// import { useOcean, usePublish } from '@oceanprotocol/react'
import { usePublish } from '@oceanprotocol/react'
import { DDO } from '@oceanprotocol/lib'
import { useState } from 'react'
import { Metadata } from '@oceanprotocol/lib/dist/node/ddo/interfaces/Metadata'

export function Publish() {
const { publish, publishStepText, isLoading } = usePublish()
const { createPricing, pricingStep, pricingStepText, pricingIsLoading, pricingError} = useCreatePricing()
const { createPricing, pricingStep, pricingStepText, pricingIsLoading, pricingError} = usePricing()
const [ddo, setDdo] = useState<DDO | undefined | null>()

const asset = {
Expand All @@ -32,37 +31,16 @@ export function Publish() {
}

const publishAsset = async () => {
const priceOptions = {
price: 7,
dtAmount: 10,
type: 'fixed',
weightOnDataToken: '',
swapFee: ''
}

const datatokenOptions = {
tokensToMint:10

}
const ddo = await publish(asset as Metadata, 'access', datatokenOptions)
console.log(ddo)
setDdo(ddo)
}

const handlePostForSale = async () => {
if(ddo){
const priceOptions = {
price: 7,
dtAmount: 10,
type: 'fixed',
weightOnDataToken: '',
swapFee: ''
}
const tx = await createPricing(ddo.dataToken,priceOptions)
console.log(tx)
}
else{
console.error("Publish the asset first")
}
}

return (
<>
<div>Publish</div>
Expand All @@ -73,13 +51,7 @@ export function Publish() {
IsLoading: {isLoading.toString()} || Status: {publishStepText}
</div>
<div>DID: {ddo && ddo.id} </div>
<div>
<button onClick={handlePostForSale}>Post for sale</button>
</div>
<div>
IsLoading: {pricingIsLoading.toString()} || pricingStatus: {pricingStepText}
</div>


</>
)
}
55 changes: 0 additions & 55 deletions example/src/Trade.tsx

This file was deleted.

3 changes: 1 addition & 2 deletions src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ export * from './useConsume'
export * from './useMetadata'
export * from './usePublish'
export * from './useCompute'
export * from './useCreatePricing'
export * from './useTrade'
export * from './usePricing'
2 changes: 0 additions & 2 deletions src/hooks/useCreatePricing/index.ts

This file was deleted.

114 changes: 0 additions & 114 deletions src/hooks/useCreatePricing/useCreatePricing.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# `usePricing`

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

## Usage

Expand All @@ -13,7 +13,7 @@ export default function MyComponent() {
const { accountId } = useOcean()
const dataTokenAddress = '0x00000'
// Publish helpers
const { createPricing } = useCreatePricing()
const { createPricing } = usePricing()

const priceOptions = {
price: 10,
Expand All @@ -27,13 +27,25 @@ export default function MyComponent() {
await createPricing(dataTokenAddress, priceOptions)
}

async function handleMint() {
await mint(dataTokenAddress, '1')
}
async function handleBuyDT() {
await buyDT(dataTokenAddress, '1')
}
async function handleSellDT() {
await sellDT(dataTokenAddress, '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>
)
}
Expand Down
2 changes: 2 additions & 0 deletions src/hooks/usePricing/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './usePricing'
export * from './PriceOptions'
Loading

0 comments on commit 6e5ae7b

Please sign in to comment.