|
|
|
@ -31,11 +31,15 @@ export default class AdvancedTab extends PureComponent { |
|
|
|
|
threeBoxSyncingAllowed: PropTypes.bool.isRequired, |
|
|
|
|
setThreeBoxSyncingPermission: PropTypes.func.isRequired, |
|
|
|
|
threeBoxDisabled: PropTypes.bool.isRequired, |
|
|
|
|
setIpfsGateway: PropTypes.func.isRequired, |
|
|
|
|
ipfsGateway: PropTypes.string.isRequired, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
state = { |
|
|
|
|
autoLogoutTimeLimit: this.props.autoLogoutTimeLimit, |
|
|
|
|
logoutTimeError: '', |
|
|
|
|
ipfsGateway: this.props.ipfsGateway, |
|
|
|
|
ipfsGatewayError: '', |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
renderMobileSync () { |
|
|
|
@ -354,6 +358,85 @@ export default class AdvancedTab extends PureComponent { |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
handleIpfsGatewayChange (url) { |
|
|
|
|
const { t } = this.context |
|
|
|
|
|
|
|
|
|
this.setState(() => { |
|
|
|
|
let ipfsGatewayError = '' |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
|
|
const urlObj = new URL(addUrlProtocolPrefix(url)) |
|
|
|
|
if (!urlObj.host) { |
|
|
|
|
throw new Error() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// don't allow the use of this gateway
|
|
|
|
|
if (urlObj.host === 'gateway.ipfs.io') { |
|
|
|
|
throw new Error('Forbidden gateway') |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} catch (error) { |
|
|
|
|
ipfsGatewayError = ( |
|
|
|
|
error.message === 'Forbidden gateway' |
|
|
|
|
? t('forbiddenIpfsGateway') |
|
|
|
|
: t('invalidIpfsGateway') |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
ipfsGateway: url, |
|
|
|
|
ipfsGatewayError, |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
handleIpfsGatewaySave () { |
|
|
|
|
|
|
|
|
|
const url = new URL(addUrlProtocolPrefix(this.state.ipfsGateway)) |
|
|
|
|
const host = url.host |
|
|
|
|
|
|
|
|
|
this.props.setIpfsGateway(host) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
renderIpfsGatewayControl () { |
|
|
|
|
const { t } = this.context |
|
|
|
|
const { ipfsGatewayError } = this.state |
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
<div className="settings-page__content-row"> |
|
|
|
|
<div className="settings-page__content-item"> |
|
|
|
|
<span>{ t('ipfsGateway') }</span> |
|
|
|
|
<div className="settings-page__content-description"> |
|
|
|
|
{ t('ipfsGatewayDescription') } |
|
|
|
|
</div> |
|
|
|
|
</div> |
|
|
|
|
<div className="settings-page__content-item"> |
|
|
|
|
<div className="settings-page__content-item-col"> |
|
|
|
|
<TextField |
|
|
|
|
type="text" |
|
|
|
|
value={this.state.ipfsGateway} |
|
|
|
|
onChange={e => this.handleIpfsGatewayChange(e.target.value)} |
|
|
|
|
error={ipfsGatewayError} |
|
|
|
|
fullWidth |
|
|
|
|
margin="dense" |
|
|
|
|
/> |
|
|
|
|
<Button |
|
|
|
|
type="primary" |
|
|
|
|
className="settings-tab__rpc-save-button" |
|
|
|
|
disabled={Boolean(ipfsGatewayError)} |
|
|
|
|
onClick={() => { |
|
|
|
|
this.handleIpfsGatewaySave() |
|
|
|
|
}} |
|
|
|
|
> |
|
|
|
|
{ t('save') } |
|
|
|
|
</Button> |
|
|
|
|
</div> |
|
|
|
|
</div> |
|
|
|
|
</div> |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
renderContent () { |
|
|
|
|
const { warning } = this.props |
|
|
|
|
|
|
|
|
@ -369,6 +452,7 @@ export default class AdvancedTab extends PureComponent { |
|
|
|
|
{ this.renderUseNonceOptIn() } |
|
|
|
|
{ this.renderAutoLogoutTimeLimit() } |
|
|
|
|
{ this.renderThreeBoxControl() } |
|
|
|
|
{ this.renderIpfsGatewayControl() } |
|
|
|
|
</div> |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
@ -377,3 +461,12 @@ export default class AdvancedTab extends PureComponent { |
|
|
|
|
return this.renderContent() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function addUrlProtocolPrefix (urlString) { |
|
|
|
|
if (!urlString.match( |
|
|
|
|
/(^http:\/\/)|(^https:\/\/)/ |
|
|
|
|
)) { |
|
|
|
|
return 'https://' + urlString |
|
|
|
|
} |
|
|
|
|
return urlString |
|
|
|
|
} |
|
|
|
|