mirror of
https://github.com/oceanprotocol/react.git
synced 2025-02-14 21:10:38 +01:00
package updates, linting fixes
This commit is contained in:
parent
75b1adb699
commit
e22212bd01
@ -14,6 +14,10 @@
|
|||||||
"prettier/@typescript-eslint"
|
"prettier/@typescript-eslint"
|
||||||
],
|
],
|
||||||
"plugins": ["@typescript-eslint", "prettier"],
|
"plugins": ["@typescript-eslint", "prettier"],
|
||||||
|
"rules": {
|
||||||
|
"no-use-before-define": "off",
|
||||||
|
"@typescript-eslint/no-use-before-define": "error"
|
||||||
|
},
|
||||||
"env": { "es6": true, "node": true },
|
"env": { "es6": true, "node": true },
|
||||||
"settings": {
|
"settings": {
|
||||||
"react": {
|
"react": {
|
||||||
|
1987
package-lock.json
generated
1987
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -28,15 +28,15 @@
|
|||||||
"@oceanprotocol/lib": "^0.2.4",
|
"@oceanprotocol/lib": "^0.2.4",
|
||||||
"axios": "^0.20.0",
|
"axios": "^0.20.0",
|
||||||
"decimal.js": "^10.2.0",
|
"decimal.js": "^10.2.0",
|
||||||
"web3": "^1.2.11",
|
"web3": "^1.3.0",
|
||||||
"web3modal": "^1.9.0"
|
"web3modal": "^1.9.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@release-it/bumper": "^2.0.0",
|
"@release-it/bumper": "^2.0.0",
|
||||||
"@types/node-fetch": "^2.5.7",
|
"@types/node-fetch": "^2.5.7",
|
||||||
"@types/react": "^16.9.49",
|
"@types/react": "^16.9.49",
|
||||||
"@typescript-eslint/eslint-plugin": "^4.0.1",
|
"@typescript-eslint/eslint-plugin": "^4.1.1",
|
||||||
"@typescript-eslint/parser": "^4.0.1",
|
"@typescript-eslint/parser": "^4.1.1",
|
||||||
"auto-changelog": "^2.2.0",
|
"auto-changelog": "^2.2.0",
|
||||||
"eslint": "^7.8.1",
|
"eslint": "^7.8.1",
|
||||||
"eslint-config-oceanprotocol": "^1.5.0",
|
"eslint-config-oceanprotocol": "^1.5.0",
|
||||||
@ -45,7 +45,7 @@
|
|||||||
"eslint-plugin-react": "^7.20.5",
|
"eslint-plugin-react": "^7.20.5",
|
||||||
"microbundle": "^0.12.3",
|
"microbundle": "^0.12.3",
|
||||||
"prettier": "^2.1.1",
|
"prettier": "^2.1.1",
|
||||||
"release-it": "^14.0.2",
|
"release-it": "^14.0.3",
|
||||||
"serialize-javascript": "^5.0.1",
|
"serialize-javascript": "^5.0.1",
|
||||||
"typescript": "^4.0.2"
|
"typescript": "^4.0.2"
|
||||||
},
|
},
|
||||||
|
1
src/@types/globals.d.ts
vendored
1
src/@types/globals.d.ts
vendored
@ -1,4 +1,3 @@
|
|||||||
import Web3 from 'web3'
|
|
||||||
import { HttpProvider } from 'web3-core'
|
import { HttpProvider } from 'web3-core'
|
||||||
|
|
||||||
interface EthereumProvider extends HttpProvider {
|
interface EthereumProvider extends HttpProvider {
|
||||||
|
@ -37,6 +37,49 @@ function usePublish(): UsePublish {
|
|||||||
index && setPublishStepText(publishFeedback[index])
|
index && setPublishStepText(publishFeedback[index])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function mint(tokenAddress: string, tokensToMint: string) {
|
||||||
|
Logger.log('mint function', tokenAddress, accountId)
|
||||||
|
await ocean.datatokens.mint(tokenAddress, accountId, tokensToMint)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function createPricing(
|
||||||
|
priceOptions: PriceOptions,
|
||||||
|
dataTokenAddress: string,
|
||||||
|
mintedTokens: string
|
||||||
|
): Promise<void | null> {
|
||||||
|
switch (priceOptions.type) {
|
||||||
|
case 'dynamic': {
|
||||||
|
const pool = await ocean.pool.createDTPool(
|
||||||
|
accountId,
|
||||||
|
dataTokenAddress,
|
||||||
|
priceOptions.tokensToMint.toString(),
|
||||||
|
priceOptions.weightOnDataToken,
|
||||||
|
priceOptions.liquidityProviderFee
|
||||||
|
)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
case 'fixed': {
|
||||||
|
if (!config.fixedRateExchangeAddress) {
|
||||||
|
Logger.error(`'fixedRateExchangeAddress' not set in ccnfig.`)
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
const fixedPriceExchange = await ocean.fixedRateExchange.create(
|
||||||
|
dataTokenAddress,
|
||||||
|
priceOptions.price.toString(),
|
||||||
|
accountId
|
||||||
|
)
|
||||||
|
await ocean.datatokens.approve(
|
||||||
|
dataTokenAddress,
|
||||||
|
config.fixedRateExchangeAddress,
|
||||||
|
mintedTokens,
|
||||||
|
accountId
|
||||||
|
)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Publish an asset.It also creates the datatoken, mints tokens and gives the market allowance
|
* Publish an asset.It also creates the datatoken, mints tokens and gives the market allowance
|
||||||
* @param {Metadata} asset The metadata of the asset.
|
* @param {Metadata} asset The metadata of the asset.
|
||||||
@ -154,49 +197,6 @@ function usePublish(): UsePublish {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createPricing(
|
|
||||||
priceOptions: PriceOptions,
|
|
||||||
dataTokenAddress: string,
|
|
||||||
mintedTokens: string
|
|
||||||
): Promise<void | null> {
|
|
||||||
switch (priceOptions.type) {
|
|
||||||
case 'dynamic': {
|
|
||||||
const pool = await ocean.pool.createDTPool(
|
|
||||||
accountId,
|
|
||||||
dataTokenAddress,
|
|
||||||
priceOptions.tokensToMint.toString(),
|
|
||||||
priceOptions.weightOnDataToken,
|
|
||||||
priceOptions.liquidityProviderFee
|
|
||||||
)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
case 'fixed': {
|
|
||||||
if (!config.fixedRateExchangeAddress) {
|
|
||||||
Logger.error(`'fixedRateExchangeAddress' not set in ccnfig.`)
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
const fixedPriceExchange = await ocean.fixedRateExchange.create(
|
|
||||||
dataTokenAddress,
|
|
||||||
priceOptions.price.toString(),
|
|
||||||
accountId
|
|
||||||
)
|
|
||||||
await ocean.datatokens.approve(
|
|
||||||
dataTokenAddress,
|
|
||||||
config.fixedRateExchangeAddress,
|
|
||||||
mintedTokens,
|
|
||||||
accountId
|
|
||||||
)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function mint(tokenAddress: string, tokensToMint: string) {
|
|
||||||
Logger.log('mint function', tokenAddress, accountId)
|
|
||||||
await ocean.datatokens.mint(tokenAddress, accountId, tokensToMint)
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
publish,
|
publish,
|
||||||
mint,
|
mint,
|
||||||
|
@ -75,17 +75,6 @@ function OceanProvider({
|
|||||||
Logger.log('Web3Modal instance created.', web3ModalInstance)
|
Logger.log('Web3Modal instance created.', web3ModalInstance)
|
||||||
}
|
}
|
||||||
|
|
||||||
// On mount setup Web3Modal instance
|
|
||||||
useEffect(() => {
|
|
||||||
init()
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
// Connect automatically to cached provider if present
|
|
||||||
useEffect(() => {
|
|
||||||
if (!web3Modal) return
|
|
||||||
web3Modal.cachedProvider && connect()
|
|
||||||
}, [web3Modal])
|
|
||||||
|
|
||||||
async function connect(newConfig?: Config) {
|
async function connect(newConfig?: Config) {
|
||||||
try {
|
try {
|
||||||
Logger.log('Connecting ...', newConfig)
|
Logger.log('Connecting ...', newConfig)
|
||||||
@ -125,6 +114,18 @@ function OceanProvider({
|
|||||||
Logger.error(error)
|
Logger.error(error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// On mount setup Web3Modal instance
|
||||||
|
useEffect(() => {
|
||||||
|
init()
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
// Connect automatically to cached provider if present
|
||||||
|
useEffect(() => {
|
||||||
|
if (!web3Modal) return
|
||||||
|
web3Modal.cachedProvider && connect()
|
||||||
|
}, [web3Modal])
|
||||||
|
|
||||||
async function refreshBalance() {
|
async function refreshBalance() {
|
||||||
const balance = account && (await getBalance(account))
|
const balance = account && (await getBalance(account))
|
||||||
setBalance(balance)
|
setBalance(balance)
|
||||||
|
@ -47,40 +47,6 @@ export async function getCheapestPool(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getBestDataTokenPrice(
|
|
||||||
ocean: Ocean,
|
|
||||||
dataTokenAddress: string,
|
|
||||||
accountId: string
|
|
||||||
): Promise<BestPrice | undefined> {
|
|
||||||
const cheapestPool = await getCheapestPool(ocean, accountId, dataTokenAddress)
|
|
||||||
const cheapestExchange = await getCheapestExchange(ocean, dataTokenAddress)
|
|
||||||
Decimal.set({ precision: 5 })
|
|
||||||
|
|
||||||
const cheapestPoolPrice = new Decimal(
|
|
||||||
cheapestPool && cheapestPool.price !== ''
|
|
||||||
? cheapestPool.price
|
|
||||||
: 999999999999
|
|
||||||
)
|
|
||||||
const cheapestExchangePrice = new Decimal(
|
|
||||||
cheapestExchange && cheapestExchange?.price !== ''
|
|
||||||
? cheapestExchange.price
|
|
||||||
: 999999999999
|
|
||||||
)
|
|
||||||
|
|
||||||
if (cheapestPoolPrice < cheapestExchangePrice) {
|
|
||||||
return {
|
|
||||||
type: 'pool',
|
|
||||||
address: cheapestPool?.address,
|
|
||||||
value: cheapestPool?.price
|
|
||||||
} as BestPrice
|
|
||||||
} else {
|
|
||||||
return {
|
|
||||||
type: 'exchange',
|
|
||||||
address: cheapestExchange?.address,
|
|
||||||
value: cheapestExchange?.price
|
|
||||||
} as BestPrice
|
|
||||||
}
|
|
||||||
}
|
|
||||||
export async function getCheapestExchange(
|
export async function getCheapestExchange(
|
||||||
ocean: Ocean,
|
ocean: Ocean,
|
||||||
dataTokenAddress: string
|
dataTokenAddress: string
|
||||||
@ -118,6 +84,41 @@ export async function getCheapestExchange(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getBestDataTokenPrice(
|
||||||
|
ocean: Ocean,
|
||||||
|
dataTokenAddress: string,
|
||||||
|
accountId: string
|
||||||
|
): Promise<BestPrice | undefined> {
|
||||||
|
const cheapestPool = await getCheapestPool(ocean, accountId, dataTokenAddress)
|
||||||
|
const cheapestExchange = await getCheapestExchange(ocean, dataTokenAddress)
|
||||||
|
Decimal.set({ precision: 5 })
|
||||||
|
|
||||||
|
const cheapestPoolPrice = new Decimal(
|
||||||
|
cheapestPool && cheapestPool.price !== ''
|
||||||
|
? cheapestPool.price
|
||||||
|
: 999999999999
|
||||||
|
)
|
||||||
|
const cheapestExchangePrice = new Decimal(
|
||||||
|
cheapestExchange && cheapestExchange?.price !== ''
|
||||||
|
? cheapestExchange.price
|
||||||
|
: 999999999999
|
||||||
|
)
|
||||||
|
|
||||||
|
if (cheapestPoolPrice < cheapestExchangePrice) {
|
||||||
|
return {
|
||||||
|
type: 'pool',
|
||||||
|
address: cheapestPool?.address,
|
||||||
|
value: cheapestPool?.price
|
||||||
|
} as BestPrice
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
type: 'exchange',
|
||||||
|
address: cheapestExchange?.address,
|
||||||
|
value: cheapestExchange?.price
|
||||||
|
} as BestPrice
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function checkAndBuyDT(
|
export async function checkAndBuyDT(
|
||||||
ocean: Ocean,
|
ocean: Ocean,
|
||||||
dataTokenAddress: string,
|
dataTokenAddress: string,
|
||||||
|
Loading…
Reference in New Issue
Block a user