New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add sharing statistics on the homepage #1942
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { createAsyncResourceBundle, createSelector } from 'redux-bundler' | ||
|
||
const bundle = createAsyncResourceBundle({ | ||
name: 'bitswapStats', | ||
getPromise: async ({ getIpfs }) => { | ||
const rawData = await getIpfs().stats.bitswap() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens if this function throws? Also, prefer There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I have no idea, wtf is javascript anyway ? (I guess the ressources are never initialised which isn't that bad ?) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated with try/catch |
||
// early gc, dont keep arround the peer list | ||
return { downloadedSize: rawData.dataReceived, sharedSize: rawData.dataSent } | ||
}, | ||
staleAfter: 60000, | ||
persist: false, | ||
checkIfOnline: false | ||
}) | ||
|
||
bundle.selectDownloadedSize = createSelector( | ||
'selectBitswapStats', | ||
(bitswapStats) => { | ||
if (bitswapStats && bitswapStats.downloadedSize) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. eslint should be yelling here about using optional chaining instead, e.g.
You may want to check your editor settings. |
||
return bitswapStats.downloadedSize.toString() | ||
} | ||
} | ||
) | ||
|
||
bundle.selectSharedSize = createSelector( | ||
'selectBitswapStats', | ||
(bitswapStats) => { | ||
console.log(bitswapStats) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we still need this? If so, prefer There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Debug I forgot to remove |
||
if (bitswapStats && bitswapStats.sharedSize) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
return bitswapStats.sharedSize.toString() | ||
} | ||
} | ||
) | ||
|
||
// Fetch the config if we don't have it or it's more than `staleAfter` ms old | ||
bundle.reactBitswapStatsFetch = createSelector( | ||
'selectBitswapStatsShouldUpdate', | ||
'selectIpfsReady', | ||
(shouldUpdate, ipfsReady) => { | ||
if (shouldUpdate && ipfsReady) { | ||
return { actionCreator: 'doFetchBitswapStats' } | ||
SgtPooki marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
) | ||
|
||
export default bundle |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,22 @@ import { withTranslation, Trans } from 'react-i18next' | |
import { connect } from 'redux-bundler-react' | ||
import { humanSize } from '../lib/files' | ||
|
||
export const StatusConnected = ({ t, peersCount, repoSize }) => { | ||
export const StatusConnected = ({ t, peersCount, repoSize, downloadedSize, sharedSize }) => { | ||
const humanRepoSize = humanSize(repoSize || 0) | ||
downloadedSize = downloadedSize || 0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: we should prefer the null coalescence operator ( ditto for other vars here. |
||
const humanDownloadSize = humanSize(downloadedSize) | ||
sharedSize = sharedSize || 0 | ||
const humanSharedSize = humanSize(sharedSize) | ||
let shareRatio = sharedSize / downloadedSize | ||
if (isNaN(shareRatio)) { | ||
shareRatio = Infinity | ||
} | ||
if (shareRatio < 10) { | ||
// round to 1 decimal place if that bellow 10 | ||
shareRatio = Math.round(shareRatio * 10) / 10 | ||
} else { | ||
shareRatio = Math.round(shareRatio) | ||
} | ||
return ( | ||
<header> | ||
<h1 className='montserrat fw2 f3 charcoal ma0 pt0 pb2'> | ||
|
@@ -17,6 +31,10 @@ export const StatusConnected = ({ t, peersCount, repoSize }) => { | |
</a> | ||
</span> | ||
<span className='dn di-ns gray'> — </span> | ||
<span className='db mt1 mt0-ns dib-ns'> | ||
{t('StatusConnected.shareSize', { downloadedSize: humanDownloadSize, sharedSize: humanSharedSize, ratio: shareRatio })} | ||
</span> | ||
<span className='dn di-ns gray'> — </span> | ||
<span className='db mt1 mt0-ns dib-ns'> | ||
<a className='link blue' href='#/peers'> | ||
{t('StatusConnected.peersCount', { peersCount: peersCount.toString() })} | ||
|
@@ -32,5 +50,7 @@ export const TranslatedStatusConnected = withTranslation('status')(StatusConnect | |
export default connect( | ||
'selectPeersCount', | ||
'selectRepoSize', | ||
'selectDownloadedSize', | ||
'selectSharedSize', | ||
TranslatedStatusConnected | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Jorropo @SgtPooki @hacdias thoughts on presentation / phrasing here?
These are stats for the current session and not the total across history.
Same for "Discovered peers".
Maybe we should prefix them with "Current session" or "Since {startup date}"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should add some indication that this is not since the beginning, but just for the current session. Maybe some surrounding box saying current session?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea of a "Since {date}" prefix.
Also, this is a great candidate for #1220