From 50accc006533515f8b592775ac7f23f5fbf84beb Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Thu, 8 Oct 2020 14:32:59 +0200 Subject: [PATCH 1/2] refactor for new price --- package-lock.json | 20 ++++++------ package.json | 4 +-- src/components/atoms/Price/index.tsx | 9 ++---- .../AssetActions/Pool/PoolStatistics.tsx | 4 +-- .../organisms/AssetActions/Pool/index.tsx | 32 ++++++++----------- src/components/pages/Home.tsx | 6 ++-- 6 files changed, 32 insertions(+), 43 deletions(-) diff --git a/package-lock.json b/package-lock.json index 465f1eaec..618f6a246 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3291,9 +3291,9 @@ "integrity": "sha512-gJ8qQACJgxOPIrPE0OFQ09iYXBAisOGg56EmelQlsMUgp0yY0DKgBntDP83S/Ho1yBjGygqfxCjQrPH63hh/PA==" }, "@oceanprotocol/lib": { - "version": "0.5.5", - "resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-0.5.5.tgz", - "integrity": "sha512-TJTehUaQnFfNp0dJmw0t15+mpYbTkeF+RX4oc6D5FN7hmlhdvC8kfGf8yeHiqxI2Nb703foFLSSs38MWu/XEpg==", + "version": "0.5.6", + "resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-0.5.6.tgz", + "integrity": "sha512-S8OU/FYjDJCKkx098GDT9LfxmTTe/gA8zv5fVMy7lRG1k5WFDsHHMplqZkU9mUGXg1aDDtt7KbctwxNdt7ZGFg==", "requires": { "@ethereum-navigator/navigator": "^0.5.0", "@oceanprotocol/contracts": "^0.5.3", @@ -3308,11 +3308,11 @@ } }, "@oceanprotocol/react": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/@oceanprotocol/react/-/react-0.1.1.tgz", - "integrity": "sha512-IsB66iYOkbnUIcXJMhLKyrD6RMbGdjYnC/wVx8K7lH0IksHptcsGRhmpEXKmwZdLsJQNpug5+AyKf0g7oHvaSg==", + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/@oceanprotocol/react/-/react-0.1.2.tgz", + "integrity": "sha512-hmaH84wOI/DoyW+C+OfIyzPOKRmUrjBUE6iYsxmDGVC8nZmN2JmSpGybHDnDCYUelIxtA2/vviTsOVPdVJL4Kw==", "requires": { - "@oceanprotocol/lib": "^0.5.5", + "@oceanprotocol/lib": "^0.5.6", "axios": "^0.20.0", "decimal.js": "^10.2.1", "web3": "^1.3.0", @@ -12723,9 +12723,9 @@ } }, "detect-browser": { - "version": "5.1.1", - "resolved": "https://registry.npmjs.org/detect-browser/-/detect-browser-5.1.1.tgz", - "integrity": "sha512-5n2aWI57qC3kZaK4j2zYsG6L1LrxgLptGCNhMQgdKhVn6cSdcq43pp6xHPfTHG3TYM6myF4tIPWiZtfdVDgb9w==" + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/detect-browser/-/detect-browser-5.2.0.tgz", + "integrity": "sha512-tr7XntDAu50BVENgQfajMLzacmSe34D+qZc4zjnniz0ZVuw/TZcLcyxHQjYpJTM36sGEkZZlYLnIM1hH7alTMA==" }, "detect-indent": { "version": "6.0.0", diff --git a/package.json b/package.json index 10f89a5bd..9139a3307 100644 --- a/package.json +++ b/package.json @@ -22,8 +22,8 @@ "@coingecko/cryptoformat": "^0.4.2", "@loadable/component": "5.13.1", "@oceanprotocol/art": "^3.0.0", - "@oceanprotocol/lib": "^0.5.5", - "@oceanprotocol/react": "^0.1.1", + "@oceanprotocol/lib": "^0.5.6", + "@oceanprotocol/react": "^0.1.2", "@oceanprotocol/typographies": "^0.1.0", "@sindresorhus/slugify": "^1.0.0", "@tippyjs/react": "^4.2.0", diff --git a/src/components/atoms/Price/index.tsx b/src/components/atoms/Price/index.tsx index 3c4be9a04..c4a9c21ee 100644 --- a/src/components/atoms/Price/index.tsx +++ b/src/components/atoms/Price/index.tsx @@ -18,15 +18,12 @@ export default function Price({ small?: boolean conversion?: boolean }): ReactElement { - const { ocean } = useOcean() const { price } = useMetadata(ddo) - return !ocean ? ( -
Connect your wallet to view price
- ) : price?.value ? ( + return price?.value ? ( <> )} - ) : price?.value === '' ? ( + ) : !price || price?.value === 0 ? (
No price found{' '} diff --git a/src/components/organisms/AssetActions/Pool/PoolStatistics.tsx b/src/components/organisms/AssetActions/Pool/PoolStatistics.tsx index 1713ca801..17931dac3 100644 --- a/src/components/organisms/AssetActions/Pool/PoolStatistics.tsx +++ b/src/components/organisms/AssetActions/Pool/PoolStatistics.tsx @@ -21,13 +21,13 @@ export default function PoolStatistics({ const { debug } = useUserPreferences() const totalLiquidityInOcean = - Number(totalBalance.ocean) + Number(totalBalance.dt) * Number(price) + Number(totalBalance.ocean) + Number(totalBalance.datatoken) * Number(price) return (

Pool Statistics

- + {debug === true && } diff --git a/src/components/organisms/AssetActions/Pool/index.tsx b/src/components/organisms/AssetActions/Pool/index.tsx index b7cfaaf33..a3b5d9392 100644 --- a/src/components/organisms/AssetActions/Pool/index.tsx +++ b/src/components/organisms/AssetActions/Pool/index.tsx @@ -1,6 +1,6 @@ import React, { ReactElement, useEffect, useState } from 'react' import { useOcean, useMetadata } from '@oceanprotocol/react' -import { DDO } from '@oceanprotocol/lib' +import { DDO, Logger } from '@oceanprotocol/lib' import styles from './index.module.css' import stylesActions from './Actions.module.css' import { useUserPreferences } from '../../../../providers/UserPreferences' @@ -17,7 +17,7 @@ import Token from './Token' export interface Balance { ocean: string - dt: string + datatoken: string } /* @@ -31,7 +31,6 @@ export default function Pool({ ddo }: { ddo: DDO }): ReactElement { const [poolTokens, setPoolTokens] = useState() const [totalPoolTokens, setTotalPoolTokens] = useState() - const [totalBalance, setTotalBalance] = useState() const [dtSymbol, setDtSymbol] = useState() const [userLiquidity, setUserBalance] = useState() const [swapFee, setSwapFee] = useState() @@ -42,10 +41,11 @@ export default function Pool({ ddo }: { ddo: DDO }): ReactElement { const hasAddedLiquidity = userLiquidity && - (Number(userLiquidity.ocean) > 0 || Number(userLiquidity.dt) > 0) + (Number(userLiquidity.ocean) > 0 || Number(userLiquidity.datatoken) > 0) const poolShare = - totalBalance && + price?.ocean && + price?.datatoken && userLiquidity && ((Number(poolTokens) / Number(totalPoolTokens)) * 100).toFixed(2) @@ -65,13 +65,6 @@ export default function Pool({ ddo }: { ddo: DDO }): ReactElement { // // Get everything which is in the pool // - const oceanReserve = await ocean.pool.getOceanReserve(price.address) - const dtReserve = await ocean.pool.getDTReserve(price.address) - setTotalBalance({ - ocean: oceanReserve, - dt: dtReserve - }) - const totalPoolTokens = await ocean.pool.totalSupply(price.address) setTotalPoolTokens(totalPoolTokens) @@ -86,14 +79,15 @@ export default function Pool({ ddo }: { ddo: DDO }): ReactElement { // calculate user's provided liquidity based on pool tokens const userOceanBalance = - (Number(poolTokens) / Number(totalPoolTokens)) * Number(oceanReserve) + (Number(poolTokens) / Number(totalPoolTokens)) * Number(price.ocean) const userDtBalance = - (Number(poolTokens) / Number(totalPoolTokens)) * Number(dtReserve) + (Number(poolTokens) / Number(totalPoolTokens)) * + Number(price.datatoken) const userLiquidity = { ocean: `${userOceanBalance}`, - dt: `${userDtBalance}` + datatoken: `${userDtBalance}` } setUserBalance(userLiquidity) @@ -103,7 +97,7 @@ export default function Pool({ ddo }: { ddo: DDO }): ReactElement { const swapFee = await ocean.pool.getSwapFee(price.address) setSwapFee(`${Number(swapFee) * 100}`) } catch (error) { - console.error(error.message) + Logger.error(error.message) } finally { setIsLoading(false) } @@ -120,7 +114,7 @@ export default function Pool({ ddo }: { ddo: DDO }): ReactElement { setShowAdd={setShowAdd} poolAddress={price.address} totalPoolTokens={totalPoolTokens} - totalBalance={totalBalance} + totalBalance={{ ocean: price.ocean, datatoken: price.datatoken }} swapFee={swapFee} dtSymbol={dtSymbol} dtAddress={ddo.dataToken} @@ -159,7 +153,7 @@ export default function Pool({ ddo }: { ddo: DDO }): ReactElement { - + {debug === true && }
@@ -167,7 +161,7 @@ export default function Pool({ ddo }: { ddo: DDO }): ReactElement { diff --git a/src/components/pages/Home.tsx b/src/components/pages/Home.tsx index 7d27d03d6..6e627de5c 100644 --- a/src/components/pages/Home.tsx +++ b/src/components/pages/Home.tsx @@ -14,10 +14,8 @@ import { useOcean } from '@oceanprotocol/react' const queryHighest = { page: 1, offset: 3, - query: { - dtPrice: [0, 9999999] - }, - sort: { dtPrice: 1 } + query: { 'price.ocean': [0, 99999] }, + sort: { 'price.value': 1 } } const queryLatest = { From 4b0f7c00422f1721675724dc978c3045ea2bcbf7 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Thu, 8 Oct 2020 14:45:55 +0200 Subject: [PATCH 2/2] typing fixes --- .../AssetActions/Pool/PoolStatistics.tsx | 4 ++-- .../organisms/AssetActions/Pool/Remove.tsx | 6 +++--- .../organisms/AssetActions/Pool/index.tsx | 18 +++++++++--------- .../organisms/AssetActions/index.tsx | 6 +----- 4 files changed, 15 insertions(+), 19 deletions(-) diff --git a/src/components/organisms/AssetActions/Pool/PoolStatistics.tsx b/src/components/organisms/AssetActions/Pool/PoolStatistics.tsx index 17931dac3..f69cd5e1c 100644 --- a/src/components/organisms/AssetActions/Pool/PoolStatistics.tsx +++ b/src/components/organisms/AssetActions/Pool/PoolStatistics.tsx @@ -26,8 +26,8 @@ export default function PoolStatistics({ return (

Pool Statistics

- - + + {debug === true && } diff --git a/src/components/organisms/AssetActions/Pool/Remove.tsx b/src/components/organisms/AssetActions/Pool/Remove.tsx index ff38bebe2..245f1e2a1 100644 --- a/src/components/organisms/AssetActions/Pool/Remove.tsx +++ b/src/components/organisms/AssetActions/Pool/Remove.tsx @@ -50,7 +50,7 @@ export default function Remove({ } function handleMax() { - setAmount(userLiquidity.ocean) + setAmount(`${userLiquidity.ocean}`) } return ( @@ -63,7 +63,7 @@ export default function Remove({
Your pool liquidity: - +
- {userLiquidity.ocean > amount && ( + {userLiquidity.ocean > Number(amount) && (