Skip to content

Commit

Permalink
feat(nfts): check if user is authenticated before refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
plondon committed May 4, 2022
1 parent 93f59c3 commit 2fa9b29
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 19 deletions.
50 changes: 31 additions & 19 deletions packages/blockchain-wallet-v4-frontend/src/layouts/Nfts/Nfts.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'
import React, { useEffect } from 'react'
import { connect, ConnectedProps } from 'react-redux'
import { Route } from 'react-router-dom'
import { bindActionCreators } from 'redux'
Expand All @@ -8,26 +8,38 @@ import { actions, selectors } from 'data'

import NftsTemplate from './NftsTemplate'

class NftsContainer extends React.PureComponent<Props> {
componentDidMount() {
this.props.coinsActions.fetchCoinsRates()
}
const NftsContainer = (props) => {
useEffect(() => {
props.coinsActions.fetchCoinsRates()
}, [props.coinsActions])

const { component: Component, pageTitle, path, ...rest } = props
if (pageTitle) document.title = pageTitle

render() {
const { component: Component, pageTitle, path, ...rest } = this.props
if (pageTitle) document.title = pageTitle

return (
<Route
path={path}
render={() => (
<NftsTemplate {...this.props}>
<Component computedMatch={rest.computedMatch} {...rest} />
</NftsTemplate>
)}
/>
)
const doRefresh = (e) => {
if (props.isAuthenticated) {
e.preventDefault()
e.returnValue = ''
}
}

useEffect(() => {
window.addEventListener('beforeunload', doRefresh)
return () => {
window.removeEventListener('beforeunload', doRefresh)
}
})

return (
<Route
path={path}
render={() => (
<NftsTemplate {...props}>
<Component computedMatch={rest.computedMatch} {...rest} />
</NftsTemplate>
)}
/>
)
}

const mapStateToProps = (state) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ const TraitGridFilters: React.FC<Props> = ({
</>
)
}

const mapDispatchToProps = (dispatch) => ({
analyticsActions: bindActionCreators(actions.analytics, dispatch),
routerActions: bindActionCreators(actions.router, dispatch)
Expand Down

0 comments on commit 2fa9b29

Please sign in to comment.