Skip to content

Commit d4710e8

Browse files
authored
chore: remove selectApiUrl selector (#2412)
1 parent d4e7fca commit d4710e8

File tree

3 files changed

+18
-24
lines changed

3 files changed

+18
-24
lines changed

src/bundles/config.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import memoize from 'p-memoize'
22
import { multiaddrToUri as toUri } from '@multiformats/multiaddr-to-uri'
33
import { createAsyncResourceBundle, createSelector } from 'redux-bundler'
4+
import { contextBridge } from '../helpers/context-bridge'
45

56
const LOCAL_HOSTNAMES = ['127.0.0.1', '[::1]', '0.0.0.0', '[::]']
67

@@ -53,10 +54,13 @@ bundle.selectConfigObject = createSelector(
5354
(configStr) => JSON.parse(configStr)
5455
)
5556

56-
bundle.selectApiUrl = createSelector(
57+
bundle.reactIsSameOriginToBridge = createSelector(
5758
'selectConfigObject',
5859
'selectPublicGateway',
59-
(config, publicGateway) => getURLFromAddress('API', config) || publicGateway
60+
(config, publicGateway) => {
61+
const apiUrl = getURLFromAddress('API', config) || publicGateway
62+
contextBridge.setContext('selectIsSameOrigin', window.location.origin === apiUrl)
63+
}
6064
)
6165

6266
bundle.selectGatewayUrl = createSelector(

src/components/is-not-connected/IsNotConnected.js

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,26 @@
11
import React, { useState } from 'react'
2-
import { connect } from 'redux-bundler-react'
3-
import { withTranslation, Trans } from 'react-i18next'
2+
import { Trans, useTranslation } from 'react-i18next'
43
import classNames from 'classnames'
54
import ApiAddressForm from '../api-address-form/api-address-form'
65
import Box from '../box/Box.js'
76
import Shell from '../shell/Shell.js'
87
import GlyphAttention from '../../icons/GlyphAttention.js'
8+
import { useBridgeSelector } from '../../helpers/context-bridge'
99

1010
const TABS = {
1111
UNIX: 'unix',
1212
POWERSHELL: 'windowsPS',
1313
WINDOWS: 'windowsCMD'
1414
}
1515

16-
/**
17-
* @param {Object} props
18-
* @param {import('i18next').TFunction} props.t
19-
* @param {string} props.apiUrl
20-
* @param {boolean} props.connected
21-
* @param {boolean} props.sameOrigin
22-
*/
23-
const IsNotConnected = ({ t, apiUrl: _apiUrl, connected: _connected, sameOrigin }) => {
16+
const IsNotConnected = () => {
17+
const { t } = useTranslation('welcome')
18+
const isSameOrigin = useBridgeSelector('selectIsSameOrigin')
2419
const [activeTab, setActiveTab] = useState(TABS.UNIX)
2520
const defaultDomains = ['http://localhost:3000', 'http://127.0.0.1:5001', 'https://webui.ipfs.io']
2621
const origin = window.location.origin
2722
const addOrigin = defaultDomains.indexOf(origin) === -1
23+
2824
return (
2925
<Box className='pv3 ph4 lh-copy charcoal'>
3026
<div className='flex flex-wrap items-center'>
@@ -43,7 +39,7 @@ const IsNotConnected = ({ t, apiUrl: _apiUrl, connected: _connected, sameOrigin
4339
<code className='db'>Initializing daemon...</code>
4440
<code className='db'>RPC API server listening on /ip4/127.0.0.1/tcp/5001</code>
4541
</Shell>
46-
{ !sameOrigin && (
42+
{ !isSameOrigin && (
4743
<div>
4844
<Trans i18nKey='notConnected.paragraph3' t={t}>
4945
<li className='mb3 mt4'>Is your Kubo RPC API configured to allow <a className='link blue' href='https://github.com/ipfs/ipfs-webui#configure-kubo-rpc-api-cors-headers'>cross-origin (CORS) requests</a>? If not, run these commands and then start your daemon from the terminal:</li>
@@ -92,8 +88,4 @@ const IsNotConnected = ({ t, apiUrl: _apiUrl, connected: _connected, sameOrigin
9288
)
9389
}
9490

95-
export default connect(
96-
'selectIpfsConnected',
97-
'selectApiUrl',
98-
withTranslation('welcome')(IsNotConnected)
99-
)
91+
export default IsNotConnected

src/welcome/WelcomePage.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,24 @@ import IsNotConnected from '../components/is-not-connected/IsNotConnected.js'
1313
import AboutIpfs from '../components/about-ipfs/AboutIpfs.js'
1414
import AboutWebUI from '../components/about-webui/AboutWebUI.js'
1515
import ComponentLoader from '../loader/ComponentLoader.js'
16+
import { useBridgeSelector } from '../helpers/context-bridge'
1617

1718
/**
1819
* @param {Object} props
1920
* @param {import('i18next').TFunction} props.t
20-
* @param {string} props.apiUrl
2121
* @param {boolean} props.ipfsInitFailed
2222
* @param {boolean} props.ipfsConnected
2323
* @param {boolean} props.ipfsReady
2424
* @param {boolean} props.toursEnabled
2525
* @param {(data: any) => void} props.handleJoyrideCallback
2626
*/
27-
const WelcomePage = ({ t, apiUrl, ipfsInitFailed, ipfsConnected, ipfsReady, toursEnabled, handleJoyrideCallback }) => {
27+
const WelcomePage = ({ t, ipfsInitFailed, ipfsConnected, ipfsReady, toursEnabled, handleJoyrideCallback }) => {
28+
const isSameOrigin = useBridgeSelector('selectIsSameOrigin')
29+
2830
if (!ipfsInitFailed && !ipfsReady) {
2931
return <ComponentLoader />
3032
}
3133

32-
const isSameOrigin = window.location.origin === apiUrl
33-
3434
return (
3535
<div>
3636
<Helmet>
@@ -75,7 +75,6 @@ const ConnectionStatus = ({ t: _t, connected, sameOrigin: _sameOrigin }) => {
7575
)
7676
}
7777
return (
78-
// @ts-expect-error - IsNotConnected needs type fixes
7978
<IsNotConnected />
8079
)
8180
}
@@ -84,7 +83,6 @@ export default connect(
8483
'selectIpfsInitFailed',
8584
'selectIpfsConnected',
8685
'selectIpfsReady',
87-
'selectApiUrl',
8886
'selectToursEnabled',
8987
withTour(withTranslation('welcome')(WelcomePage))
9088
)

0 commit comments

Comments
 (0)