1
0
mirror of https://github.com/oceanprotocol/react.git synced 2025-02-14 21:10:38 +01:00
This commit is contained in:
mihaisc 2020-05-08 15:54:16 +03:00
parent 7658e56683
commit 135f297e07
2 changed files with 5 additions and 6 deletions

View File

@ -19,8 +19,6 @@ export const consumeFeedback: { [key in number]: string } = {
} }
function useConsume(): UseConsume { function useConsume(): UseConsume {
// TODO: figure out if a hook within a hook could lead to problems.
// Otherwise we could just require `ocean` to be passed to `useConsume()`
const { ocean, account, accountId } = useOcean() const { ocean, account, accountId } = useOcean()
const [consumeStep, setConsumeStep] = useState<number | undefined>() const [consumeStep, setConsumeStep] = useState<number | undefined>()
const [consumeStepText, setConsumeStepText] = useState<string | undefined>() const [consumeStepText, setConsumeStepText] = useState<string | undefined>()
@ -36,19 +34,20 @@ function useConsume(): UseConsume {
accountId accountId
) )
const agreement = agreements.find((el: { did: string }) => el.did === did) const agreement = agreements.find((el: { did: string }) => el.did === did)
console.log('existing agre',agreement) console.log('existing agre', agreements)
const agreementId = agreement const agreementId = agreement
? agreement.agreementId ? agreement.agreementId
: await ocean.assets : await ocean.assets
.order(did as string, account) .order(did as string, account)
.next((step: number) => { setConsumeStep(step); setConsumeStepText(consumeFeedback[step]) }) .next((step: number) => { setConsumeStep(step); setConsumeStepText(consumeFeedback[step]); })
console.log('aggrement ok', agreementId)
// manually add another step here for better UX // manually add another step here for better UX
setConsumeStep(4) setConsumeStep(4)
setConsumeStepText(consumeFeedback[4]) setConsumeStepText(consumeFeedback[4])
await ocean.assets.consume(agreementId, did as string, account, '') await ocean.assets.consume(agreementId, did as string, account, '')
console.log('consume ok') console.log('consume ok')
} catch (error) { } catch (error) {
console.log(error)
setConsumeError(error.message) setConsumeError(error.message)
} finally { } finally {
setConsumeStep(undefined) setConsumeStep(undefined)

View File

@ -57,7 +57,7 @@ function OceanProvider({
// 2. Once `web3` becomes available, connect to the whole network // 2. Once `web3` becomes available, connect to the whole network
// ------------------------------------------------------------- // -------------------------------------------------------------
useEffect(() => { useEffect(() => {
console.log('ocean', web3)
if (!web3) return if (!web3) return
async function init(): Promise<void> { async function init(): Promise<void> {