Skip to content

Commit fd8819e

Browse files
authored
fix: set Explore defaults on app load (#2268)
* fix: set Explore defaults on app load * chore: fix types * fix: do not allow insecure remote gateways for explore page * chore: use [email protected]
1 parent eb3076b commit fd8819e

File tree

4 files changed

+51
-25
lines changed

4 files changed

+51
-25
lines changed

package-lock.json

Lines changed: 24 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
"ipfs-css": "^1.4.0",
6868
"ipfs-geoip": "^9.1.0",
6969
"ipfs-provider": "^2.1.0",
70-
"ipld-explorer-components": "^7.0.2",
70+
"ipld-explorer-components": "^7.0.3",
7171
"is-ipfs": "^8.0.1",
7272
"istextorbinary": "^6.0.0",
7373
"it-all": "^1.0.5",

src/App.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import FilesExploreForm from './files/explore-form/FilesExploreForm.js'
2121

2222
export class App extends Component {
2323
static propTypes = {
24+
doSetupLocalStorage: PropTypes.func.isRequired,
2425
doTryInitIpfs: PropTypes.func.isRequired,
2526
doInitHelia: PropTypes.func.isRequired,
2627
doUpdateUrl: PropTypes.func.isRequired,
@@ -32,6 +33,11 @@ export class App extends Component {
3233
isOver: PropTypes.bool.isRequired
3334
}
3435

36+
constructor (props) {
37+
super(props)
38+
props.doSetupLocalStorage()
39+
}
40+
3541
componentDidMount () {
3642
this.props.doTryInitIpfs()
3743
this.props.doInitHelia()
@@ -131,6 +137,7 @@ export default connect(
131137
'doExploreUserProvidedPath',
132138
'doUpdateUrl',
133139
'doUpdateHash',
140+
'doSetupLocalStorage',
134141
'doTryInitIpfs',
135142
'doInitHelia',
136143
'doFilesWrite',

src/bundles/ipfs-provider.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,25 @@ const selectors = {
315315
*/
316316

317317
const actions = {
318+
319+
doSetupLocalStorage: () => async () => {
320+
/** For the Explore page (i.e. ipld-explorer-components) */
321+
const useRemoteGatewaysToExplore = localStorage.getItem('explore.ipld.gatewayEnabled')
322+
if (useRemoteGatewaysToExplore === null) {
323+
// by default, disable remote gateways for the Explore page (i.e. ipld-explorer-components)
324+
await writeSetting('explore.ipld.gatewayEnabled', false)
325+
}
326+
327+
const kuboGateway = readSetting('kuboGateway')
328+
if (kuboGateway === null || typeof kuboGateway === 'string' || typeof kuboGateway === 'boolean' || typeof kuboGateway === 'number') {
329+
// empty or invalid, set defaults
330+
await writeSetting('kuboGateway', { trustlessBlockBrokerConfig: { init: { allowLocal: true, allowInsecure: false } } })
331+
} else if (/** @type {Record<string, any>} */(kuboGateway).trustlessBlockBrokerConfig == null) {
332+
// missing trustlessBlockBrokerConfig, set defaults
333+
await writeSetting('kuboGateway', { ...kuboGateway, trustlessBlockBrokerConfig: { init: { allowLocal: true, allowInsecure: false } } })
334+
}
335+
},
336+
318337
/**
319338
* @returns {function(Context):Promise<boolean>}
320339
*/

0 commit comments

Comments
 (0)