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

feat: Remove old identity module in favor of new one #2110

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
10 changes: 10 additions & 0 deletions webapp/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 webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,4 @@
"@walletconnect/core": "2.9.2",
"@walletconnect/keyvaluestorage": "1.0.0"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import { connect } from 'react-redux'
import { AuthIdentity } from 'decentraland-crypto-fetch'
import { getCurrentIdentity } from '../../../modules/identity/selectors'
import { RootState } from '../../../modules/reducer'
import { getWallet } from '../../../modules/wallet/selectors'
import { MapStateProps } from './FavoritesModal.types'
import FavoritesModal from './FavoritesModal'

const mapState = (state: RootState): MapStateProps => {
return {
identity: (getCurrentIdentity(state) as AuthIdentity | null) ?? undefined
}
return { wallet: getWallet(state) }
}

export default connect(mapState)(FavoritesModal)
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { waitForElementToBeRemoved } from '@testing-library/react'
import { AuthIdentity } from 'decentraland-crypto-fetch'
import { Wallet } from 'decentraland-dapps/dist/modules/wallet/types'
import { FavoritesAPI } from '../../../modules/vendor/decentraland/favorites'
import { renderWithProviders } from '../../../utils/test'
import FavoritesModal from './FavoritesModal'
import { Props } from './FavoritesModal.types'

jest.mock('@dcl/single-sign-on-client', () => ({
localStorageGetIdentity: jest.fn()
}))

// Fixing warning: `NaN` is an invalid value for the `height` css style property.
jest.mock('react-virtualized-auto-sizer', () => {
return {
Expand All @@ -17,14 +21,13 @@ jest.mock('react-virtualized-auto-sizer', () => {
jest.mock('../../../modules/vendor/decentraland/favorites')

const itemId = 'anItemId'
const identity = {} as AuthIdentity

function renderFavoritesModal(props: Partial<Props> = {}) {
return renderWithProviders(
<FavoritesModal
wallet={{} as Wallet}
name={'A name'}
metadata={{ itemId }}
identity={identity}
onClose={jest.fn()}
{...props}
/>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
Empty,
Loader
} from 'decentraland-ui'
import { localStorageGetIdentity } from '@dcl/single-sign-on-client'
import { t } from 'decentraland-dapps/dist/modules/translation/utils'
import { Modal } from 'decentraland-dapps/dist/containers'
import { isErrorWithMessage } from '../../../lib/error'
Expand All @@ -25,7 +26,7 @@ const ITEM_HEIGHT = 55
const DEFAULT_LIST_HEIGHT = 300
const DEFAULT_LIST_WIDTH = 650

const FavoritesModal = ({ metadata: { itemId }, identity, onClose }: Props) => {
const FavoritesModal = ({ metadata: { itemId }, wallet, onClose }: Props) => {
const [isLoading, setIsLoading] = useState(false)
const [error, setError] = useState<string>()
const [favorites, setFavorites] = useState<{
Expand All @@ -39,9 +40,11 @@ const FavoritesModal = ({ metadata: { itemId }, identity, onClose }: Props) => {
return new FavoritesAPI(MARKETPLACE_FAVORITES_SERVER_URL, {
retries: retryParams.attempts,
retryDelay: retryParams.delay,
identity
identity: wallet
? localStorageGetIdentity(wallet.address) || undefined
: undefined
})
}, [identity])
}, [])

const fetchNextPage = useCallback(
async (startIndex: number, stopIndex: number) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { AuthIdentity } from 'decentraland-crypto-fetch'
import { ModalProps } from 'decentraland-dapps/dist/providers/ModalProvider/ModalProvider.types'
import { Wallet } from 'decentraland-dapps/dist/modules/wallet/types'

export type Metadata = {
itemId: string
}

export type Props = Omit<ModalProps, 'metadata'> & {
metadata: Metadata
identity: AuthIdentity | undefined
wallet: Wallet | null
}

export type MapStateProps = Pick<Props, 'identity'>
export type MapStateProps = Pick<Props, 'wallet'>

export type OwnProps = Pick<Props, 'metadata'>
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { connect } from 'react-redux'
import { Dispatch } from 'redux'
import { AuthIdentity } from 'decentraland-crypto-fetch'
import {
closeModal,
openModal
} from 'decentraland-dapps/dist/modules/modal/actions'
import { RootState } from '../../../modules/reducer'
import { bulkPickUnpickRequest } from '../../../modules/favorites/actions'
import { isLoadingBulkPicksUnpicks } from '../../../modules/favorites/selectors'
import { getCurrentIdentity } from '../../../modules/identity/selectors'
import { getWallet } from '../../../modules/wallet/selectors'
import { ListOfLists } from '../../../modules/vendor/decentraland/favorites'
import {
MapDispatchProps,
Expand All @@ -20,7 +19,7 @@ import { OverrideCreateListTypes } from '../CreateOrEditListModal/CreateOrEditLi

const mapState = (state: RootState): MapStateProps => {
return {
identity: (getCurrentIdentity(state) as AuthIdentity | null) ?? undefined,
wallet: getWallet(state),
isSavingPicks: isLoadingBulkPicksUnpicks(state)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Item } from '@dcl/schemas'
import { act } from 'react-dom/test-utils'
import { fireEvent } from '@testing-library/react'
import { AuthIdentity } from 'decentraland-crypto-fetch'
import { Wallet } from 'decentraland-dapps/dist/modules/wallet/types'
import { FavoritesAPI } from '../../../modules/vendor/decentraland/favorites/api'
import { ListOfLists } from '../../../modules/vendor/decentraland/favorites'
import { renderWithProviders } from '../../../utils/test'
Expand All @@ -16,6 +16,10 @@ import {
import SaveToListModal from './SaveToListModal'
import { Props } from './SaveToListModal.types'

jest.mock('@dcl/single-sign-on-client', () => ({
localStorageGetIdentity: jest.fn()
}))

jest.mock('react-virtualized-auto-sizer', () => {
return {
__esModule: true,
Expand All @@ -28,9 +32,9 @@ jest.mock('react-virtualized-auto-sizer', () => {
function renderSaveToListModalModal(props: Partial<Props> = {}) {
return renderWithProviders(
<SaveToListModal
wallet={{} as Wallet}
name={'A name'}
metadata={{ item: { id: 'anItemId' } as Item }}
identity={{} as AuthIdentity}
isSavingPicks={false}
onCreateList={jest.fn()}
onSavePicks={jest.fn()}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useCallback, useEffect, useMemo, useState } from 'react'
import { localStorageGetIdentity } from '@dcl/single-sign-on-client'
import AutoSizer from 'react-virtualized-auto-sizer'
import InfiniteLoader from 'react-window-infinite-loader'
import { FixedSizeList } from 'react-window'
Expand Down Expand Up @@ -40,11 +41,11 @@ import { getAnalytics } from 'decentraland-dapps/dist/modules/analytics/utils'

const SaveToListModal = (props: Props) => {
const {
wallet,
onClose,
onSavePicks,
onCreateList,
isSavingPicks,
identity,
onFinishListCreation,
metadata: { item }
} = props
Expand Down Expand Up @@ -129,9 +130,11 @@ const SaveToListModal = (props: Props) => {
return new FavoritesAPI(MARKETPLACE_FAVORITES_SERVER_URL, {
retries: retryParams.attempts,
retryDelay: retryParams.delay,
identity
identity: wallet
? localStorageGetIdentity(wallet.address) || undefined
: undefined
})
}, [identity])
}, [wallet])

const fetchNextPage = useCallback(
async (startIndex: number, stopIndex: number) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Item } from '@dcl/schemas'
import { AuthIdentity } from 'decentraland-crypto-fetch'
import { Wallet } from 'decentraland-dapps/dist/modules/wallet/types'
import { ModalProps } from 'decentraland-dapps/dist/providers/ModalProvider/ModalProvider.types'
import { ListOfLists } from '../../../modules/vendor/decentraland/favorites'
import { OverrideCreateListTypes } from '../CreateOrEditListModal/CreateOrEditListModal.types'
Expand All @@ -15,14 +15,14 @@ export enum PickType {

export type Props = Omit<ModalProps, 'metadata'> & {
metadata: Metadata
identity: AuthIdentity | undefined
isSavingPicks: boolean
wallet: Wallet | null
onSavePicks: (picksFor: ListOfLists[], picksFrom: ListOfLists[]) => void
onCreateList: (params: OverrideCreateListTypes) => void
onFinishListCreation: () => void
}

export type MapStateProps = Pick<Props, 'identity' | 'isSavingPicks'>
export type MapStateProps = Pick<Props, 'isSavingPicks' | 'wallet'>
export type OwnProps = Pick<Props, 'metadata' | 'onClose'>
export type MapDispatchProps = Pick<
Props,
Expand Down
19 changes: 8 additions & 11 deletions webapp/src/components/Navbar/Navbar.container.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
import { connect } from 'react-redux'
import { push, getLocation } from 'connected-react-router'
import { isPending } from 'decentraland-dapps/dist/modules/transaction/utils'

import { TransactionStatus } from 'decentraland-dapps/dist/modules/transaction/types'
import { RootState } from '../../modules/reducer'
import { getTransactions } from '../../modules/transaction/selectors'
import {
getIsAuthDappEnabled,
} from '../../modules/features/selectors'
import { getWallet } from '../../modules/wallet/selectors'
import { getIsAuthDappEnabled } from '../../modules/features/selectors'
import { MapStateProps, MapDispatch, MapDispatchProps } from './Navbar.types'
import Navbar from './Navbar'
import { getCurrentIdentity } from '../../modules/identity/selectors'
import { TransactionStatus } from 'decentraland-dapps/dist/modules/transaction/types'

const mapState = (state: RootState): MapStateProps => ({
wallet: getWallet(state),
location: getLocation(state),
hasPendingTransactions: getTransactions(state).some((tx: { status: TransactionStatus | null }) =>
isPending(tx.status)
),
identity: getCurrentIdentity(state) || undefined,
isAuthDappEnabled: getIsAuthDappEnabled(state),
hasPendingTransactions: getTransactions(
state
).some((tx: { status: TransactionStatus | null }) => isPending(tx.status)),
isAuthDappEnabled: getIsAuthDappEnabled(state)
})

const mapDispatch = (dispatch: MapDispatch): MapDispatchProps => ({
Expand Down
5 changes: 3 additions & 2 deletions webapp/src/components/Navbar/Navbar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useCallback } from 'react'
import { localStorageGetIdentity } from '@dcl/single-sign-on-client'
import { Navbar as BaseNavbar } from 'decentraland-dapps/dist/containers'
import { NavbarPages } from 'decentraland-ui/dist/components/Navbar/Navbar.types'
import { config } from '../../config'
Expand All @@ -7,7 +8,7 @@ import { Props } from './Navbar.types'
import './Navbar.css'

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

const handleOnSignIn = useCallback(() => {
Expand Down Expand Up @@ -40,7 +41,7 @@ const Navbar = (props: Props) => {
withNotifications
activePage={NavbarPages.MARKETPLACE}
hasActivity={props.hasPendingTransactions}
identity={props.identity}
identity={wallet ? localStorageGetIdentity(wallet.address) : undefined}
onSignIn={handleOnSignIn}
onClickAccountSettings={handleOnClickAccount}
/>
Expand Down
9 changes: 3 additions & 6 deletions webapp/src/components/Navbar/Navbar.types.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
import { Dispatch } from 'redux'
import { CallHistoryMethodAction, RouterLocation } from 'connected-react-router'
import { NavbarProps } from 'decentraland-ui/dist/components/Navbar/Navbar.types'
import { AuthIdentity } from '@dcl/crypto'
import { Wallet } from 'decentraland-dapps/dist/modules/wallet/types'

export type Props = Partial<NavbarProps> & {
wallet: Wallet | null
location: RouterLocation<unknown>
hasPendingTransactions: boolean
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' | 'isAuthDappEnabled' | 'wallet'
>
export type MapDispatchProps = Pick<Props, 'onNavigate'>
export type MapDispatch = Dispatch<CallHistoryMethodAction>
Loading
Loading