mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
more config refactor
This commit is contained in:
parent
a73fac1611
commit
fd3a436a31
@ -1,20 +1,15 @@
|
||||
const { ConfigHelper } = require('@oceanprotocol/lib')
|
||||
const { getOceanConfig } = require('./src/utils/getConfig')
|
||||
|
||||
const networkConfig = new ConfigHelper().getConfig(
|
||||
process.env.GATSBY_NETWORK || 'rinkeby'
|
||||
)
|
||||
const oceanConfig = getOceanConfig()
|
||||
|
||||
module.exports = {
|
||||
oceanConfig: {
|
||||
...networkConfig,
|
||||
...oceanConfig,
|
||||
url: `https://rinkeby.infura.io/${process.env.GATSBY_INFURA_PROJECT_ID}`,
|
||||
verbose: 3
|
||||
},
|
||||
// Main, Rinkeby, Kovan
|
||||
// networks: [1, 4, 42],
|
||||
networks: [4],
|
||||
infuraProjectId: process.env.GATSBY_INFURA_PROJECT_ID || 'xxx',
|
||||
marketAddress:
|
||||
process.env.GATSBY_MARKET_ADDRESS ||
|
||||
'0x36A7f3383A63279cDaF4DfC0F3ABc07d90252C6b'
|
||||
infuraProjectId: process.env.GATSBY_INFURA_PROJECT_ID || 'xxx'
|
||||
}
|
||||
|
@ -7,17 +7,18 @@ import { updateQueryStringParameter } from '../../utils'
|
||||
import styles from './AssetList.module.css'
|
||||
import { MetadataMarket } from '../../@types/Metadata'
|
||||
import { DDO } from '@oceanprotocol/lib'
|
||||
import { useSiteMetadata } from '../../hooks/useSiteMetadata'
|
||||
import { getOceanConfig } from '../../utils/getConfig'
|
||||
|
||||
declare type AssetListProps = {
|
||||
queryResult: QueryResult
|
||||
}
|
||||
|
||||
const AssetList: React.FC<AssetListProps> = ({ queryResult }) => {
|
||||
const { appConfig } = useSiteMetadata()
|
||||
const location = useLocation()
|
||||
const navigate = useNavigate()
|
||||
|
||||
const { metadataStoreUri } = getOceanConfig()
|
||||
|
||||
// Construct the urls on the pagination links. This is only for UX,
|
||||
// since the links are no <Link> they will not work by itself.
|
||||
function hrefBuilder(pageIndex: number) {
|
||||
@ -55,7 +56,7 @@ const AssetList: React.FC<AssetListProps> = ({ queryResult }) => {
|
||||
})
|
||||
) : (
|
||||
<div className={styles.empty}>
|
||||
No results found in {appConfig.oceanConfig.metadataStoreUri}
|
||||
No results found in {metadataStoreUri}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
@ -6,10 +6,11 @@ import AssetList from '../organisms/AssetList'
|
||||
import { QueryResult } from '@oceanprotocol/lib/dist/node/metadatastore/MetadataStore'
|
||||
import Container from '../atoms/Container'
|
||||
import Loader from '../atoms/Loader'
|
||||
import { useSiteMetadata } from '../../hooks/useSiteMetadata'
|
||||
import { getOceanConfig } from '../../utils/getConfig'
|
||||
|
||||
async function getLatestAssets(metadataStoreUri: string) {
|
||||
async function getLatestAssets() {
|
||||
try {
|
||||
const { metadataStoreUri } = getOceanConfig()
|
||||
const metadataStore = new MetadataStore(metadataStoreUri, Logger)
|
||||
|
||||
const result = await metadataStore.queryMetadata({
|
||||
@ -26,15 +27,12 @@ async function getLatestAssets(metadataStoreUri: string) {
|
||||
}
|
||||
|
||||
export default function HomePage(): ReactElement {
|
||||
const { appConfig } = useSiteMetadata()
|
||||
const [queryResult, setQueryResult] = useState<QueryResult>()
|
||||
const [loading, setLoading] = useState(true)
|
||||
|
||||
useEffect(() => {
|
||||
async function init() {
|
||||
const results = await getLatestAssets(
|
||||
appConfig.oceanConfig.metadataStoreUri
|
||||
)
|
||||
const results = await getLatestAssets()
|
||||
setQueryResult(results)
|
||||
setLoading(false)
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ import PublishForm from './PublishForm'
|
||||
import Web3Feedback from '../../molecules/Wallet/Feedback'
|
||||
import { FormContent } from '../../../@types/Form'
|
||||
import { initialValues, validationSchema } from './validation'
|
||||
import { useSiteMetadata } from '../../../hooks/useSiteMetadata'
|
||||
import { MetadataPublishForm } from '../../../@types/Metadata'
|
||||
import { transformPublishFormToMetadata } from './utils'
|
||||
import Preview from './Preview'
|
||||
@ -20,7 +19,7 @@ export default function PublishPage({
|
||||
}): ReactElement {
|
||||
const { publish, publishError } = usePublish()
|
||||
const navigate = useNavigate()
|
||||
const { marketAddress } = useSiteMetadata()
|
||||
const marketAddress = '0x36A7f3383A63279cDaF4DfC0F3ABc07d90252C6b'
|
||||
|
||||
async function handleSubmit(values: MetadataPublishForm): Promise<void> {
|
||||
console.log(`
|
||||
|
@ -6,7 +6,7 @@ import { MetadataMarket, ServiceMetadataMarket } from '../../@types/Metadata'
|
||||
import { MetadataStore, Logger, DDO } from '@oceanprotocol/lib'
|
||||
import Alert from '../../components/atoms/Alert'
|
||||
import Loader from '../../components/atoms/Loader'
|
||||
import { useSiteMetadata } from '../../hooks/useSiteMetadata'
|
||||
import { getOceanConfig } from '../../utils/getConfig'
|
||||
|
||||
export default function PageTemplateAssetDetails({
|
||||
did,
|
||||
@ -15,7 +15,6 @@ export default function PageTemplateAssetDetails({
|
||||
did: string
|
||||
uri: string
|
||||
}): ReactElement {
|
||||
const { appConfig } = useSiteMetadata()
|
||||
const [metadata, setMetadata] = useState<MetadataMarket>()
|
||||
const [title, setTitle] = useState<string>()
|
||||
const [error, setError] = useState<string>()
|
||||
@ -24,10 +23,8 @@ export default function PageTemplateAssetDetails({
|
||||
useEffect(() => {
|
||||
async function init() {
|
||||
try {
|
||||
const metadataStore = new MetadataStore(
|
||||
appConfig.oceanConfig.metadataStoreUri,
|
||||
Logger
|
||||
)
|
||||
const { metadataStoreUri } = getOceanConfig()
|
||||
const metadataStore = new MetadataStore(metadataStoreUri, Logger)
|
||||
const ddo = await metadataStore.retrieveDDO(did)
|
||||
setDdo(ddo)
|
||||
|
||||
|
@ -4,7 +4,7 @@ import {
|
||||
} from '@oceanprotocol/lib/dist/node/metadatastore/MetadataStore'
|
||||
import { priceQueryParamToWei } from '../../../utils'
|
||||
import { MetadataStore, Logger } from '@oceanprotocol/lib'
|
||||
import { oceanConfig } from '../../../../app.config'
|
||||
import { getOceanConfig } from '../../../utils/getConfig'
|
||||
|
||||
export function getSearchQuery(
|
||||
page?: string | string[],
|
||||
@ -52,7 +52,8 @@ export async function getResults(params: any): Promise<QueryResult> {
|
||||
])
|
||||
: undefined
|
||||
|
||||
const metadataStore = new MetadataStore(oceanConfig.metadataStoreUri, Logger)
|
||||
const { metadataStoreUri } = getOceanConfig()
|
||||
const metadataStore = new MetadataStore(metadataStoreUri, Logger)
|
||||
const queryResult = await metadataStore.queryMetadata(
|
||||
getSearchQuery(page, offset, text, tag, priceQuery)
|
||||
)
|
||||
|
@ -16,15 +16,6 @@ const query = graphql`
|
||||
appConfig {
|
||||
infuraProjectId
|
||||
networks
|
||||
marketAddress
|
||||
oceanConfig {
|
||||
url
|
||||
factoryAddress
|
||||
oceanTokenAddress
|
||||
metadataStoreUri
|
||||
providerUri
|
||||
verbose
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
5
src/utils/getConfig.ts
Normal file
5
src/utils/getConfig.ts
Normal file
@ -0,0 +1,5 @@
|
||||
import { ConfigHelper, Config } from '@oceanprotocol/lib'
|
||||
|
||||
export function getOceanConfig(): Config {
|
||||
return new ConfigHelper().getConfig(process.env.GATSBY_NETWORK || 'rinkeby')
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
import axios, { AxiosResponse } from 'axios'
|
||||
import { oceanConfig } from '../../app.config'
|
||||
|
||||
export interface FaucetResponse {
|
||||
success: boolean
|
||||
message: string
|
||||
trxHash?: string
|
||||
}
|
||||
|
||||
export default async function getFromFaucet(
|
||||
account: string
|
||||
): Promise<FaucetResponse> {
|
||||
try {
|
||||
const response: AxiosResponse = await axios({
|
||||
method: 'POST',
|
||||
url: `${oceanConfig.faucetUri}/faucet`,
|
||||
data: {
|
||||
address: account,
|
||||
agent: 'market'
|
||||
}
|
||||
})
|
||||
|
||||
return response.data
|
||||
} catch (error) {
|
||||
return { success: false, message: error.message }
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
import axios, { AxiosResponse } from 'axios'
|
||||
import getFromFaucet from '../../../src/utils/getFromFaucet'
|
||||
|
||||
jest.mock('axios')
|
||||
|
||||
describe('getFromFaucet()', () => {
|
||||
;(axios as any).mockResolvedValue({
|
||||
data: { success: true, message: 'hello' }
|
||||
} as AxiosResponse)
|
||||
|
||||
it('can be called', async () => {
|
||||
const response = await getFromFaucet('0x0000000')
|
||||
expect(response.message).toBe('hello')
|
||||
})
|
||||
})
|
Loading…
Reference in New Issue
Block a user