diff --git a/package-lock.json b/package-lock.json index 153f41abd..4110cb34f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ "@coingecko/cryptoformat": "^0.4.4", "@loadable/component": "^5.15.0", "@oceanprotocol/art": "^3.2.0", - "@oceanprotocol/lib": "^0.17.3", + "@oceanprotocol/lib": "^0.18.0", "@oceanprotocol/typographies": "^0.1.0", "@portis/web3": "^4.1.0", "@sindresorhus/slugify": "^2.1.0", @@ -5666,9 +5666,9 @@ } }, "node_modules/@oceanprotocol/lib": { - "version": "0.17.3", - "resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-0.17.3.tgz", - "integrity": "sha512-vBu84tP5vWgEu0mzwUfuoeTHzS2AcQXg1xDifh7ZxFlIhmYSlHeJrUcsm+6Pyojixs7rQuWdMuMVgPSai4xTNg==", + "version": "0.18.0", + "resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-0.18.0.tgz", + "integrity": "sha512-iZL4bKtK5JDBYGqrzaA/bom5Uq/kgrwBQ76m2sU2U4qCkluN67kyAHD9EwOE/g+osZ4E56v+JVnzi3bGurxmsw==", "dependencies": { "@ethereum-navigator/navigator": "^0.5.3", "@oceanprotocol/contracts": "^0.6.5", @@ -5681,10 +5681,193 @@ "save-file": "^2.3.1", "uuid": "^8.3.2", "web3": "^1.5.2", + "web3-core": "^1.5.3", "web3-eth-contract": "^1.5.2" }, "peerDependencies": { - "web3": "^1.3.5" + "web3": ">=1.3.5" + } + }, + "node_modules/@oceanprotocol/lib/node_modules/@types/node": { + "version": "12.20.26", + "resolved": "https://registry.npmjs.org/@types/node/-/node-12.20.26.tgz", + "integrity": "sha512-gIt+h4u2uTho2bsH1K250fUv5fHU71ET1yWT7bM4523zV/XrFb9jlWBOV4DO8FpscY+Sz/WEr1EEjIP2H4yumQ==" + }, + "node_modules/@oceanprotocol/lib/node_modules/bignumber.js": { + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.0.1.tgz", + "integrity": "sha512-IdZR9mh6ahOBv/hYGiXyVuyCetmGJhtYkqLBpTStdhEGjegpPlUawydyaF3pbIOFynJTpllEs+NP+CS9jKFLjA==", + "engines": { + "node": "*" + } + }, + "node_modules/@oceanprotocol/lib/node_modules/bn.js": { + "version": "4.12.0", + "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.12.0.tgz", + "integrity": "sha512-c98Bf3tPniI+scsdk237ku1Dc3ujXQTSgyiPUDEOe7tRkhrqridvh8klBv0HCEso1OLOYcHuCv/cS6DNxKH+ZA==" + }, + "node_modules/@oceanprotocol/lib/node_modules/eth-lib": { + "version": "0.2.8", + "resolved": "https://registry.npmjs.org/eth-lib/-/eth-lib-0.2.8.tgz", + "integrity": "sha512-ArJ7x1WcWOlSpzdoTBX8vkwlkSQ85CjjifSZtV4co64vWxSV8geWfPI9x4SVYu3DSxnX4yWFVTtGL+j9DUFLNw==", + "dependencies": { + "bn.js": "^4.11.6", + "elliptic": "^6.4.0", + "xhr-request-promise": "^0.1.2" + } + }, + "node_modules/@oceanprotocol/lib/node_modules/eventemitter3": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.4.tgz", + "integrity": "sha512-rlaVLnVxtxvoyLsQQFBx53YmXHDxRIzzTLbdfxqi4yocpSjAxXwkU0cScM5JgSKMqEhrZpnvQ2D9gjylR0AimQ==" + }, + "node_modules/@oceanprotocol/lib/node_modules/web3-core": { + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/web3-core/-/web3-core-1.5.3.tgz", + "integrity": "sha512-ACTbu8COCu+0eUNmd9pG7Q9EVsNkAg2w3Y7SqhDr+zjTgbSHZV01jXKlapm9z+G3AN/BziV3zGwudClJ4u4xXQ==", + "dependencies": { + "@types/bn.js": "^4.11.5", + "@types/node": "^12.12.6", + "bignumber.js": "^9.0.0", + "web3-core-helpers": "1.5.3", + "web3-core-method": "1.5.3", + "web3-core-requestmanager": "1.5.3", + "web3-utils": "1.5.3" + }, + "engines": { + "node": ">=8.0.0" + } + }, + "node_modules/@oceanprotocol/lib/node_modules/web3-core-helpers": { + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/web3-core-helpers/-/web3-core-helpers-1.5.3.tgz", + "integrity": "sha512-Ip1IjB3S8vN7Kf1PPjK41U5gskmMk6IJQlxIVuS8/1U7n/o0jC8krqtpRwiMfAgYyw3TXwBFtxSRTvJtnLyXZw==", + "dependencies": { + "web3-eth-iban": "1.5.3", + "web3-utils": "1.5.3" + }, + "engines": { + "node": ">=8.0.0" + } + }, + "node_modules/@oceanprotocol/lib/node_modules/web3-core-method": { + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/web3-core-method/-/web3-core-method-1.5.3.tgz", + "integrity": "sha512-8wJrwQ2qD9ibWieF9oHXwrJsUGrv3XAtEkNeyvyNMpktNTIjxJ2jaFGQUuLiyUrMubD18XXgLk4JS6PJU4Loeg==", + "dependencies": { + "@ethereumjs/common": "^2.4.0", + "@ethersproject/transactions": "^5.0.0-beta.135", + "web3-core-helpers": "1.5.3", + "web3-core-promievent": "1.5.3", + "web3-core-subscriptions": "1.5.3", + "web3-utils": "1.5.3" + }, + "engines": { + "node": ">=8.0.0" + } + }, + "node_modules/@oceanprotocol/lib/node_modules/web3-core-promievent": { + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/web3-core-promievent/-/web3-core-promievent-1.5.3.tgz", + "integrity": "sha512-CFfgqvk3Vk6PIAxtLLuX+pOMozxkKCY+/GdGr7weMh033mDXEPvwyVjoSRO1PqIKj668/hMGQsVoIgbyxkJ9Mg==", + "dependencies": { + "eventemitter3": "4.0.4" + }, + "engines": { + "node": ">=8.0.0" + } + }, + "node_modules/@oceanprotocol/lib/node_modules/web3-core-requestmanager": { + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/web3-core-requestmanager/-/web3-core-requestmanager-1.5.3.tgz", + "integrity": "sha512-9k/Bze2rs8ONix5IZR+hYdMNQv+ark2Ek2kVcrFgWO+LdLgZui/rn8FikPunjE+ub7x7pJaKCgVRbYFXjo3ZWg==", + "dependencies": { + "util": "^0.12.0", + "web3-core-helpers": "1.5.3", + "web3-providers-http": "1.5.3", + "web3-providers-ipc": "1.5.3", + "web3-providers-ws": "1.5.3" + }, + "engines": { + "node": ">=8.0.0" + } + }, + "node_modules/@oceanprotocol/lib/node_modules/web3-core-subscriptions": { + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/web3-core-subscriptions/-/web3-core-subscriptions-1.5.3.tgz", + "integrity": "sha512-L2m9vG1iRN6thvmv/HQwO2YLhOQlmZU8dpLG6GSo9FBN14Uch868Swk0dYVr3rFSYjZ/GETevSXU+O+vhCummA==", + "dependencies": { + "eventemitter3": "4.0.4", + "web3-core-helpers": "1.5.3" + }, + "engines": { + "node": ">=8.0.0" + } + }, + "node_modules/@oceanprotocol/lib/node_modules/web3-eth-iban": { + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/web3-eth-iban/-/web3-eth-iban-1.5.3.tgz", + "integrity": "sha512-vMzmGqolYZvRHwP9P4Nf6G8uYM5aTLlQu2a34vz78p0KlDC+eV1th3+90Qeaupa28EG7OO0IT1F0BejiIauOPw==", + "dependencies": { + "bn.js": "^4.11.9", + "web3-utils": "1.5.3" + }, + "engines": { + "node": ">=8.0.0" + } + }, + "node_modules/@oceanprotocol/lib/node_modules/web3-providers-http": { + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/web3-providers-http/-/web3-providers-http-1.5.3.tgz", + "integrity": "sha512-5DpUyWGHtDAr2RYmBu34Fu+4gJuBAuNx2POeiJIooUtJ+Mu6pIx4XkONWH6V+Ez87tZAVAsFOkJRTYuzMr3rPw==", + "dependencies": { + "web3-core-helpers": "1.5.3", + "xhr2-cookies": "1.1.0" + }, + "engines": { + "node": ">=8.0.0" + } + }, + "node_modules/@oceanprotocol/lib/node_modules/web3-providers-ipc": { + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/web3-providers-ipc/-/web3-providers-ipc-1.5.3.tgz", + "integrity": "sha512-JmeAptugVpmXI39LGxUSAymx0NOFdgpuI1hGQfIhbEAcd4sv7fhfd5D+ZU4oLHbRI8IFr4qfGU0uhR8BXhDzlg==", + "dependencies": { + "oboe": "2.1.5", + "web3-core-helpers": "1.5.3" + }, + "engines": { + "node": ">=8.0.0" + } + }, + "node_modules/@oceanprotocol/lib/node_modules/web3-providers-ws": { + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/web3-providers-ws/-/web3-providers-ws-1.5.3.tgz", + "integrity": "sha512-6DhTw4Q7nm5CFYEUHOJM0gAb3xFx+9gWpVveg3YxJ/ybR1BUvEWo3bLgIJJtX56cYX0WyY6DS35a7f0LOI1kVg==", + "dependencies": { + "eventemitter3": "4.0.4", + "web3-core-helpers": "1.5.3", + "websocket": "^1.0.32" + }, + "engines": { + "node": ">=8.0.0" + } + }, + "node_modules/@oceanprotocol/lib/node_modules/web3-utils": { + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/web3-utils/-/web3-utils-1.5.3.tgz", + "integrity": "sha512-56nRgA+Ad9SEyCv39g36rTcr5fpsd4L9LgV3FK0aB66nAMazLAA6Qz4lH5XrUKPDyBIPGJIR+kJsyRtwcu2q1Q==", + "dependencies": { + "bn.js": "^4.11.9", + "eth-lib": "0.2.8", + "ethereum-bloom-filters": "^1.0.6", + "ethjs-unit": "0.1.6", + "number-to-bn": "1.7.0", + "randombytes": "^2.1.0", + "utf8": "3.0.0" + }, + "engines": { + "node": ">=8.0.0" } }, "node_modules/@oceanprotocol/typographies": { @@ -62944,9 +63127,9 @@ } }, "@oceanprotocol/lib": { - "version": "0.17.3", - "resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-0.17.3.tgz", - "integrity": "sha512-vBu84tP5vWgEu0mzwUfuoeTHzS2AcQXg1xDifh7ZxFlIhmYSlHeJrUcsm+6Pyojixs7rQuWdMuMVgPSai4xTNg==", + "version": "0.18.0", + "resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-0.18.0.tgz", + "integrity": "sha512-iZL4bKtK5JDBYGqrzaA/bom5Uq/kgrwBQ76m2sU2U4qCkluN67kyAHD9EwOE/g+osZ4E56v+JVnzi3bGurxmsw==", "requires": { "@ethereum-navigator/navigator": "^0.5.3", "@oceanprotocol/contracts": "^0.6.5", @@ -62959,7 +63142,156 @@ "save-file": "^2.3.1", "uuid": "^8.3.2", "web3": "^1.5.2", + "web3-core": "^1.5.3", "web3-eth-contract": "^1.5.2" + }, + "dependencies": { + "@types/node": { + "version": "12.20.26", + "resolved": "https://registry.npmjs.org/@types/node/-/node-12.20.26.tgz", + "integrity": "sha512-gIt+h4u2uTho2bsH1K250fUv5fHU71ET1yWT7bM4523zV/XrFb9jlWBOV4DO8FpscY+Sz/WEr1EEjIP2H4yumQ==" + }, + "bignumber.js": { + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.0.1.tgz", + "integrity": "sha512-IdZR9mh6ahOBv/hYGiXyVuyCetmGJhtYkqLBpTStdhEGjegpPlUawydyaF3pbIOFynJTpllEs+NP+CS9jKFLjA==" + }, + "bn.js": { + "version": "4.12.0", + "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.12.0.tgz", + "integrity": "sha512-c98Bf3tPniI+scsdk237ku1Dc3ujXQTSgyiPUDEOe7tRkhrqridvh8klBv0HCEso1OLOYcHuCv/cS6DNxKH+ZA==" + }, + "eth-lib": { + "version": "0.2.8", + "resolved": "https://registry.npmjs.org/eth-lib/-/eth-lib-0.2.8.tgz", + "integrity": "sha512-ArJ7x1WcWOlSpzdoTBX8vkwlkSQ85CjjifSZtV4co64vWxSV8geWfPI9x4SVYu3DSxnX4yWFVTtGL+j9DUFLNw==", + "requires": { + "bn.js": "^4.11.6", + "elliptic": "^6.4.0", + "xhr-request-promise": "^0.1.2" + } + }, + "eventemitter3": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.4.tgz", + "integrity": "sha512-rlaVLnVxtxvoyLsQQFBx53YmXHDxRIzzTLbdfxqi4yocpSjAxXwkU0cScM5JgSKMqEhrZpnvQ2D9gjylR0AimQ==" + }, + "web3-core": { + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/web3-core/-/web3-core-1.5.3.tgz", + "integrity": "sha512-ACTbu8COCu+0eUNmd9pG7Q9EVsNkAg2w3Y7SqhDr+zjTgbSHZV01jXKlapm9z+G3AN/BziV3zGwudClJ4u4xXQ==", + "requires": { + "@types/bn.js": "^4.11.5", + "@types/node": "^12.12.6", + "bignumber.js": "^9.0.0", + "web3-core-helpers": "1.5.3", + "web3-core-method": "1.5.3", + "web3-core-requestmanager": "1.5.3", + "web3-utils": "1.5.3" + } + }, + "web3-core-helpers": { + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/web3-core-helpers/-/web3-core-helpers-1.5.3.tgz", + "integrity": "sha512-Ip1IjB3S8vN7Kf1PPjK41U5gskmMk6IJQlxIVuS8/1U7n/o0jC8krqtpRwiMfAgYyw3TXwBFtxSRTvJtnLyXZw==", + "requires": { + "web3-eth-iban": "1.5.3", + "web3-utils": "1.5.3" + } + }, + "web3-core-method": { + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/web3-core-method/-/web3-core-method-1.5.3.tgz", + "integrity": "sha512-8wJrwQ2qD9ibWieF9oHXwrJsUGrv3XAtEkNeyvyNMpktNTIjxJ2jaFGQUuLiyUrMubD18XXgLk4JS6PJU4Loeg==", + "requires": { + "@ethereumjs/common": "^2.4.0", + "@ethersproject/transactions": "^5.0.0-beta.135", + "web3-core-helpers": "1.5.3", + "web3-core-promievent": "1.5.3", + "web3-core-subscriptions": "1.5.3", + "web3-utils": "1.5.3" + } + }, + "web3-core-promievent": { + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/web3-core-promievent/-/web3-core-promievent-1.5.3.tgz", + "integrity": "sha512-CFfgqvk3Vk6PIAxtLLuX+pOMozxkKCY+/GdGr7weMh033mDXEPvwyVjoSRO1PqIKj668/hMGQsVoIgbyxkJ9Mg==", + "requires": { + "eventemitter3": "4.0.4" + } + }, + "web3-core-requestmanager": { + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/web3-core-requestmanager/-/web3-core-requestmanager-1.5.3.tgz", + "integrity": "sha512-9k/Bze2rs8ONix5IZR+hYdMNQv+ark2Ek2kVcrFgWO+LdLgZui/rn8FikPunjE+ub7x7pJaKCgVRbYFXjo3ZWg==", + "requires": { + "util": "^0.12.0", + "web3-core-helpers": "1.5.3", + "web3-providers-http": "1.5.3", + "web3-providers-ipc": "1.5.3", + "web3-providers-ws": "1.5.3" + } + }, + "web3-core-subscriptions": { + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/web3-core-subscriptions/-/web3-core-subscriptions-1.5.3.tgz", + "integrity": "sha512-L2m9vG1iRN6thvmv/HQwO2YLhOQlmZU8dpLG6GSo9FBN14Uch868Swk0dYVr3rFSYjZ/GETevSXU+O+vhCummA==", + "requires": { + "eventemitter3": "4.0.4", + "web3-core-helpers": "1.5.3" + } + }, + "web3-eth-iban": { + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/web3-eth-iban/-/web3-eth-iban-1.5.3.tgz", + "integrity": "sha512-vMzmGqolYZvRHwP9P4Nf6G8uYM5aTLlQu2a34vz78p0KlDC+eV1th3+90Qeaupa28EG7OO0IT1F0BejiIauOPw==", + "requires": { + "bn.js": "^4.11.9", + "web3-utils": "1.5.3" + } + }, + "web3-providers-http": { + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/web3-providers-http/-/web3-providers-http-1.5.3.tgz", + "integrity": "sha512-5DpUyWGHtDAr2RYmBu34Fu+4gJuBAuNx2POeiJIooUtJ+Mu6pIx4XkONWH6V+Ez87tZAVAsFOkJRTYuzMr3rPw==", + "requires": { + "web3-core-helpers": "1.5.3", + "xhr2-cookies": "1.1.0" + } + }, + "web3-providers-ipc": { + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/web3-providers-ipc/-/web3-providers-ipc-1.5.3.tgz", + "integrity": "sha512-JmeAptugVpmXI39LGxUSAymx0NOFdgpuI1hGQfIhbEAcd4sv7fhfd5D+ZU4oLHbRI8IFr4qfGU0uhR8BXhDzlg==", + "requires": { + "oboe": "2.1.5", + "web3-core-helpers": "1.5.3" + } + }, + "web3-providers-ws": { + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/web3-providers-ws/-/web3-providers-ws-1.5.3.tgz", + "integrity": "sha512-6DhTw4Q7nm5CFYEUHOJM0gAb3xFx+9gWpVveg3YxJ/ybR1BUvEWo3bLgIJJtX56cYX0WyY6DS35a7f0LOI1kVg==", + "requires": { + "eventemitter3": "4.0.4", + "web3-core-helpers": "1.5.3", + "websocket": "^1.0.32" + } + }, + "web3-utils": { + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/web3-utils/-/web3-utils-1.5.3.tgz", + "integrity": "sha512-56nRgA+Ad9SEyCv39g36rTcr5fpsd4L9LgV3FK0aB66nAMazLAA6Qz4lH5XrUKPDyBIPGJIR+kJsyRtwcu2q1Q==", + "requires": { + "bn.js": "^4.11.9", + "eth-lib": "0.2.8", + "ethereum-bloom-filters": "^1.0.6", + "ethjs-unit": "0.1.6", + "number-to-bn": "1.7.0", + "randombytes": "^2.1.0", + "utf8": "3.0.0" + } + } } }, "@oceanprotocol/typographies": { diff --git a/package.json b/package.json index 318ef028c..827689f43 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "@coingecko/cryptoformat": "^0.4.4", "@loadable/component": "^5.15.0", "@oceanprotocol/art": "^3.2.0", - "@oceanprotocol/lib": "^0.17.3", + "@oceanprotocol/lib": "^0.18.0", "@oceanprotocol/typographies": "^0.1.0", "@portis/web3": "^4.1.0", "@sindresorhus/slugify": "^2.1.0", diff --git a/src/components/organisms/AssetActions/Compute/index.tsx b/src/components/organisms/AssetActions/Compute/index.tsx index 168127855..014ed129e 100644 --- a/src/components/organisms/AssetActions/Compute/index.tsx +++ b/src/components/organisms/AssetActions/Compute/index.tsx @@ -159,7 +159,7 @@ export default function Compute({ query: `${algorithmQuery} service.attributes.main.type:algorithm AND chainId:${chainId} -isInPurgatory:true` } }, - sort: { created: -1 } + sort: { created: 'desc' } } return query } diff --git a/src/components/pages/Home.tsx b/src/components/pages/Home.tsx index f12bc7764..dd6dac69a 100644 --- a/src/components/pages/Home.tsx +++ b/src/components/pages/Home.tsx @@ -1,9 +1,6 @@ import React, { ReactElement, useEffect, useState } from 'react' import AssetList from '../organisms/AssetList' -import { - QueryResult, - SearchQuery -} from '@oceanprotocol/lib/dist/node/metadatacache/MetadataCache' +import { SearchQuery } from '@oceanprotocol/lib/dist/node/metadatacache/MetadataCache' import Button from '../atoms/Button' import Bookmarks from '../molecules/Bookmarks' import axios from 'axios' @@ -23,8 +20,7 @@ async function getQueryHighest( ): Promise<[SearchQuery, string]> { const [dids, didsLength] = await getHighestLiquidityDIDs(chainIds) const queryHighest = { - page: 1, - offset: didsLength > 0 ? didsLength : 1, + size: didsLength > 0 ? didsLength : 1, query: { query_string: { query: `${dids && `(${dids}) AND`}(${transformChainIdsListToQuery( @@ -38,10 +34,9 @@ async function getQueryHighest( return [queryHighest, dids] } -function getQueryLatest(chainIds: number[]): SearchQuery { +function getQueryLatest(chainIds: number[]): any { return { - page: 1, - offset: 9, + size: 9, query: { query_string: { query: `(${transformChainIdsListToQuery( @@ -49,7 +44,7 @@ function getQueryLatest(chainIds: number[]): SearchQuery { )}) AND -isInPurgatory:true ` } }, - sort: { created: -1 } + sort: { created: 'desc' } } } @@ -73,7 +68,7 @@ function SectionQueryResult({ }) { const { appConfig } = useSiteMetadata() const { chainIds } = useUserPreferences() - const [result, setResult] = useState() + const [result, setResult] = useState() const [loading, setLoading] = useState() useEffect(() => { @@ -82,7 +77,7 @@ function SectionQueryResult({ async function init() { if (chainIds.length === 0) { - const result: QueryResult = { + const result: any = { results: [], page: 0, totalPages: 0, @@ -94,6 +89,7 @@ function SectionQueryResult({ try { setLoading(true) const result = await queryMetadata(query, source.token) + if (queryData && result.totalResults > 0) { const searchDIDs = queryData.split(' ') const sortedAssets = sortElements(result.results, searchDIDs) diff --git a/src/components/pages/Profile/History/PublishedList.tsx b/src/components/pages/Profile/History/PublishedList.tsx index 21995ef76..651ec311b 100644 --- a/src/components/pages/Profile/History/PublishedList.tsx +++ b/src/components/pages/Profile/History/PublishedList.tsx @@ -1,5 +1,4 @@ import { Logger } from '@oceanprotocol/lib' -import { QueryResult } from '@oceanprotocol/lib/dist/node/metadatacache/MetadataCache' import React, { ReactElement, useEffect, useState } from 'react' import AssetList from '../../../organisms/AssetList' import { getPublishedAssets } from '../../../../utils/aquarius' @@ -17,7 +16,7 @@ export default function PublishedList({ const { appConfig } = useSiteMetadata() const { chainIds } = useUserPreferences() - const [queryResult, setQueryResult] = useState() + const [queryResult, setQueryResult] = useState() const [isLoading, setIsLoading] = useState(false) const [page, setPage] = useState(1) const [service, setServiceType] = useState('dataset OR algorithm') diff --git a/src/components/templates/Search/index.tsx b/src/components/templates/Search/index.tsx index 4a5d18bdd..9642ce209 100644 --- a/src/components/templates/Search/index.tsx +++ b/src/components/templates/Search/index.tsx @@ -1,6 +1,5 @@ import React, { ReactElement, useState, useEffect } from 'react' import Permission from '../../organisms/Permission' -import { QueryResult } from '@oceanprotocol/lib/dist/node/metadatacache/MetadataCache' import AssetList from '../../organisms/AssetList' import queryString from 'query-string' import Filters from './Filters' @@ -10,6 +9,7 @@ import { navigate } from 'gatsby' import { updateQueryStringParameter } from '../../../utils' import { useSiteMetadata } from '../../../hooks/useSiteMetadata' import { useUserPreferences } from '../../../providers/UserPreferences' +import axios from 'axios' import styles from './index.module.css' export default function SearchPage({ @@ -26,7 +26,7 @@ export default function SearchPage({ const { text, owner, tags, page, sort, sortOrder, serviceType, accessType } = parsed const { chainIds } = useUserPreferences() - const [queryResult, setQueryResult] = useState() + const [queryResult, setQueryResult] = useState() const [loading, setLoading] = useState() const [service, setServiceType] = useState(serviceType as string) const [access, setAccessType] = useState(accessType as string) @@ -36,21 +36,21 @@ export default function SearchPage({ ) useEffect(() => { - if (!appConfig.metadataCacheUri) return + const source = axios.CancelToken.source() + async function initSearch() { setLoading(true) setTotalResults(undefined) - const queryResult = await getResults( - parsed, - appConfig.metadataCacheUri, - chainIds - ) + const queryResult = await getResults(parsed, chainIds, source.token) setQueryResult(queryResult) setTotalResults(queryResult.totalResults) setTotalPagesNumber(queryResult.totalPages) setLoading(false) } initSearch() + return () => { + source.cancel() + } }, [ text, owner, @@ -60,7 +60,6 @@ export default function SearchPage({ serviceType, accessType, sortOrder, - appConfig.metadataCacheUri, chainIds ]) diff --git a/src/components/templates/Search/sort.tsx b/src/components/templates/Search/sort.tsx index 09a1d3139..cf7b59d5a 100644 --- a/src/components/templates/Search/sort.tsx +++ b/src/components/templates/Search/sort.tsx @@ -12,7 +12,7 @@ import classNames from 'classnames/bind' const cx = classNames.bind(styles) const sortItems = [ - // { display: 'Relevance', value: SortTermOptions.Relevance }, + { display: 'Relevance', value: SortTermOptions.Relevance }, { display: 'Published', value: SortTermOptions.Created } ] diff --git a/src/components/templates/Search/utils.ts b/src/components/templates/Search/utils.ts index f4a7bbcb1..751329908 100644 --- a/src/components/templates/Search/utils.ts +++ b/src/components/templates/Search/utils.ts @@ -1,11 +1,10 @@ -import { QueryResult } from '@oceanprotocol/lib/dist/node/metadatacache/MetadataCache' import { Logger } from '@oceanprotocol/lib' import { queryMetadata, transformChainIdsListToQuery } from '../../../utils/aquarius' import queryString from 'query-string' -import axios from 'axios' +import { CancelToken } from 'axios' export const SortTermOptions = { Created: 'created', @@ -61,8 +60,6 @@ export function getSearchQuery( serviceType?: string, accessType?: string ): any { - const sortTerm = getSortType(sort) - const sortValue = sortOrder === SortValueOptions.Ascending ? 1 : -1 const emptySearchTerm = text === undefined || text === '' let searchTerm = owner ? `(publicKey.owner:${owner})` @@ -96,8 +93,8 @@ export function getSearchQuery( 'service.attributes.additionalInformation.tags' ] return { - page: Number(page) || 1, - offset: Number(offset) || 21, + from: (Number(page) || 0) * (Number(offset) || 21), + size: Number(offset) || 21, query: { bool: { must: [ @@ -167,7 +164,7 @@ export function getSearchQuery( } }, sort: { - [sortTerm]: sortValue + [sort]: sortOrder } } } @@ -185,9 +182,9 @@ export async function getResults( serviceType?: string accessType?: string }, - metadataCacheUri: string, - chainIds: number[] -): Promise { + chainIds: number[], + cancelToken?: CancelToken +): Promise { const { text, owner, @@ -214,9 +211,7 @@ export async function getResults( serviceType, accessType ) - const source = axios.CancelToken.source() - // const queryResult = await metadataCache.queryMetadata(searchQuery) - const queryResult = await queryMetadata(searchQuery, source.token) + const queryResult = await queryMetadata(searchQuery, cancelToken) return queryResult } @@ -240,7 +235,7 @@ export async function addExistingParamsToUrl( } else { // sort should be relevance when fixed in aqua urlLocation = `${urlLocation}sort=${encodeURIComponent( - SortTermOptions.Created + SortTermOptions.Relevance )}&sortOrder=${SortValueOptions.Descending}&` } urlLocation = urlLocation.slice(0, -1) diff --git a/src/utils/aquarius.ts b/src/utils/aquarius.ts index 1841ac58b..f65615880 100644 --- a/src/utils/aquarius.ts +++ b/src/utils/aquarius.ts @@ -5,16 +5,11 @@ import { publisherTrustedAlgorithm as PublisherTrustedAlgorithm } from '@oceanprotocol/lib/' -import { - QueryResult, - SearchQuery -} from '@oceanprotocol/lib/dist/node/metadatacache/MetadataCache' import { AssetSelectionAsset } from '../components/molecules/FormFields/AssetSelection' import { PriceList, getAssetsPriceList } from './subgraph' import axios, { CancelToken, AxiosResponse } from 'axios' import { OrdersData_tokenOrders as OrdersData } from '../@types/apollo/OrdersData' import { metadataCacheUri } from '../../app.config' -import web3 from '../../tests/unit/__mocks__/web3' export interface DownloadedAsset { dtSymbol: string @@ -41,24 +36,25 @@ function getQueryForAlgorithmDatasets(algorithmDid: string, chainId?: number) { // and not just strings of DDOs. For now, taken from // https://github.com/oceanprotocol/ocean.js/blob/main/src/metadatacache/MetadataCache.ts#L361-L375 export function transformQueryResult( - { - results, - page, - total_pages: totalPages, - total_results: totalResults - }: any = { - result: [], + queryResult: any, + from = 0, + size = 21 +): any { + const result: any = { + results: [], page: 0, - total_pages: 0, - total_results: 0 - } -): QueryResult { - return { - results: (results || []).map((ddo: DDO) => new DDO(ddo as DDO)), - page, - totalPages, - totalResults + totalPages: 0, + totalResults: 0 } + + result.results = (queryResult.hits.hits || []).map( + (hit: any) => new DDO(hit._source as DDO) + ) + result.totalResults = queryResult.hits.total + result.totalPages = Math.floor(result.totalResults / size) + result.page = from ? from / size : 1 + + return result } export function transformChainIdsListToQuery(chainIds: number[]): string { @@ -71,17 +67,17 @@ export function transformChainIdsListToQuery(chainIds: number[]): string { } export async function queryMetadata( - query: SearchQuery, + query: any, cancelToken: CancelToken -): Promise { +): Promise { try { const response: AxiosResponse = await axios.post( - `${metadataCacheUri}/api/v1/aquarius/assets/ddo/query`, + `${metadataCacheUri}/api/v1/aquarius/assets/query`, { ...query }, { cancelToken } ) if (!response || response.status !== 200 || !response.data) return - return transformQueryResult(response.data) + return transformQueryResult(response.data, query.from, query.size) } catch (error) { if (axios.isCancel(error)) { Logger.log(error.message) @@ -221,7 +217,7 @@ export async function getPublishedAssets( cancelToken: CancelToken, page?: number, type?: string -): Promise { +): Promise { if (!accountId) return page = page || 1 @@ -256,7 +252,7 @@ export async function getAssetsFromDidList( didList: string[], chainIds: number[], cancelToken: CancelToken -): Promise { +): Promise { try { // TODO: figure out cleaner way to transform string[] into csv const searchDids = JSON.stringify(didList) @@ -309,7 +305,7 @@ export async function getDownloadAssets( for (let i = 0; i < tokenOrders?.length; i++) { const ddo = ddoList.filter( - (ddo) => + (ddo: { dataToken: string }) => tokenOrders[i].datatokenId.address.toLowerCase() === ddo.dataToken.toLowerCase() )[0]