Skip to content

Commit

Permalink
fix: reconnect when switching wallet (#376)
Browse files Browse the repository at this point in the history
  • Loading branch information
braianj authored Jun 5, 2024
1 parent 8e2e38d commit 79ff85c
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 19 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@sentry/react": "^7.64.0",
"@typechain/ethers-v5": "^10.0.0",
"connected-react-router": "^6.9.1",
"decentraland-dapps": "^22.0.0",
"decentraland-dapps": "^22.1.0",
"decentraland-transactions": "^2.6.0",
"decentraland-ui": "^6.1.0",
"decentraland-ui2": "^0.0.2",
Expand Down
7 changes: 5 additions & 2 deletions src/components/ProtectedRoute/ProtectedRoute.container.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { connect } from 'react-redux'
import { localStorageGetIdentity } from '@dcl/single-sign-on-client'
import { getData as getWallet, isConnected, isConnecting } from 'decentraland-dapps/dist/modules/wallet/selectors'
import { RootState } from '../../modules/reducer'
import ProtectedRoute from './ProtectedRoute'
import { MapStateProps } from './ProtectedRoute.types'

const mapState = (state: RootState): MapStateProps => {
const wallet = getWallet(state)
const identity = wallet ? localStorageGetIdentity(wallet?.address) : null

return {
wallet: getWallet(state),
isConnecting: isConnecting(state),
isConnected: isConnected(state)
isConnected: isConnected(state) && !!identity
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/components/ProtectedRoute/ProtectedRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import { locations } from '../../modules/locations'
import { Props } from './ProtectedRoute.types'

const ProtectedRoute = (props: Props) => {
const { isConnecting, wallet, isConnected, ...rest } = props

const { isConnecting, isConnected, ...rest } = props
const { pathname, search } = useLocation()

if (!isConnecting && !wallet && !isConnected) {
if (!isConnecting && !isConnected) {
return <Redirect to={locations.signIn(`${pathname}${search}`)} />
}

Expand Down
4 changes: 1 addition & 3 deletions src/components/ProtectedRoute/ProtectedRoute.types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { RouteProps } from 'react-router-dom'
import { Wallet } from 'decentraland-dapps/dist/modules/wallet/types'

export type Props = RouteProps & {
isConnected: boolean
isConnecting: boolean
wallet: Wallet | null
}

export type MapStateProps = Pick<Props, 'wallet' | 'isConnecting' | 'isConnected'>
export type MapStateProps = Pick<Props, 'isConnecting' | 'isConnected'>
17 changes: 11 additions & 6 deletions src/components/SignInPage/SignInPage.container.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import { connect } from 'react-redux'
import { isConnected, isConnecting } from 'decentraland-dapps/dist/modules/wallet/selectors'
import { localStorageGetIdentity } from '@dcl/single-sign-on-client'
import { getData as getWallet, isConnected, isConnecting } from 'decentraland-dapps/dist/modules/wallet/selectors'
import { getIsAuthDappEnabled } from '../../modules/features/selectors'
import { RootState } from '../../modules/reducer'
import SignInPage from './SignInPage'
import { MapStateProps } from './SignInPage.types'

const mapState = (state: RootState): MapStateProps => ({
isAuthDappEnabled: !!getIsAuthDappEnabled(state),
isConnecting: isConnecting(state),
isConnected: isConnected(state)
})
const mapState = (state: RootState): MapStateProps => {
const wallet = getWallet(state)
const identity = wallet ? localStorageGetIdentity(wallet?.address) : null
return {
isAuthDappEnabled: !!getIsAuthDappEnabled(state),
isConnecting: isConnecting(state),
isConnected: isConnected(state) && !!identity
}
}

export default connect(mapState)(SignInPage)

0 comments on commit 79ff85c

Please sign in to comment.