From 2aa4f7b14004f50ebb7c0d21d7aa2069b3266ad5 Mon Sep 17 00:00:00 2001 From: mihaisc Date: Tue, 14 Jul 2020 15:05:31 +0300 Subject: [PATCH] test fix --- src/hooks/useConsume/useConsume.ts | 8 +++--- src/hooks/usePublish/usePublish.ts | 21 +++++---------- src/providers/OceanProvider/OceanProvider.tsx | 7 ----- src/providers/OceanProvider/utils.ts | 27 ------------------- 4 files changed, 11 insertions(+), 52 deletions(-) delete mode 100644 src/providers/OceanProvider/utils.ts diff --git a/src/hooks/useConsume/useConsume.ts b/src/hooks/useConsume/useConsume.ts index a4a95f5..95c0105 100644 --- a/src/hooks/useConsume/useConsume.ts +++ b/src/hooks/useConsume/useConsume.ts @@ -44,10 +44,10 @@ function useConsume(): UseConsume { setConsumeStepText(consumeFeedback[2]) const res = JSON.parse(order) const tokenTransfer = await ocean.datatokens.transfer( - res['dataToken'], - res['to'], - res['numTokens'], - res['from'] + res.dataToken, + res.to, + res.numTokens, + res.from ) setConsumeStep(3) setConsumeStepText(consumeFeedback[3]) diff --git a/src/hooks/usePublish/usePublish.ts b/src/hooks/usePublish/usePublish.ts index c9b4bbb..de8d4d4 100644 --- a/src/hooks/usePublish/usePublish.ts +++ b/src/hooks/usePublish/usePublish.ts @@ -12,8 +12,6 @@ interface UsePublish { ) => Promise mint: (tokenAddress: string, tokensToMint: number) => void } -const factory = require('@oceanprotocol/contracts/artifacts/development/Factory.json') -const datatokensTemplate = require('@oceanprotocol/contracts/artifacts/development/DataTokenTemplate.json') function usePublish(): UsePublish { const { web3, ocean, status, account, accountId, config } = useOcean() @@ -21,14 +19,14 @@ function usePublish(): UsePublish { async function publish( asset: Metadata, tokensToMint: number, - price: number = 1 + price = 1 ): Promise { if (status !== ProviderStatus.CONNECTED) return const datatoken = new DataTokens( ocean.datatokens.factoryAddress, - factory.abi, - datatokensTemplate.abi, + ocean.datatokens.factoryABI, + ocean.datatokens.datatokensABI, web3 ) @@ -80,8 +78,8 @@ function usePublish(): UsePublish { if (datatoken === undefined) datatoken = new DataTokens( ocean.datatokens.factoryAddress, - factory.abi, - datatokensTemplate.abi, + ocean.datatokens.factoryABI, + ocean.datatokens.datatokensABI, web3 ) @@ -97,8 +95,8 @@ function usePublish(): UsePublish { if (datatoken === undefined) datatoken = new DataTokens( ocean.datatokens.factoryAddress, - factory.abi, - datatokensTemplate.abi, + ocean.datatokens.factoryABI, + ocean.datatokens.datatokensABI, web3 ) @@ -117,11 +115,6 @@ function usePublish(): UsePublish { ) } - useEffect(() => { - async function init(): Promise {} - init() - }, []) - return { publish, mint diff --git a/src/providers/OceanProvider/OceanProvider.tsx b/src/providers/OceanProvider/OceanProvider.tsx index 099655a..79517ba 100644 --- a/src/providers/OceanProvider/OceanProvider.tsx +++ b/src/providers/OceanProvider/OceanProvider.tsx @@ -4,9 +4,6 @@ import ProviderStatus from './ProviderStatus' import { Ocean, Logger, Account, Config } from '@oceanprotocol/lib' import Web3Modal, { ICoreOptions } from 'web3modal' -const factory = require('@oceanprotocol/contracts/artifacts/development/Factory.json') -const datatokensTemplate = require('@oceanprotocol/contracts/artifacts/development/DataTokenTemplate.json') - interface OceanProviderValue { web3: Web3 | undefined web3Provider: any @@ -61,10 +58,6 @@ function OceanProvider({ const web3 = new Web3(provider) setWeb3(web3) - config.factoryABI = config.factoryABI ? config.factoryABI : factory.abi - config.datatokensABI = config.datatokensABI - ? config.datatokensABI - : datatokensTemplate.abi config.web3Provider = web3 const ocean = await Ocean.getInstance(config) diff --git a/src/providers/OceanProvider/utils.ts b/src/providers/OceanProvider/utils.ts deleted file mode 100644 index d4bfc41..0000000 --- a/src/providers/OceanProvider/utils.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { Ocean, Config, Account, Logger } from '@oceanprotocol/squid' -import Balance from '@oceanprotocol/squid/dist/node/models/Balance' -import Web3 from 'web3' - -export async function connectOcean( - web3: Web3, - config: Config -): Promise<{ - ocean: Ocean - account: Account - accountId: string - balance: Balance -}> { - Logger.debug('Connecting to Ocean...') - const ocean = await Ocean.getInstance({ - web3Provider: web3.currentProvider, - ...config - }) - Logger.debug('Ocean instance ready.') - // TODO : ocean was not connected and yet i got here and account was undefined so getId() threw an unmanaged error - const oceanAccounts = await ocean.accounts.list() - const account = oceanAccounts[0] - const accountId = account.getId() - const balance = await account.getBalance() - - return { ocean, account, accountId, balance } -}