mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
* wagmi + ethers + web3modal setup * refactor wallet components * fallback providers, more config * kick out useWeb3 * remove all useWeb3 imports * more web3.js usage removal * isAddress utils replacement * restore add token / add network * less accountId changes * web3 legacy tinkering, utils/web3 → utils/wallet * legacy web3 object for ocean.js * graph sync fix, remove custom network switching code * package updates, merge fixes * downgrade to ethers v5 * fix project id * switch to ConnectKit * connectkit theming * add existing chains to wagmi * rewrite getPaymentCollector() * kick out getPaymentCollector completely, use wagmi hooks instead * Revert "kick out getPaymentCollector completely, use wagmi hooks instead" This reverts commit 54c7d1ef1a2dec0b1575a685125ba78336b30f59. * switch getPaymentCollector * calcBaseInGivenDatatokensOut reorg * wip integrate ocean lib 3.0.0 * update orbis components to use wagmi instead of web hooks * more oceanjs integration updates * more refactors * fix build * update ocean lib * fix publish * fix order fixed rate * remove logs * debug and stop infinite cycle orbis connect * fix orbis dm connection * mock use network and fix some more tests * mock wagmi switch network * mock wagmi useProvider createClient and connectKit getDefaultClient * fix jest tests * try storybook fix * cleanups and bump ocean lib * fix order * bump lib to next.5 and add more modal style * bump ocean.js lib to 3.0.0 --------- Co-authored-by: Matthias Kretschmann <m@kretschmann.io>
84 lines
2.6 KiB
TypeScript
84 lines
2.6 KiB
TypeScript
import { ReactElement, useEffect } from 'react'
|
|
import { useFormikContext } from 'formik'
|
|
import { wizardSteps, initialPublishFeedback } from './_constants'
|
|
import { FormPublishData, PublishFeedback } from './_types'
|
|
import { getOceanConfig } from '@utils/ocean'
|
|
import { useAccount, useNetwork } from 'wagmi'
|
|
import { useMarketMetadata } from '@context/MarketMetadata'
|
|
|
|
export function Steps({
|
|
feedback
|
|
}: {
|
|
feedback: PublishFeedback
|
|
}): ReactElement {
|
|
const { address: accountId } = useAccount()
|
|
const { chain } = useNetwork()
|
|
const { approvedBaseTokens } = useMarketMetadata()
|
|
const { values, setFieldValue, touched, setTouched } =
|
|
useFormikContext<FormPublishData>()
|
|
|
|
const isCustomProviderUrl = values?.services?.[0]?.providerUrl.custom
|
|
|
|
// auto-sync user chain?.id & account into form data values
|
|
useEffect(() => {
|
|
if (!chain?.id || !accountId) return
|
|
|
|
setFieldValue('user.chainId', chain?.id)
|
|
setFieldValue('user.accountId', accountId)
|
|
}, [chain?.id, accountId, setFieldValue])
|
|
|
|
useEffect(() => {
|
|
if (!approvedBaseTokens?.length) return
|
|
|
|
const defaultBaseToken =
|
|
approvedBaseTokens?.find((token) =>
|
|
token.name.toLowerCase().includes('ocean')
|
|
) || approvedBaseTokens?.[0]
|
|
const isBaseTokenSet = !!approvedBaseTokens?.find(
|
|
(token) => token?.address === values?.pricing?.baseToken?.address
|
|
)
|
|
if (isBaseTokenSet) return
|
|
|
|
setFieldValue('pricing.baseToken', defaultBaseToken)
|
|
}, [approvedBaseTokens, values?.pricing?.baseToken?.address])
|
|
|
|
// auto-sync publish feedback into form data values
|
|
useEffect(() => {
|
|
setFieldValue('feedback', feedback)
|
|
}, [feedback, setFieldValue])
|
|
|
|
// auto-switch some feedback content based on pricing type
|
|
useEffect(() => {
|
|
setFieldValue('feedback', {
|
|
...feedback,
|
|
'1': {
|
|
...feedback['1'],
|
|
txCount: 1,
|
|
description: initialPublishFeedback['1'].description
|
|
}
|
|
})
|
|
}, [values.pricing.type, feedback, setFieldValue])
|
|
|
|
// Auto-change default providerUrl on user network change
|
|
useEffect(() => {
|
|
if (!values?.user?.chainId || isCustomProviderUrl === true) return
|
|
|
|
const config = getOceanConfig(values.user.chainId)
|
|
if (config) {
|
|
setFieldValue('services[0].providerUrl', {
|
|
url: config.providerUri,
|
|
valid: true,
|
|
custom: false
|
|
})
|
|
}
|
|
|
|
setTouched({ ...touched, services: [{ providerUrl: { url: true } }] })
|
|
}, [values?.user?.chainId, isCustomProviderUrl, setFieldValue, setTouched])
|
|
|
|
const { component } = wizardSteps.filter((stepContent) => {
|
|
return stepContent.step === values.user.stepCurrent
|
|
})[0]
|
|
|
|
return component
|
|
}
|