1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-12-02 05:57:29 +01:00

Merge branch 'main' into feature/issue-1657-shacl-schema

This commit is contained in:
EnzoVezzaro 2022-09-21 08:49:13 -04:00
commit 5943ff2450
27 changed files with 14273 additions and 24430 deletions

12
.jest/testRender.ts Normal file
View File

@ -0,0 +1,12 @@
import { render } from '@testing-library/react'
import { ReactElement } from 'react'
const testRender = (component: ReactElement): void => {
it('renders without crashing', () => {
const { container } = render(component)
expect(container.firstChild).toBeInTheDocument()
})
}
export default testRender

View File

@ -1,14 +0,0 @@
import initStoryshots from '@storybook/addon-storyshots'
import { render, waitFor } from '@testing-library/react'
// Stories are render-tested with @testing-library/react,
// overwriting default snapshot testing behavior
initStoryshots({
asyncJest: true,
test: async ({ story, done }) => {
const storyElement = story.render()
// render the story with @testing-library/react
render(storyElement)
await waitFor(() => done())
}
})

View File

@ -66,7 +66,7 @@ module.exports = {
// Refers to Coingecko API tokenIds. // Refers to Coingecko API tokenIds.
coingeckoTokenIds: ['ocean-protocol', 'h2o', 'ethereum', 'matic-network'], coingeckoTokenIds: ['ocean-protocol', 'h2o', 'ethereum', 'matic-network'],
// Config for https://github.com/donavon/use-dark-mode // Config for https://github.com/oceanprotocol/use-dark-mode
darkModeConfig: { darkModeConfig: {
classNameDark: 'dark', classNameDark: 'dark',
classNameLight: 'light', classNameLight: 'light',

38486
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -17,7 +17,7 @@
"format": "prettier --ignore-path .gitignore './**/*.{css,yml,js,ts,tsx,json}' --write", "format": "prettier --ignore-path .gitignore './**/*.{css,yml,js,ts,tsx,json}' --write",
"type-check": "tsc --noEmit", "type-check": "tsc --noEmit",
"deploy:s3": "bash scripts/deploy-s3.sh", "deploy:s3": "bash scripts/deploy-s3.sh",
"postinstall": "husky install", "postinstall": "husky install && rm -r node_modules/apollo-language-server/node_modules/graphql",
"codegen:apollo": "apollo client:codegen --endpoint=https://v4.subgraph.ropsten.oceanprotocol.com/subgraphs/name/oceanprotocol/ocean-subgraph --target typescript --tsFileExtension=d.ts --outputFlat src/@types/subgraph/", "codegen:apollo": "apollo client:codegen --endpoint=https://v4.subgraph.ropsten.oceanprotocol.com/subgraphs/name/oceanprotocol/ocean-subgraph --target typescript --tsFileExtension=d.ts --outputFlat src/@types/subgraph/",
"storybook": "cross-env NODE_ENV=test start-storybook -p 6006 --quiet", "storybook": "cross-env NODE_ENV=test start-storybook -p 6006 --quiet",
"storybook:build": "cross-env NODE_ENV=test build-storybook" "storybook:build": "cross-env NODE_ENV=test build-storybook"
@ -26,18 +26,19 @@
"@coingecko/cryptoformat": "^0.5.4", "@coingecko/cryptoformat": "^0.5.4",
"@loadable/component": "^5.15.2", "@loadable/component": "^5.15.2",
"@oceanprotocol/art": "^3.2.0", "@oceanprotocol/art": "^3.2.0",
"@oceanprotocol/lib": "^1.1.6", "@oceanprotocol/lib": "^2.0.2",
"@oceanprotocol/typographies": "^0.1.0", "@oceanprotocol/typographies": "^0.1.0",
"@oceanprotocol/use-dark-mode": "^2.4.3",
"@tippyjs/react": "^4.2.6", "@tippyjs/react": "^4.2.6",
"@urql/exchange-refocus": "^0.2.5", "@urql/exchange-refocus": "^1.0.0",
"@walletconnect/web3-provider": "^1.7.8", "@walletconnect/web3-provider": "^1.8.0",
"axios": "^0.27.2", "axios": "^0.27.2",
"classnames": "^2.3.1", "classnames": "^2.3.2",
"date-fns": "^2.29.1", "date-fns": "^2.29.3",
"decimal.js": "^10.3.1", "decimal.js": "^10.3.1",
"dom-confetti": "^0.2.2", "dom-confetti": "^0.2.2",
"dotenv": "^16.0.1", "dotenv": "^16.0.1",
"filesize": "^9.0.1", "filesize": "^9.0.11",
"formik": "^2.2.9", "formik": "^2.2.9",
"gray-matter": "^4.0.3", "gray-matter": "^4.0.3",
"is-url-superb": "^6.1.0", "is-url-superb": "^6.1.0",
@ -46,7 +47,7 @@
"lodash.debounce": "^4.0.8", "lodash.debounce": "^4.0.8",
"lodash.omit": "^4.5.0", "lodash.omit": "^4.5.0",
"myetherwallet-blockies": "^0.1.1", "myetherwallet-blockies": "^0.1.1",
"next": "^12.1.6", "next": "12.1.6",
"query-string": "^7.1.1", "query-string": "^7.1.1",
"react": "^18.2.0", "react": "^18.2.0",
"react-clipboard.js": "^2.0.16", "react-clipboard.js": "^2.0.16",
@ -64,58 +65,52 @@
"remove-markdown": "^0.5.0", "remove-markdown": "^0.5.0",
"slugify": "^1.6.5", "slugify": "^1.6.5",
"swr": "^1.3.0", "swr": "^1.3.0",
"urql": "^2.2.1", "urql": "^3.0.3",
"use-dark-mode": "^2.3.1", "web3": "^1.8.0",
"web3": "^1.7.4", "web3modal": "^1.9.9",
"web3modal": "^1.9.8",
"yup": "^0.32.11" "yup": "^0.32.11"
}, },
"devDependencies": { "devDependencies": {
"@storybook/addon-essentials": "^6.5.7", "@storybook/addon-essentials": "^6.5.12",
"@storybook/addon-storyshots": "^6.5.9", "@storybook/builder-webpack5": "^6.5.12",
"@storybook/builder-webpack5": "^6.5.9", "@storybook/manager-webpack5": "^6.5.12",
"@storybook/manager-webpack5": "^6.5.7", "@storybook/react": "^6.5.12",
"@storybook/react": "^6.5.7", "@svgr/webpack": "^6.3.1",
"@storybook/testing-library": "^0.0.11", "@testing-library/jest-dom": "^5.16.5",
"@storybook/testing-react": "^1.3.0", "@testing-library/react": "^13.4.0",
"@svgr/webpack": "^6.2.1",
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^13.3.0",
"@types/js-cookie": "^3.0.2", "@types/js-cookie": "^3.0.2",
"@types/loadable__component": "^5.13.4", "@types/loadable__component": "^5.13.4",
"@types/lodash.debounce": "^4.0.7", "@types/lodash.debounce": "^4.0.7",
"@types/lodash.omit": "^4.5.7", "@types/lodash.omit": "^4.5.7",
"@types/node": "^17.0.41", "@types/node": "^18.7.18",
"@types/react": "^18.0.14", "@types/react": "^18.0.14",
"@types/react-dom": "^18.0.5", "@types/react-dom": "^18.0.5",
"@types/react-modal": "^3.13.1", "@types/react-modal": "^3.13.1",
"@types/react-paginate": "^7.1.1", "@types/react-paginate": "^7.1.1",
"@types/remove-markdown": "^0.3.1", "@types/remove-markdown": "^0.3.1",
"@types/yup": "^0.29.14", "@typescript-eslint/eslint-plugin": "^5.38.0",
"@typescript-eslint/eslint-plugin": "^5.31.0", "@typescript-eslint/parser": "^5.38.0",
"@typescript-eslint/parser": "^5.27.1",
"apollo": "^2.34.0", "apollo": "^2.34.0",
"cross-env": "^7.0.3", "cross-env": "^7.0.3",
"eslint": "^8.21.0", "eslint": "^8.23.1",
"eslint-config-oceanprotocol": "^2.0.3", "eslint-config-oceanprotocol": "^2.0.3",
"eslint-config-prettier": "^8.5.0", "eslint-config-prettier": "^8.5.0",
"eslint-plugin-jest-dom": "^4.0.2", "eslint-plugin-jest-dom": "^4.0.2",
"eslint-plugin-prettier": "^4.0.0", "eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-react": "^7.30.0", "eslint-plugin-react": "^7.31.8",
"eslint-plugin-react-hooks": "^4.5.0", "eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-testing-library": "^5.5.1", "eslint-plugin-testing-library": "^5.6.4",
"file-loader": "^6.2.0",
"https-browserify": "^1.0.0", "https-browserify": "^1.0.0",
"husky": "^8.0.1", "husky": "^8.0.1",
"jest": "^28.1.2", "jest": "^29.0.3",
"jest-environment-jsdom": "^28.1.2", "jest-environment-jsdom": "^29.0.3",
"prettier": "^2.6.2", "prettier": "^2.7.1",
"pretty-quick": "^3.1.3", "pretty-quick": "^3.1.3",
"process": "^0.11.10", "process": "^0.11.10",
"serve": "^13.0.2", "serve": "^14.0.1",
"stream-http": "^3.2.0", "stream-http": "^3.2.0",
"tsconfig-paths-webpack-plugin": "^3.5.2", "tsconfig-paths-webpack-plugin": "^4.0.0",
"typescript": "^4.7.3" "typescript": "^4.8.3"
}, },
"repository": { "repository": {
"type": "git", "type": "git",

View File

@ -10,7 +10,7 @@ function useNftFactory(): NftFactory {
useEffect(() => { useEffect(() => {
if (!web3 || !chainId) return if (!web3 || !chainId) return
const config = getOceanConfig(chainId) const config = getOceanConfig(chainId)
const factory = new NftFactory(config?.erc721FactoryAddress, web3) const factory = new NftFactory(config?.nftFactoryAddress, web3)
setNftFactory(factory) setNftFactory(factory)
}, [web3, chainId]) }, [web3, chainId])

View File

@ -23,7 +23,7 @@ import {
const tokensPriceQuery = gql` const tokensPriceQuery = gql`
query TokensPriceQuery($datatokenIds: [ID!], $account: String) { query TokensPriceQuery($datatokenIds: [ID!], $account: String) {
tokens(where: { id_in: $datatokenIds }) { tokens(first: 1000, where: { id_in: $datatokenIds }) {
id id
symbol symbol
name name

View File

@ -9,7 +9,7 @@ export async function setMinterToPublisher(
accountId: string, accountId: string,
setError: (msg: string) => void setError: (msg: string) => void
): Promise<TransactionReceipt> { ): Promise<TransactionReceipt> {
const dispenserInstance = new Dispenser(web3, dispenserAddress) const dispenserInstance = new Dispenser(dispenserAddress, web3)
const status = await dispenserInstance.status(datatokenAddress) const status = await dispenserInstance.status(datatokenAddress)
if (!status?.active) return if (!status?.active) return

View File

@ -25,8 +25,8 @@ export async function getFixedBuyPrice(
const config = getOceanConfig(chainId) const config = getOceanConfig(chainId)
const fixed = new FixedRateExchange(web3, config.fixedRateExchangeAddress) const fixed = new FixedRateExchange(config.fixedRateExchangeAddress, web3)
const estimatedPrice = await fixed.calcBaseInGivenOutDT( const estimatedPrice = await fixed.calcBaseInGivenDatatokensOut(
accessDetails.addressOrId, accessDetails.addressOrId,
'1', '1',
consumeMarketFixedSwapFee consumeMarketFixedSwapFee

View File

@ -171,15 +171,6 @@ export async function setNFTMetadataAndTokenURI(
metadataProofs: [] metadataProofs: []
} }
const estGasSetMetadataAndTokenURI = await nft.estGasSetMetadataAndTokenURI(
asset.nftAddress,
accountId,
metadataAndTokenURI
)
LoggerInstance.log(
'[setNFTMetadataAndTokenURI] est Gas set metadata and token uri --',
estGasSetMetadataAndTokenURI
)
const setMetadataAndTokenURITx = await nft.setMetadataAndTokenURI( const setMetadataAndTokenURITx = await nft.setMetadataAndTokenURI(
asset.nftAddress, asset.nftAddress,
accountId, accountId,

View File

@ -68,6 +68,7 @@ export async function order(
// this assumes all fees are in ocean // this assumes all fees are in ocean
const txApprove = await approve( const txApprove = await approve(
web3, web3,
config,
accountId, accountId,
asset.accessDetails.baseToken.address, asset.accessDetails.baseToken.address,
asset.accessDetails.datatoken.address, asset.accessDetails.datatoken.address,
@ -154,19 +155,21 @@ async function approveProviderFee(
accountId: string, accountId: string,
web3: Web3, web3: Web3,
providerFeeAmount: string providerFeeAmount: string
): Promise<string> { ): Promise<TransactionReceipt> {
const config = getOceanConfig(asset.chainId)
const baseToken = const baseToken =
asset?.accessDetails?.type === 'free' asset?.accessDetails?.type === 'free'
? getOceanConfig(asset.chainId).oceanTokenAddress ? getOceanConfig(asset.chainId).oceanTokenAddress
: asset?.accessDetails?.baseToken?.address : asset?.accessDetails?.baseToken?.address
const txApproveWei = await approveWei( const txApproveWei = await approveWei(
web3, web3,
config,
accountId, accountId,
baseToken, baseToken,
asset?.accessDetails?.datatoken?.address, asset?.accessDetails?.datatoken?.address,
providerFeeAmount providerFeeAmount
) )
return txApproveWei as string // thanks ocean.js return txApproveWei
} }
async function startOrder( async function startOrder(

View File

@ -71,7 +71,7 @@ function checkError(
parsedFieldName: string[], parsedFieldName: string[],
field: FieldInputProps<any> field: FieldInputProps<any>
) { ) {
if (form?.errors === {}) { if (form?.errors && Object.entries(form?.errors).length === 0) {
return false return false
} else if ( } else if (
(form?.touched?.[parsedFieldName[0]]?.[parsedFieldName[1]] && (form?.touched?.[parsedFieldName[0]]?.[parsedFieldName[1]] &&

View File

@ -0,0 +1,7 @@
import React from 'react'
import testRender from '../../../../../.jest/testRender'
import Alert from '@shared/atoms/Alert'
describe('Alert', () => {
testRender(<Alert text="Alert text" state="info" />)
})

View File

@ -0,0 +1,7 @@
import React from 'react'
import testRender from '../../../../../.jest/testRender'
import Badge from '@shared/atoms/Badge'
describe('Badge', () => {
testRender(<Badge label="Badge text" />)
})

View File

@ -0,0 +1,8 @@
import React from 'react'
import testRender from '../../../../../.jest/testRender'
import Blockies from '@shared/atoms/Blockies'
import { Default } from './index.stories'
describe('Blockies', () => {
testRender(<Blockies {...Default.args} />)
})

View File

@ -0,0 +1,8 @@
import React from 'react'
import testRender from '../../../../../.jest/testRender'
import Container from '@shared/atoms/Container'
import { Default } from './index.stories'
describe('Container', () => {
testRender(<Container {...Default.args} />)
})

View File

@ -1,12 +1,13 @@
import React from 'react' import React from 'react'
import { render, act, screen, fireEvent } from '@testing-library/react' import { render, act, screen, fireEvent } from '@testing-library/react'
import { Default } from './index.stories' import { Default } from './index.stories'
import Copy from '.'
jest.useFakeTimers() jest.useFakeTimers()
describe('Copy', () => { describe('Copy', () => {
test('should change class on click', () => { test('should change class on click', () => {
render(<Default {...Default.args} />) render(<Copy {...Default.args} />)
const element = screen.getByTitle('Copy to clipboard') const element = screen.getByTitle('Copy to clipboard')
fireEvent.click(element) fireEvent.click(element)
@ -14,7 +15,7 @@ describe('Copy', () => {
}) })
test('should remove class after timer end', () => { test('should remove class after timer end', () => {
render(<Default {...Default.args} />) render(<Copy {...Default.args} />)
const element = screen.getByTitle('Copy to clipboard') const element = screen.getByTitle('Copy to clipboard')
fireEvent.click(element) fireEvent.click(element)

View File

@ -0,0 +1,8 @@
import React from 'react'
import testRender from '../../../../../.jest/testRender'
import Loader from '@shared/atoms/Loader'
import { Default } from './index.stories'
describe('Loader', () => {
testRender(<Loader {...Default.args} />)
})

View File

@ -0,0 +1,8 @@
import React from 'react'
import testRender from '../../../../../.jest/testRender'
import Logo from '@shared/atoms/Logo'
import { Default } from './index.stories'
describe('Logo', () => {
testRender(<Logo {...Default.args} />)
})

View File

@ -0,0 +1,8 @@
import React from 'react'
import testRender from '../../../../../.jest/testRender'
import Status from '@shared/atoms/Status'
import { Default } from './index.stories'
describe('Status', () => {
testRender(<Status {...Default.args} />)
})

View File

@ -0,0 +1,8 @@
import React from 'react'
import testRender from '../../../../../.jest/testRender'
import Time from '@shared/atoms/Time'
import { Default } from './index.stories'
describe('Time', () => {
testRender(<Time {...Default.args} />)
})

View File

@ -43,8 +43,8 @@ export default function Edit({
const config = getOceanConfig(asset.chainId) const config = getOceanConfig(asset.chainId)
const fixedRateInstance = new FixedRateExchange( const fixedRateInstance = new FixedRateExchange(
web3, config.fixedRateExchangeAddress,
config.fixedRateExchangeAddress web3
) )
const setPriceResp = await fixedRateInstance.setRate( const setPriceResp = await fixedRateInstance.setRate(

View File

@ -1,5 +1,5 @@
import React, { ReactElement, ChangeEvent } from 'react' import React, { ReactElement, ChangeEvent } from 'react'
import { DarkMode } from 'use-dark-mode' import { DarkMode } from '@oceanprotocol/use-dark-mode'
import FormHelp from '@shared/FormInput/Help' import FormHelp from '@shared/FormInput/Help'
import Label from '@shared/FormInput/Label' import Label from '@shared/FormInput/Label'
import Moon from '@images/moon.svg' import Moon from '@images/moon.svg'

View File

@ -5,7 +5,7 @@ import styles from './index.module.css'
import Currency from './Currency' import Currency from './Currency'
import Debug from './Debug' import Debug from './Debug'
import Caret from '@images/caret.svg' import Caret from '@images/caret.svg'
import useDarkMode from 'use-dark-mode' import useDarkMode from '@oceanprotocol/use-dark-mode'
import Appearance from './Appearance' import Appearance from './Appearance'
import TokenApproval from './TokenApproval' import TokenApproval from './TokenApproval'
import { useMarketMetadata } from '@context/MarketMetadata' import { useMarketMetadata } from '@context/MarketMetadata'

View File

@ -48,7 +48,7 @@ export default function Bookmarks(): ReactElement {
const newCancelToken = useCancelToken() const newCancelToken = useCancelToken()
useEffect(() => { useEffect(() => {
if (!appConfig?.metadataCacheUri || bookmarks === []) return if (!appConfig?.metadataCacheUri || bookmarks?.length === 0) return
async function init() { async function init() {
if (!bookmarks?.length) { if (!bookmarks?.length) {

View File

@ -1,9 +1,10 @@
import { import {
Config, Config,
DDO, DDO,
Erc20CreateParams,
FreCreationParams, FreCreationParams,
generateDid, generateDid,
DatatokenCreateParams,
DispenserCreationParams,
getHash, getHash,
LoggerInstance, LoggerInstance,
Metadata, Metadata,
@ -202,7 +203,7 @@ export async function createTokensAndPricing(
LoggerInstance.log('[publish] Creating NFT with metadata', nftCreateData) LoggerInstance.log('[publish] Creating NFT with metadata', nftCreateData)
// TODO: cap is hardcoded for now to 1000, this needs to be discussed at some point // TODO: cap is hardcoded for now to 1000, this needs to be discussed at some point
const ercParams: Erc20CreateParams = { const ercParams: DatatokenCreateParams = {
templateIndex: 2, templateIndex: 2,
minter: accountId, minter: accountId,
paymentCollector: accountId, paymentCollector: accountId,
@ -238,7 +239,7 @@ export async function createTokensAndPricing(
freParams freParams
) )
const result = await nftFactory.createNftErc20WithFixedRate( const result = await nftFactory.createNftWithDatatokenWithFixedRate(
accountId, accountId,
nftCreateData, nftCreateData,
ercParams, ercParams,
@ -257,7 +258,7 @@ export async function createTokensAndPricing(
// maxTokens - how many tokens cand be dispensed when someone requests . If maxTokens=2 then someone can't request 3 in one tx // maxTokens - how many tokens cand be dispensed when someone requests . If maxTokens=2 then someone can't request 3 in one tx
// maxBalance - how many dt the user has in it's wallet before the dispenser will not dispense dt // maxBalance - how many dt the user has in it's wallet before the dispenser will not dispense dt
// both will be just 1 for the market // both will be just 1 for the market
const dispenserParams = { const dispenserParams: DispenserCreationParams = {
dispenserAddress: config.dispenserAddress, dispenserAddress: config.dispenserAddress,
maxTokens: web3.utils.toWei('1'), maxTokens: web3.utils.toWei('1'),
maxBalance: web3.utils.toWei('1'), maxBalance: web3.utils.toWei('1'),
@ -270,7 +271,7 @@ export async function createTokensAndPricing(
dispenserParams dispenserParams
) )
const result = await nftFactory.createNftErc20WithDispenser( const result = await nftFactory.createNftWithDatatokenWithDispenser(
accountId, accountId,
nftCreateData, nftCreateData,
ercParams, ercParams,

View File

@ -29,5 +29,5 @@
"incremental": true "incremental": true
}, },
"exclude": ["node_modules", ".next", "*.js"], "exclude": ["node_modules", ".next", "*.js"],
"include": ["./src/**/*", "./tests/**/*", "./next-env.d.ts", "./content/**/*"] "include": ["./src/**/*", "./.jest/**/*", "./next-env.d.ts", "./content/**/*"]
} }