Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Remove auth flag #2127

Merged
merged 3 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions webapp/src/components/Navbar/Navbar.container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import { isPending } from 'decentraland-dapps/dist/modules/transaction/utils'

import { RootState } from '../../modules/reducer'
import { getTransactions } from '../../modules/transaction/selectors'
import {
getIsAuthDappEnabled,
} from '../../modules/features/selectors'
import { MapStateProps, MapDispatch, MapDispatchProps } from './Navbar.types'
import Navbar from './Navbar'
import { getCurrentIdentity } from '../../modules/identity/selectors'
Expand All @@ -17,8 +14,7 @@ const mapState = (state: RootState): MapStateProps => ({
hasPendingTransactions: getTransactions(state).some((tx: { status: TransactionStatus | null }) =>
isPending(tx.status)
),
identity: getCurrentIdentity(state) || undefined,
isAuthDappEnabled: getIsAuthDappEnabled(state),
identity: getCurrentIdentity(state) || undefined
})

const mapDispatch = (dispatch: MapDispatch): MapDispatchProps => ({
Expand Down
15 changes: 6 additions & 9 deletions webapp/src/components/Navbar/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Props } from './Navbar.types'
import './Navbar.css'

const Navbar = (props: Props) => {
const { location, onNavigate, isAuthDappEnabled } = props
const { location, onNavigate } = props
const { pathname, search } = location

const handleOnSignIn = useCallback(() => {
Expand All @@ -21,14 +21,11 @@ const Navbar = (props: Props) => {
const redirectTo = !currentRedirectTo
? `${basename}${pathname}${search}`
: `${basename}${currentRedirectTo}`
if (isAuthDappEnabled) {
window.location.replace(
`${config.get('AUTH_URL')}/login?redirectTo=${redirectTo}`
)
} else {
onNavigate(locations.signIn(redirectTo))
}
}, [onNavigate, pathname, search, isAuthDappEnabled])

window.location.replace(
`${config.get('AUTH_URL')}/login?redirectTo=${redirectTo}`
)
}, [pathname, search])

const handleOnClickAccount = useCallback(() => {
onNavigate(locations.settings())
Expand Down
6 changes: 1 addition & 5 deletions webapp/src/components/Navbar/Navbar.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@ export type Props = Partial<NavbarProps> & {
enablePartialSupportAlert?: boolean
onNavigate: (path: string) => void
identity?: AuthIdentity
isAuthDappEnabled: boolean
}

export type OwnProps = Pick<Props, 'enablePartialSupportAlert'>

export type MapStateProps = Pick<
Props,
| 'location'
| 'hasPendingTransactions'
| 'identity'
| 'isAuthDappEnabled'
'location' | 'hasPendingTransactions' | 'identity'
>
export type MapDispatchProps = Pick<Props, 'onNavigate'>
export type MapDispatch = Dispatch<CallHistoryMethodAction>
2 changes: 0 additions & 2 deletions webapp/src/components/SignInPage/SignInPage.container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ import {
isConnected
} from 'decentraland-dapps/dist/modules/wallet/selectors'
import { RootState } from '../../modules/reducer'
import { getIsAuthDappEnabled } from '../../modules/features/selectors'
import { MapStateProps } from './SignInPage.types'
import SignInPage from './SignInPage'

const mapState = (state: RootState): MapStateProps => {
return {
isAuthDappEnabled: getIsAuthDappEnabled(state),
isConnecting: isConnecting(state),
isConnected: isConnected(state)
}
Expand Down
5 changes: 3 additions & 2 deletions webapp/src/components/SignInPage/SignInPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import { Props } from './SignInPage.types'
import './SignInPage.css'

const SignInPage = (props: Props) => {
const { isAuthDappEnabled, isConnecting, isConnected } = props
const { isConnecting, isConnected } = props

const handleConnect = useCallback(() => {
if (!isConnected && !isConnecting) {
const params = new URLSearchParams(window.location.search)
Expand All @@ -29,7 +30,7 @@ const SignInPage = (props: Props) => {
<>
<Navbar />
<Page className="SignInPage" isFullscreen>
<SignIn onConnect={isAuthDappEnabled ? handleConnect : undefined} />
<SignIn onConnect={handleConnect} />
</Page>
<Footer isFullscreen />
</>
Expand Down
6 changes: 1 addition & 5 deletions webapp/src/components/SignInPage/SignInPage.types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
export type Props = {
isAuthDappEnabled: boolean
isConnecting: boolean
isConnected: boolean
}

export type MapStateProps = Pick<
Props,
'isAuthDappEnabled' | 'isConnected' | 'isConnecting'
>
export type MapStateProps = Pick<Props, 'isConnected' | 'isConnecting'>
1 change: 0 additions & 1 deletion webapp/src/config/env/dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
"EXPLORER_URL": "https://play.decentraland.zone",
"MARKETPLACE_URL": "https://decentraland.zone/marketplace",
"PROFILE_URL": "https://decentraland.zone/profile",
"SSO_URL": "https://id.decentraland.zone",
"SUBGRAPH_WORKER": "https://subgraph.decentraland.zone",
"SENTRY_DSN": "https://1dc401149e1c819b8477565c9cdd9b70@o4504361728212992.ingest.sentry.io/4505743351676928",
"SQUID_API_URL": "https://testnet.v2.api.squidrouter.com/",
Expand Down
1 change: 0 additions & 1 deletion webapp/src/config/env/prod.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
"EXPLORER_URL": "https://play.decentraland.org",
"MARKETPLACE_URL": "https://decentraland.org/marketplace",
"PROFILE_URL": "https://decentraland.org/profile",
"SSO_URL": "https://id.decentraland.org",
"SUBGRAPH_WORKER": "https://subgraph.decentraland.org",
"SENTRY_DSN": "https://1dc401149e1c819b8477565c9cdd9b70@o4504361728212992.ingest.sentry.io/4505743351676928",
"SQUID_API_URL": "https://v2.api.squidrouter.com",
Expand Down
1 change: 0 additions & 1 deletion webapp/src/config/env/stg.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
"EXPLORER_URL": "https://play.decentraland.org",
"MARKETPLACE_URL": "https://decentraland.today/marketplace",
"PROFILE_URL": "https://decentraland.today/profile",
"SSO_URL": "https://id.decentraland.today",
"SUBGRAPH_WORKER": "https://subgraph.decentraland.today",
"SENTRY_DSN": "https://1dc401149e1c819b8477565c9cdd9b70@o4504361728212992.ingest.sentry.io/4505743351676928",
"SQUID_API_URL": "https://v2.api.squidrouter.com",
Expand Down
7 changes: 0 additions & 7 deletions webapp/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import ReactDOM from 'react-dom'
import { Provider } from 'react-redux'

import { ConnectedRouter } from 'connected-react-router'
import * as SingleSignOn from '@dcl/single-sign-on-client'
import WalletProvider from 'decentraland-dapps/dist/providers/WalletProvider'
import ToastProvider from 'decentraland-dapps/dist/providers/ToastProvider'
import TranslationProvider from 'decentraland-dapps/dist/providers/TranslationProvider'
Expand All @@ -16,16 +15,10 @@ import * as locales from './modules/translation/locales'
import { initStore, createHistory } from './modules/store'
import { Routes } from './components/Routes'
import * as modals from './components/Modals'
import { config } from './config'

import './themes'
import './index.css'

// Initializes the SSO client.
// This will create a new iframe and append it to the body.
// It is ideal to do this as soon as possible to avoid any availability issues.
SingleSignOn.init(config.get('SSO_URL'))

const history = createHistory()
const store = initStore(history)

Expand Down
7 changes: 0 additions & 7 deletions webapp/src/modules/features/selectors.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
getIsMarketplaceLaunchPopupEnabled,
getIsSmartWearablesFTUEnabled,
isLoadingFeatureFlags,
getIsAuthDappEnabled,
getIsClaimingNamesWithFiatEnabled,
getIsEnsAddressEnabled
} from './selectors'
Expand Down Expand Up @@ -159,12 +158,6 @@ const waitForInitialLoadingSelectors = [
feature: FeatureName.EMOTES_V2_FTU,
selector: getIsEmotesV2FTUEnabled
},
{
name: 'auth-dapp',
feature: FeatureName.AUTH_DAPP,
selector: getIsAuthDappEnabled,
applicationName: ApplicationName.DAPPS
},
{
name: 'claim-name-with-fiat',
feature: FeatureName.CLAIM_NAMES_WITH_FIAT,
Expand Down
11 changes: 0 additions & 11 deletions webapp/src/modules/features/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,6 @@ export const getIsMarketplaceServerEnabled = (state: RootState) => {
return false
}

export const getIsAuthDappEnabled = (state: RootState) => {
if (hasLoadedInitialFlags(state)) {
return getIsFeatureEnabled(
state,
ApplicationName.DAPPS,
FeatureName.AUTH_DAPP
)
}
return false
}

export const getIsClaimingNamesWithFiatEnabled = (state: RootState) => {
if (hasLoadedInitialFlags(state)) {
return getIsFeatureEnabled(
Expand Down
125 changes: 35 additions & 90 deletions webapp/src/modules/identity/sagas.spec.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
import { expectSaga } from 'redux-saga-test-plan'
import { call, select } from 'redux-saga/effects'
import { call } from 'redux-saga/effects'
import { Wallet } from 'decentraland-dapps/dist/modules/wallet/types'
import {
connectWalletSuccess,
disconnectWallet
} from 'decentraland-dapps/dist/modules/wallet/actions'
import {
getIdentity,
clearIdentity,
localStorageClearIdentity,
localStorageGetIdentity
} from '@dcl/single-sign-on-client'
import { identitySaga, setAuxAddress } from './sagas'
import { generateIdentityRequest, generateIdentitySuccess } from './actions'
import { getIsAuthDappEnabled } from '../features/selectors'
import { generateIdentitySuccess } from './actions'
import { AuthIdentity } from '@dcl/crypto'

jest.mock('@dcl/single-sign-on-client', () => {
return {
getIdentity: jest.fn(),
clearIdentity: jest.fn(),
localStorageClearIdentity: jest.fn(),
localStorageGetIdentity: jest.fn(),
localStorageStoreIdentity: jest.fn()
Expand All @@ -42,74 +37,38 @@ describe('when handling the wallet connection success', () => {
} as Wallet
})

describe('and the auth dapp is enabled', () => {
describe("and there's no identity", () => {
beforeEach(() => {
windowLocation = window.location
delete (window as any).location
window.location = ({
replace: jest.fn()
} as any) as Location
})
afterEach(() => {
window.location = windowLocation
})
it('should redirect to auth dapp', async () => {
await expectSaga(identitySaga)
.provide([
[call(localStorageGetIdentity, wallet.address), null],
[select(getIsAuthDappEnabled), true]
])
.dispatch(connectWalletSuccess(wallet))
.run({ silenceTimeout: true })
expect(window.location.replace).toHaveBeenCalled()
})
describe("and there's no identity", () => {
beforeEach(() => {
windowLocation = window.location
delete (window as any).location
window.location = ({
replace: jest.fn()
} as any) as Location
})

describe("and there's an identity", () => {
let identity: AuthIdentity

beforeEach(() => {
identity = {} as any
;(localStorageGetIdentity as jest.Mock).mockReturnValue(identity)
})
it('should put an action to store the identity', () => {
return expectSaga(identitySaga)
.provide([[select(getIsAuthDappEnabled), true]])
.put(generateIdentitySuccess(wallet.address, identity))
.dispatch(connectWalletSuccess(wallet))
.run({ silenceTimeout: true })
})
afterEach(() => {
window.location = windowLocation
})
})

describe('and the auth dapp is not enabled', () => {
describe("and there's no identity", () => {
it('should put an action to generate the identity', () => {
return expectSaga(identitySaga)
.provide([
[call(getIdentity, wallet.address), null],
[select(getIsAuthDappEnabled), false]
])
.put(generateIdentityRequest(wallet.address))
.dispatch(connectWalletSuccess(wallet))
.run({ silenceTimeout: true })
})
it('should redirect to auth dapp', async () => {
await expectSaga(identitySaga)
.provide([[call(localStorageGetIdentity, wallet.address), null]])
.dispatch(connectWalletSuccess(wallet))
.run({ silenceTimeout: true })
expect(window.location.replace).toHaveBeenCalled()
})
})

describe("and there's an identity", () => {
it('should put an action to store the identity', () => {
const identity = {} as any
describe("and there's an identity", () => {
let identity: AuthIdentity

return expectSaga(identitySaga)
.provide([
[call(getIdentity, wallet.address), identity],
[select(getIsAuthDappEnabled), false]
])
.put(generateIdentitySuccess(wallet.address, identity))
.dispatch(connectWalletSuccess(wallet))
.run({ silenceTimeout: true })
})
beforeEach(() => {
identity = {} as any
;(localStorageGetIdentity as jest.Mock).mockReturnValue(identity)
})
it('should put an action to store the identity', () => {
return expectSaga(identitySaga)
.put(generateIdentitySuccess(wallet.address, identity))
.dispatch(connectWalletSuccess(wallet))
.run({ silenceTimeout: true })
})
})
})
Expand All @@ -122,26 +81,12 @@ describe('when handling the disconnect', () => {
setAuxAddress(address)
})

describe('and the auth dapp is enabled', () => {
it('should call the sso client to clear the identity in the local storage', async () => {
await expectSaga(identitySaga)
.provide([[select(getIsAuthDappEnabled), true]])
.dispatch(disconnectWallet())
.run({ silenceTimeout: true })

expect(localStorageClearIdentity).toHaveBeenCalledWith(address)
})
})

describe('and the auth dapp is not enabled', () => {
it('should call the sso client to clear the identity', async () => {
await expectSaga(identitySaga)
.provide([[select(getIsAuthDappEnabled), false]])
.dispatch(disconnectWallet())
.run({ silenceTimeout: true })
it('should call the sso client to clear the identity in the local storage', async () => {
await expectSaga(identitySaga)
.dispatch(disconnectWallet())
.run({ silenceTimeout: true })

expect(clearIdentity).toHaveBeenCalledWith(address)
})
expect(localStorageClearIdentity).toHaveBeenCalledWith(address)
})
})

Expand All @@ -155,7 +100,7 @@ describe('when handling the disconnect', () => {
.dispatch(disconnectWallet())
.run({ silenceTimeout: true })

expect(clearIdentity).not.toHaveBeenCalled()
expect(localStorageClearIdentity).not.toHaveBeenCalled()
})
})
})
Loading
Loading