mirror of
https://github.com/oceanprotocol/commons.git
synced 2023-03-15 18:03:00 +01:00
output js-ipfs version
This commit is contained in:
parent
3b889725f1
commit
9c38c82496
@ -5,6 +5,7 @@ import { useEffect, useState } from 'react'
|
||||
|
||||
let ipfs: any = null
|
||||
let ipfsMessage = ''
|
||||
let ipfsVersion = ''
|
||||
|
||||
export default function useIpfs() {
|
||||
const [isIpfsReady, setIpfsReady] = useState(Boolean(ipfs))
|
||||
@ -25,6 +26,9 @@ export default function useIpfs() {
|
||||
ipfs = await Ipfs.create()
|
||||
console.timeEnd(message)
|
||||
ipfsMessage = message
|
||||
|
||||
const { version } = await ipfs.version()
|
||||
ipfsVersion = version
|
||||
} catch (error) {
|
||||
const message = `IPFS init error: ${error.message}`
|
||||
ipfsMessage = message
|
||||
@ -47,11 +51,12 @@ export default function useIpfs() {
|
||||
setIpfsReady(false)
|
||||
ipfs = null
|
||||
ipfsMessage = ''
|
||||
ipfsVersion = ''
|
||||
setIpfsInitError(null)
|
||||
console.timeEnd('IPFS stopped')
|
||||
}
|
||||
}
|
||||
}, [])
|
||||
|
||||
return { ipfs, isIpfsReady, ipfsInitError, ipfsMessage }
|
||||
return { ipfs, ipfsVersion, isIpfsReady, ipfsInitError, ipfsMessage }
|
||||
}
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
input {
|
||||
display: block;
|
||||
width: fit-content;
|
||||
width: 100%;
|
||||
cursor: pointer;
|
||||
border: .1rem solid $brand-grey-lighter;
|
||||
border-radius: $border-radius;
|
||||
|
@ -30,7 +30,13 @@ function formatBytes(a: number, b: number) {
|
||||
}
|
||||
|
||||
export default function Ipfs({ addFile }: { addFile(url: string): void }) {
|
||||
const { ipfs, isIpfsReady, ipfsInitError, ipfsMessage } = useIpfs()
|
||||
const {
|
||||
ipfs,
|
||||
ipfsVersion,
|
||||
isIpfsReady,
|
||||
ipfsInitError,
|
||||
ipfsMessage
|
||||
} = useIpfs()
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [message, setMessage] = useState('')
|
||||
|
||||
@ -92,7 +98,12 @@ export default function Ipfs({ addFile }: { addFile(url: string): void }) {
|
||||
/>
|
||||
)}
|
||||
{ipfsMessage !== '' && (
|
||||
<div className={styles.message}>{ipfsMessage}</div>
|
||||
<div
|
||||
className={styles.message}
|
||||
title={`js-ipfs v${ipfsVersion}`}
|
||||
>
|
||||
{ipfsMessage}
|
||||
</div>
|
||||
)}
|
||||
{ipfsInitError && (
|
||||
<div className={styles.error}>{ipfsInitError}</div>
|
||||
|
Loading…
Reference in New Issue
Block a user