From a4510459f1a4ee6e380fe039723a8d71576617e7 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Thu, 10 Sep 2020 20:32:30 +0200 Subject: [PATCH] updates for new @oceanprotocol/react price model --- package-lock.json | 47 +++++++++---------- package.json | 4 +- src/components/atoms/Price/index.tsx | 6 +-- .../organisms/AssetActions/Pool/index.tsx | 30 +++++++----- .../organisms/AssetActions/index.tsx | 9 ++-- 5 files changed, 51 insertions(+), 45 deletions(-) diff --git a/package-lock.json b/package-lock.json index 6e6dcb4c1..0eb43881e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1704,10 +1704,7 @@ "cross-fetch": { "version": "3.0.5", "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.0.5.tgz", - "integrity": "sha512-FFLcLtraisj5eteosnX1gf01qYDCOc4fDy0+euOt8Kn9YBY2NtXL/pCoYPavw24NIQkQqm5ZOLsGD5Zzj0gyew==", - "requires": { - "node-fetch": "2.6.0" - } + "integrity": "sha512-FFLcLtraisj5eteosnX1gf01qYDCOc4fDy0+euOt8Kn9YBY2NtXL/pCoYPavw24NIQkQqm5ZOLsGD5Zzj0gyew==" }, "form-data": { "version": "3.0.0", @@ -3351,11 +3348,11 @@ } }, "@oceanprotocol/react": { - "version": "0.0.42", - "resolved": "https://registry.npmjs.org/@oceanprotocol/react/-/react-0.0.42.tgz", - "integrity": "sha512-7CBE4utcoZrK1aLTV3bxUBE6LisbImYS2gTmRBbylL00RUwWHlLqQBzkdIOkw8VYFUi72kcDvEuZkHQDiMDacg==", + "version": "0.0.43", + "resolved": "https://registry.npmjs.org/@oceanprotocol/react/-/react-0.0.43.tgz", + "integrity": "sha512-dkhz+olYmCjYsZHvXxzbZry5d37JL+Hevgg1Iwsqkc94Qb3FfvjiRSv1zEHs2ZVimGXPlp3z5a2ChVFr/sjjsA==", "requires": { - "@oceanprotocol/lib": "^0.2.3", + "@oceanprotocol/lib": "^0.2.4", "axios": "^0.20.0", "decimal.js": "^10.2.0", "web3": "^1.2.11", @@ -5429,9 +5426,9 @@ } }, "@types/node": { - "version": "14.6.4", - "resolved": "https://registry.npmjs.org/@types/node/-/node-14.6.4.tgz", - "integrity": "sha512-Wk7nG1JSaMfMpoMJDKUsWYugliB2Vy55pdjLpmLixeyMi7HizW2I/9QoxsPCkXl3dO+ZOVqPumKaDUv5zJu2uQ==" + "version": "14.10.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-14.10.0.tgz", + "integrity": "sha512-SOIyrdADB4cq6eY1F+9iU48iIomFAPltu11LCvA9PKcyEwHadjCFzNVPotAR+oEJA0bCP4Xvvgy+vwu1ZjVh8g==" }, "@types/node-fetch": { "version": "2.5.7", @@ -13243,20 +13240,20 @@ } }, "eth-json-rpc-infura": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/eth-json-rpc-infura/-/eth-json-rpc-infura-4.0.2.tgz", - "integrity": "sha512-dvgOrci9lZqpjpp0hoC3Zfedhg3aIpLFVDH0TdlKxRlkhR75hTrKTwxghDrQwE0bn3eKrC8RsN1m/JdnIWltpw==", + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/eth-json-rpc-infura/-/eth-json-rpc-infura-4.1.0.tgz", + "integrity": "sha512-DFYitKovzVlCdUulEccdm4g6k/vnvyByuw7rd5OoWDBSIiaeinI8Z/SntLjSIs2c+YvE20DGwk/GLwZGCWDN1Q==", "requires": { - "cross-fetch": "^2.1.1", - "eth-json-rpc-errors": "^1.0.1", - "eth-json-rpc-middleware": "^4.1.4", - "json-rpc-engine": "^5.1.3" + "eth-json-rpc-middleware": "^4.4.0", + "eth-rpc-errors": "^3.0.0", + "json-rpc-engine": "^5.1.3", + "node-fetch": "^2.6.0" }, "dependencies": { - "eth-json-rpc-errors": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/eth-json-rpc-errors/-/eth-json-rpc-errors-1.1.1.tgz", - "integrity": "sha512-WT5shJ5KfNqHi9jOZD+ID8I1kuYWNrigtZat7GOQkvwo99f8SzAVaEcWhJUv656WiZOAg3P1RiJQANtUmDmbIg==", + "eth-rpc-errors": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/eth-rpc-errors/-/eth-rpc-errors-3.0.0.tgz", + "integrity": "sha512-iPPNHPrLwUlR9xCSYm7HHQjWBasor3+KZfRvwEWxMz3ca0yqnlBeJrnyphkGIXZ4J7AMAaOLmwy4AWhnxOiLxg==", "requires": { "fast-safe-stringify": "^2.0.6" } @@ -25492,9 +25489,9 @@ "integrity": "sha1-n7CwmbzSoCGUDmA8ZCVNwAPZp6g=" }, "node-fetch": { - "version": "2.6.0", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz", - "integrity": "sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA==" + "version": "2.6.1", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz", + "integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==" }, "node-forge": { "version": "0.9.0", diff --git a/package.json b/package.json index ff17095e5..36c24e898 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "@loadable/component": "^5.13.1", "@oceanprotocol/art": "^3.0.0", "@oceanprotocol/lib": "^0.2.4", - "@oceanprotocol/react": "^0.0.42", + "@oceanprotocol/react": "^0.0.43", "@oceanprotocol/typographies": "^0.1.0", "@sindresorhus/slugify": "^1.0.0", "@tippyjs/react": "^4.1.0", @@ -88,7 +88,7 @@ "@types/loadable__component": "^5.13.0", "@types/lodash.debounce": "^4.0.3", "@types/lodash.omit": "^4.5.6", - "@types/node": "^14.6.4", + "@types/node": "^14.10.0", "@types/react": "^16.9.49", "@types/react-datepicker": "^3.1.1", "@types/react-helmet": "^6.1.0", diff --git a/src/components/atoms/Price/index.tsx b/src/components/atoms/Price/index.tsx index d03fe5dfb..5b3303d75 100644 --- a/src/components/atoms/Price/index.tsx +++ b/src/components/atoms/Price/index.tsx @@ -22,14 +22,14 @@ export default function Price({ return !ocean ? (
Connect your wallet to view price
- ) : price ? ( + ) : price && price.value ? ( - ) : price === '' ? ( + ) : price && price.value === '' ? (
No price found{' '} diff --git a/src/components/organisms/AssetActions/Pool/index.tsx b/src/components/organisms/AssetActions/Pool/index.tsx index 7f232f150..02197a1d9 100644 --- a/src/components/organisms/AssetActions/Pool/index.tsx +++ b/src/components/organisms/AssetActions/Pool/index.tsx @@ -26,7 +26,7 @@ export interface Balance { export default function Pool({ ddo }: { ddo: DDO }): ReactElement { const { debug } = useUserPreferences() const { ocean, accountId } = useOcean() - const { price, poolAddress } = useMetadata(ddo) + const { price } = useMetadata(ddo) const [poolTokens, setPoolTokens] = useState() const [totalPoolTokens, setTotalPoolTokens] = useState() @@ -47,7 +47,7 @@ export default function Pool({ ddo }: { ddo: DDO }): ReactElement { ((Number(poolTokens) / Number(totalPoolTokens)) * 100).toFixed(2) useEffect(() => { - if (!ocean || !accountId || !poolAddress || !price) return + if (!ocean || !accountId || !price || !price.value) return async function init() { setIsLoading(true) @@ -67,15 +67,18 @@ export default function Pool({ ddo }: { ddo: DDO }): ReactElement { // const oceanReserve = await ocean.pool.getOceanReserve( accountId, - poolAddress + price.address + ) + const dtReserve = await ocean.pool.getDTReserve( + accountId, + price.address ) - const dtReserve = await ocean.pool.getDTReserve(accountId, poolAddress) setTotalBalance({ ocean: oceanReserve, dt: dtReserve }) - const totalPoolTokens = await ocean.pool.totalSupply(poolAddress) + const totalPoolTokens = await ocean.pool.totalSupply(price.address) setTotalPoolTokens(totalPoolTokens) // @@ -83,7 +86,7 @@ export default function Pool({ ddo }: { ddo: DDO }): ReactElement { // const poolTokens = await ocean.pool.sharesBalance( accountId, - poolAddress + price.address ) setPoolTokens(poolTokens) @@ -107,7 +110,7 @@ export default function Pool({ ddo }: { ddo: DDO }): ReactElement { } } init() - }, [ocean, accountId, price, poolAddress]) + }, [ocean, accountId, price]) return ( <> @@ -116,25 +119,28 @@ export default function Pool({ ddo }: { ddo: DDO }): ReactElement { ) : showAdd ? ( ) : showRemove ? ( ) : ( <>
={' '} - - + +
- + Pool diff --git a/src/components/organisms/AssetActions/index.tsx b/src/components/organisms/AssetActions/index.tsx index 6d23badf5..78338df97 100644 --- a/src/components/organisms/AssetActions/index.tsx +++ b/src/components/organisms/AssetActions/index.tsx @@ -19,10 +19,13 @@ export default function AssetActions({ ddo }: { ddo: DDO }): ReactElement { // Check user balance against price useEffect(() => { - if (!price || !balance || !balance.ocean) return + if (!price || !price.value || !balance || !balance.ocean) return - const isFree = price === '0' - setIsBalanceSufficient(isFree ? true : compareAsBN(balance.ocean, price)) + const isFree = price.value === '0' + + setIsBalanceSufficient( + isFree ? true : compareAsBN(balance.ocean, price.value) + ) return () => { setIsBalanceSufficient(false)