mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
Update ocean.js (#1013)
* update * merge pr #1012 * fix header * fix * abort controller * up next.8 * build fix * update lock * fix * another fix * ssh fix * another ssh fix * remove optional
This commit is contained in:
parent
409f0c51fb
commit
487bcad8b4
23628
package-lock.json
generated
23628
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -21,7 +21,7 @@
|
|||||||
"@coingecko/cryptoformat": "^0.4.4",
|
"@coingecko/cryptoformat": "^0.4.4",
|
||||||
"@loadable/component": "^5.15.2",
|
"@loadable/component": "^5.15.2",
|
||||||
"@oceanprotocol/art": "^3.2.0",
|
"@oceanprotocol/art": "^3.2.0",
|
||||||
"@oceanprotocol/lib": "^1.0.0-next.6",
|
"@oceanprotocol/lib": "^1.0.0-next.8",
|
||||||
"@oceanprotocol/typographies": "^0.1.0",
|
"@oceanprotocol/typographies": "^0.1.0",
|
||||||
"@portis/web3": "^4.0.6",
|
"@portis/web3": "^4.0.6",
|
||||||
"@tippyjs/react": "^4.2.6",
|
"@tippyjs/react": "^4.2.6",
|
||||||
|
17
src/@hooks/useAbortController.ts
Normal file
17
src/@hooks/useAbortController.ts
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import { useRef, useEffect, useCallback } from 'react'
|
||||||
|
export const useAbortController = (): (() => AbortSignal) => {
|
||||||
|
const axiosSource = useRef(null)
|
||||||
|
const newAbortController = useCallback(() => {
|
||||||
|
axiosSource.current = new AbortController()
|
||||||
|
return axiosSource.current.signal
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
useEffect(
|
||||||
|
() => () => {
|
||||||
|
if (axiosSource.current) axiosSource.current.abort()
|
||||||
|
},
|
||||||
|
[]
|
||||||
|
)
|
||||||
|
|
||||||
|
return newAbortController
|
||||||
|
}
|
@ -1,28 +1,18 @@
|
|||||||
import axios, { CancelToken, AxiosResponse, Method } from 'axios'
|
|
||||||
import {
|
import {
|
||||||
FileMetadata,
|
FileMetadata,
|
||||||
LoggerInstance,
|
LoggerInstance,
|
||||||
ProviderInstance
|
ProviderInstance
|
||||||
} from '@oceanprotocol/lib'
|
} from '@oceanprotocol/lib'
|
||||||
|
|
||||||
|
// TODO: Why do we have these functions ?!?!?!
|
||||||
export async function getEncryptedFiles(
|
export async function getEncryptedFiles(
|
||||||
files: FileMetadata[],
|
files: FileMetadata[],
|
||||||
providerUrl: string
|
providerUrl: string
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
try {
|
try {
|
||||||
// https://github.com/oceanprotocol/provider/blob/v4main/API.md#encrypt-endpoint
|
// https://github.com/oceanprotocol/provider/blob/v4main/API.md#encrypt-endpoint
|
||||||
const response = await ProviderInstance.encrypt(
|
const response = await ProviderInstance.encrypt(files, providerUrl)
|
||||||
files,
|
return response
|
||||||
providerUrl,
|
|
||||||
(httpMethod: Method, url: string, body: string, headers: any) => {
|
|
||||||
return axios(url, {
|
|
||||||
method: httpMethod,
|
|
||||||
data: body,
|
|
||||||
headers: headers
|
|
||||||
})
|
|
||||||
}
|
|
||||||
)
|
|
||||||
return response.data
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error parsing json: ' + error.message)
|
console.error('Error parsing json: ' + error.message)
|
||||||
}
|
}
|
||||||
@ -33,17 +23,7 @@ export async function getFileInfo(
|
|||||||
providerUrl: string
|
providerUrl: string
|
||||||
): Promise<FileMetadata[]> {
|
): Promise<FileMetadata[]> {
|
||||||
try {
|
try {
|
||||||
const response = await ProviderInstance.checkFileUrl(
|
const response = await ProviderInstance.checkFileUrl(url, providerUrl)
|
||||||
url,
|
|
||||||
providerUrl,
|
|
||||||
(method: Method, path: string, body: string) => {
|
|
||||||
return fetch(path, {
|
|
||||||
method: method,
|
|
||||||
body: body,
|
|
||||||
headers: { 'Content-Type': 'application/json' }
|
|
||||||
})
|
|
||||||
}
|
|
||||||
)
|
|
||||||
return response
|
return response
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
LoggerInstance.error(error.message)
|
LoggerInstance.error(error.message)
|
||||||
|
@ -16,7 +16,7 @@ export default function CustomProvider(props: InputProps): ReactElement {
|
|||||||
setIsLoading(true)
|
setIsLoading(true)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const isValid = await ProviderInstance.isValidProvider(url, fetch)
|
const isValid = await ProviderInstance.isValidProvider(url)
|
||||||
helpers.setValue({ url, valid: isValid })
|
helpers.setValue({ url, valid: isValid })
|
||||||
helpers.setError(undefined)
|
helpers.setError(undefined)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
|
approve,
|
||||||
Config,
|
Config,
|
||||||
DDO,
|
DDO,
|
||||||
Erc20CreateParams,
|
Erc20CreateParams,
|
||||||
@ -226,16 +227,16 @@ export async function createTokensAndPricing(
|
|||||||
// TODO: discuss swapFeeLiquidityProvider, swapFeeMarketPlaceRunner
|
// TODO: discuss swapFeeLiquidityProvider, swapFeeMarketPlaceRunner
|
||||||
const poolParams: PoolCreationParams = {
|
const poolParams: PoolCreationParams = {
|
||||||
ssContract: config.sideStakingAddress,
|
ssContract: config.sideStakingAddress,
|
||||||
basetokenAddress: config.oceanTokenAddress,
|
baseTokenAddress: config.oceanTokenAddress,
|
||||||
basetokenSender: config.erc721FactoryAddress,
|
baseTokenSender: config.erc721FactoryAddress,
|
||||||
publisherAddress: accountId,
|
publisherAddress: accountId,
|
||||||
marketFeeCollector: marketFeeAddress,
|
marketFeeCollector: marketFeeAddress,
|
||||||
poolTemplateAddress: config.poolTemplateAddress,
|
poolTemplateAddress: config.poolTemplateAddress,
|
||||||
rate: values.pricing.price.toString(),
|
rate: values.pricing.price.toString(),
|
||||||
basetokenDecimals: 18,
|
baseTokenDecimals: 18,
|
||||||
vestingAmount: '0',
|
vestingAmount: '0',
|
||||||
vestedBlocks: 2726000,
|
vestedBlocks: 2726000,
|
||||||
initialBasetokenLiquidity: values.pricing.amountOcean.toString(),
|
initialBaseTokenLiquidity: values.pricing.amountOcean.toString(),
|
||||||
swapFeeLiquidityProvider: 1e15,
|
swapFeeLiquidityProvider: 1e15,
|
||||||
swapFeeMarketRunner: 1e15
|
swapFeeMarketRunner: 1e15
|
||||||
}
|
}
|
||||||
@ -247,7 +248,8 @@ export async function createTokensAndPricing(
|
|||||||
|
|
||||||
// the spender in this case is the erc721Factory because we are delegating
|
// the spender in this case is the erc721Factory because we are delegating
|
||||||
const pool = new Pool(web3, LoggerInstance)
|
const pool = new Pool(web3, LoggerInstance)
|
||||||
const txApprove = await pool.approve(
|
const txApprove = await approve(
|
||||||
|
web3,
|
||||||
accountId,
|
accountId,
|
||||||
config.oceanTokenAddress,
|
config.oceanTokenAddress,
|
||||||
config.erc721FactoryAddress,
|
config.erc721FactoryAddress,
|
||||||
@ -277,7 +279,7 @@ export async function createTokensAndPricing(
|
|||||||
owner: accountId,
|
owner: accountId,
|
||||||
marketFeeCollector: marketFeeAddress,
|
marketFeeCollector: marketFeeAddress,
|
||||||
baseTokenDecimals: 18,
|
baseTokenDecimals: 18,
|
||||||
dataTokenDecimals: 18,
|
datatokenDecimals: 18,
|
||||||
fixedRate: values.pricing.price.toString(),
|
fixedRate: values.pricing.price.toString(),
|
||||||
marketFee: 1e15,
|
marketFee: 1e15,
|
||||||
withMint: true
|
withMint: true
|
||||||
|
@ -22,10 +22,9 @@ import {
|
|||||||
DDO
|
DDO
|
||||||
} from '@oceanprotocol/lib'
|
} from '@oceanprotocol/lib'
|
||||||
import { useSiteMetadata } from '@hooks/useSiteMetadata'
|
import { useSiteMetadata } from '@hooks/useSiteMetadata'
|
||||||
import axios, { Method } from 'axios'
|
|
||||||
import { useCancelToken } from '@hooks/useCancelToken'
|
|
||||||
import { getOceanConfig } from '@utils/ocean'
|
import { getOceanConfig } from '@utils/ocean'
|
||||||
import { validationSchema } from './_validation'
|
import { validationSchema } from './_validation'
|
||||||
|
import { useAbortController } from '@hooks/useAbortController'
|
||||||
|
|
||||||
// TODO: restore FormikPersist, add back clear form action
|
// TODO: restore FormikPersist, add back clear form action
|
||||||
const formName = 'ocean-publish-form'
|
const formName = 'ocean-publish-form'
|
||||||
@ -41,7 +40,7 @@ export default function PublishPage({
|
|||||||
const scrollToRef = useRef()
|
const scrollToRef = useRef()
|
||||||
const { appConfig } = useSiteMetadata()
|
const { appConfig } = useSiteMetadata()
|
||||||
const nftFactory = useNftFactory()
|
const nftFactory = useNftFactory()
|
||||||
const newCancelToken = useCancelToken()
|
const newAbortController = useAbortController()
|
||||||
|
|
||||||
const [feedback, setFeedback] = useState<PublishFeedback>(
|
const [feedback, setFeedback] = useState<PublishFeedback>(
|
||||||
initialPublishFeedback
|
initialPublishFeedback
|
||||||
@ -137,16 +136,9 @@ export default function PublishPage({
|
|||||||
const encryptedResponse = await ProviderInstance.encrypt(
|
const encryptedResponse = await ProviderInstance.encrypt(
|
||||||
ddo,
|
ddo,
|
||||||
values.services[0].providerUrl.url,
|
values.services[0].providerUrl.url,
|
||||||
(httpMethod: Method, url: string, body: string, headers: any) => {
|
newAbortController()
|
||||||
return axios(url, {
|
|
||||||
method: httpMethod,
|
|
||||||
data: body,
|
|
||||||
headers: headers,
|
|
||||||
cancelToken: newCancelToken()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
const encryptedDdo = encryptedResponse.data
|
const encryptedDdo = encryptedResponse
|
||||||
_encryptedDdo = encryptedDdo
|
_encryptedDdo = encryptedDdo
|
||||||
LoggerInstance.log('[publish] Got encrypted DDO', encryptedDdo)
|
LoggerInstance.log('[publish] Got encrypted DDO', encryptedDdo)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user