1
0
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:
Matthias Kretschmann 2019-09-05 00:14:38 +02:00
parent 3b889725f1
commit 9c38c82496
Signed by: m
GPG Key ID: 606EEEF3C479A91F
3 changed files with 20 additions and 4 deletions

View File

@ -5,6 +5,7 @@ import { useEffect, useState } from 'react'
let ipfs: any = null let ipfs: any = null
let ipfsMessage = '' let ipfsMessage = ''
let ipfsVersion = ''
export default function useIpfs() { export default function useIpfs() {
const [isIpfsReady, setIpfsReady] = useState(Boolean(ipfs)) const [isIpfsReady, setIpfsReady] = useState(Boolean(ipfs))
@ -25,6 +26,9 @@ export default function useIpfs() {
ipfs = await Ipfs.create() ipfs = await Ipfs.create()
console.timeEnd(message) console.timeEnd(message)
ipfsMessage = message ipfsMessage = message
const { version } = await ipfs.version()
ipfsVersion = version
} catch (error) { } catch (error) {
const message = `IPFS init error: ${error.message}` const message = `IPFS init error: ${error.message}`
ipfsMessage = message ipfsMessage = message
@ -47,11 +51,12 @@ export default function useIpfs() {
setIpfsReady(false) setIpfsReady(false)
ipfs = null ipfs = null
ipfsMessage = '' ipfsMessage = ''
ipfsVersion = ''
setIpfsInitError(null) setIpfsInitError(null)
console.timeEnd('IPFS stopped') console.timeEnd('IPFS stopped')
} }
} }
}, []) }, [])
return { ipfs, isIpfsReady, ipfsInitError, ipfsMessage } return { ipfs, ipfsVersion, isIpfsReady, ipfsInitError, ipfsMessage }
} }

View File

@ -9,7 +9,7 @@
input { input {
display: block; display: block;
width: fit-content; width: 100%;
cursor: pointer; cursor: pointer;
border: .1rem solid $brand-grey-lighter; border: .1rem solid $brand-grey-lighter;
border-radius: $border-radius; border-radius: $border-radius;

View File

@ -30,7 +30,13 @@ function formatBytes(a: number, b: number) {
} }
export default function Ipfs({ addFile }: { addFile(url: string): void }) { 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 [loading, setLoading] = useState(false)
const [message, setMessage] = useState('') const [message, setMessage] = useState('')
@ -92,7 +98,12 @@ export default function Ipfs({ addFile }: { addFile(url: string): void }) {
/> />
)} )}
{ipfsMessage !== '' && ( {ipfsMessage !== '' && (
<div className={styles.message}>{ipfsMessage}</div> <div
className={styles.message}
title={`js-ipfs v${ipfsVersion}`}
>
{ipfsMessage}
</div>
)} )}
{ipfsInitError && ( {ipfsInitError && (
<div className={styles.error}>{ipfsInitError}</div> <div className={styles.error}>{ipfsInitError}</div>