-
Notifications
You must be signed in to change notification settings - Fork 488
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
59 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
// 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) { | ||
return bitswapStats.downloadedSize.toString() | ||
} | ||
} | ||
) | ||
|
||
bundle.selectSharedSize = createSelector( | ||
'selectBitswapStats', | ||
(bitswapStats) => { | ||
console.log(bitswapStats) | ||
if (bitswapStats && bitswapStats.sharedSize) { | ||
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' } | ||
} | ||
} | ||
) | ||
|
||
export default bundle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters