1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-12-02 05:57:29 +01:00

partial tests fix,hook implementation fix

This commit is contained in:
mihaisc 2020-05-13 12:17:22 +03:00
parent fe61e586da
commit 391d5f2742
9 changed files with 49 additions and 31 deletions

View File

@ -2,7 +2,12 @@ import React from 'react'
import Status from '../../atoms/Status' import Status from '../../atoms/Status'
import Wallet from './Wallet' import Wallet from './Wallet'
import styles from './index.module.css' import styles from './index.module.css'
import { useWeb3, useOcean, InjectedProviderStatus, OceanConnectionStatus } from '@oceanprotocol/react' import {
useWeb3,
useOcean,
InjectedProviderStatus,
OceanConnectionStatus
} from '@oceanprotocol/react'
export declare type Web3Error = { export declare type Web3Error = {
status: 'error' | 'warning' | 'success' status: 'error' | 'warning' | 'success'
@ -21,8 +26,7 @@ export default function Web3Feedback({
ethProviderStatus === InjectedProviderStatus.NOT_AVAILABLE ethProviderStatus === InjectedProviderStatus.NOT_AVAILABLE
const isEthProviderDisconnected = const isEthProviderDisconnected =
ethProviderStatus === InjectedProviderStatus.NOT_CONNECTED ethProviderStatus === InjectedProviderStatus.NOT_CONNECTED
const isOceanDisconnected = const isOceanDisconnected = status === OceanConnectionStatus.NOT_CONNECTED
status === OceanConnectionStatus.NOT_CONNECTED
const isOceanConnectionError = const isOceanConnectionError =
status === OceanConnectionStatus.OCEAN_CONNECTION_ERROR status === OceanConnectionStatus.OCEAN_CONNECTION_ERROR
const hasSuccess = const hasSuccess =

View File

@ -12,8 +12,6 @@ import styles from './Consume.module.css'
import Loader from '../atoms/Loader' import Loader from '../atoms/Loader'
import { useWeb3, useOcean, useConsume } from '@oceanprotocol/react' import { useWeb3, useOcean, useConsume } from '@oceanprotocol/react'
export default function Consume({ ddo }: { ddo: DDO | undefined }) { export default function Consume({ ddo }: { ddo: DDO | undefined }) {
if (!ddo) return null if (!ddo) return null
@ -25,7 +23,8 @@ export default function Consume({ ddo }: { ddo: DDO | undefined }) {
const file = (attributes as MetaDataDexFreight).main.files[0] const file = (attributes as MetaDataDexFreight).main.files[0]
const isFree = price === '0' const isFree = price === '0'
const isBalanceSufficient = const isBalanceSufficient =
isFree || compareAsBN(balanceInOcean, Web3.utils.fromWei(price), Comparisson.gte) isFree ||
compareAsBN(balanceInOcean, Web3.utils.fromWei(price), Comparisson.gte)
const isDisabled = !ocean || !isBalanceSufficient || isLoading const isDisabled = !ocean || !isBalanceSufficient || isLoading
const PurchaseButton = () => { const PurchaseButton = () => {
@ -36,11 +35,7 @@ export default function Consume({ ddo }: { ddo: DDO | undefined }) {
return isLoading ? ( return isLoading ? (
<Loader message={consumeStepText} isHorizontal /> <Loader message={consumeStepText} isHorizontal />
) : ( ) : (
<Button <Button primary onClick={() => consume(ddo.id)} disabled={isDisabled}>
primary
onClick={() => consume(ddo.id)}
disabled={isDisabled}
>
{isFree ? 'Download' : 'Buy'} {isFree ? 'Download' : 'Buy'}
</Button> </Button>
) )

View File

@ -38,7 +38,8 @@ export default function dexfreightApp({ Component, pageProps }: AppProps) {
process.env.SECRET_STORE_URI || 'https://secret-store.oceanprotocol.com', process.env.SECRET_STORE_URI || 'https://secret-store.oceanprotocol.com',
faucetUri: process.env.FAUCET_URI || 'https://faucet.oceanprotocol.com', faucetUri: process.env.FAUCET_URI || 'https://faucet.oceanprotocol.com',
ratingUri: ratingUri:
process.env.RATING_URI || 'https://rating.pacific.dexfreight.dev-ocean.com', process.env.RATING_URI ||
'https://rating.pacific.dexfreight.dev-ocean.com',
verbose: 3 verbose: 3
} }
@ -70,7 +71,6 @@ export default function dexfreightApp({ Component, pageProps }: AppProps) {
/> />
<NProgress /> <NProgress />
<Web3Provider> <Web3Provider>
<OceanProvider config={config}> <OceanProvider config={config}>
<Component {...pageProps} /> <Component {...pageProps} />
</OceanProvider> </OceanProvider>

View File

@ -1,9 +1,22 @@
import web3Mock from './web3' import web3Mock from './web3'
import React from 'react'
import { Web3ProviderValue } from '@oceanprotocol/react'
export const context = React.createContext<Web3ProviderValue | undefined>({
web3: web3Mock,
ethProviderStatus: -1,
account: '0x0000',
balance: '',
chainId: 1,
web3Connect: {} as any,
enable: () => null as any
})
export default { export default {
web3: web3Mock, web3: web3Mock,
ethProviderStatus: -1, ethProviderStatus: -1,
account: '0x0000', account: '0x0000',
balance: '', balance: '',
web3Connect: {} as any chainId: 1,
web3Connect: {} as any,
enable: () => null as any
} }

View File

@ -1,6 +1,6 @@
import React from 'react' import React from 'react'
import { render } from '@testing-library/react' import { render } from '@testing-library/react'
import Web3Provider from '../../../src/context/Web3Provider' import { Web3Provider } from '@oceanprotocol/react'
describe('Web3Provider', () => { describe('Web3Provider', () => {
it('renders without crashing', () => { it('renders without crashing', () => {

View File

@ -3,9 +3,10 @@ import { render } from '@testing-library/react'
import AssetDetails, { getMetadata } from '../../../src/pages/asset/[did]' import AssetDetails, { getMetadata } from '../../../src/pages/asset/[did]'
import ddo from '../__fixtures__/ddo' import ddo from '../__fixtures__/ddo'
import { findServiceByType } from '../../../src/utils' import { findServiceByType } from '../../../src/utils'
import { context } from '../../../src/context/Web3Context' import web3ProviderMock, { context } from '../__mocks__/web3provider'
import web3ProviderMock from '../__mocks__/web3provider'
import { MetaDataDexFreight } from '../../../src/@types/MetaData' import { MetaDataDexFreight } from '../../../src/@types/MetaData'
import { OceanProvider, Config } from '@oceanprotocol/react'
import { config } from '../../../src/config/ocean'
const { attributes } = findServiceByType(ddo, 'metadata') const { attributes } = findServiceByType(ddo, 'metadata')
@ -15,11 +16,13 @@ describe('AssetDetails', () => {
it('renders without crashing', () => { it('renders without crashing', () => {
const { container } = render( const { container } = render(
<context.Provider value={web3ProviderMock}> <context.Provider value={web3ProviderMock}>
<OceanProvider config={config as Config}>
<AssetDetails <AssetDetails
ddo={JSON.stringify(ddo) as any} ddo={JSON.stringify(ddo) as any}
attributes={attributes as MetaDataDexFreight} attributes={attributes as MetaDataDexFreight}
title="Hello" title="Hello"
/> />
</OceanProvider>
</context.Provider> </context.Provider>
) )
expect(container.firstChild).toBeInTheDocument() expect(container.firstChild).toBeInTheDocument()

View File

@ -1,14 +1,17 @@
import React from 'react' import React from 'react'
import { render } from '@testing-library/react' import { render } from '@testing-library/react'
import Publish from '../../../src/pages/publish' import Publish from '../../../src/pages/publish'
import web3ProviderMock from '../__mocks__/web3provider' import web3ProviderMock, { context } from '../__mocks__/web3provider'
import { context } from '../../../src/context/Web3Context' import { OceanProvider, Config } from '@oceanprotocol/react'
import { config } from '../../../src/config/ocean'
describe('Home', () => { describe('Home', () => {
it('renders without crashing', () => { it('renders without crashing', () => {
const { container } = render( const { container } = render(
<context.Provider value={web3ProviderMock}> <context.Provider value={web3ProviderMock}>
<OceanProvider config={config as Config}>
<Publish /> <Publish />
</OceanProvider>
</context.Provider> </context.Provider>
) )
expect(container.firstChild).toBeInTheDocument() expect(container.firstChild).toBeInTheDocument()