mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
merge v4
This commit is contained in:
commit
936985a0f8
11
.eslintrc
11
.eslintrc
@ -30,9 +30,16 @@
|
|||||||
"plugin:@typescript-eslint/eslint-recommended",
|
"plugin:@typescript-eslint/eslint-recommended",
|
||||||
"plugin:@typescript-eslint/recommended",
|
"plugin:@typescript-eslint/recommended",
|
||||||
"plugin:prettier/recommended",
|
"plugin:prettier/recommended",
|
||||||
"plugin:react-hooks/recommended"
|
"plugin:react-hooks/recommended",
|
||||||
|
"plugin:testing-library/react",
|
||||||
|
"plugin:jest-dom/recommended"
|
||||||
|
],
|
||||||
|
"plugins": [
|
||||||
|
"@typescript-eslint",
|
||||||
|
"prettier",
|
||||||
|
"testing-library",
|
||||||
|
"jest-dom"
|
||||||
],
|
],
|
||||||
"plugins": ["@typescript-eslint", "prettier"],
|
|
||||||
"rules": {
|
"rules": {
|
||||||
"react/prop-types": "off",
|
"react/prop-types": "off",
|
||||||
"react/no-unused-prop-types": "off",
|
"react/no-unused-prop-types": "off",
|
||||||
|
79
.github/workflows/ci.yml
vendored
79
.github/workflows/ci.yml
vendored
@ -12,14 +12,14 @@ on:
|
|||||||
- '**'
|
- '**'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
build:
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
|
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||||
node: ['16', '14']
|
node: ['16']
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
@ -37,19 +37,80 @@ jobs:
|
|||||||
restore-keys: ${{ runner.os }}-${{ matrix.node }}-build-${{ env.cache-name }}-
|
restore-keys: ${{ runner.os }}-${{ matrix.node }}-build-${{ env.cache-name }}-
|
||||||
|
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
- run: npm run codegen:apollo
|
|
||||||
- run: npm run lint
|
|
||||||
# - run: npm test
|
|
||||||
- run: npm run build
|
- run: npm run build
|
||||||
|
|
||||||
|
test:
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||||
|
node: ['16']
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: actions/setup-node@v2
|
||||||
|
with:
|
||||||
|
node-version: ${{ matrix.node }}
|
||||||
|
|
||||||
|
- name: Cache node_modules
|
||||||
|
uses: actions/cache@v2
|
||||||
|
env:
|
||||||
|
cache-name: cache-node-modules
|
||||||
|
with:
|
||||||
|
path: ~/.npm
|
||||||
|
key: ${{ runner.os }}-${{ matrix.node }}-test-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
|
||||||
|
restore-keys: ${{ runner.os }}-${{ matrix.node }}-test-${{ env.cache-name }}-
|
||||||
|
|
||||||
|
- run: npm ci
|
||||||
|
- run: npm test
|
||||||
|
|
||||||
|
- name: Upload coverage artifact
|
||||||
|
uses: actions/upload-artifact@v2
|
||||||
|
with:
|
||||||
|
name: coverage-${{ runner.os }}
|
||||||
|
path: coverage/
|
||||||
|
|
||||||
# coverage:
|
# coverage:
|
||||||
# runs-on: ubuntu-latest
|
# runs-on: ubuntu-latest
|
||||||
|
# needs: [test]
|
||||||
|
# if: ${{ success() && github.actor != 'dependabot[bot]' }}
|
||||||
# steps:
|
# steps:
|
||||||
# - uses: actions/checkout@v2
|
# - uses: actions/checkout@v2
|
||||||
# - uses: actions/setup-node@v2
|
# - uses: actions/download-artifact@v2
|
||||||
# - run: npm ci
|
# with:
|
||||||
# - uses: paambaati/codeclimate-action@v2.7.5
|
# name: coverage-${{ runner.os }}
|
||||||
|
|
||||||
|
# - uses: paambaati/codeclimate-action@v3.0.0
|
||||||
# env:
|
# env:
|
||||||
# CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
|
# CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
|
||||||
# with:
|
# with:
|
||||||
# coverageCommand: npm test
|
# debug: true
|
||||||
|
|
||||||
|
storybook:
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||||
|
node: ['16']
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: actions/setup-node@v2
|
||||||
|
with:
|
||||||
|
node-version: ${{ matrix.node }}
|
||||||
|
|
||||||
|
- name: Cache node_modules
|
||||||
|
uses: actions/cache@v2
|
||||||
|
env:
|
||||||
|
cache-name: cache-node-modules
|
||||||
|
with:
|
||||||
|
path: ~/.npm
|
||||||
|
key: ${{ runner.os }}-${{ matrix.node }}-storybook-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
|
||||||
|
restore-keys: ${{ runner.os }}-${{ matrix.node }}-storybook-${{ env.cache-name }}-
|
||||||
|
|
||||||
|
- run: npm ci
|
||||||
|
- run: npm run storybook:build
|
||||||
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -15,3 +15,5 @@ src/@types/apollo/
|
|||||||
graphql.schema.json
|
graphql.schema.json
|
||||||
src/@types/graph.types.ts
|
src/@types/graph.types.ts
|
||||||
tsconfig.tsbuildinfo
|
tsconfig.tsbuildinfo
|
||||||
|
__snapshots__
|
||||||
|
storybook-static
|
34
.jest/jest.config.js
Normal file
34
.jest/jest.config.js
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
const nextJest = require('next/jest')
|
||||||
|
|
||||||
|
const createJestConfig = nextJest({
|
||||||
|
// Provide the path to your Next.js app to load next.config.js and .env files in your test environment
|
||||||
|
dir: './'
|
||||||
|
})
|
||||||
|
|
||||||
|
// Add any custom config to be passed to Jest
|
||||||
|
const customJestConfig = {
|
||||||
|
rootDir: '../',
|
||||||
|
// Add more setup options before each test is run
|
||||||
|
setupFilesAfterEnv: ['<rootDir>/.jest/jest.setup.js'],
|
||||||
|
// if using TypeScript with a baseUrl set to the root directory then you need the below for alias' to work
|
||||||
|
moduleDirectories: ['node_modules', '<rootDir>/src'],
|
||||||
|
testEnvironment: 'jest-environment-jsdom',
|
||||||
|
moduleNameMapper: {
|
||||||
|
// '^@/components/(.*)$': '<rootDir>/components/$1',
|
||||||
|
'@shared(.*)$': '<rootDir>/src/components/@shared/$1',
|
||||||
|
'@hooks/(.*)$': '<rootDir>/src/@hooks/$1',
|
||||||
|
'@context/(.*)$': '<rootDir>/src/@context/$1',
|
||||||
|
'@images/(.*)$': '<rootDir>/src/@images/$1',
|
||||||
|
'@utils/(.*)$': '<rootDir>/src/@utils/$1',
|
||||||
|
'@content/(.*)$': '<rootDir>/@content/$1'
|
||||||
|
},
|
||||||
|
collectCoverage: true,
|
||||||
|
collectCoverageFrom: [
|
||||||
|
'src/**/*.{ts,tsx}',
|
||||||
|
'!src/**/*.{stories,test}.{ts,tsx}'
|
||||||
|
],
|
||||||
|
testPathIgnorePatterns: ['node_modules', '\\.cache', '.next', 'coverage']
|
||||||
|
}
|
||||||
|
|
||||||
|
// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
|
||||||
|
module.exports = createJestConfig(customJestConfig)
|
1
.jest/jest.setup.js
Normal file
1
.jest/jest.setup.js
Normal file
@ -0,0 +1 @@
|
|||||||
|
import '@testing-library/jest-dom/extend-expect'
|
47
.storybook/main.js
Normal file
47
.storybook/main.js
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin')
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
core: { builder: 'webpack5' },
|
||||||
|
stories: ['../src/**/*.stories.tsx'],
|
||||||
|
addons: ['@storybook/addon-essentials'],
|
||||||
|
framework: '@storybook/react',
|
||||||
|
webpackFinal: async (config) => {
|
||||||
|
config.resolve.plugins = [
|
||||||
|
...(config.resolve.plugins || []),
|
||||||
|
new TsconfigPathsPlugin({
|
||||||
|
extensions: config.resolve.extensions
|
||||||
|
})
|
||||||
|
]
|
||||||
|
|
||||||
|
// Mimic next.config.js webpack config
|
||||||
|
config.module.rules.push(
|
||||||
|
{
|
||||||
|
test: /\.svg$/,
|
||||||
|
issuer: /\.(tsx|ts)$/,
|
||||||
|
use: [
|
||||||
|
{ loader: require.resolve('@svgr/webpack'), options: { icon: true } }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
test: /\.gif$/,
|
||||||
|
// yay for webpack 5
|
||||||
|
// https://webpack.js.org/guides/asset-management/#loading-images
|
||||||
|
type: 'asset/resource'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
const fallback = config.resolve.fallback || {}
|
||||||
|
Object.assign(fallback, {
|
||||||
|
http: require.resolve('stream-http'),
|
||||||
|
https: require.resolve('https-browserify'),
|
||||||
|
fs: false,
|
||||||
|
crypto: false,
|
||||||
|
os: false,
|
||||||
|
stream: false,
|
||||||
|
assert: false
|
||||||
|
})
|
||||||
|
config.resolve.fallback = fallback
|
||||||
|
|
||||||
|
return config
|
||||||
|
}
|
||||||
|
}
|
19
.storybook/preview.js
Normal file
19
.storybook/preview.js
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import '@oceanprotocol/typographies/css/ocean-typo.css'
|
||||||
|
import '../src/stylesGlobal/styles.css'
|
||||||
|
|
||||||
|
export const parameters = {
|
||||||
|
backgrounds: {
|
||||||
|
default: 'light',
|
||||||
|
values: [
|
||||||
|
{ name: 'dark', value: 'rgb(10, 10, 10)' },
|
||||||
|
{ name: 'light', value: '#fcfcfc' }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
actions: { argTypesRegex: '^on[A-Z].*' },
|
||||||
|
controls: {
|
||||||
|
matchers: {
|
||||||
|
color: /(background|color)$/i,
|
||||||
|
date: /Date$/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
14
.storybook/storyshots.test.tsx
Normal file
14
.storybook/storyshots.test.tsx
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
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())
|
||||||
|
}
|
||||||
|
})
|
66
README.md
66
README.md
@ -19,6 +19,8 @@
|
|||||||
- [3Box](#3box)
|
- [3Box](#3box)
|
||||||
- [Purgatory](#purgatory)
|
- [Purgatory](#purgatory)
|
||||||
- [Network Metadata](#network-metadata)
|
- [Network Metadata](#network-metadata)
|
||||||
|
- [👩🎤 Storybook](#-storybook)
|
||||||
|
- [🤖 Testing](#-testing)
|
||||||
- [✨ Code Style](#-code-style)
|
- [✨ Code Style](#-code-style)
|
||||||
- [🛳 Production](#-production)
|
- [🛳 Production](#-production)
|
||||||
- [⬆️ Deployment](#️-deployment)
|
- [⬆️ Deployment](#️-deployment)
|
||||||
@ -276,18 +278,77 @@ export default function NetworkName(): ReactElement {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## 👩🎤 Storybook
|
||||||
|
|
||||||
|
Storybook helps us build UI components in isolation from our app's business logic, data, and context. That makes it easy to develop hard-to-reach states and save these UI states as stories to revisit during development, testing, or QA.
|
||||||
|
|
||||||
|
To start adding stories, create a `index.stories.tsx` inside the component's folder:
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
src
|
||||||
|
└─── components
|
||||||
|
│ └─── @shared
|
||||||
|
│ └─── <your component>
|
||||||
|
│ │ index.tsx
|
||||||
|
│ │ index.module.css
|
||||||
|
│ │ <b>index.stories.tsx</b>
|
||||||
|
│ │ index.test.tsx
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
Starting up the Storybook server with this command will make it accessible under `http://localhost:6006`:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm run storybook
|
||||||
|
```
|
||||||
|
|
||||||
|
If you want to build a portable static version under `storybook-static/`:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm run storybook:build
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🤖 Testing
|
||||||
|
|
||||||
|
Test runs utilize [Jest](https://jestjs.io/) as test runner and [Testing Library](https://testing-library.com/docs/react-testing-library/intro) for writing tests.
|
||||||
|
|
||||||
|
All created Storybook stories will automatically run as individual tests by using the [StoryShots Addon](https://storybook.js.org/addons/@storybook/addon-storyshots).
|
||||||
|
|
||||||
|
Creating Storybook stories for a component will provide good coverage of a component in many cases. Additional tests for dedicated component functionality which can't be done with Storybook are created as usual [Testing Library](https://testing-library.com/docs/react-testing-library/intro) tests, but you can also [import exisiting Storybook stories](https://storybook.js.org/docs/react/writing-tests/importing-stories-in-tests#example-with-testing-library) into those tests.
|
||||||
|
|
||||||
|
Executing linting, type checking, and full test run:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm test
|
||||||
|
```
|
||||||
|
|
||||||
|
Which is a combination of multiple scripts which can also be run individually:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm run lint
|
||||||
|
npm run type-check
|
||||||
|
npm run jest
|
||||||
|
```
|
||||||
|
|
||||||
|
A coverage report is automatically shown in console whenever `npm run jest` is called. Generated reports are sent to CodeClimate during CI runs.
|
||||||
|
|
||||||
|
During local development you can continously get coverage report feedback in your console by running Jest in watch mode:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm run jest:watch
|
||||||
|
```
|
||||||
|
|
||||||
## ✨ Code Style
|
## ✨ Code Style
|
||||||
|
|
||||||
Code style is automatically enforced through [ESLint](https://eslint.org) & [Prettier](https://prettier.io) rules:
|
Code style is automatically enforced through [ESLint](https://eslint.org) & [Prettier](https://prettier.io) rules:
|
||||||
|
|
||||||
- Git pre-commit hook runs `prettier` on staged files, setup with [Husky](https://typicode.github.io/husky)
|
- Git pre-commit hook runs `prettier` on staged files, setup with [Husky](https://typicode.github.io/husky)
|
||||||
- VS Code suggested extensions and settings for auto-formatting on file save
|
- VS Code suggested extensions and settings for auto-formatting on file save
|
||||||
- CI runs a linting & TypeScript typings check with `npm run lint`, and fails if errors are found
|
- CI runs a linting & TypeScript typings check as part of `npm test`, and fails if errors are found
|
||||||
|
|
||||||
For running linting and auto-formatting manually, you can use from the root of the project:
|
For running linting and auto-formatting manually, you can use from the root of the project:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# linting check, also runs Typescript typings check
|
# linting check
|
||||||
npm run lint
|
npm run lint
|
||||||
|
|
||||||
# auto format all files in the project with prettier, taking all configs into account
|
# auto format all files in the project with prettier, taking all configs into account
|
||||||
@ -300,6 +361,7 @@ To create a production build, run from the root of the project:
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
npm run build
|
npm run build
|
||||||
|
|
||||||
# serve production build
|
# serve production build
|
||||||
npm run serve
|
npm run serve
|
||||||
```
|
```
|
||||||
|
@ -54,8 +54,7 @@
|
|||||||
"titleIn": "You will receive",
|
"titleIn": "You will receive",
|
||||||
"titleOut": "Pool conversion"
|
"titleOut": "Pool conversion"
|
||||||
},
|
},
|
||||||
"action": "Supply",
|
"action": "Supply"
|
||||||
"warning": "Use at your own risk. Please familiarize yourself [with the risks](https://blog.oceanprotocol.com/on-staking-on-data-in-ocean-market-3d8e09eb0a13) and the [Terms of Use](/terms)."
|
|
||||||
},
|
},
|
||||||
"remove": {
|
"remove": {
|
||||||
"title": "Remove Liquidity",
|
"title": "Remove Liquidity",
|
||||||
@ -68,7 +67,6 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"trade": {
|
"trade": {
|
||||||
"action": "Swap",
|
"action": "Swap"
|
||||||
"warning": "Use at your own risk. Please familiarize yourself [with the risks](https://blog.oceanprotocol.com/on-staking-on-data-in-ocean-market-3d8e09eb0a13) and the [Terms of Use](/terms)."
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
46873
package-lock.json
generated
46873
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
67
package.json
67
package.json
@ -9,31 +9,35 @@
|
|||||||
"build": "npm run pregenerate && next build",
|
"build": "npm run pregenerate && next build",
|
||||||
"serve": "serve -s public/",
|
"serve": "serve -s public/",
|
||||||
"pregenerate": "bash scripts/pregenerate.sh",
|
"pregenerate": "bash scripts/pregenerate.sh",
|
||||||
"test": "npm run pregenerate && npm run lint && npm run type-check",
|
"test": "npm run pregenerate && npm run lint && npm run type-check && npm run jest",
|
||||||
|
"jest": "jest -c .jest/jest.config.js",
|
||||||
|
"jest:watch": "jest -c .jest/jest.config.js --watch",
|
||||||
"lint": "eslint --ignore-path .gitignore --ext .js --ext .ts --ext .tsx .",
|
"lint": "eslint --ignore-path .gitignore --ext .js --ext .ts --ext .tsx .",
|
||||||
"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",
|
||||||
"codegen:apollo": "apollo client:codegen --endpoint=https://v4.subgraph.rinkeby.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.rinkeby.oceanprotocol.com/subgraphs/name/oceanprotocol/ocean-subgraph --target typescript --tsFileExtension=d.ts --outputFlat src/@types/subgraph/",
|
||||||
|
"storybook": "start-storybook -p 6006 --quiet",
|
||||||
|
"storybook:build": "build-storybook"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@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.37",
|
"@oceanprotocol/lib": "^1.0.0-next.42",
|
||||||
"@oceanprotocol/typographies": "^0.1.0",
|
"@oceanprotocol/typographies": "^0.1.0",
|
||||||
"@portis/web3": "^4.0.7",
|
"@portis/web3": "^4.0.7",
|
||||||
"@tippyjs/react": "^4.2.6",
|
"@tippyjs/react": "^4.2.6",
|
||||||
"@urql/exchange-refocus": "^0.2.5",
|
"@urql/exchange-refocus": "^0.2.5",
|
||||||
"@walletconnect/web3-provider": "^1.7.7",
|
"@walletconnect/web3-provider": "^1.7.8",
|
||||||
"axios": "^0.26.1",
|
"axios": "^0.27.2",
|
||||||
"chart.js": "^3.7.1",
|
"chart.js": "^3.7.1",
|
||||||
"classnames": "^2.3.1",
|
"classnames": "^2.3.1",
|
||||||
"date-fns": "^2.28.0",
|
"date-fns": "^2.28.0",
|
||||||
"decimal.js": "^10.3.1",
|
"decimal.js": "^10.3.1",
|
||||||
"dom-confetti": "^0.2.2",
|
"dom-confetti": "^0.2.2",
|
||||||
"dotenv": "^16.0.0",
|
"dotenv": "^16.0.1",
|
||||||
"filesize": "^8.0.7",
|
"filesize": "^8.0.7",
|
||||||
"formik": "^2.2.9",
|
"formik": "^2.2.9",
|
||||||
"gray-matter": "^4.0.3",
|
"gray-matter": "^4.0.3",
|
||||||
@ -43,17 +47,17 @@
|
|||||||
"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.5",
|
"next": "^12.1.6",
|
||||||
"query-string": "^7.1.1",
|
"query-string": "^7.1.1",
|
||||||
"react": "^17.0.2",
|
"react": "^18.1.0",
|
||||||
"react-chartjs-2": "^4.1.0",
|
"react-chartjs-2": "^4.1.0",
|
||||||
"react-clipboard.js": "^2.0.16",
|
"react-clipboard.js": "^2.0.16",
|
||||||
"react-data-table-component": "^6.11.7",
|
"react-data-table-component": "^6.11.7",
|
||||||
"react-dom": "^17.0.2",
|
"react-dom": "^18.1.0",
|
||||||
"react-dotdotdot": "^1.3.1",
|
"react-dotdotdot": "^1.3.1",
|
||||||
"react-modal": "^3.14.4",
|
"react-modal": "^3.15.1",
|
||||||
"react-paginate": "^8.1.3",
|
"react-paginate": "^8.1.3",
|
||||||
"react-spring": "^9.4.4",
|
"react-spring": "^9.4.5",
|
||||||
"react-tabs": "^3.2.3",
|
"react-tabs": "^3.2.3",
|
||||||
"react-toastify": "^8.2.0",
|
"react-toastify": "^8.2.0",
|
||||||
"remark": "^13.0.0",
|
"remark": "^13.0.0",
|
||||||
@ -69,7 +73,16 @@
|
|||||||
"yup": "^0.32.11"
|
"yup": "^0.32.11"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@storybook/addon-essentials": "^6.4.22",
|
||||||
|
"@storybook/addon-storyshots": "^6.4.22",
|
||||||
|
"@storybook/builder-webpack5": "^6.4.22",
|
||||||
|
"@storybook/manager-webpack5": "^6.4.22",
|
||||||
|
"@storybook/react": "^6.4.22",
|
||||||
|
"@storybook/testing-library": "^0.0.11",
|
||||||
|
"@storybook/testing-react": "^1.2.4",
|
||||||
"@svgr/webpack": "^6.2.1",
|
"@svgr/webpack": "^6.2.1",
|
||||||
|
"@testing-library/jest-dom": "^5.16.4",
|
||||||
|
"@testing-library/react": "^13.2.0",
|
||||||
"@types/chart.js": "^2.9.37",
|
"@types/chart.js": "^2.9.37",
|
||||||
"@types/d3": "^7.1.0",
|
"@types/d3": "^7.1.0",
|
||||||
"@types/js-cookie": "^3.0.1",
|
"@types/js-cookie": "^3.0.1",
|
||||||
@ -77,31 +90,37 @@
|
|||||||
"@types/lodash.debounce": "^4.0.3",
|
"@types/lodash.debounce": "^4.0.3",
|
||||||
"@types/lodash.omit": "^4.5.6",
|
"@types/lodash.omit": "^4.5.6",
|
||||||
"@types/node": "^17.0.13",
|
"@types/node": "^17.0.13",
|
||||||
"@types/react": "^17.0.38",
|
"@types/react": "^18.0.9",
|
||||||
"@types/react-dom": "^17.0.11",
|
"@types/react-dom": "^18.0.3",
|
||||||
"@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/react-tabs": "^2.3.4",
|
"@types/react-tabs": "^2.3.4",
|
||||||
"@types/remove-markdown": "^0.3.1",
|
"@types/remove-markdown": "^0.3.1",
|
||||||
"@types/yup": "^0.29.11",
|
"@types/yup": "^0.29.13",
|
||||||
"@typescript-eslint/eslint-plugin": "^5.15.0",
|
"@typescript-eslint/eslint-plugin": "^5.23.0",
|
||||||
"@typescript-eslint/parser": "^5.15.0",
|
"@typescript-eslint/parser": "^5.23.0",
|
||||||
"apollo": "^2.33.9",
|
"apollo": "^2.33.9",
|
||||||
"eslint": "^7.27.0",
|
"eslint": "^8.15.0",
|
||||||
"eslint-config-oceanprotocol": "^1.5.0",
|
"eslint-config-oceanprotocol": "^2.0.1",
|
||||||
"eslint-config-prettier": "^8.3.0",
|
"eslint-config-prettier": "^8.5.0",
|
||||||
|
"eslint-plugin-jest-dom": "^4.0.1",
|
||||||
"eslint-plugin-prettier": "^4.0.0",
|
"eslint-plugin-prettier": "^4.0.0",
|
||||||
"eslint-plugin-react": "^7.28.0",
|
"eslint-plugin-react": "^7.29.4",
|
||||||
"eslint-plugin-react-hooks": "^4.3.0",
|
"eslint-plugin-react-hooks": "^4.5.0",
|
||||||
|
"eslint-plugin-testing-library": "^5.4.0",
|
||||||
"file-loader": "^6.2.0",
|
"file-loader": "^6.2.0",
|
||||||
"https-browserify": "^1.0.0",
|
"https-browserify": "^1.0.0",
|
||||||
"husky": "^7.0.4",
|
"husky": "^8.0.1",
|
||||||
"prettier": "^2.6.0",
|
"jest": "^28.1.0",
|
||||||
|
"jest-environment-jsdom": "^28.1.0",
|
||||||
|
"prettier": "^2.6.2",
|
||||||
"pretty-quick": "^3.1.3",
|
"pretty-quick": "^3.1.3",
|
||||||
"process": "^0.11.10",
|
"process": "^0.11.10",
|
||||||
"serve": "^13.0.2",
|
"serve": "^13.0.2",
|
||||||
"stream-http": "^3.2.0",
|
"stream-http": "^3.2.0",
|
||||||
"typescript": "^4.6.3"
|
"ts-jest": "^28.0.2",
|
||||||
|
"tsconfig-paths-webpack-plugin": "^3.5.2",
|
||||||
|
"typescript": "^4.6.4"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
@ -41,6 +41,7 @@ function ConsentProvider({ children }: { children: ReactNode }): ReactElement {
|
|||||||
cookies.optionalCookies?.map((cookie) => {
|
cookies.optionalCookies?.map((cookie) => {
|
||||||
deleteCookie(cookie.cookieName)
|
deleteCookie(cookie.cookieName)
|
||||||
resetCookieConsent[cookie.cookieName] = status
|
resetCookieConsent[cookie.cookieName] = status
|
||||||
|
return status
|
||||||
})
|
})
|
||||||
setConsentStatus(resetCookieConsent)
|
setConsentStatus(resetCookieConsent)
|
||||||
}
|
}
|
||||||
@ -97,12 +98,15 @@ function ConsentProvider({ children }: { children: ReactNode }): ReactElement {
|
|||||||
initialValues[cookie.cookieName] = CookieConsentStatus.NOT_AVAILABLE
|
initialValues[cookie.cookieName] = CookieConsentStatus.NOT_AVAILABLE
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return initialValues
|
||||||
})
|
})
|
||||||
|
|
||||||
setConsentStatus(initialValues)
|
setConsentStatus(initialValues)
|
||||||
}, [cookies.optionalCookies, appConfig])
|
}, [cookies.optionalCookies, appConfig])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
// eslint-disable-next-line array-callback-return
|
||||||
Object.keys(consentStatus).map((cookieName) => {
|
Object.keys(consentStatus).map((cookieName) => {
|
||||||
switch (consentStatus[cookieName]) {
|
switch (consentStatus[cookieName]) {
|
||||||
case CookieConsentStatus.APPROVED:
|
case CookieConsentStatus.APPROVED:
|
||||||
|
@ -16,12 +16,14 @@ export const poolDataQuery = gql`
|
|||||||
baseToken {
|
baseToken {
|
||||||
address
|
address
|
||||||
symbol
|
symbol
|
||||||
|
decimals
|
||||||
}
|
}
|
||||||
baseTokenWeight
|
baseTokenWeight
|
||||||
baseTokenLiquidity
|
baseTokenLiquidity
|
||||||
datatoken {
|
datatoken {
|
||||||
address
|
address
|
||||||
symbol
|
symbol
|
||||||
|
decimals
|
||||||
}
|
}
|
||||||
datatokenWeight
|
datatokenWeight
|
||||||
datatokenLiquidity
|
datatokenLiquidity
|
||||||
@ -43,10 +45,12 @@ export const poolDataQuery = gql`
|
|||||||
baseToken {
|
baseToken {
|
||||||
address
|
address
|
||||||
symbol
|
symbol
|
||||||
|
decimals
|
||||||
}
|
}
|
||||||
datatoken {
|
datatoken {
|
||||||
address
|
address
|
||||||
symbol
|
symbol
|
||||||
|
decimals
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,10 @@ export interface PoolInfo {
|
|||||||
weightDt: string
|
weightDt: string
|
||||||
datatokenSymbol: string
|
datatokenSymbol: string
|
||||||
datatokenAddress: string
|
datatokenAddress: string
|
||||||
|
datatokenDecimals: number
|
||||||
baseTokenSymbol: string
|
baseTokenSymbol: string
|
||||||
baseTokenAddress: string
|
baseTokenAddress: string
|
||||||
|
baseTokenDecimals: number
|
||||||
totalPoolTokens: string
|
totalPoolTokens: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,7 +45,6 @@ function PoolProvider({ children }: { children: ReactNode }): ReactElement {
|
|||||||
)
|
)
|
||||||
const [poolSnapshots, setPoolSnapshots] = useState<PoolDataPoolSnapshots[]>()
|
const [poolSnapshots, setPoolSnapshots] = useState<PoolDataPoolSnapshots[]>()
|
||||||
const [hasUserAddedLiquidity, setUserHasAddedLiquidity] = useState(false)
|
const [hasUserAddedLiquidity, setUserHasAddedLiquidity] = useState(false)
|
||||||
// const [fetchInterval, setFetchInterval] = useState<NodeJS.Timeout>()
|
|
||||||
|
|
||||||
const fetchAllData = useCallback(async () => {
|
const fetchAllData = useCallback(async () => {
|
||||||
if (!asset?.chainId || !asset?.accessDetails?.addressOrId || !owner) return
|
if (!asset?.chainId || !asset?.accessDetails?.addressOrId || !owner) return
|
||||||
@ -56,14 +55,36 @@ function PoolProvider({ children }: { children: ReactNode }): ReactElement {
|
|||||||
owner,
|
owner,
|
||||||
accountId || ''
|
accountId || ''
|
||||||
)
|
)
|
||||||
|
|
||||||
if (!response) return
|
if (!response) return
|
||||||
|
|
||||||
setPoolData(response.poolData)
|
setPoolData(response.poolData)
|
||||||
setPoolInfoUser((prevState) => ({
|
|
||||||
|
// calculate pool info user
|
||||||
|
const poolInfoShares = response.poolDataUser?.shares[0]?.shares || '0'
|
||||||
|
const userLiquidity = calcSingleOutGivenPoolIn(
|
||||||
|
response.poolData.baseTokenLiquidity,
|
||||||
|
response.poolData.totalShares,
|
||||||
|
poolInfoShares
|
||||||
|
)
|
||||||
|
|
||||||
|
// Pool share in %.
|
||||||
|
const poolSharePercentage = new Decimal(poolInfoShares)
|
||||||
|
.dividedBy(new Decimal(response.poolData.totalShares))
|
||||||
|
.mul(100)
|
||||||
|
.toFixed(2)
|
||||||
|
|
||||||
|
setUserHasAddedLiquidity(Number(poolSharePercentage) > 0)
|
||||||
|
|
||||||
|
const newPoolInfoUser: PoolInfoUser = {
|
||||||
|
liquidity: userLiquidity,
|
||||||
|
poolShares: poolInfoShares,
|
||||||
|
poolSharePercentage
|
||||||
|
}
|
||||||
|
setPoolInfoUser((prevState: PoolInfoUser) => ({
|
||||||
...prevState,
|
...prevState,
|
||||||
poolShares: response.poolDataUser?.shares[0]?.shares || '0'
|
...newPoolInfoUser
|
||||||
}))
|
}))
|
||||||
|
|
||||||
setPoolSnapshots(response.poolSnapshots)
|
setPoolSnapshots(response.poolSnapshots)
|
||||||
LoggerInstance.log('[pool] Fetched pool data:', response.poolData)
|
LoggerInstance.log('[pool] Fetched pool data:', response.poolData)
|
||||||
LoggerInstance.log('[pool] Fetched user data:', response.poolDataUser)
|
LoggerInstance.log('[pool] Fetched user data:', response.poolDataUser)
|
||||||
@ -99,8 +120,10 @@ function PoolProvider({ children }: { children: ReactNode }): ReactElement {
|
|||||||
weightDt: getWeight(poolData.datatokenWeight),
|
weightDt: getWeight(poolData.datatokenWeight),
|
||||||
datatokenSymbol: poolData.datatoken.symbol,
|
datatokenSymbol: poolData.datatoken.symbol,
|
||||||
datatokenAddress: poolData.datatoken.address,
|
datatokenAddress: poolData.datatoken.address,
|
||||||
|
datatokenDecimals: poolData.datatoken.decimals,
|
||||||
baseTokenSymbol: poolData.baseToken.symbol,
|
baseTokenSymbol: poolData.baseToken.symbol,
|
||||||
baseTokenAddress: poolData.baseToken.address,
|
baseTokenAddress: poolData.baseToken.address,
|
||||||
|
baseTokenDecimals: poolData.baseToken.decimals,
|
||||||
totalPoolTokens: poolData.totalShares
|
totalPoolTokens: poolData.totalShares
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,54 +168,6 @@ function PoolProvider({ children }: { children: ReactNode }): ReactElement {
|
|||||||
poolInfo?.totalPoolTokens
|
poolInfo?.totalPoolTokens
|
||||||
])
|
])
|
||||||
|
|
||||||
//
|
|
||||||
// 3 User Pool Info
|
|
||||||
//
|
|
||||||
useEffect(() => {
|
|
||||||
if (
|
|
||||||
!poolData ||
|
|
||||||
!poolInfo?.totalPoolTokens ||
|
|
||||||
!poolInfoUser?.poolShares ||
|
|
||||||
!poolData?.baseTokenLiquidity ||
|
|
||||||
!asset?.chainId
|
|
||||||
)
|
|
||||||
return
|
|
||||||
|
|
||||||
const userLiquidity = calcSingleOutGivenPoolIn(
|
|
||||||
poolData.baseTokenLiquidity,
|
|
||||||
poolData.totalShares,
|
|
||||||
poolInfoUser.poolShares
|
|
||||||
)
|
|
||||||
|
|
||||||
// Pool share in %.
|
|
||||||
const poolSharePercentage = new Decimal(poolInfoUser.poolShares)
|
|
||||||
.dividedBy(new Decimal(poolInfo.totalPoolTokens))
|
|
||||||
.mul(100)
|
|
||||||
.toFixed(2)
|
|
||||||
|
|
||||||
setUserHasAddedLiquidity(Number(poolSharePercentage) > 0)
|
|
||||||
|
|
||||||
const newPoolInfoUser: PoolInfoUser = {
|
|
||||||
liquidity: userLiquidity,
|
|
||||||
poolShares: poolInfoUser.poolShares,
|
|
||||||
poolSharePercentage
|
|
||||||
}
|
|
||||||
setPoolInfoUser((prevState: PoolInfoUser) => ({
|
|
||||||
...prevState,
|
|
||||||
...newPoolInfoUser
|
|
||||||
}))
|
|
||||||
|
|
||||||
LoggerInstance.log('[pool] Created new user pool info:', {
|
|
||||||
...newPoolInfoUser
|
|
||||||
})
|
|
||||||
}, [
|
|
||||||
poolData,
|
|
||||||
poolInfoUser?.poolShares,
|
|
||||||
asset?.chainId,
|
|
||||||
owner,
|
|
||||||
poolInfo?.totalPoolTokens
|
|
||||||
])
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PoolContext.Provider
|
<PoolContext.Provider
|
||||||
value={
|
value={
|
||||||
|
@ -129,7 +129,7 @@ function ProfileProvider({
|
|||||||
const [poolSharesInterval, setPoolSharesInterval] = useState<NodeJS.Timeout>()
|
const [poolSharesInterval, setPoolSharesInterval] = useState<NodeJS.Timeout>()
|
||||||
|
|
||||||
const fetchPoolShares = useCallback(
|
const fetchPoolShares = useCallback(
|
||||||
async (accountId, chainIds, isEthAddress) => {
|
async (accountId: string, chainIds: number[], isEthAddress: boolean) => {
|
||||||
if (!accountId || !chainIds || !isEthAddress) return
|
if (!accountId || !chainIds || !isEthAddress) return
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -163,7 +163,7 @@ export async function getAssetsFromDidList(
|
|||||||
if (!(didList.length > 0)) return
|
if (!(didList.length > 0)) return
|
||||||
|
|
||||||
const baseParams = {
|
const baseParams = {
|
||||||
chainIds: chainIds,
|
chainIds,
|
||||||
filters: [getFilterTerm('_id', didList)],
|
filters: [getFilterTerm('_id', didList)],
|
||||||
ignorePurgatory: true
|
ignorePurgatory: true
|
||||||
} as BaseQueryParams
|
} as BaseQueryParams
|
||||||
@ -185,7 +185,7 @@ export async function getAssetsFromDtList(
|
|||||||
if (!(dtList.length > 0)) return
|
if (!(dtList.length > 0)) return
|
||||||
|
|
||||||
const baseParams = {
|
const baseParams = {
|
||||||
chainIds: chainIds,
|
chainIds,
|
||||||
filters: [getFilterTerm('services.datatokenAddress', dtList)],
|
filters: [getFilterTerm('services.datatokenAddress', dtList)],
|
||||||
ignorePurgatory: true
|
ignorePurgatory: true
|
||||||
} as BaseQueryParams
|
} as BaseQueryParams
|
||||||
|
@ -32,7 +32,9 @@ export async function calculateBuyPrice(
|
|||||||
accessDetails.baseToken.address,
|
accessDetails.baseToken.address,
|
||||||
accessDetails.datatoken.address,
|
accessDetails.datatoken.address,
|
||||||
'1',
|
'1',
|
||||||
consumeMarketPoolSwapFee
|
consumeMarketPoolSwapFee,
|
||||||
|
accessDetails.baseToken.decimals,
|
||||||
|
accessDetails.datatoken.decimals
|
||||||
)
|
)
|
||||||
|
|
||||||
return estimatedPrice
|
return estimatedPrice
|
||||||
@ -52,7 +54,8 @@ export async function buyDtFromPool(
|
|||||||
accessDetails.baseToken.address,
|
accessDetails.baseToken.address,
|
||||||
accessDetails.addressOrId,
|
accessDetails.addressOrId,
|
||||||
dtPrice.tokenAmount,
|
dtPrice.tokenAmount,
|
||||||
false
|
false,
|
||||||
|
accessDetails.baseToken.decimals
|
||||||
)
|
)
|
||||||
if (!approveTx) {
|
if (!approveTx) {
|
||||||
return
|
return
|
||||||
@ -63,7 +66,9 @@ export async function buyDtFromPool(
|
|||||||
{
|
{
|
||||||
marketFeeAddress,
|
marketFeeAddress,
|
||||||
tokenIn: accessDetails.baseToken.address,
|
tokenIn: accessDetails.baseToken.address,
|
||||||
tokenOut: accessDetails.datatoken.address
|
tokenOut: accessDetails.datatoken.address,
|
||||||
|
tokenInDecimals: accessDetails.baseToken.decimals,
|
||||||
|
tokenOutDecimals: accessDetails.datatoken.decimals
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// this is just to be safe
|
// this is just to be safe
|
||||||
@ -163,6 +168,7 @@ export function calcSingleOutGivenPoolIn(
|
|||||||
export async function getLiquidityByShares(
|
export async function getLiquidityByShares(
|
||||||
pool: string,
|
pool: string,
|
||||||
tokenAddress: string,
|
tokenAddress: string,
|
||||||
|
tokenDecimals: number,
|
||||||
shares: string,
|
shares: string,
|
||||||
chainId: number
|
chainId: number
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
@ -174,7 +180,9 @@ export async function getLiquidityByShares(
|
|||||||
const amountBaseToken = await poolInstance.calcSingleOutGivenPoolIn(
|
const amountBaseToken = await poolInstance.calcSingleOutGivenPoolIn(
|
||||||
pool,
|
pool,
|
||||||
tokenAddress,
|
tokenAddress,
|
||||||
shares
|
shares,
|
||||||
|
18,
|
||||||
|
tokenDecimals
|
||||||
)
|
)
|
||||||
|
|
||||||
return amountBaseToken
|
return amountBaseToken
|
||||||
|
@ -279,10 +279,7 @@ export async function getPreviousOrders(
|
|||||||
account: string,
|
account: string,
|
||||||
assetTimeout: string
|
assetTimeout: string
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const variables = {
|
const variables = { id, account }
|
||||||
id: id,
|
|
||||||
account: account
|
|
||||||
}
|
|
||||||
const fetchedPreviousOrders: OperationResult<AssetPreviousOrder> =
|
const fetchedPreviousOrders: OperationResult<AssetPreviousOrder> =
|
||||||
await fetchData(PreviousOrderQuery, variables, null)
|
await fetchData(PreviousOrderQuery, variables, null)
|
||||||
if (fetchedPreviousOrders.data?.orders?.length === 0) return null
|
if (fetchedPreviousOrders.data?.orders?.length === 0) return null
|
||||||
@ -347,7 +344,7 @@ export async function getAccountLiquidityInOwnAssets(
|
|||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const queryVariables = {
|
const queryVariables = {
|
||||||
user: accountId.toLowerCase(),
|
user: accountId.toLowerCase(),
|
||||||
pools: pools
|
pools
|
||||||
}
|
}
|
||||||
const results: PoolSharesList[] = await fetchDataForMultipleChains(
|
const results: PoolSharesList[] = await fetchDataForMultipleChains(
|
||||||
UserSharesQuery,
|
UserSharesQuery,
|
||||||
|
10
src/@utils/url.ts
Normal file
10
src/@utils/url.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
export function sanitizeUrl(url: string) {
|
||||||
|
const u = decodeURI(url).trim().toLowerCase()
|
||||||
|
if (
|
||||||
|
u.startsWith('javascript:') ||
|
||||||
|
u.startsWith('data:') ||
|
||||||
|
u.startsWith('vbscript:')
|
||||||
|
)
|
||||||
|
return 'about:blank'
|
||||||
|
return url
|
||||||
|
}
|
@ -26,7 +26,7 @@ export default function AddToken({
|
|||||||
|
|
||||||
const styleClasses = cx({
|
const styleClasses = cx({
|
||||||
button: true,
|
button: true,
|
||||||
minimal: minimal,
|
minimal,
|
||||||
[className]: className
|
[className]: className
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ export default function FileIcon({
|
|||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const styleClasses = cx({
|
const styleClasses = cx({
|
||||||
file: true,
|
file: true,
|
||||||
small: small,
|
small,
|
||||||
[className]: className
|
[className]: className
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ export default function PageHeader({
|
|||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const styleClasses = cx({
|
const styleClasses = cx({
|
||||||
header: true,
|
header: true,
|
||||||
center: center
|
center
|
||||||
})
|
})
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
.alert {
|
.alert {
|
||||||
composes: box from './Box.module.css';
|
composes: box from '../Box.module.css';
|
||||||
max-width: 40rem;
|
max-width: 40rem;
|
||||||
margin: auto;
|
margin: auto;
|
||||||
border-width: 0;
|
border-width: 0;
|
37
src/components/@shared/atoms/Alert/index.stories.tsx
Normal file
37
src/components/@shared/atoms/Alert/index.stories.tsx
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import { ComponentStory, ComponentMeta } from '@storybook/react'
|
||||||
|
|
||||||
|
import Alert, { AlertProps } from '@shared/atoms/Alert'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
title: 'Component/@shared/atoms/Alert',
|
||||||
|
component: Alert
|
||||||
|
} as ComponentMeta<typeof Alert>
|
||||||
|
|
||||||
|
const Template: ComponentStory<typeof Alert> = (args) => <Alert {...args} />
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
args: AlertProps
|
||||||
|
}
|
||||||
|
|
||||||
|
export const Default: Props = Template.bind({})
|
||||||
|
Default.args = {
|
||||||
|
text: 'Alert text',
|
||||||
|
state: 'info',
|
||||||
|
onDismiss: () => console.log('Alert closed!')
|
||||||
|
}
|
||||||
|
|
||||||
|
export const Full: Props = Template.bind({})
|
||||||
|
Full.args = {
|
||||||
|
title: 'Alert',
|
||||||
|
text: 'Alert text',
|
||||||
|
state: 'info',
|
||||||
|
action: {
|
||||||
|
name: 'Action',
|
||||||
|
handleAction: () => null as any
|
||||||
|
},
|
||||||
|
badge: 'Hello',
|
||||||
|
onDismiss: () => {
|
||||||
|
console.log('Alert closed!')
|
||||||
|
}
|
||||||
|
}
|
@ -1,21 +1,13 @@
|
|||||||
import React, { ReactElement, FormEvent } from 'react'
|
import React, { ReactElement, FormEvent } from 'react'
|
||||||
import classNames from 'classnames/bind'
|
import classNames from 'classnames/bind'
|
||||||
import styles from './Alert.module.css'
|
import styles from './index.module.css'
|
||||||
import Button from './Button'
|
import Button from '../Button'
|
||||||
import Markdown from '../Markdown'
|
import Markdown from '../../Markdown'
|
||||||
import Badge from './Badge'
|
import Badge from '../Badge'
|
||||||
|
|
||||||
const cx = classNames.bind(styles)
|
const cx = classNames.bind(styles)
|
||||||
|
|
||||||
export default function Alert({
|
export interface AlertProps {
|
||||||
title,
|
|
||||||
badge,
|
|
||||||
text,
|
|
||||||
state,
|
|
||||||
action,
|
|
||||||
onDismiss,
|
|
||||||
className
|
|
||||||
}: {
|
|
||||||
title?: string
|
title?: string
|
||||||
badge?: string
|
badge?: string
|
||||||
text: string
|
text: string
|
||||||
@ -28,7 +20,17 @@ export default function Alert({
|
|||||||
}
|
}
|
||||||
onDismiss?: () => void
|
onDismiss?: () => void
|
||||||
className?: string
|
className?: string
|
||||||
}): ReactElement {
|
}
|
||||||
|
|
||||||
|
export default function Alert({
|
||||||
|
title,
|
||||||
|
badge,
|
||||||
|
text,
|
||||||
|
state,
|
||||||
|
action,
|
||||||
|
onDismiss,
|
||||||
|
className
|
||||||
|
}: AlertProps): ReactElement {
|
||||||
const styleClasses = cx({
|
const styleClasses = cx({
|
||||||
alert: true,
|
alert: true,
|
||||||
[state]: state,
|
[state]: state,
|
47
src/components/@shared/atoms/Button/index.stories.tsx
Normal file
47
src/components/@shared/atoms/Button/index.stories.tsx
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import { ComponentStory, ComponentMeta } from '@storybook/react'
|
||||||
|
import Button, { ButtonProps } from '@shared/atoms/Button'
|
||||||
|
|
||||||
|
// More on default export: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
|
||||||
|
export default {
|
||||||
|
title: 'Component/@shared/atoms/Button',
|
||||||
|
component: Button
|
||||||
|
} as ComponentMeta<typeof Button>
|
||||||
|
|
||||||
|
// More on component templates: https://storybook.js.org/docs/react/writing-stories/introduction#using-args
|
||||||
|
const Template: ComponentStory<typeof Button> = (args: ButtonProps) => (
|
||||||
|
<Button {...args} />
|
||||||
|
)
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
args: ButtonProps
|
||||||
|
}
|
||||||
|
|
||||||
|
export const Default: Props = Template.bind({})
|
||||||
|
// More on args: https://storybook.js.org/docs/react/writing-stories/args
|
||||||
|
Default.args = {
|
||||||
|
children: 'Button',
|
||||||
|
onClick: () => {
|
||||||
|
console.log('Button pressed!')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const Primary: Props = Template.bind({})
|
||||||
|
// More on args: https://storybook.js.org/docs/react/writing-stories/args
|
||||||
|
Primary.args = {
|
||||||
|
children: 'Button',
|
||||||
|
style: 'primary',
|
||||||
|
onClick: () => {
|
||||||
|
console.log('Button pressed!')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const Small: Props = Template.bind({})
|
||||||
|
// More on args: https://storybook.js.org/docs/react/writing-stories/args
|
||||||
|
Small.args = {
|
||||||
|
children: 'Button',
|
||||||
|
size: 'small',
|
||||||
|
onClick: () => {
|
||||||
|
console.log('Button pressed!')
|
||||||
|
}
|
||||||
|
}
|
25
src/components/@shared/atoms/Button/index.test.tsx
Normal file
25
src/components/@shared/atoms/Button/index.test.tsx
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import { render, screen } from '@testing-library/react'
|
||||||
|
import Button from './'
|
||||||
|
|
||||||
|
test('returns correct markup when href or to is passed', async () => {
|
||||||
|
const { rerender } = render(
|
||||||
|
<Button href="https://oceanprotocol.com">Hello Button</Button>
|
||||||
|
)
|
||||||
|
|
||||||
|
let button = screen.getByText('Hello Button')
|
||||||
|
expect(button).toHaveAttribute('href', 'https://oceanprotocol.com')
|
||||||
|
expect(button).toContainHTML('<a')
|
||||||
|
|
||||||
|
rerender(<Button to="/publish">Hello Button</Button>)
|
||||||
|
button = screen.getByText('Hello Button')
|
||||||
|
expect(button).toHaveAttribute('href', '/publish')
|
||||||
|
expect(button).toContainHTML('<a')
|
||||||
|
})
|
||||||
|
|
||||||
|
test('returns correct markup when no href or to is passed', async () => {
|
||||||
|
render(<Button>Hello Button</Button>)
|
||||||
|
|
||||||
|
const button = screen.getByText('Hello Button')
|
||||||
|
expect(button).toContainHTML('<button')
|
||||||
|
})
|
@ -1,7 +1,7 @@
|
|||||||
import React, { ReactNode, FormEvent, ReactElement } from 'react'
|
import React, { ReactNode, FormEvent, ReactElement } from 'react'
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
import classNames from 'classnames/bind'
|
import classNames from 'classnames/bind'
|
||||||
import styles from './Button.module.css'
|
import styles from './index.module.css'
|
||||||
|
|
||||||
const cx = classNames.bind(styles)
|
const cx = classNames.bind(styles)
|
||||||
|
|
@ -15,7 +15,7 @@ export default function Container({
|
|||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const styleClasses = cx({
|
const styleClasses = cx({
|
||||||
container: true,
|
container: true,
|
||||||
narrow: narrow,
|
narrow,
|
||||||
[className]: className
|
[className]: className
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
import React, { ReactElement, useEffect, useState } from 'react'
|
import React, { ReactElement, useEffect, useState } from 'react'
|
||||||
import loadable from '@loadable/component'
|
|
||||||
import styles from './Copy.module.css'
|
import styles from './Copy.module.css'
|
||||||
import IconCopy from '@images/copy.svg'
|
import IconCopy from '@images/copy.svg'
|
||||||
|
import Clipboard from 'react-clipboard.js'
|
||||||
// lazy load when needed only, as library is a bit big
|
|
||||||
const Clipboard = loadable(() => import('react-clipboard.js'))
|
|
||||||
|
|
||||||
export default function Copy({ text }: { text: string }): ReactElement {
|
export default function Copy({ text }: { text: string }): ReactElement {
|
||||||
const [isCopied, setIsCopied] = useState(false)
|
const [isCopied, setIsCopied] = useState(false)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import React, { ReactElement } from 'react'
|
import React, { ReactElement, ReactNode } from 'react'
|
||||||
import DataTable, { IDataTableProps } from 'react-data-table-component'
|
import DataTable, { IDataTableProps } from 'react-data-table-component'
|
||||||
import Loader from './Loader'
|
import Loader from './Loader'
|
||||||
import Pagination from '@shared/Pagination'
|
import Pagination from '@shared/Pagination'
|
||||||
@ -47,7 +47,7 @@ export default function Table({
|
|||||||
noDataComponent={<Empty message={emptyMessage} />}
|
noDataComponent={<Empty message={emptyMessage} />}
|
||||||
progressPending={isLoading}
|
progressPending={isLoading}
|
||||||
progressComponent={<Loader />}
|
progressComponent={<Loader />}
|
||||||
paginationComponent={Pagination}
|
paginationComponent={Pagination as unknown as ReactNode}
|
||||||
defaultSortField={sortField}
|
defaultSortField={sortField}
|
||||||
defaultSortAsc={sortAsc}
|
defaultSortAsc={sortAsc}
|
||||||
{...props}
|
{...props}
|
||||||
|
@ -49,7 +49,9 @@ export default function FormAdd({
|
|||||||
const poolTokens = await poolInstance.calcPoolOutGivenSingleIn(
|
const poolTokens = await poolInstance.calcPoolOutGivenSingleIn(
|
||||||
poolData.id,
|
poolData.id,
|
||||||
poolInfo.baseTokenAddress,
|
poolInfo.baseTokenAddress,
|
||||||
values.amount.toString()
|
values.amount.toString(),
|
||||||
|
18,
|
||||||
|
poolInfo.baseTokenDecimals
|
||||||
)
|
)
|
||||||
setNewPoolTokens(poolTokens)
|
setNewPoolTokens(poolTokens)
|
||||||
const newPoolShareDecimal =
|
const newPoolShareDecimal =
|
||||||
@ -68,6 +70,7 @@ export default function FormAdd({
|
|||||||
calculatePoolShares()
|
calculatePoolShares()
|
||||||
}, [
|
}, [
|
||||||
poolInfo?.baseTokenAddress,
|
poolInfo?.baseTokenAddress,
|
||||||
|
poolInfo?.baseTokenDecimals,
|
||||||
web3,
|
web3,
|
||||||
values.amount,
|
values.amount,
|
||||||
poolInfo?.totalPoolTokens,
|
poolInfo?.totalPoolTokens,
|
||||||
|
@ -40,7 +40,6 @@ export default function Add({
|
|||||||
const [amountMax, setAmountMax] = useState<string>()
|
const [amountMax, setAmountMax] = useState<string>()
|
||||||
const [newPoolTokens, setNewPoolTokens] = useState('0')
|
const [newPoolTokens, setNewPoolTokens] = useState('0')
|
||||||
const [newPoolShare, setNewPoolShare] = useState('0')
|
const [newPoolShare, setNewPoolShare] = useState('0')
|
||||||
const [isWarningAccepted, setIsWarningAccepted] = useState(false)
|
|
||||||
|
|
||||||
// Live validation rules
|
// Live validation rules
|
||||||
// https://github.com/jquense/yup#number
|
// https://github.com/jquense/yup#number
|
||||||
@ -77,7 +76,8 @@ export default function Add({
|
|||||||
|
|
||||||
const poolReserve = await poolInstance.getReserve(
|
const poolReserve = await poolInstance.getReserve(
|
||||||
poolData.id,
|
poolData.id,
|
||||||
poolInfo.baseTokenAddress
|
poolInfo.baseTokenAddress,
|
||||||
|
poolInfo.baseTokenDecimals
|
||||||
)
|
)
|
||||||
|
|
||||||
const amountMaxPool = calcMaxExactIn(poolReserve)
|
const amountMaxPool = calcMaxExactIn(poolReserve)
|
||||||
@ -97,6 +97,7 @@ export default function Add({
|
|||||||
isAssetNetwork,
|
isAssetNetwork,
|
||||||
poolData?.id,
|
poolData?.id,
|
||||||
poolInfo?.baseTokenAddress,
|
poolInfo?.baseTokenAddress,
|
||||||
|
poolInfo?.baseTokenDecimals,
|
||||||
balance?.ocean
|
balance?.ocean
|
||||||
])
|
])
|
||||||
|
|
||||||
@ -141,37 +142,17 @@ export default function Add({
|
|||||||
{({ isSubmitting, setSubmitting, submitForm, values, isValid }) => (
|
{({ isSubmitting, setSubmitting, submitForm, values, isValid }) => (
|
||||||
<>
|
<>
|
||||||
<div className={styles.addInput}>
|
<div className={styles.addInput}>
|
||||||
{isWarningAccepted ? (
|
<FormAdd
|
||||||
<FormAdd
|
amountMax={amountMax}
|
||||||
amountMax={amountMax}
|
setNewPoolTokens={setNewPoolTokens}
|
||||||
setNewPoolTokens={setNewPoolTokens}
|
setNewPoolShare={setNewPoolShare}
|
||||||
setNewPoolShare={setNewPoolShare}
|
/>
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
content.pool.add.warning && (
|
|
||||||
<Alert
|
|
||||||
className={styles.warning}
|
|
||||||
text={content.pool.add.warning.toString()}
|
|
||||||
state="info"
|
|
||||||
action={{
|
|
||||||
name: 'I understand',
|
|
||||||
style: 'text',
|
|
||||||
handleAction: () => setIsWarningAccepted(true)
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Output newPoolTokens={newPoolTokens} newPoolShare={newPoolShare} />
|
<Output newPoolTokens={newPoolTokens} newPoolShare={newPoolShare} />
|
||||||
|
|
||||||
<Actions
|
<Actions
|
||||||
isDisabled={
|
isDisabled={!isValid || !values.amount || values.amount === 0}
|
||||||
!isValid ||
|
|
||||||
!isWarningAccepted ||
|
|
||||||
!values.amount ||
|
|
||||||
values.amount === 0
|
|
||||||
}
|
|
||||||
isLoading={isSubmitting}
|
isLoading={isSubmitting}
|
||||||
loaderMessage="Adding Liquidity..."
|
loaderMessage="Adding Liquidity..."
|
||||||
successMessage="Successfully added liquidity."
|
successMessage="Successfully added liquidity."
|
||||||
|
@ -40,10 +40,14 @@ export default function Remove({
|
|||||||
const [amountOcean, setAmountOcean] = useState('0')
|
const [amountOcean, setAmountOcean] = useState('0')
|
||||||
const [isLoading, setIsLoading] = useState<boolean>()
|
const [isLoading, setIsLoading] = useState<boolean>()
|
||||||
const [txId, setTxId] = useState<string>()
|
const [txId, setTxId] = useState<string>()
|
||||||
const [slippage, setSlippage] = useState<string>('5')
|
const [slippage, setSlippage] = useState(slippagePresets[0])
|
||||||
const [minOceanAmount, setMinOceanAmount] = useState<string>('0')
|
const [minOceanAmount, setMinOceanAmount] = useState<string>('0')
|
||||||
|
const [poolInstance, setPoolInstance] = useState<Pool>()
|
||||||
|
|
||||||
const poolInstance = new Pool(web3)
|
useEffect(() => {
|
||||||
|
if (!web3) return
|
||||||
|
setPoolInstance(new Pool(web3))
|
||||||
|
}, [web3])
|
||||||
|
|
||||||
async function handleRemoveLiquidity() {
|
async function handleRemoveLiquidity() {
|
||||||
setIsLoading(true)
|
setIsLoading(true)
|
||||||
@ -74,28 +78,21 @@ export default function Remove({
|
|||||||
// Calculate and set maximum shares user is able to remove
|
// Calculate and set maximum shares user is able to remove
|
||||||
//
|
//
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!accountId || !poolInfoUser?.poolShares || !poolInfo?.totalPoolTokens)
|
if (!accountId || !poolInfoUser || !poolInfo || !poolInstance) return
|
||||||
return
|
|
||||||
|
|
||||||
getMax(poolInstance, poolInfo, poolInfoUser, poolData).then((max) =>
|
getMax(poolInstance, poolInfo, poolInfoUser, poolData).then((max) =>
|
||||||
setAmountMaxPercent(max)
|
setAmountMaxPercent(max)
|
||||||
)
|
)
|
||||||
}, [
|
}, [accountId, poolInfoUser, poolInfo, poolInstance, poolData])
|
||||||
accountId,
|
|
||||||
poolInfoUser?.poolShares,
|
|
||||||
poolInfo?.totalPoolTokens,
|
|
||||||
poolInfoUser,
|
|
||||||
poolInfo,
|
|
||||||
poolInstance,
|
|
||||||
poolData
|
|
||||||
])
|
|
||||||
|
|
||||||
const getValues = useRef(
|
const getValues = useRef(
|
||||||
debounce(async (newAmountPoolShares) => {
|
debounce(async (poolInstance, id, poolInfo, newAmountPoolShares) => {
|
||||||
const newAmountOcean = await poolInstance.calcSingleOutGivenPoolIn(
|
const newAmountOcean = await poolInstance.calcSingleOutGivenPoolIn(
|
||||||
poolData?.id,
|
id,
|
||||||
poolInfo?.baseTokenAddress,
|
poolInfo.baseTokenAddress,
|
||||||
newAmountPoolShares
|
newAmountPoolShares,
|
||||||
|
18,
|
||||||
|
poolInfo.baseTokenDecimals
|
||||||
)
|
)
|
||||||
setAmountOcean(newAmountOcean)
|
setAmountOcean(newAmountOcean)
|
||||||
}, 150)
|
}, 150)
|
||||||
@ -103,21 +100,9 @@ export default function Remove({
|
|||||||
|
|
||||||
// Check and set outputs when amountPoolShares changes
|
// Check and set outputs when amountPoolShares changes
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (
|
if (!accountId || !poolInfo || !poolData?.id || !poolInstance) return
|
||||||
!accountId ||
|
getValues.current(poolInstance, poolData?.id, poolInfo, amountPoolShares)
|
||||||
!poolInfoUser?.poolShares ||
|
}, [amountPoolShares, accountId, poolInfo, poolData?.id, poolInstance])
|
||||||
!poolInfo?.totalPoolTokens ||
|
|
||||||
!poolData?.id
|
|
||||||
)
|
|
||||||
return
|
|
||||||
getValues.current(amountPoolShares)
|
|
||||||
}, [
|
|
||||||
amountPoolShares,
|
|
||||||
accountId,
|
|
||||||
poolInfoUser?.poolShares,
|
|
||||||
poolData?.id,
|
|
||||||
poolInfo?.totalPoolTokens
|
|
||||||
])
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!amountOcean || amountPercent === '0') {
|
if (!amountOcean || amountPercent === '0') {
|
||||||
|
@ -41,7 +41,6 @@ export default function FormTrade({
|
|||||||
const [coinFrom, setCoinFrom] = useState<string>('OCEAN')
|
const [coinFrom, setCoinFrom] = useState<string>('OCEAN')
|
||||||
const [maximumBaseToken, setMaximumBaseToken] = useState('0')
|
const [maximumBaseToken, setMaximumBaseToken] = useState('0')
|
||||||
const [maximumDt, setMaximumDt] = useState('0')
|
const [maximumDt, setMaximumDt] = useState('0')
|
||||||
const [isWarningAccepted, setIsWarningAccepted] = useState(false)
|
|
||||||
|
|
||||||
const validationSchema: Yup.SchemaOf<FormTradeData> = Yup.object()
|
const validationSchema: Yup.SchemaOf<FormTradeData> = Yup.object()
|
||||||
.shape({
|
.shape({
|
||||||
@ -82,7 +81,15 @@ export default function FormTrade({
|
|||||||
values.type === 'sell'
|
values.type === 'sell'
|
||||||
? poolInfo.baseTokenAddress
|
? poolInfo.baseTokenAddress
|
||||||
: poolInfo.datatokenAddress,
|
: poolInfo.datatokenAddress,
|
||||||
marketFeeAddress: appConfig.marketFeeAddress
|
marketFeeAddress: appConfig.marketFeeAddress,
|
||||||
|
tokenInDecimals:
|
||||||
|
values.type === 'sell'
|
||||||
|
? poolInfo.datatokenDecimals
|
||||||
|
: poolInfo.baseTokenDecimals,
|
||||||
|
tokenOutDecimals:
|
||||||
|
values.type === 'sell'
|
||||||
|
? poolInfo.baseTokenDecimals
|
||||||
|
: poolInfo.datatokenDecimals
|
||||||
}
|
}
|
||||||
|
|
||||||
const amountsInOutMaxFee: AmountsInMaxFee = {
|
const amountsInOutMaxFee: AmountsInMaxFee = {
|
||||||
@ -120,7 +127,15 @@ export default function FormTrade({
|
|||||||
values.type === 'sell'
|
values.type === 'sell'
|
||||||
? poolInfo.baseTokenAddress
|
? poolInfo.baseTokenAddress
|
||||||
: poolInfo.datatokenAddress,
|
: poolInfo.datatokenAddress,
|
||||||
marketFeeAddress: appConfig.marketFeeAddress
|
marketFeeAddress: appConfig.marketFeeAddress,
|
||||||
|
tokenInDecimals:
|
||||||
|
values.type === 'sell'
|
||||||
|
? poolInfo.datatokenDecimals
|
||||||
|
: poolInfo.baseTokenDecimals,
|
||||||
|
tokenOutDecimals:
|
||||||
|
values.type === 'sell'
|
||||||
|
? poolInfo.baseTokenDecimals
|
||||||
|
: poolInfo.datatokenDecimals
|
||||||
}
|
}
|
||||||
|
|
||||||
const amountsOutMaxFee: AmountsOutMaxFee = {
|
const amountsOutMaxFee: AmountsOutMaxFee = {
|
||||||
@ -169,32 +184,17 @@ export default function FormTrade({
|
|||||||
>
|
>
|
||||||
{({ isSubmitting, setSubmitting, submitForm, values, isValid }) => (
|
{({ isSubmitting, setSubmitting, submitForm, values, isValid }) => (
|
||||||
<>
|
<>
|
||||||
{isWarningAccepted ? (
|
<Swap
|
||||||
<Swap
|
asset={asset}
|
||||||
asset={asset}
|
balance={balance}
|
||||||
balance={balance}
|
setCoin={setCoinFrom}
|
||||||
setCoin={setCoinFrom}
|
setMaximumBaseToken={setMaximumBaseToken}
|
||||||
setMaximumBaseToken={setMaximumBaseToken}
|
setMaximumDt={setMaximumDt}
|
||||||
setMaximumDt={setMaximumDt}
|
isLoading={isSubmitting}
|
||||||
isLoading={isSubmitting}
|
/>
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<div className={styles.alertWrap}>
|
|
||||||
<Alert
|
|
||||||
text={content.trade.warning}
|
|
||||||
state="info"
|
|
||||||
action={{
|
|
||||||
name: 'I understand',
|
|
||||||
style: 'text',
|
|
||||||
handleAction: () => setIsWarningAccepted(true)
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
<Actions
|
<Actions
|
||||||
isDisabled={
|
isDisabled={
|
||||||
!isValid ||
|
!isValid ||
|
||||||
!isWarningAccepted ||
|
|
||||||
!isAssetNetwork ||
|
!isAssetNetwork ||
|
||||||
values.datatoken === undefined ||
|
values.datatoken === undefined ||
|
||||||
values.baseToken === undefined
|
values.baseToken === undefined
|
||||||
|
@ -78,11 +78,13 @@ export default function Swap({
|
|||||||
async function calculateMaximum() {
|
async function calculateMaximum() {
|
||||||
const datatokenLiquidity = await poolInstance.getReserve(
|
const datatokenLiquidity = await poolInstance.getReserve(
|
||||||
poolData.id,
|
poolData.id,
|
||||||
poolData.datatoken.address
|
poolData.datatoken.address,
|
||||||
|
poolData.datatoken.decimals
|
||||||
)
|
)
|
||||||
const baseTokenLiquidity = await poolInstance.getReserve(
|
const baseTokenLiquidity = await poolInstance.getReserve(
|
||||||
poolData.id,
|
poolData.id,
|
||||||
poolData.baseToken.address
|
poolData.baseToken.address,
|
||||||
|
poolData.baseToken.decimals
|
||||||
)
|
)
|
||||||
if (values.type === 'buy') {
|
if (values.type === 'buy') {
|
||||||
const maxBaseTokenFromPool = calcMaxExactIn(baseTokenLiquidity)
|
const maxBaseTokenFromPool = calcMaxExactIn(baseTokenLiquidity)
|
||||||
@ -98,7 +100,9 @@ export default function Swap({
|
|||||||
poolInfo.baseTokenAddress,
|
poolInfo.baseTokenAddress,
|
||||||
poolInfo.datatokenAddress,
|
poolInfo.datatokenAddress,
|
||||||
maxBaseTokens.toString(),
|
maxBaseTokens.toString(),
|
||||||
appConfig.consumeMarketPoolSwapFee
|
appConfig.consumeMarketPoolSwapFee,
|
||||||
|
poolInfo.baseTokenDecimals,
|
||||||
|
poolInfo.datatokenDecimals
|
||||||
)
|
)
|
||||||
const maximumDt = new Decimal(maxDt.tokenAmount)
|
const maximumDt = new Decimal(maxDt.tokenAmount)
|
||||||
.toDecimalPlaces(MAX_DECIMALS)
|
.toDecimalPlaces(MAX_DECIMALS)
|
||||||
@ -130,7 +134,9 @@ export default function Swap({
|
|||||||
poolInfo?.datatokenAddress,
|
poolInfo?.datatokenAddress,
|
||||||
poolInfo?.baseTokenAddress,
|
poolInfo?.baseTokenAddress,
|
||||||
maxDatatokens.toString(),
|
maxDatatokens.toString(),
|
||||||
appConfig.consumeMarketPoolSwapFee
|
appConfig.consumeMarketPoolSwapFee,
|
||||||
|
poolInfo.datatokenDecimals,
|
||||||
|
poolInfo.baseTokenDecimals
|
||||||
)
|
)
|
||||||
const maximumBasetokens = new Decimal(maxBaseTokens.tokenAmount)
|
const maximumBasetokens = new Decimal(maxBaseTokens.tokenAmount)
|
||||||
.toDecimalPlaces(MAX_DECIMALS)
|
.toDecimalPlaces(MAX_DECIMALS)
|
||||||
|
@ -9,7 +9,8 @@ export default function MetaFull({ ddo }: { ddo: Asset }): ReactElement {
|
|||||||
const { isInPurgatory } = useAsset()
|
const { isInPurgatory } = useAsset()
|
||||||
|
|
||||||
function DockerImage() {
|
function DockerImage() {
|
||||||
const { image, tag } = ddo?.metadata?.algorithm?.container
|
const containerInfo = ddo?.metadata?.algorithm?.container
|
||||||
|
const { image, tag } = containerInfo
|
||||||
return <span>{`${image}:${tag}`}</span>
|
return <span>{`${image}:${tag}`}</span>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ import React, { ReactElement } from 'react'
|
|||||||
import DebugOutput from '@shared/DebugOutput'
|
import DebugOutput from '@shared/DebugOutput'
|
||||||
import { MetadataEditForm } from './_types'
|
import { MetadataEditForm } from './_types'
|
||||||
import { mapTimeoutStringToSeconds } from '@utils/ddo'
|
import { mapTimeoutStringToSeconds } from '@utils/ddo'
|
||||||
|
import { sanitizeUrl } from '@utils/url'
|
||||||
|
|
||||||
export default function DebugEditMetadata({
|
export default function DebugEditMetadata({
|
||||||
values,
|
values,
|
||||||
@ -12,7 +13,8 @@ export default function DebugEditMetadata({
|
|||||||
asset: Asset
|
asset: Asset
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const linksTransformed = values.links?.length &&
|
const linksTransformed = values.links?.length &&
|
||||||
values.links[0].valid && [values.links[0].url.replace('javascript:', '')]
|
values.links[0].valid && [sanitizeUrl(values.links[0].url)]
|
||||||
|
|
||||||
const newMetadata: Metadata = {
|
const newMetadata: Metadata = {
|
||||||
...asset?.metadata,
|
...asset?.metadata,
|
||||||
name: values.name,
|
name: values.name,
|
||||||
|
@ -23,6 +23,7 @@ import { getOceanConfig } from '@utils/ocean'
|
|||||||
import EditFeedback from './EditFeedback'
|
import EditFeedback from './EditFeedback'
|
||||||
import { useAsset } from '@context/Asset'
|
import { useAsset } from '@context/Asset'
|
||||||
import { setNftMetadata } from '@utils/nft'
|
import { setNftMetadata } from '@utils/nft'
|
||||||
|
import { sanitizeUrl } from '@utils/url'
|
||||||
|
|
||||||
export default function Edit({
|
export default function Edit({
|
||||||
asset
|
asset
|
||||||
@ -64,9 +65,7 @@ export default function Edit({
|
|||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
const linksTransformed = values.links?.length &&
|
const linksTransformed = values.links?.length &&
|
||||||
values.links[0].valid && [
|
values.links[0].valid && [sanitizeUrl(values.links[0].url)]
|
||||||
values.links[0].url.replace('javascript:', '')
|
|
||||||
]
|
|
||||||
const updatedMetadata: Metadata = {
|
const updatedMetadata: Metadata = {
|
||||||
...asset.metadata,
|
...asset.metadata,
|
||||||
name: values.name,
|
name: values.name,
|
||||||
|
@ -33,7 +33,7 @@ export default function FormEditComputeDataset({
|
|||||||
const { publisherTrustedAlgorithms } = getServiceByName(
|
const { publisherTrustedAlgorithms } = getServiceByName(
|
||||||
asset,
|
asset,
|
||||||
'compute'
|
'compute'
|
||||||
)?.compute
|
).compute
|
||||||
|
|
||||||
async function getAlgorithmList(
|
async function getAlgorithmList(
|
||||||
publisherTrustedAlgorithms: PublisherTrustedAlgorithm[]
|
publisherTrustedAlgorithms: PublisherTrustedAlgorithm[]
|
||||||
|
@ -117,7 +117,7 @@ export default function HomePage(): ReactElement {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const baseParams = {
|
const baseParams = {
|
||||||
chainIds: chainIds,
|
chainIds,
|
||||||
esPaginationOptions: {
|
esPaginationOptions: {
|
||||||
size: 9
|
size: 9
|
||||||
},
|
},
|
||||||
|
@ -21,8 +21,10 @@ export default function NumberUnit({
|
|||||||
return (
|
return (
|
||||||
<div className={styles.unit}>
|
<div className={styles.unit}>
|
||||||
<div className={`${styles.number} ${small && styles.small}`}>
|
<div className={`${styles.number} ${small && styles.small}`}>
|
||||||
{icon && icon}
|
<>
|
||||||
{value}
|
{icon && icon}
|
||||||
|
{value}
|
||||||
|
</>
|
||||||
</div>
|
</div>
|
||||||
<span className={styles.label}>
|
<span className={styles.label}>
|
||||||
{label}{' '}
|
{label}{' '}
|
||||||
|
@ -7,6 +7,7 @@ import styles from './PublishedList.module.css'
|
|||||||
import { useCancelToken } from '@hooks/useCancelToken'
|
import { useCancelToken } from '@hooks/useCancelToken'
|
||||||
import Filters from '../../Search/Filters'
|
import Filters from '../../Search/Filters'
|
||||||
import { useMarketMetadata } from '@context/MarketMetadata'
|
import { useMarketMetadata } from '@context/MarketMetadata'
|
||||||
|
import { CancelToken } from 'axios'
|
||||||
|
|
||||||
export default function PublishedList({
|
export default function PublishedList({
|
||||||
accountId
|
accountId
|
||||||
@ -19,12 +20,19 @@ export default function PublishedList({
|
|||||||
const [queryResult, setQueryResult] = useState<PagedAssets>()
|
const [queryResult, setQueryResult] = useState<PagedAssets>()
|
||||||
const [isLoading, setIsLoading] = useState(false)
|
const [isLoading, setIsLoading] = useState(false)
|
||||||
const [page, setPage] = useState<number>(1)
|
const [page, setPage] = useState<number>(1)
|
||||||
const [service, setServiceType] = useState()
|
const [service, setServiceType] = useState<string>()
|
||||||
const [access, setAccsesType] = useState()
|
const [access, setAccessType] = useState<string>()
|
||||||
const newCancelToken = useCancelToken()
|
const newCancelToken = useCancelToken()
|
||||||
|
|
||||||
const getPublished = useCallback(
|
const getPublished = useCallback(
|
||||||
async (accountId, chainIds, page, service, access, cancelToken) => {
|
async (
|
||||||
|
accountId: string,
|
||||||
|
chainIds: number[],
|
||||||
|
page: number,
|
||||||
|
service: string,
|
||||||
|
access: string,
|
||||||
|
cancelToken: CancelToken
|
||||||
|
) => {
|
||||||
try {
|
try {
|
||||||
setIsLoading(true)
|
setIsLoading(true)
|
||||||
const result = await getPublishedAssets(
|
const result = await getPublishedAssets(
|
||||||
@ -70,7 +78,7 @@ export default function PublishedList({
|
|||||||
serviceType={service}
|
serviceType={service}
|
||||||
setServiceType={setServiceType}
|
setServiceType={setServiceType}
|
||||||
accessType={access}
|
accessType={access}
|
||||||
setAccessType={setAccsesType}
|
setAccessType={setAccessType}
|
||||||
className={styles.filters}
|
className={styles.filters}
|
||||||
/>
|
/>
|
||||||
<AssetList
|
<AssetList
|
||||||
|
@ -49,7 +49,9 @@ export default function Coin({
|
|||||||
{datatokenOptions?.symbol === 'OCEAN' && (
|
{datatokenOptions?.symbol === 'OCEAN' && (
|
||||||
<Conversion price={field.value} />
|
<Conversion price={field.value} />
|
||||||
)}
|
)}
|
||||||
<Error meta={meta} />
|
<div>
|
||||||
|
<Error meta={meta} />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
@ -8,6 +8,7 @@ import { getOpcFees } from '../../../@utils/subgraph'
|
|||||||
import { OpcFeesQuery_opc as OpcFeesData } from '../../../@types/subgraph/OpcFeesQuery'
|
import { OpcFeesQuery_opc as OpcFeesData } from '../../../@types/subgraph/OpcFeesQuery'
|
||||||
import { useWeb3 } from '@context/Web3'
|
import { useWeb3 } from '@context/Web3'
|
||||||
import { useMarketMetadata } from '@context/MarketMetadata'
|
import { useMarketMetadata } from '@context/MarketMetadata'
|
||||||
|
import Decimal from 'decimal.js'
|
||||||
|
|
||||||
const Default = ({
|
const Default = ({
|
||||||
title,
|
title,
|
||||||
@ -43,13 +44,17 @@ export default function Fees({
|
|||||||
pricingType: 'dynamic' | 'fixed'
|
pricingType: 'dynamic' | 'fixed'
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const [field, meta] = useField('pricing.swapFee')
|
const [field, meta] = useField('pricing.swapFee')
|
||||||
const [opcFees, setOpcFees] = useState<OpcFeesData>(undefined)
|
const [oceanCommunitySwapFee, setOceanCommunitySwapFee] = useState<string>('')
|
||||||
const { chainId } = useWeb3()
|
const { chainId } = useWeb3()
|
||||||
const { appConfig } = useMarketMetadata()
|
const { appConfig } = useMarketMetadata()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getOpcFees(chainId || 1).then((response: OpcFeesData) => {
|
getOpcFees(chainId || 1).then((response: OpcFeesData) => {
|
||||||
setOpcFees(response)
|
setOceanCommunitySwapFee(
|
||||||
|
response?.swapOceanFee
|
||||||
|
? new Decimal(response.swapOceanFee).mul(100).toString()
|
||||||
|
: '0'
|
||||||
|
)
|
||||||
})
|
})
|
||||||
}, [chainId])
|
}, [chainId])
|
||||||
|
|
||||||
@ -76,10 +81,10 @@ export default function Fees({
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
<Default
|
<Default
|
||||||
title="Community Fee"
|
title="Community Swap Fee"
|
||||||
name="communityFee"
|
name="communityFee"
|
||||||
tooltip={tooltips.communityFee}
|
tooltip={tooltips.communityFee}
|
||||||
value={opcFees?.swapOceanFee || '0'}
|
value={oceanCommunitySwapFee}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Default
|
<Default
|
||||||
|
@ -31,6 +31,7 @@ import {
|
|||||||
publisherMarketPoolSwapFee,
|
publisherMarketPoolSwapFee,
|
||||||
publisherMarketFixedSwapFee
|
publisherMarketFixedSwapFee
|
||||||
} from '../../../app.config'
|
} from '../../../app.config'
|
||||||
|
import { sanitizeUrl } from '@utils/url'
|
||||||
|
|
||||||
export function getFieldContent(
|
export function getFieldContent(
|
||||||
fieldName: string,
|
fieldName: string,
|
||||||
@ -95,9 +96,9 @@ export async function transformPublishFormToDdo(
|
|||||||
|
|
||||||
// Transform from files[0].url to string[] assuming only 1 file
|
// Transform from files[0].url to string[] assuming only 1 file
|
||||||
const filesTransformed = files?.length &&
|
const filesTransformed = files?.length &&
|
||||||
files[0].valid && [files[0].url.replace('javascript:', '')]
|
files[0].valid && [sanitizeUrl(files[0].url)]
|
||||||
const linksTransformed = links?.length &&
|
const linksTransformed = links?.length &&
|
||||||
links[0].valid && [links[0].url.replace('javascript:', '')]
|
links[0].valid && [sanitizeUrl(links[0].url)]
|
||||||
|
|
||||||
const newMetadata: Metadata = {
|
const newMetadata: Metadata = {
|
||||||
created: currentTime,
|
created: currentTime,
|
||||||
|
@ -134,7 +134,7 @@ export function getSearchQuery(
|
|||||||
from: (Number(page) - 1 || 0) * (Number(offset) || 21),
|
from: (Number(page) - 1 || 0) * (Number(offset) || 21),
|
||||||
size: Number(offset) || 21
|
size: Number(offset) || 21
|
||||||
},
|
},
|
||||||
sortOptions: { sortBy: sort, sortDirection: sortDirection },
|
sortOptions: { sortBy: sort, sortDirection },
|
||||||
filters
|
filters
|
||||||
} as BaseQueryParams
|
} as BaseQueryParams
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user