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(
|
const oceanConfig = getOceanConfig()
|
||||||
process.env.GATSBY_NETWORK || 'rinkeby'
|
|
||||||
)
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
oceanConfig: {
|
oceanConfig: {
|
||||||
...networkConfig,
|
...oceanConfig,
|
||||||
url: `https://rinkeby.infura.io/${process.env.GATSBY_INFURA_PROJECT_ID}`,
|
url: `https://rinkeby.infura.io/${process.env.GATSBY_INFURA_PROJECT_ID}`,
|
||||||
verbose: 3
|
verbose: 3
|
||||||
},
|
},
|
||||||
// Main, Rinkeby, Kovan
|
// Main, Rinkeby, Kovan
|
||||||
// networks: [1, 4, 42],
|
// networks: [1, 4, 42],
|
||||||
networks: [4],
|
networks: [4],
|
||||||
infuraProjectId: process.env.GATSBY_INFURA_PROJECT_ID || 'xxx',
|
infuraProjectId: process.env.GATSBY_INFURA_PROJECT_ID || 'xxx'
|
||||||
marketAddress:
|
|
||||||
process.env.GATSBY_MARKET_ADDRESS ||
|
|
||||||
'0x36A7f3383A63279cDaF4DfC0F3ABc07d90252C6b'
|
|
||||||
}
|
}
|
||||||
|
@ -7,17 +7,18 @@ import { updateQueryStringParameter } from '../../utils'
|
|||||||
import styles from './AssetList.module.css'
|
import styles from './AssetList.module.css'
|
||||||
import { MetadataMarket } from '../../@types/Metadata'
|
import { MetadataMarket } from '../../@types/Metadata'
|
||||||
import { DDO } from '@oceanprotocol/lib'
|
import { DDO } from '@oceanprotocol/lib'
|
||||||
import { useSiteMetadata } from '../../hooks/useSiteMetadata'
|
import { getOceanConfig } from '../../utils/getConfig'
|
||||||
|
|
||||||
declare type AssetListProps = {
|
declare type AssetListProps = {
|
||||||
queryResult: QueryResult
|
queryResult: QueryResult
|
||||||
}
|
}
|
||||||
|
|
||||||
const AssetList: React.FC<AssetListProps> = ({ queryResult }) => {
|
const AssetList: React.FC<AssetListProps> = ({ queryResult }) => {
|
||||||
const { appConfig } = useSiteMetadata()
|
|
||||||
const location = useLocation()
|
const location = useLocation()
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
|
|
||||||
|
const { metadataStoreUri } = getOceanConfig()
|
||||||
|
|
||||||
// Construct the urls on the pagination links. This is only for UX,
|
// Construct the urls on the pagination links. This is only for UX,
|
||||||
// since the links are no <Link> they will not work by itself.
|
// since the links are no <Link> they will not work by itself.
|
||||||
function hrefBuilder(pageIndex: number) {
|
function hrefBuilder(pageIndex: number) {
|
||||||
@ -55,7 +56,7 @@ const AssetList: React.FC<AssetListProps> = ({ queryResult }) => {
|
|||||||
})
|
})
|
||||||
) : (
|
) : (
|
||||||
<div className={styles.empty}>
|
<div className={styles.empty}>
|
||||||
No results found in {appConfig.oceanConfig.metadataStoreUri}
|
No results found in {metadataStoreUri}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
@ -6,10 +6,11 @@ import AssetList from '../organisms/AssetList'
|
|||||||
import { QueryResult } from '@oceanprotocol/lib/dist/node/metadatastore/MetadataStore'
|
import { QueryResult } from '@oceanprotocol/lib/dist/node/metadatastore/MetadataStore'
|
||||||
import Container from '../atoms/Container'
|
import Container from '../atoms/Container'
|
||||||
import Loader from '../atoms/Loader'
|
import Loader from '../atoms/Loader'
|
||||||
import { useSiteMetadata } from '../../hooks/useSiteMetadata'
|
import { getOceanConfig } from '../../utils/getConfig'
|
||||||
|
|
||||||
async function getLatestAssets(metadataStoreUri: string) {
|
async function getLatestAssets() {
|
||||||
try {
|
try {
|
||||||
|
const { metadataStoreUri } = getOceanConfig()
|
||||||
const metadataStore = new MetadataStore(metadataStoreUri, Logger)
|
const metadataStore = new MetadataStore(metadataStoreUri, Logger)
|
||||||
|
|
||||||
const result = await metadataStore.queryMetadata({
|
const result = await metadataStore.queryMetadata({
|
||||||
@ -26,15 +27,12 @@ async function getLatestAssets(metadataStoreUri: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function HomePage(): ReactElement {
|
export default function HomePage(): ReactElement {
|
||||||
const { appConfig } = useSiteMetadata()
|
|
||||||
const [queryResult, setQueryResult] = useState<QueryResult>()
|
const [queryResult, setQueryResult] = useState<QueryResult>()
|
||||||
const [loading, setLoading] = useState(true)
|
const [loading, setLoading] = useState(true)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function init() {
|
async function init() {
|
||||||
const results = await getLatestAssets(
|
const results = await getLatestAssets()
|
||||||
appConfig.oceanConfig.metadataStoreUri
|
|
||||||
)
|
|
||||||
setQueryResult(results)
|
setQueryResult(results)
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,6 @@ import PublishForm from './PublishForm'
|
|||||||
import Web3Feedback from '../../molecules/Wallet/Feedback'
|
import Web3Feedback from '../../molecules/Wallet/Feedback'
|
||||||
import { FormContent } from '../../../@types/Form'
|
import { FormContent } from '../../../@types/Form'
|
||||||
import { initialValues, validationSchema } from './validation'
|
import { initialValues, validationSchema } from './validation'
|
||||||
import { useSiteMetadata } from '../../../hooks/useSiteMetadata'
|
|
||||||
import { MetadataPublishForm } from '../../../@types/Metadata'
|
import { MetadataPublishForm } from '../../../@types/Metadata'
|
||||||
import { transformPublishFormToMetadata } from './utils'
|
import { transformPublishFormToMetadata } from './utils'
|
||||||
import Preview from './Preview'
|
import Preview from './Preview'
|
||||||
@ -20,7 +19,7 @@ export default function PublishPage({
|
|||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const { publish, publishError } = usePublish()
|
const { publish, publishError } = usePublish()
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const { marketAddress } = useSiteMetadata()
|
const marketAddress = '0x36A7f3383A63279cDaF4DfC0F3ABc07d90252C6b'
|
||||||
|
|
||||||
async function handleSubmit(values: MetadataPublishForm): Promise<void> {
|
async function handleSubmit(values: MetadataPublishForm): Promise<void> {
|
||||||
console.log(`
|
console.log(`
|
||||||
|
@ -6,7 +6,7 @@ import { MetadataMarket, ServiceMetadataMarket } from '../../@types/Metadata'
|
|||||||
import { MetadataStore, Logger, DDO } from '@oceanprotocol/lib'
|
import { MetadataStore, Logger, DDO } from '@oceanprotocol/lib'
|
||||||
import Alert from '../../components/atoms/Alert'
|
import Alert from '../../components/atoms/Alert'
|
||||||
import Loader from '../../components/atoms/Loader'
|
import Loader from '../../components/atoms/Loader'
|
||||||
import { useSiteMetadata } from '../../hooks/useSiteMetadata'
|
import { getOceanConfig } from '../../utils/getConfig'
|
||||||
|
|
||||||
export default function PageTemplateAssetDetails({
|
export default function PageTemplateAssetDetails({
|
||||||
did,
|
did,
|
||||||
@ -15,7 +15,6 @@ export default function PageTemplateAssetDetails({
|
|||||||
did: string
|
did: string
|
||||||
uri: string
|
uri: string
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const { appConfig } = useSiteMetadata()
|
|
||||||
const [metadata, setMetadata] = useState<MetadataMarket>()
|
const [metadata, setMetadata] = useState<MetadataMarket>()
|
||||||
const [title, setTitle] = useState<string>()
|
const [title, setTitle] = useState<string>()
|
||||||
const [error, setError] = useState<string>()
|
const [error, setError] = useState<string>()
|
||||||
@ -24,10 +23,8 @@ export default function PageTemplateAssetDetails({
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function init() {
|
async function init() {
|
||||||
try {
|
try {
|
||||||
const metadataStore = new MetadataStore(
|
const { metadataStoreUri } = getOceanConfig()
|
||||||
appConfig.oceanConfig.metadataStoreUri,
|
const metadataStore = new MetadataStore(metadataStoreUri, Logger)
|
||||||
Logger
|
|
||||||
)
|
|
||||||
const ddo = await metadataStore.retrieveDDO(did)
|
const ddo = await metadataStore.retrieveDDO(did)
|
||||||
setDdo(ddo)
|
setDdo(ddo)
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ import {
|
|||||||
} from '@oceanprotocol/lib/dist/node/metadatastore/MetadataStore'
|
} from '@oceanprotocol/lib/dist/node/metadatastore/MetadataStore'
|
||||||
import { priceQueryParamToWei } from '../../../utils'
|
import { priceQueryParamToWei } from '../../../utils'
|
||||||
import { MetadataStore, Logger } from '@oceanprotocol/lib'
|
import { MetadataStore, Logger } from '@oceanprotocol/lib'
|
||||||
import { oceanConfig } from '../../../../app.config'
|
import { getOceanConfig } from '../../../utils/getConfig'
|
||||||
|
|
||||||
export function getSearchQuery(
|
export function getSearchQuery(
|
||||||
page?: string | string[],
|
page?: string | string[],
|
||||||
@ -52,7 +52,8 @@ export async function getResults(params: any): Promise<QueryResult> {
|
|||||||
])
|
])
|
||||||
: undefined
|
: undefined
|
||||||
|
|
||||||
const metadataStore = new MetadataStore(oceanConfig.metadataStoreUri, Logger)
|
const { metadataStoreUri } = getOceanConfig()
|
||||||
|
const metadataStore = new MetadataStore(metadataStoreUri, Logger)
|
||||||
const queryResult = await metadataStore.queryMetadata(
|
const queryResult = await metadataStore.queryMetadata(
|
||||||
getSearchQuery(page, offset, text, tag, priceQuery)
|
getSearchQuery(page, offset, text, tag, priceQuery)
|
||||||
)
|
)
|
||||||
|
@ -16,15 +16,6 @@ const query = graphql`
|
|||||||
appConfig {
|
appConfig {
|
||||||
infuraProjectId
|
infuraProjectId
|
||||||
networks
|
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