From 6d7b59821ca8969622805be94c7bda75fdc0876a Mon Sep 17 00:00:00 2001 From: Juanma Hidalgo Date: Tue, 23 Jan 2024 14:32:20 +0100 Subject: [PATCH 1/8] wip --- .../FavoritesModal.container.ts | 14 -- .../FavoritesModal/FavoritesModal.types.ts | 4 - .../components/Modals/FavoritesModal/index.ts | 2 +- .../SaveToListModal.container.ts | 5 +- .../SaveToListModal/SaveToListModal.tsx | 9 +- .../SaveToListModal/SaveToListModal.types.ts | 6 +- .../src/components/Navbar/Navbar.container.ts | 19 +-- webapp/src/components/Navbar/Navbar.tsx | 5 +- webapp/src/components/Navbar/Navbar.types.ts | 9 +- webapp/src/modules/favorites/sagas.ts | 26 +-- webapp/src/modules/identity/actions.ts | 27 --- webapp/src/modules/identity/reducer.ts | 65 ------- webapp/src/modules/identity/sagas.spec.ts | 161 ------------------ webapp/src/modules/identity/sagas.ts | 123 ------------- webapp/src/modules/identity/selectors.ts | 27 --- webapp/src/modules/identity/utils.ts | 80 --------- webapp/src/modules/item/sagas.ts | 6 +- webapp/src/modules/nft/sagas.ts | 5 +- webapp/src/modules/reducer.ts | 3 - webapp/src/modules/rental/sagas.ts | 5 +- webapp/src/modules/sagas.ts | 20 +-- webapp/src/modules/store.ts | 14 +- webapp/src/modules/store/sagas.spec.ts | 11 +- webapp/src/modules/store/sagas.ts | 5 +- webapp/src/modules/wallet/utils.ts | 3 +- webapp/src/utils/tests.tsx | 5 +- 26 files changed, 76 insertions(+), 583 deletions(-) delete mode 100644 webapp/src/components/Modals/FavoritesModal/FavoritesModal.container.ts delete mode 100644 webapp/src/modules/identity/actions.ts delete mode 100644 webapp/src/modules/identity/reducer.ts delete mode 100644 webapp/src/modules/identity/sagas.spec.ts delete mode 100644 webapp/src/modules/identity/sagas.ts delete mode 100644 webapp/src/modules/identity/selectors.ts delete mode 100644 webapp/src/modules/identity/utils.ts diff --git a/webapp/src/components/Modals/FavoritesModal/FavoritesModal.container.ts b/webapp/src/components/Modals/FavoritesModal/FavoritesModal.container.ts deleted file mode 100644 index e9215fa843..0000000000 --- a/webapp/src/components/Modals/FavoritesModal/FavoritesModal.container.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { connect } from 'react-redux' -import { AuthIdentity } from 'decentraland-crypto-fetch' -import { getCurrentIdentity } from '../../../modules/identity/selectors' -import { RootState } from '../../../modules/reducer' -import { MapStateProps } from './FavoritesModal.types' -import FavoritesModal from './FavoritesModal' - -const mapState = (state: RootState): MapStateProps => { - return { - identity: (getCurrentIdentity(state) as AuthIdentity | null) ?? undefined - } -} - -export default connect(mapState)(FavoritesModal) diff --git a/webapp/src/components/Modals/FavoritesModal/FavoritesModal.types.ts b/webapp/src/components/Modals/FavoritesModal/FavoritesModal.types.ts index 1da8bbc56c..12eed426d5 100644 --- a/webapp/src/components/Modals/FavoritesModal/FavoritesModal.types.ts +++ b/webapp/src/components/Modals/FavoritesModal/FavoritesModal.types.ts @@ -1,4 +1,3 @@ -import { AuthIdentity } from 'decentraland-crypto-fetch' import { ModalProps } from 'decentraland-dapps/dist/providers/ModalProvider/ModalProvider.types' export type Metadata = { @@ -7,9 +6,6 @@ export type Metadata = { export type Props = Omit & { metadata: Metadata - identity: AuthIdentity | undefined } -export type MapStateProps = Pick - export type OwnProps = Pick diff --git a/webapp/src/components/Modals/FavoritesModal/index.ts b/webapp/src/components/Modals/FavoritesModal/index.ts index 6ea3b5b05f..859ce77ffe 100644 --- a/webapp/src/components/Modals/FavoritesModal/index.ts +++ b/webapp/src/components/Modals/FavoritesModal/index.ts @@ -1,2 +1,2 @@ -import FavoritesModal from './FavoritesModal.container' +import FavoritesModal from './FavoritesModal' export { FavoritesModal } diff --git a/webapp/src/components/Modals/SaveToListModal/SaveToListModal.container.ts b/webapp/src/components/Modals/SaveToListModal/SaveToListModal.container.ts index 118e22aaec..86c75b7b72 100644 --- a/webapp/src/components/Modals/SaveToListModal/SaveToListModal.container.ts +++ b/webapp/src/components/Modals/SaveToListModal/SaveToListModal.container.ts @@ -1,6 +1,5 @@ import { connect } from 'react-redux' import { Dispatch } from 'redux' -import { AuthIdentity } from 'decentraland-crypto-fetch' import { closeModal, openModal @@ -8,7 +7,7 @@ import { 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, @@ -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) } } diff --git a/webapp/src/components/Modals/SaveToListModal/SaveToListModal.tsx b/webapp/src/components/Modals/SaveToListModal/SaveToListModal.tsx index f1a5969cc2..a57fa06ffe 100644 --- a/webapp/src/components/Modals/SaveToListModal/SaveToListModal.tsx +++ b/webapp/src/components/Modals/SaveToListModal/SaveToListModal.tsx @@ -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' @@ -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 @@ -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) => { diff --git a/webapp/src/components/Modals/SaveToListModal/SaveToListModal.types.ts b/webapp/src/components/Modals/SaveToListModal/SaveToListModal.types.ts index 233d6d4030..33678a527b 100644 --- a/webapp/src/components/Modals/SaveToListModal/SaveToListModal.types.ts +++ b/webapp/src/components/Modals/SaveToListModal/SaveToListModal.types.ts @@ -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' @@ -15,14 +15,14 @@ export enum PickType { export type Props = Omit & { 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 +export type MapStateProps = Pick export type OwnProps = Pick export type MapDispatchProps = Pick< Props, diff --git a/webapp/src/components/Navbar/Navbar.container.ts b/webapp/src/components/Navbar/Navbar.container.ts index 6235336dec..8dfa9f7fe0 100644 --- a/webapp/src/components/Navbar/Navbar.container.ts +++ b/webapp/src/components/Navbar/Navbar.container.ts @@ -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 => ({ diff --git a/webapp/src/components/Navbar/Navbar.tsx b/webapp/src/components/Navbar/Navbar.tsx index 573626365a..32613ecd4e 100644 --- a/webapp/src/components/Navbar/Navbar.tsx +++ b/webapp/src/components/Navbar/Navbar.tsx @@ -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' @@ -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(() => { @@ -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} /> diff --git a/webapp/src/components/Navbar/Navbar.types.ts b/webapp/src/components/Navbar/Navbar.types.ts index 9808ce99f3..6006a617d1 100644 --- a/webapp/src/components/Navbar/Navbar.types.ts +++ b/webapp/src/components/Navbar/Navbar.types.ts @@ -1,14 +1,14 @@ 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 & { + wallet: Wallet | null location: RouterLocation hasPendingTransactions: boolean enablePartialSupportAlert?: boolean onNavigate: (path: string) => void - identity?: AuthIdentity isAuthDappEnabled: boolean } @@ -16,10 +16,7 @@ export type OwnProps = Pick export type MapStateProps = Pick< Props, - | 'location' - | 'hasPendingTransactions' - | 'identity' - | 'isAuthDappEnabled' + 'location' | 'hasPendingTransactions' | 'isAuthDappEnabled' | 'wallet' > export type MapDispatchProps = Pick export type MapDispatch = Dispatch diff --git a/webapp/src/modules/favorites/sagas.ts b/webapp/src/modules/favorites/sagas.ts index a40ea2d3f3..fefe6f90c8 100644 --- a/webapp/src/modules/favorites/sagas.ts +++ b/webapp/src/modules/favorites/sagas.ts @@ -1,7 +1,6 @@ import { getLocation, push } from 'connected-react-router' import { call, put, race, select, take, takeEvery } from 'redux-saga/effects' import { CatalogFilters, Item } from '@dcl/schemas' -import { AuthIdentity } from 'decentraland-crypto-fetch' import { ConnectWalletSuccessAction, CONNECT_WALLET_FAILURE, @@ -19,7 +18,6 @@ import { FavoritesAPI, MARKETPLACE_FAVORITES_SERVER_URL } from '../vendor/decentraland/favorites/api' -import { getIdentity as getAccountIdentity } from '../identity/utils' import { CatalogAPI } from '../vendor/decentraland/catalog/api' import { retryParams } from '../vendor/decentraland/utils' import { getAddress } from '../wallet/selectors' @@ -84,12 +82,12 @@ import { convertListsBrowseSortByIntoApiSortBy } from './utils' import { List } from './types' import { getData as getItemsData } from '../item/selectors' import { getIsMarketplaceServerEnabled } from '../features/selectors' +import { getIdentityOrRedirect } from 'decentraland-dapps/dist/modules/identity/sagas' -export function* favoritesSaga(getIdentity: () => AuthIdentity | undefined) { +export function* favoritesSaga() { const API_OPTS = { retries: retryParams.attempts, - retryDelay: retryParams.delay, - identity: getIdentity + retryDelay: retryParams.delay } const favoritesAPI = new FavoritesAPI( MARKETPLACE_FAVORITES_SERVER_URL, @@ -155,7 +153,8 @@ export function* favoritesSaga(getIdentity: () => AuthIdentity | undefined) { try { const address: ReturnType = yield select(getAddress) // Force the user to have the signed identity - if (address) yield call(getAccountIdentity) + console.log('check redirect3') + if (address) yield call(getIdentityOrRedirect) let items: Item[] = [] const listId: string = yield select(getListId) @@ -217,7 +216,8 @@ export function* favoritesSaga(getIdentity: () => AuthIdentity | undefined) { try { // Force the user to have the signed identity - yield call(getAccountIdentity) + console.log('check redirect4') + yield call(getIdentityOrRedirect) let sortBy: ListsSortBy | undefined let sortDirection: SortDirection | undefined @@ -282,7 +282,8 @@ export function* favoritesSaga(getIdentity: () => AuthIdentity | undefined) { try { // Force the user to have the signed identity - yield call(getAccountIdentity) + console.log('check redirect4') + yield call(getIdentityOrRedirect) yield call([favoritesAPI, 'deleteList'], list.id) yield put(deleteListSuccess(list)) } catch (error) { @@ -342,7 +343,8 @@ export function* favoritesSaga(getIdentity: () => AuthIdentity | undefined) { try { const { pathname } = yield select(getLocation) // Force the user to have the signed identity - yield call(getAccountIdentity) + console.log('check redirect4') + yield call(getIdentityOrRedirect) const list: Awaited> = yield call([favoritesAPI, 'createList'], { @@ -393,7 +395,8 @@ export function* favoritesSaga(getIdentity: () => AuthIdentity | undefined) { } // Force the user to have the signed identity - yield call(getAccountIdentity) + console.log('check redirect5') + yield call(getIdentityOrRedirect) yield put(openModal('SaveToListModal', { item })) @@ -438,7 +441,8 @@ export function* favoritesSaga(getIdentity: () => AuthIdentity | undefined) { try { // Force the user to have the signed identity - yield call(getAccountIdentity) + console.log('check redirect7') + yield call(getIdentityOrRedirect) const { pickedByUser }: Awaited> = yield call( diff --git a/webapp/src/modules/identity/actions.ts b/webapp/src/modules/identity/actions.ts deleted file mode 100644 index 6473b0a20a..0000000000 --- a/webapp/src/modules/identity/actions.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { action } from 'typesafe-actions' -import { AuthIdentity } from '@dcl/crypto' - -// Generate identity - -export const GENERATE_IDENTITY_REQUEST = '[Request] Generate Identity' -export const GENERATE_IDENTITY_SUCCESS = '[Success] Generate Identity' -export const GENERATE_IDENTITY_FAILURE = '[Failure] Generate Identity' - -export const generateIdentityRequest = (address: string) => - action(GENERATE_IDENTITY_REQUEST, { address }) -export const generateIdentitySuccess = ( - address: string, - identity: AuthIdentity -) => action(GENERATE_IDENTITY_SUCCESS, { address, identity }) -export const generateIdentityFailure = (address: string, error: string) => - action(GENERATE_IDENTITY_FAILURE, { address, error }) - -export type GenerateIdentityRequestAction = ReturnType< - typeof generateIdentityRequest -> -export type GenerateIdentitySuccessAction = ReturnType< - typeof generateIdentitySuccess -> -export type GenerateIdentityFailureAction = ReturnType< - typeof generateIdentityFailure -> diff --git a/webapp/src/modules/identity/reducer.ts b/webapp/src/modules/identity/reducer.ts deleted file mode 100644 index 20c37c50d6..0000000000 --- a/webapp/src/modules/identity/reducer.ts +++ /dev/null @@ -1,65 +0,0 @@ -import { AuthIdentity } from '@dcl/crypto' -import { - loadingReducer, - LoadingState -} from 'decentraland-dapps/dist/modules/loading/reducer' -import { - GenerateIdentityRequestAction, - GenerateIdentitySuccessAction, - GenerateIdentityFailureAction, - GENERATE_IDENTITY_REQUEST, - GENERATE_IDENTITY_SUCCESS, - GENERATE_IDENTITY_FAILURE -} from './actions' - -export type IdentityState = { - data: Record - loading: LoadingState - error: string | null -} - -export const INITIAL_STATE: IdentityState = { - data: {}, - loading: [], - error: null -} - -export type IdentityReducerAction = - | GenerateIdentityRequestAction - | GenerateIdentitySuccessAction - | GenerateIdentityFailureAction - -export function identityReducer( - state: IdentityState = INITIAL_STATE, - action: IdentityReducerAction -): IdentityState { - switch (action.type) { - case GENERATE_IDENTITY_REQUEST: { - return { - ...state, - loading: loadingReducer(state.loading, action) - } - } - case GENERATE_IDENTITY_SUCCESS: { - const { address, identity } = action.payload - return { - ...state, - loading: loadingReducer(state.loading, action), - error: null, - data: { - ...state.data, - [address]: identity - } - } - } - case GENERATE_IDENTITY_FAILURE: { - return { - ...state, - loading: loadingReducer(state.loading, action), - error: action.payload.error - } - } - default: - return state - } -} diff --git a/webapp/src/modules/identity/sagas.spec.ts b/webapp/src/modules/identity/sagas.spec.ts deleted file mode 100644 index db6221accd..0000000000 --- a/webapp/src/modules/identity/sagas.spec.ts +++ /dev/null @@ -1,161 +0,0 @@ -import { expectSaga } from 'redux-saga-test-plan' -import { call, select } 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 { 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() - } -}) - -beforeEach(() => { - jest.resetAllMocks() - - setAuxAddress(null) -}) - -describe('when handling the wallet connection success', () => { - let wallet: Wallet - let windowLocation: Location - - beforeEach(() => { - wallet = { - address: '0x0' - } 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 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 }) - }) - }) - }) - - 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 }) - }) - }) - - describe("and there's an identity", () => { - it('should put an action to store the identity', () => { - const identity = {} as any - - return expectSaga(identitySaga) - .provide([ - [call(getIdentity, wallet.address), identity], - [select(getIsAuthDappEnabled), false] - ]) - .put(generateIdentitySuccess(wallet.address, identity)) - .dispatch(connectWalletSuccess(wallet)) - .run({ silenceTimeout: true }) - }) - }) - }) -}) - -describe('when handling the disconnect', () => { - describe('when the auxiliary address is set', () => { - const address = '0xSomeAddress' - - beforeEach(() => { - 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 }) - - expect(clearIdentity).toHaveBeenCalledWith(address) - }) - }) - }) - - describe('when the auxiliary address is not set', () => { - beforeEach(() => { - setAuxAddress(null) - }) - - it('should not call the sso client to clear the identity', async () => { - await expectSaga(identitySaga) - .dispatch(disconnectWallet()) - .run({ silenceTimeout: true }) - - expect(clearIdentity).not.toHaveBeenCalled() - }) - }) -}) diff --git a/webapp/src/modules/identity/sagas.ts b/webapp/src/modules/identity/sagas.ts deleted file mode 100644 index 31e5c858b3..0000000000 --- a/webapp/src/modules/identity/sagas.ts +++ /dev/null @@ -1,123 +0,0 @@ -import { takeLatest, put, call, select } from 'redux-saga/effects' -import { ethers } from 'ethers' -import { Authenticator, AuthIdentity } from '@dcl/crypto' -import { - getIdentity, - storeIdentity, - clearIdentity, - localStorageGetIdentity, - localStorageClearIdentity -} from '@dcl/single-sign-on-client' -import { t } from 'decentraland-dapps/dist/modules/translation/utils' -import { - CONNECT_WALLET_SUCCESS, - DISCONNECT_WALLET, - DisconnectWalletAction -} from 'decentraland-dapps/dist/modules/wallet/actions' -import { ConnectWalletSuccessAction } from 'decentraland-dapps/dist/modules/wallet/actions' -import { isErrorWithMessage } from '../../lib/error' -import { config } from '../../config' -import { getIsAuthDappEnabled } from '../features/selectors' -import { getEth } from '../wallet/utils' - -import { - GENERATE_IDENTITY_REQUEST, - GenerateIdentityRequestAction, - generateIdentityFailure, - generateIdentityRequest, - generateIdentitySuccess -} from './actions' -import { IDENTITY_EXPIRATION_IN_MINUTES } from './utils' - -export function* identitySaga() { - yield takeLatest(GENERATE_IDENTITY_REQUEST, handleGenerateIdentityRequest) - yield takeLatest(CONNECT_WALLET_SUCCESS, handleConnectWalletSuccess) - yield takeLatest(DISCONNECT_WALLET, handleDisconnect) -} - -function* handleGenerateIdentityRequest(action: GenerateIdentityRequestAction) { - const address = action.payload.address.toLowerCase() - - try { - const eth: ethers.providers.Web3Provider = yield call(getEth) - const account = ethers.Wallet.createRandom() - - const payload = { - address: account.address.toString(), - publicKey: ethers.utils.hexlify(account.publicKey), - privateKey: ethers.utils.hexlify(account.privateKey) - } - - const signer = eth.getSigner() - - const identity: AuthIdentity = yield Authenticator.initializeAuthChain( - address, - payload, - IDENTITY_EXPIRATION_IN_MINUTES, - message => signer.signMessage(message) - ) - - // Stores the identity into the SSO iframe. - yield call(storeIdentity, address, identity) - - yield put(generateIdentitySuccess(address, identity)) - } catch (error) { - yield put( - generateIdentityFailure( - address, - isErrorWithMessage(error) ? error.message : t('global.unknown_error') - ) - ) - } -} - -// Persist the address of the connected wallet. -// This is a workaround for when the user disconnects as there is no selector that provides the address at that point -let auxAddress: string | null = null - -export function setAuxAddress(address: string | null) { - auxAddress = address -} - -function* handleConnectWalletSuccess(action: ConnectWalletSuccessAction) { - const address = action.payload.wallet.address - - yield call(setAuxAddress, address) - - const isAuthDappEnabled: boolean = yield select(getIsAuthDappEnabled) - - if (isAuthDappEnabled) { - const identity: AuthIdentity | null = localStorageGetIdentity(address) - if (identity) { - yield put(generateIdentitySuccess(address, identity)) - } else { - window.location.replace( - `${config.get('AUTH_URL')}/login?redirectTo=${encodeURIComponent(window.location.href)}` - ) - } - return - } - - // Obtains the identity from the SSO iframe. - const identity: AuthIdentity | null = yield call(getIdentity, address) - - // If the identity was persisted in the iframe, store in in redux. - // If not, generate a new one, which wil be stored in the iframe. - if (!identity) { - yield put(generateIdentityRequest(address)) - } else { - yield put(generateIdentitySuccess(address, identity)) - } -} - -function* handleDisconnect(_action: DisconnectWalletAction) { - if (auxAddress) { - const isAuthDappEnabled: boolean = yield select(getIsAuthDappEnabled) - if (isAuthDappEnabled) { - localStorageClearIdentity(auxAddress) - } else { - // Clears the identity from the SSO iframe when the user disconnects the wallet. - yield call(clearIdentity, auxAddress) - } - } -} diff --git a/webapp/src/modules/identity/selectors.ts b/webapp/src/modules/identity/selectors.ts deleted file mode 100644 index 39b5ee6394..0000000000 --- a/webapp/src/modules/identity/selectors.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { createSelector } from 'reselect' -import { RootState } from '../reducer' -import { getAddress } from '../wallet/selectors' -import { isValid } from './utils' - -export const getState = (state: RootState) => state.identity -export const getData = (state: RootState) => getState(state).data -export const getLoading = (state: RootState) => getState(state).loading -export const getError = (state: RootState) => getState(state).error - -export const getCurrentIdentity = createSelector( - getData, - getAddress, - (identities, address) => { - if (!address) { - return null - } - - const identity = identities[address] - - if (!isValid(identity)) { - return null - } - - return identity - } -) diff --git a/webapp/src/modules/identity/utils.ts b/webapp/src/modules/identity/utils.ts deleted file mode 100644 index f08a4e76a9..0000000000 --- a/webapp/src/modules/identity/utils.ts +++ /dev/null @@ -1,80 +0,0 @@ -import { select, put, race, take, call } from 'redux-saga/effects' -import { AuthIdentity } from '@dcl/crypto' -import { - connectWalletRequest, - CONNECT_WALLET_SUCCESS, - CONNECT_WALLET_FAILURE, - ConnectWalletSuccessAction -} from 'decentraland-dapps/dist/modules/wallet/actions' -import { getAddress } from '../wallet/selectors' -import { config } from '../../config' -import { getCurrentIdentity } from './selectors' -import { - generateIdentityRequest, - GenerateIdentitySuccessAction, - GENERATE_IDENTITY_FAILURE, - GENERATE_IDENTITY_SUCCESS -} from './actions' - -const ONE_MONTH_IN_MINUTES = 31 * 24 * 60 - -export const IDENTITY_EXPIRATION_IN_MINUTES = (() => { - const expiration = config.get('IDENTITY_EXPIRATION_MINUTES') - - if (!expiration) { - return ONE_MONTH_IN_MINUTES - } - - return Number(expiration) -})() - -const IDENTITY_ERROR = 'Could not get identity' - -// Helper that always yields a valid identity -// If the wallet is not connected it will try to connect -// If the identity is invalid or has not been generated. It will try to generate it -export function* getIdentity(): Generator { - const address: ReturnType = yield select(getAddress) - - if (!address) { - yield put(connectWalletRequest()) - - const { success }: { success: ConnectWalletSuccessAction } = yield race({ - success: take(CONNECT_WALLET_SUCCESS), - failure: take(CONNECT_WALLET_FAILURE) - }) - - if (success) { - return yield call(getIdentity) - } - - throw new Error(IDENTITY_ERROR) - } - - const identity: ReturnType = yield select( - getCurrentIdentity - ) - - if (identity) { - return identity - } - - yield put(generateIdentityRequest(address)) - - const { success }: { success: GenerateIdentitySuccessAction } = yield race({ - success: take(GENERATE_IDENTITY_SUCCESS), - failure: take(GENERATE_IDENTITY_FAILURE) - }) - - if (success) { - return yield call(getIdentity) - } else { - throw new Error(IDENTITY_ERROR) - } -} - -// Return if an identity is valid according to its expiration -// or its nullity -export function isValid(identity?: AuthIdentity | null) { - return !!identity && Date.now() < +new Date(identity.expiration) -} diff --git a/webapp/src/modules/item/sagas.ts b/webapp/src/modules/item/sagas.ts index 6f59520c57..0a8b79526c 100644 --- a/webapp/src/modules/item/sagas.ts +++ b/webapp/src/modules/item/sagas.ts @@ -16,7 +16,6 @@ import { Item } from '@dcl/schemas' import { getConnectedProvider } from 'decentraland-dapps/dist/lib/eth' import { ContractName, getContract } from 'decentraland-transactions' import { Provider } from 'decentraland-connect' -import { AuthIdentity } from 'decentraland-crypto-fetch' import { sendTransaction } from 'decentraland-dapps/dist/modules/wallet/utils' import { t } from 'decentraland-dapps/dist/modules/translation/utils' import { @@ -82,11 +81,10 @@ import { getItem } from './utils' export const NFT_SERVER_URL = config.get('NFT_SERVER_URL')! export const CANCEL_FETCH_ITEMS = 'CANCEL_FETCH_ITEMS' -export function* itemSaga(getIdentity: () => AuthIdentity | undefined) { +export function* itemSaga() { const API_OPTS = { retries: retryParams.attempts, - retryDelay: retryParams.delay, - identity: getIdentity + retryDelay: retryParams.delay } const itemAPI = new ItemAPI(NFT_SERVER_URL, API_OPTS) const marketplaceServerCatalogAPI = new CatalogAPI( diff --git a/webapp/src/modules/nft/sagas.ts b/webapp/src/modules/nft/sagas.ts index 75aa71b060..661ed081ca 100644 --- a/webapp/src/modules/nft/sagas.ts +++ b/webapp/src/modules/nft/sagas.ts @@ -42,11 +42,10 @@ import { } from './actions' import { NFT } from './types' -export function* nftSaga(getIdentity: () => AuthIdentity | undefined) { +export function* nftSaga() { const API_OPTS = { retries: retryParams.attempts, - retryDelay: retryParams.delay, - identity: getIdentity + retryDelay: retryParams.delay } yield takeEvery(FETCH_NFTS_REQUEST, handleFetchNFTsRequest) diff --git a/webapp/src/modules/reducer.ts b/webapp/src/modules/reducer.ts index 0029acd6e7..9e56c9c5d0 100644 --- a/webapp/src/modules/reducer.ts +++ b/webapp/src/modules/reducer.ts @@ -11,7 +11,6 @@ import { toastReducer as toast } from 'decentraland-dapps/dist/modules/toast/red import { featuresReducer as features } from 'decentraland-dapps/dist/modules/features/reducer' import { modalReducer as modal } from 'decentraland-dapps/dist/modules/modal/reducer' import { gatewayReducer as gateway } from 'decentraland-dapps/dist/modules/gateway/reducer' - import { accountReducer as account } from './account/reducer' import { bidReducer as bid } from './bid/reducer' import { itemReducer as item } from './item/reducer' @@ -24,7 +23,6 @@ import { uiReducer as ui } from './ui/reducer' import { collectionReducer as collection } from './collection/reducer' import { storeReducer as store } from './store/reducer' import { saleReducer as sale } from './sale/reducer' -import { identityReducer as identity } from './identity/reducer' import { analyticsReducer as analytics } from './analytics/reducer' import { rentalReducer as rental } from './rental/reducer' import { eventReducer as event } from './event/reducer' @@ -57,7 +55,6 @@ export const createRootReducer = (history: History) => collection, store, sale, - identity, analytics, features, event, diff --git a/webapp/src/modules/rental/sagas.ts b/webapp/src/modules/rental/sagas.ts index e6a560988c..8bee5e6325 100644 --- a/webapp/src/modules/rental/sagas.ts +++ b/webapp/src/modules/rental/sagas.ts @@ -13,6 +13,7 @@ import { getContract, Provider } from 'decentraland-transactions' +import { getIdentity } from '@dcl/single-sign-on-client' import { getConnectedProvider } from 'decentraland-dapps/dist/lib/eth' import { waitForTx } from 'decentraland-dapps/dist/modules/transaction/utils' import { sendTransaction } from 'decentraland-dapps/dist/modules/wallet/utils' @@ -22,7 +23,6 @@ import { } from 'decentraland-dapps/dist/modules/modal/actions' import { ethers } from 'ethers' import { call, delay, put, select, take, takeEvery } from 'redux-saga/effects' -import { getIdentity } from '../identity/utils' import { rentalsAPI } from '../vendor/decentraland/rentals/api' import { getAddress } from '../wallet/selectors' import { getContract as getContractByQuery } from '../contract/selectors' @@ -124,7 +124,8 @@ function* handleCreateOrEditRentalRequest(action: UpsertRentalRequestAction) { target: ethers.constants.AddressZero // For now, all rent listing will be "public", for all addresses to use. } - const identity: AuthIdentity = yield getIdentity() + console.log('check redirect2') + const identity: AuthIdentity = yield getIdentity(address) const rental: RentalListing = yield call( [rentalsAPI, 'createRentalListing'], diff --git a/webapp/src/modules/sagas.ts b/webapp/src/modules/sagas.ts index f00121f0ce..6bbf1316a1 100644 --- a/webapp/src/modules/sagas.ts +++ b/webapp/src/modules/sagas.ts @@ -1,5 +1,4 @@ import { all } from 'redux-saga/effects' -import { AuthIdentity } from 'decentraland-crypto-fetch' import { ApplicationName } from 'decentraland-dapps/dist/modules/features/types' import { authorizationSaga } from 'decentraland-dapps/dist/modules/authorization/sagas' import { FiatGateway } from 'decentraland-dapps/dist/modules/gateway/types' @@ -14,7 +13,6 @@ import { createLambdasClient } from 'dcl-catalyst-client/dist/client/LambdasClie import { createContentClient } from 'dcl-catalyst-client/dist/client/ContentClient' import { NetworkGatewayType } from 'decentraland-ui/dist/components/BuyManaWithFiatModal/Network' import { createFetchComponent } from '@well-known-components/fetch-component' - import { config } from '../config' import { peerUrl } from '../lib/environment' import { analyticsSagas as marketplaceAnalyticsSagas } from './analytics/sagas' @@ -33,7 +31,6 @@ import { collectionSaga } from './collection/sagas' import { saleSaga } from './sale/sagas' import { accountSaga } from './account/sagas' import { storeSaga } from './store/sagas' -import { identitySaga } from './identity/sagas' import { rentalSaga } from './rental/sagas' import { modalSaga } from './modal/sagas' import { eventSaga } from './event/sagas' @@ -45,8 +42,7 @@ import { loginSaga } from './login/sagas' import { ensSaga } from './ens/sagas' const analyticsSaga = createAnalyticsSaga() -const profileSaga = (getIdentity: () => AuthIdentity | undefined) => - createProfileSaga({ getIdentity, peerUrl }) +const profileSaga = () => createProfileSaga({ peerUrl }) const lambdasClient = createLambdasClient({ url: `${peerUrl}/lambdas`, fetcher: createFetchComponent() @@ -83,16 +79,16 @@ const gatewaySaga = createGatewaySaga({ } }) -export function* rootSaga(getIdentity: () => AuthIdentity | undefined) { +export function* rootSaga() { yield all([ analyticsSaga(), assetSaga(), authorizationSaga(), bidSaga(), - itemSaga(getIdentity), - nftSaga(getIdentity), + itemSaga(), + nftSaga(), orderSaga(), - profileSaga(getIdentity)(), + profileSaga()(), proximitySaga(), routingSaga(), tileSaga(), @@ -106,7 +102,6 @@ export function* rootSaga(getIdentity: () => AuthIdentity | undefined) { accountSaga(lambdasClient), collectionSaga(), storeSaga(contentClient), - identitySaga(), newIdentitySaga(), marketplaceAnalyticsSagas(), featuresSaga({ @@ -122,8 +117,9 @@ export function* rootSaga(getIdentity: () => AuthIdentity | undefined) { gatewaySaga(), locationSaga(), transakSaga(), - favoritesSaga(getIdentity), + favoritesSaga(), loginSaga(), - ensSaga() + ensSaga(), + newIdentitySaga() ]) } diff --git a/webapp/src/modules/store.ts b/webapp/src/modules/store.ts index 960f06cd7d..d574dbe5c0 100644 --- a/webapp/src/modules/store.ts +++ b/webapp/src/modules/store.ts @@ -1,3 +1,4 @@ +import { createMemoryHistory, createBrowserHistory, History } from 'history' import { applyMiddleware, compose, createStore } from 'redux' import createSagasMiddleware from 'redux-saga' import { routerMiddleware } from 'connected-react-router' @@ -15,9 +16,6 @@ import { rootSaga } from './sagas' import { fetchTilesRequest } from './tile/actions' import { ARCHIVE_BID, UNARCHIVE_BID } from './bid/actions' import { SET_IS_TRYING_ON } from './ui/preview/actions' -import { getCurrentIdentity } from './identity/selectors' -import { AuthIdentity } from 'decentraland-crypto-fetch' -import { createMemoryHistory, createBrowserHistory, History } from 'history' const basename = /^decentraland.(zone|org|today)$/.test(window.location.host) ? '/marketplace' @@ -74,12 +72,8 @@ export function initStore(history: History) { (rootReducer as unknown) as ReturnType, enhancer ) - const getIdentity = () => { - return ( - (getCurrentIdentity(store.getState()) as AuthIdentity | null) ?? undefined - ) - } - sagasMiddleware.run(rootSaga, getIdentity) + + sagasMiddleware.run(rootSaga) loadStorageMiddleware(store) if (isDev) { @@ -116,7 +110,7 @@ export function initTestStore(preloadedState = {}) { ) const enhancer = compose(middleware) const store = createStore(rootReducer, preloadedState, enhancer) - sagasMiddleware.run(rootSaga, () => undefined) + sagasMiddleware.run(rootSaga) loadStorageMiddleware(store) store.dispatch(fetchTilesRequest()) diff --git a/webapp/src/modules/store/sagas.spec.ts b/webapp/src/modules/store/sagas.spec.ts index 90a051d78b..1d4af1a823 100644 --- a/webapp/src/modules/store/sagas.spec.ts +++ b/webapp/src/modules/store/sagas.spec.ts @@ -1,10 +1,12 @@ import { Entity } from '@dcl/schemas' import { AuthIdentity } from '@dcl/crypto' -import { createContentClient, ContentClient } from 'dcl-catalyst-client/dist/client/ContentClient' +import { + createContentClient, + ContentClient +} from 'dcl-catalyst-client/dist/client/ContentClient' import { createFetchComponent } from '@well-known-components/fetch-component' import { expectSaga } from 'redux-saga-test-plan' import { call, select } from 'redux-saga/effects' -import { getIdentity } from '../identity/utils' import { getAddress } from '../wallet/selectors' import { fetchStoreFailure, @@ -32,7 +34,10 @@ let mockStore: Store beforeEach(() => { mockAddress = 'address' - mockClient = createContentClient({ url: 'some-url', fetcher: createFetchComponent() }) + mockClient = createContentClient({ + url: 'some-url', + fetcher: createFetchComponent() + }) mockStore = getEmptyStore({ owner: mockAddress }) }) diff --git a/webapp/src/modules/store/sagas.ts b/webapp/src/modules/store/sagas.ts index 14a8619f93..e13c298731 100644 --- a/webapp/src/modules/store/sagas.ts +++ b/webapp/src/modules/store/sagas.ts @@ -6,7 +6,6 @@ import { getAddress } from 'decentraland-dapps/dist/modules/wallet/selectors' import { t } from 'decentraland-dapps/dist/modules/translation/utils' import { ContentClient } from 'dcl-catalyst-client/dist/client/ContentClient' import { isErrorWithMessage } from '../../lib/error' -import { getIdentity } from '../identity/utils' import { fetchStoreFailure, FetchStoreRequestAction, @@ -24,6 +23,7 @@ import { getStoreFromEntity } from './utils' import { getIsLocalStoreDirty } from './selectors' +import { getIdentityOrRedirect } from 'decentraland-dapps/dist/modules/identity/sagas' export function* storeSaga(client: ContentClient) { yield takeEvery(FETCH_STORE_REQUEST, handleFetchStoreRequest) @@ -73,7 +73,8 @@ export function* storeSaga(client: ContentClient) { payload: { store } }: UpdateStoreRequestAction) { try { - const identity: AuthIdentity = yield call(getIdentity) + console.log('check redirect1') + const identity: AuthIdentity = yield call(getIdentityOrRedirect) yield call(deployStoreEntity, client, identity, store) diff --git a/webapp/src/modules/wallet/utils.ts b/webapp/src/modules/wallet/utils.ts index ccc7dfe8b5..158882ba58 100644 --- a/webapp/src/modules/wallet/utils.ts +++ b/webapp/src/modules/wallet/utils.ts @@ -10,7 +10,7 @@ import { isConnecting } from 'decentraland-dapps/dist/modules/wallet/selectors' import { GENERATE_IDENTITY_FAILURE, GENERATE_IDENTITY_SUCCESS -} from '../identity/actions' +} from 'decentraland-dapps/dist/modules/identity/actions' import { config } from '../../config' export const TRANSACTIONS_API_URL = config.get('TRANSACTIONS_API_URL') @@ -53,6 +53,7 @@ export function formatBalance(balance: number) { export function* waitForWalletConnectionAndIdentityIfConnecting() { const isConnectingToWallet: boolean = yield select(isConnecting) + console.log('isConnectingToWallet: ', isConnectingToWallet); if (isConnectingToWallet) { const { success } = yield race({ success: take(CONNECT_WALLET_SUCCESS), diff --git a/webapp/src/utils/tests.tsx b/webapp/src/utils/tests.tsx index 900212f885..175e7cd4fa 100644 --- a/webapp/src/utils/tests.tsx +++ b/webapp/src/utils/tests.tsx @@ -9,10 +9,11 @@ import { storageReducerWrapper } from 'decentraland-dapps/dist/modules/storage/r import { createTransactionMiddleware } from 'decentraland-dapps/dist/modules/transaction/middleware' import { CLEAR_TRANSACTIONS } from 'decentraland-dapps/dist/modules/transaction/actions' import TranslationProvider from 'decentraland-dapps/dist/providers/TranslationProvider' +import { GENERATE_IDENTITY_SUCCESS } from 'decentraland-dapps/dist/modules/identity/actions' import { createRootReducer, RootState } from '../modules/reducer' import * as locales from '../modules/translation/locales' import { ARCHIVE_BID, UNARCHIVE_BID } from '../modules/bid/actions' -import { GENERATE_IDENTITY_SUCCESS } from '../modules/identity/actions' +// import { GENERATE_IDENTITY_SUCCESS } from '../modules/identity/actions' import { SET_IS_TRYING_ON } from '../modules/ui/preview/actions' import { rootSaga } from '../modules/sagas' import { fetchTilesRequest } from '../modules/tile/actions' @@ -49,7 +50,7 @@ export function initTestStore(preloadedState = {}) { const enhancer = compose(middleware) const store = createStore(rootReducer, preloadedState, enhancer) - sagasMiddleware.run(rootSaga, () => undefined) + sagasMiddleware.run(rootSaga) loadStorageMiddleware(store) store.dispatch(fetchTilesRequest()) From b39bcf78a30f99057e3513feeea5296fd59b50fa Mon Sep 17 00:00:00 2001 From: Juanma Hidalgo Date: Tue, 23 Jan 2024 18:13:54 +0100 Subject: [PATCH 2/8] feat: reeplace the old identity usage for the new one --- webapp/package.json | 2 +- .../FavoritesModal.container.tsx | 11 ++ .../FavoritesModal/FavoritesModal.spec.tsx | 5 +- .../Modals/FavoritesModal/FavoritesModal.tsx | 9 +- .../FavoritesModal/FavoritesModal.types.ts | 4 + .../components/Modals/FavoritesModal/index.ts | 2 +- .../SaveToListModal/SaveToListModal.spec.tsx | 4 +- webapp/src/modules/favorites/sagas.spec.ts | 160 +++++++++--------- webapp/src/modules/item/sagas.spec.ts | 52 +++--- webapp/src/modules/nft/sagas.spec.ts | 28 +-- webapp/src/modules/nft/sagas.ts | 1 - webapp/src/modules/rental/sagas.spec.ts | 8 +- webapp/src/modules/rental/sagas.ts | 19 ++- webapp/src/modules/sagas.ts | 3 +- webapp/src/modules/store/sagas.spec.ts | 3 +- 15 files changed, 163 insertions(+), 148 deletions(-) create mode 100644 webapp/src/components/Modals/FavoritesModal/FavoritesModal.container.tsx diff --git a/webapp/package.json b/webapp/package.json index 2774c97c45..98280575da 100644 --- a/webapp/package.json +++ b/webapp/package.json @@ -124,4 +124,4 @@ "@walletconnect/core": "2.9.2", "@walletconnect/keyvaluestorage": "1.0.0" } -} +} \ No newline at end of file diff --git a/webapp/src/components/Modals/FavoritesModal/FavoritesModal.container.tsx b/webapp/src/components/Modals/FavoritesModal/FavoritesModal.container.tsx new file mode 100644 index 0000000000..11be41e5b5 --- /dev/null +++ b/webapp/src/components/Modals/FavoritesModal/FavoritesModal.container.tsx @@ -0,0 +1,11 @@ +import { connect } from 'react-redux' +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 { wallet: getWallet(state) } +} + +export default connect(mapState)(FavoritesModal) diff --git a/webapp/src/components/Modals/FavoritesModal/FavoritesModal.spec.tsx b/webapp/src/components/Modals/FavoritesModal/FavoritesModal.spec.tsx index 810983f4a3..1e28db6639 100644 --- a/webapp/src/components/Modals/FavoritesModal/FavoritesModal.spec.tsx +++ b/webapp/src/components/Modals/FavoritesModal/FavoritesModal.spec.tsx @@ -1,5 +1,5 @@ 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' @@ -17,14 +17,13 @@ jest.mock('react-virtualized-auto-sizer', () => { jest.mock('../../../modules/vendor/decentraland/favorites') const itemId = 'anItemId' -const identity = {} as AuthIdentity function renderFavoritesModal(props: Partial = {}) { return renderWithProviders( , diff --git a/webapp/src/components/Modals/FavoritesModal/FavoritesModal.tsx b/webapp/src/components/Modals/FavoritesModal/FavoritesModal.tsx index 84d9d49c74..b0ad5f3f8f 100644 --- a/webapp/src/components/Modals/FavoritesModal/FavoritesModal.tsx +++ b/webapp/src/components/Modals/FavoritesModal/FavoritesModal.tsx @@ -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' @@ -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() const [favorites, setFavorites] = useState<{ @@ -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) => { diff --git a/webapp/src/components/Modals/FavoritesModal/FavoritesModal.types.ts b/webapp/src/components/Modals/FavoritesModal/FavoritesModal.types.ts index 12eed426d5..64bab152de 100644 --- a/webapp/src/components/Modals/FavoritesModal/FavoritesModal.types.ts +++ b/webapp/src/components/Modals/FavoritesModal/FavoritesModal.types.ts @@ -1,4 +1,5 @@ import { ModalProps } from 'decentraland-dapps/dist/providers/ModalProvider/ModalProvider.types' +import { Wallet } from 'decentraland-dapps/dist/modules/wallet/types' export type Metadata = { itemId: string @@ -6,6 +7,9 @@ export type Metadata = { export type Props = Omit & { metadata: Metadata + wallet: Wallet | null } +export type MapStateProps = Pick + export type OwnProps = Pick diff --git a/webapp/src/components/Modals/FavoritesModal/index.ts b/webapp/src/components/Modals/FavoritesModal/index.ts index 859ce77ffe..6ea3b5b05f 100644 --- a/webapp/src/components/Modals/FavoritesModal/index.ts +++ b/webapp/src/components/Modals/FavoritesModal/index.ts @@ -1,2 +1,2 @@ -import FavoritesModal from './FavoritesModal' +import FavoritesModal from './FavoritesModal.container' export { FavoritesModal } diff --git a/webapp/src/components/Modals/SaveToListModal/SaveToListModal.spec.tsx b/webapp/src/components/Modals/SaveToListModal/SaveToListModal.spec.tsx index 37968ffd25..1fba73214c 100644 --- a/webapp/src/components/Modals/SaveToListModal/SaveToListModal.spec.tsx +++ b/webapp/src/components/Modals/SaveToListModal/SaveToListModal.spec.tsx @@ -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' @@ -28,9 +28,9 @@ jest.mock('react-virtualized-auto-sizer', () => { function renderSaveToListModalModal(props: Partial = {}) { return renderWithProviders( undefined - beforeEach(() => { error = new Error('error') item = { id: 'anAddress-itemId', itemId: 'itemId' } as Item @@ -102,7 +100,7 @@ describe('when handling the request for fetching favorited items', () => { describe('and getting the address fails', () => { it('should dispatch an action signaling the failure of the handled action', () => { - return expectSaga(favoritesSaga, getIdentity) + return expectSaga(favoritesSaga) .provide([ [select(getListId), listId], [select(getAddress), Promise.reject(error)], @@ -116,12 +114,12 @@ describe('when handling the request for fetching favorited items', () => { describe('and getting the identity fails', () => { it('should dispatch an action signaling the failure of the handled action', () => { - return expectSaga(favoritesSaga, getIdentity) + return expectSaga(favoritesSaga) .provide([ [select(getListId), listId], [select(getAddress), address], [select(getIsMarketplaceServerEnabled), true], - [call(getAccountIdentity), Promise.reject(error)] + [call(getIdentityOrRedirect), Promise.reject(error)] ]) .put(fetchFavoritedItemsFailure(error.message)) .dispatch(fetchFavoritedItemsRequest(options)) @@ -132,12 +130,12 @@ describe('when handling the request for fetching favorited items', () => { describe('and the user is logged in', () => { describe('and the call to the favorites api fails', () => { it('should dispatch an action signaling the failure of the handled action', () => { - return expectSaga(favoritesSaga, getIdentity) + return expectSaga(favoritesSaga) .provide([ [select(getListId), listId], [select(getAddress), address], [select(getIsMarketplaceServerEnabled), true], - [call(getAccountIdentity), Promise.resolve()], + [call(getIdentityOrRedirect), Promise.resolve()], [ matchers.call.fn(FavoritesAPI.prototype.getPicksByList), Promise.reject(error) @@ -172,12 +170,12 @@ describe('when handling the request for fetching favorited items', () => { }) describe('and the call to the items api fails', () => { it('should dispatch an action signaling the failure of the handled action', () => { - return expectSaga(favoritesSaga, getIdentity) + return expectSaga(favoritesSaga) .provide([ [select(getListId), listId], [select(getIsMarketplaceServerEnabled), isMarketplaceFFOn], [select(getAddress), address], - [call(getAccountIdentity), Promise.resolve()], + [call(getIdentityOrRedirect), Promise.resolve()], [ matchers.call.fn(FavoritesAPI.prototype.getPicksByList), Promise.resolve({ results: favoritedItemIds, total }) @@ -210,12 +208,12 @@ describe('when handling the request for fetching favorited items', () => { }) describe('and the call to the items api fails', () => { it('should dispatch an action signaling the failure of the handled action', () => { - return expectSaga(favoritesSaga, getIdentity) + return expectSaga(favoritesSaga) .provide([ [select(getListId), listId], [select(getIsMarketplaceServerEnabled), isMarketplaceFFOn], [select(getAddress), address], - [call(getAccountIdentity), Promise.resolve()], + [call(getIdentityOrRedirect), Promise.resolve()], [ matchers.call.fn(FavoritesAPI.prototype.getPicksByList), Promise.resolve({ results: favoritedItemIds, total }) @@ -251,12 +249,12 @@ describe('when handling the request for fetching favorited items', () => { }) it('should dispatch an action signaling the success of the handled action and the request of the retrieved items', () => { - return expectSaga(favoritesSaga, getIdentity) + return expectSaga(favoritesSaga) .provide([ [select(getListId), listId], [select(getAddress), address], [select(getIsMarketplaceServerEnabled), true], - [call(getAccountIdentity), Promise.resolve()], + [call(getIdentityOrRedirect), Promise.resolve()], [ matchers.call.fn(FavoritesAPI.prototype.getPicksByList), Promise.resolve({ results: favoritedItemIds, total }) @@ -306,12 +304,12 @@ describe('when handling the request for fetching favorited items', () => { }) it('should dispatch an action signaling the success of the handled action', () => { - return expectSaga(favoritesSaga, getIdentity) + return expectSaga(favoritesSaga) .provide([ [select(getListId), listId], [select(getAddress), address], [select(getIsMarketplaceServerEnabled), true], - [call(getAccountIdentity), Promise.resolve()], + [call(getIdentityOrRedirect), Promise.resolve()], [ matchers.call.fn(FavoritesAPI.prototype.getPicksByList), { results: favoritedItemIds, total } @@ -347,7 +345,7 @@ describe('when handling the request for fetching favorited items', () => { describe('and the user is not logged in', () => { describe('and the call to the favorites api fails', () => { it('should dispatch an action signaling the failure of the handled action', () => { - return expectSaga(favoritesSaga, getIdentity) + return expectSaga(favoritesSaga) .provide([ [select(getListId), listId], [select(getAddress), null], @@ -381,7 +379,7 @@ describe('when handling the request for fetching favorited items', () => { describe('and the call to the items api fails', () => { it('should dispatch an action signaling the failure of the handled action', () => { - return expectSaga(favoritesSaga, getIdentity) + return expectSaga(favoritesSaga) .provide([ [select(getListId), listId], [select(getAddress), null], @@ -420,7 +418,7 @@ describe('when handling the request for fetching favorited items', () => { }) it('should dispatch an action signaling the success of the handled action and the request of the retrieved items', () => { - return expectSaga(favoritesSaga, getIdentity) + return expectSaga(favoritesSaga) .provide([ [select(getListId), listId], [select(getAddress), null], @@ -474,7 +472,7 @@ describe('when handling the request for fetching favorited items', () => { }) it('should dispatch an action signaling the success of the handled action', () => { - return expectSaga(favoritesSaga, getIdentity) + return expectSaga(favoritesSaga) .provide([ [select(getListId), listId], [select(getAddress), null], @@ -524,8 +522,8 @@ describe('when handling the request for fetching lists', () => { describe('and getting the identity fails', () => { it('should dispatch an action signaling the failure of the handled action', () => { - return expectSaga(favoritesSaga, getIdentity) - .provide([[call(getAccountIdentity), Promise.reject(error)]]) + return expectSaga(favoritesSaga) + .provide([[call(getIdentityOrRedirect), Promise.reject(error)]]) .put(fetchListsFailure(error.message)) .dispatch(fetchListsRequest(options)) .run({ silenceTimeout: true }) @@ -534,9 +532,9 @@ describe('when handling the request for fetching lists', () => { describe('and the call to the favorites api fails', () => { it('should dispatch an action signaling the failure of the handled action', () => { - return expectSaga(favoritesSaga, getIdentity) + return expectSaga(favoritesSaga) .provide([ - [call(getAccountIdentity), Promise.resolve()], + [call(getIdentityOrRedirect), Promise.resolve()], [ matchers.call.fn(FavoritesAPI.prototype.getLists), Promise.reject(error) @@ -574,9 +572,9 @@ describe('when handling the request for fetching lists', () => { }) it('should convert the sort by options and call the api with the sortBy and sortDirection options', () => { - return expectSaga(favoritesSaga, getIdentity) + return expectSaga(favoritesSaga) .provide([ - [call(getAccountIdentity), Promise.resolve()], + [call(getIdentityOrRedirect), Promise.resolve()], [ matchers.call.fn(FavoritesAPI.prototype.getLists), Promise.reject(error) @@ -611,9 +609,9 @@ describe('when handling the request for fetching lists', () => { }) it('should call the api with the skip option', () => { - return expectSaga(favoritesSaga, getIdentity) + return expectSaga(favoritesSaga) .provide([ - [call(getAccountIdentity), Promise.resolve()], + [call(getIdentityOrRedirect), Promise.resolve()], [ matchers.call.fn(FavoritesAPI.prototype.getLists), Promise.reject(error) @@ -672,9 +670,9 @@ describe('when handling the request for fetching lists', () => { describe('and there are no items in the state', () => { it('should dispatch an action signaling the success of the handled action', () => { - return expectSaga(favoritesSaga, getIdentity) + return expectSaga(favoritesSaga) .provide([ - [call(getAccountIdentity), Promise.resolve()], + [call(getIdentityOrRedirect), Promise.resolve()], [select(getIsMarketplaceServerEnabled), true], [ matchers.call.fn(FavoritesAPI.prototype.getLists), @@ -717,9 +715,9 @@ describe('when handling the request for fetching lists', () => { describe('and there are already some items in the sate', () => { it('should dispatch an action signaling the success of the handled action', () => { - return expectSaga(favoritesSaga, getIdentity) + return expectSaga(favoritesSaga) .provide([ - [call(getAccountIdentity), Promise.resolve()], + [call(getIdentityOrRedirect), Promise.resolve()], [select(getIsMarketplaceServerEnabled), true], [ matchers.call.fn(FavoritesAPI.prototype.getLists), @@ -759,9 +757,9 @@ describe('when handling the request for fetching lists', () => { describe('and there are already all the items in the state', () => { it('should dispatch an action signaling the success of the handled action without fetching the catalog items', () => { - return expectSaga(favoritesSaga, getIdentity) + return expectSaga(favoritesSaga) .provide([ - [call(getAccountIdentity), Promise.resolve()], + [call(getIdentityOrRedirect), Promise.resolve()], [ matchers.call.fn(FavoritesAPI.prototype.getLists), Promise.resolve({ results: lists, total }) @@ -815,9 +813,9 @@ describe('when handling the request for fetching lists', () => { }) it('should dispatch an action signaling the success of the handled action', () => { - return expectSaga(favoritesSaga, getIdentity) + return expectSaga(favoritesSaga) .provide([ - [call(getAccountIdentity), Promise.resolve()], + [call(getIdentityOrRedirect), Promise.resolve()], [select(getIsMarketplaceServerEnabled), true], [ matchers.call.fn(FavoritesAPI.prototype.getLists), @@ -863,9 +861,9 @@ describe('when handling the request for fetching lists', () => { describe('and the call to the catalog api fails', () => { it('should dispatch an action signaling the failure of the handled action', () => { - return expectSaga(favoritesSaga, getIdentity) + return expectSaga(favoritesSaga) .provide([ - [call(getAccountIdentity), Promise.resolve()], + [call(getIdentityOrRedirect), Promise.resolve()], [select(getIsMarketplaceServerEnabled), true], [ matchers.call.fn(FavoritesAPI.prototype.getLists), @@ -924,7 +922,7 @@ describe('when handling the start for deleting a list', () => { }) it('should only dispatch an action to open the delete list confirmation modal', () => { - return expectSaga(favoritesSaga, getIdentity) + return expectSaga(favoritesSaga) .put(openModal('ConfirmDeleteListModal', { list })) .not.put(deleteListRequest(list)) .dispatch(deleteListStart(list)) @@ -938,7 +936,7 @@ describe('when handling the start for deleting a list', () => { }) it('should only dispatch an action to start the deletion of the list', () => { - return expectSaga(favoritesSaga, getIdentity) + return expectSaga(favoritesSaga) .provide([[deleteListRequest(list), undefined]]) .put(deleteListRequest(list)) .not.put(openModal('ConfirmDeleteListModal', { list })) @@ -963,8 +961,8 @@ describe('when handling the request for deleting a list', () => { describe('and getting the identity fails', () => { it('should dispatch an action signaling the failure of the handled action', () => { - return expectSaga(favoritesSaga, getIdentity) - .provide([[call(getAccountIdentity), Promise.reject(error)]]) + return expectSaga(favoritesSaga) + .provide([[call(getIdentityOrRedirect), Promise.reject(error)]]) .put(deleteListFailure(list, error.message)) .dispatch(deleteListRequest(list)) .run({ silenceTimeout: true }) @@ -973,9 +971,9 @@ describe('when handling the request for deleting a list', () => { describe('and the call to the favorites api fails', () => { it('should dispatch an action signaling the failure of the handled action', () => { - return expectSaga(favoritesSaga, getIdentity) + return expectSaga(favoritesSaga) .provide([ - [call(getAccountIdentity), Promise.resolve()], + [call(getIdentityOrRedirect), Promise.resolve()], [ matchers.call.fn(FavoritesAPI.prototype.deleteList), Promise.reject(error) @@ -993,9 +991,9 @@ describe('when handling the request for deleting a list', () => { describe('and the call to the favorites api succeeds', () => { it('should dispatch an action signaling the success of the handled action', () => { - return expectSaga(favoritesSaga, getIdentity) + return expectSaga(favoritesSaga) .provide([ - [call(getAccountIdentity), Promise.resolve()], + [call(getIdentityOrRedirect), Promise.resolve()], [ matchers.call.fn(FavoritesAPI.prototype.deleteList), Promise.resolve() @@ -1021,7 +1019,7 @@ describe('when handling the success deletion of a list', () => { describe('and the user performed the action from the list detail page', () => { it('should dispatch an action to redirect the user to the My Lists tab', () => { - return expectSaga(favoritesSaga, getIdentity) + return expectSaga(favoritesSaga) .provide([[select(getLocation), { pathname: locations.list(list.id) }]]) .put(push(locations.lists())) .dispatch(deleteListSuccess(list)) @@ -1031,7 +1029,7 @@ describe('when handling the success deletion of a list', () => { describe('and the user performed the action from the My Lists tab', () => { it('should not dispatch the action signaling the redirection', () => { - return expectSaga(favoritesSaga, getIdentity) + return expectSaga(favoritesSaga) .provide([[select(getLocation), { pathname: locations.lists() }]]) .not.put(push(locations.lists())) .dispatch(deleteListSuccess(list)) @@ -1060,7 +1058,7 @@ describe('when handling the request for getting a list', () => { describe('and the call to the favorites api fails', () => { it('should dispatch an action signaling the failure of the handled action', () => { - return expectSaga(favoritesSaga, getIdentity) + return expectSaga(favoritesSaga) .provide([ [ matchers.call.fn(FavoritesAPI.prototype.getList), @@ -1091,7 +1089,7 @@ describe('when handling the request for getting a list', () => { describe('and non of the preview items are already in the state', () => { it('should dispatch an action signaling the success of the handled action with the received list and items', () => { - return expectSaga(favoritesSaga, getIdentity) + return expectSaga(favoritesSaga) .provide([ [ matchers.call.fn(FavoritesAPI.prototype.getList), @@ -1136,7 +1134,7 @@ describe('when handling the request for getting a list', () => { }) it('should dispatch an action signaling the success of the handled action with the received list and the items that are not in the state', () => { - return expectSaga(favoritesSaga, getIdentity) + return expectSaga(favoritesSaga) .provide([ [ matchers.call.fn(FavoritesAPI.prototype.getList), @@ -1195,7 +1193,7 @@ describe('when handling the request for updating a list', () => { describe('and the call to the favorites api fails', () => { it('should dispatch an action signaling the failure of the handled action', () => { - return expectSaga(favoritesSaga, getIdentity) + return expectSaga(favoritesSaga) .provide([ [ matchers.call.fn(FavoritesAPI.prototype.updateList), @@ -1214,7 +1212,7 @@ describe('when handling the request for updating a list', () => { describe('and the call to the favorites api succeeds', () => { it('should dispatch an action signaling the success of the handled action', () => { - return expectSaga(favoritesSaga, getIdentity) + return expectSaga(favoritesSaga) .provide([ [ matchers.call.fn(FavoritesAPI.prototype.updateList), @@ -1257,10 +1255,10 @@ describe('when handling the request for creating a list', () => { describe('and getting the identity fails', () => { it('should dispatch an action signaling the failure of the handled action', () => { - return expectSaga(favoritesSaga, getIdentity) + return expectSaga(favoritesSaga) .provide([ [select(getLocation), { pathname: locations.lists() }], - [call(getAccountIdentity), Promise.reject(error)] + [call(getIdentityOrRedirect), Promise.reject(error)] ]) .put(createListFailure(error.message)) .dispatch(createListRequest(listToCreate)) @@ -1270,10 +1268,10 @@ describe('when handling the request for creating a list', () => { describe('and the call to the favorites api fails', () => { it('should dispatch an action signaling the failure of the handled action', () => { - return expectSaga(favoritesSaga, getIdentity) + return expectSaga(favoritesSaga) .provide([ [select(getLocation), { pathname: locations.lists() }], - [call(getAccountIdentity), Promise.resolve()], + [call(getIdentityOrRedirect), Promise.resolve()], [ matchers.call.fn(FavoritesAPI.prototype.createList), Promise.reject(error) @@ -1292,10 +1290,10 @@ describe('when handling the request for creating a list', () => { describe('and the call to the favorites api succeeds', () => { describe('and the current path is the lists one', () => { it('should dispatch an action signaling the success of the handled action and a push to the created list page', () => { - return expectSaga(favoritesSaga, getIdentity) + return expectSaga(favoritesSaga) .provide([ [select(getLocation), { pathname: locations.lists() }], - [call(getAccountIdentity), Promise.resolve()], + [call(getIdentityOrRedirect), Promise.resolve()], [ matchers.call.fn(FavoritesAPI.prototype.createList), Promise.resolve(returnedList) @@ -1314,10 +1312,10 @@ describe('when handling the request for creating a list', () => { describe('and the current path is not the lists one', () => { it('should dispatch an action signaling the success of the handled action without a push to the created list page', () => { - return expectSaga(favoritesSaga, getIdentity) + return expectSaga(favoritesSaga) .provide([ [select(getLocation), { pathname: locations.browse() }], - [call(getAccountIdentity), Promise.resolve()], + [call(getIdentityOrRedirect), Promise.resolve()], [ matchers.call.fn(FavoritesAPI.prototype.createList), Promise.resolve(returnedList) @@ -1351,7 +1349,7 @@ describe('when handling the request to start the picks and unpicks in bulk proce describe('and getting the address fails', () => { it('should dispatch an action signaling the failure of the handled action', () => { - return expectSaga(favoritesSaga, getIdentity) + return expectSaga(favoritesSaga) .provide([[select(getAddress), throwError(error)]]) .put(bulkPickUnpickCancel(item, error.message)) .dispatch(bulkPickUnpickStart(item)) @@ -1363,11 +1361,11 @@ describe('when handling the request to start the picks and unpicks in bulk proce describe('and the user is not connected', () => { describe('and the user succeeds to connect the wallet', () => { it('should close the login modal after the success', () => { - return expectSaga(favoritesSaga, getIdentity) + return expectSaga(favoritesSaga) .provide([ [select(getAddress), undefined], [take(CONNECT_WALLET_SUCCESS), {}], - [call(getAccountIdentity), Promise.resolve()] + [call(getIdentityOrRedirect), Promise.resolve()] ]) .put(openModal('LoginModal')) .put(closeModal('LoginModal')) @@ -1379,7 +1377,7 @@ describe('when handling the request to start the picks and unpicks in bulk proce describe('and the user closes the login modal', () => { it('should finish the saga', () => { - return expectSaga(favoritesSaga, getIdentity) + return expectSaga(favoritesSaga) .provide([ [select(getAddress), undefined], [take(CLOSE_MODAL), {}] @@ -1398,10 +1396,10 @@ describe('when handling the request to start the picks and unpicks in bulk proce describe('and getting the identity fails', () => { it('should dispatch an action signaling the failure of the handled action', () => { - return expectSaga(favoritesSaga, getIdentity) + return expectSaga(favoritesSaga) .provide([ [select(getAddress), address], - [call(getAccountIdentity), Promise.reject(error)] + [call(getIdentityOrRedirect), Promise.reject(error)] ]) .put(bulkPickUnpickCancel(item, error.message)) .dispatch(bulkPickUnpickStart(item)) @@ -1411,10 +1409,10 @@ describe('when handling the request to start the picks and unpicks in bulk proce describe('and the user picks or unpicks in bulk without trying to create a new list', () => { it('should end the saga without dispatching a bulk request', () => { - return expectSaga(favoritesSaga, getIdentity) + return expectSaga(favoritesSaga) .provide([ [select(getAddress), address], - [call(getAccountIdentity), Promise.resolve()], + [call(getIdentityOrRedirect), Promise.resolve()], [take(BULK_PICK_SUCCESS), { payload: { list: newList } }] ]) .put(openModal('SaveToListModal', { item })) @@ -1428,10 +1426,10 @@ describe('when handling the request to start the picks and unpicks in bulk proce describe('and the user tries to create a new list', () => { describe('and the creation of the list succeeds', () => { it('should dispatch an action signaling the pick item in bulk request for the created list', () => { - return expectSaga(favoritesSaga, getIdentity) + return expectSaga(favoritesSaga) .provide([ [select(getAddress), address], - [call(getAccountIdentity), Promise.resolve()], + [call(getIdentityOrRedirect), Promise.resolve()], [take(CREATE_LIST_SUCCESS), { payload: { list: newList } }], [select(getList, newList.id), newList], [put(bulkPickUnpickRequest(item, [newList], [])), undefined] @@ -1446,10 +1444,10 @@ describe('when handling the request to start the picks and unpicks in bulk proce describe('and the user closes the creation list modal', () => { it('should dispatch an action signaling the cancel of the pick item in bulk process', () => { - return expectSaga(favoritesSaga, getIdentity) + return expectSaga(favoritesSaga) .provide([ [select(getAddress), address], - [call(getAccountIdentity), Promise.resolve()], + [call(getIdentityOrRedirect), Promise.resolve()], [take(CLOSE_MODAL), {}], [put(bulkPickUnpickRequest(item, [newList], [])), undefined] ]) @@ -1485,8 +1483,8 @@ describe('when handling the request to perform picks and unpicks in bulk', () => describe('and getting the identity fails', () => { it('should dispatch an action signaling the failure of the handled action', () => { - return expectSaga(favoritesSaga, getIdentity) - .provide([[call(getAccountIdentity), Promise.reject(error)]]) + return expectSaga(favoritesSaga) + .provide([[call(getIdentityOrRedirect), Promise.reject(error)]]) .put(bulkPickUnpickFailure(item, [fstList], [sndList], error.message)) .dispatch(bulkPickUnpickRequest(item, [fstList], [sndList])) .run({ silenceTimeout: true }) @@ -1495,9 +1493,9 @@ describe('when handling the request to perform picks and unpicks in bulk', () => describe('and the call to the favorites api fails', () => { it('should dispatch an action signaling the failure of the handled action', () => { - return expectSaga(favoritesSaga, getIdentity) + return expectSaga(favoritesSaga) .provide([ - [call(getAccountIdentity), Promise.resolve()], + [call(getIdentityOrRedirect), Promise.resolve()], [ matchers.call.fn(FavoritesAPI.prototype.bulkPickUnpick), Promise.reject(error) @@ -1515,9 +1513,9 @@ describe('when handling the request to perform picks and unpicks in bulk', () => describe('and call to the favorites api succeeds', () => { it('should dispatch an action signaling the success of the handled action', () => { - return expectSaga(favoritesSaga, getIdentity) + return expectSaga(favoritesSaga) .provide([ - [call(getAccountIdentity), Promise.resolve()], + [call(getIdentityOrRedirect), Promise.resolve()], [select(isOwnerUnpickingFromCurrentList, [sndList]), true], [ matchers.call.fn(FavoritesAPI.prototype.bulkPickUnpick), @@ -1557,7 +1555,7 @@ describe('when handling the success of the bulk pick and unpick process', () => }) it('should dispatch a pick success action and an unpick success action for each picked or unpicked lists', () => { - return expectSaga(favoritesSaga, getIdentity) + return expectSaga(favoritesSaga) .put(pickItemSuccess(item, fstList.id)) .put(unpickItemSuccess(item, sndList.id)) .dispatch(bulkPickUnpickSuccess(item, [fstList], [sndList], true, true)) @@ -1589,7 +1587,7 @@ describe('when handling the failure of the bulk pick and unpick process', () => }) it('should dispatch a pick failure action and an unpick success action for each picked or unpicked lists', () => { - return expectSaga(favoritesSaga, getIdentity) + return expectSaga(favoritesSaga) .put(pickItemFailure(item, fstList.id, error)) .put(unpickItemFailure(item, sndList.id, error)) .dispatch(bulkPickUnpickFailure(item, [fstList], [sndList], error)) diff --git a/webapp/src/modules/item/sagas.spec.ts b/webapp/src/modules/item/sagas.spec.ts index b47ffa1db8..5eb043cc51 100644 --- a/webapp/src/modules/item/sagas.spec.ts +++ b/webapp/src/modules/item/sagas.spec.ts @@ -102,12 +102,10 @@ const nftPurchase: NFTPurchase = { } } -const getIdentity = () => undefined - describe('when handling the buy items request action', () => { describe("when there's no wallet loaded in the state", () => { it('should dispatch an action signaling the failure of the action handling', () => { - return expectSaga(itemSaga, getIdentity) + return expectSaga(itemSaga) .provide([[select(getWallet), null]]) .put(buyItemFailure('A defined wallet is required to buy an item')) .dispatch(buyItemRequest(item)) @@ -117,7 +115,7 @@ describe('when handling the buy items request action', () => { describe('when sending the meta transaction fails', () => { it('should dispatch an action signaling the failure of the action handling', () => { - return expectSaga(itemSaga, getIdentity) + return expectSaga(itemSaga) .provide([ [select(getWallet), wallet], [matchers.call.fn(sendTransaction), Promise.reject(anError)] @@ -130,7 +128,7 @@ describe('when handling the buy items request action', () => { describe('when the meta transaction is sent succesfully', () => { it('should send a meta transaction to the collection store contract living in the chain provided by the item and dispatch the success action', () => { - return expectSaga(itemSaga, getIdentity) + return expectSaga(itemSaga) .provide([ [select(getWallet), wallet], [matchers.call.fn(sendTransaction), Promise.resolve(txHash)] @@ -153,7 +151,7 @@ describe('when handling the buy items with card action', () => { describe('when the explanation modal has already been shown', () => { it('should open Transak widget', () => { - return expectSaga(itemSaga, getIdentity) + return expectSaga(itemSaga) .provide([ [ call( @@ -175,7 +173,7 @@ describe('when handling the buy items with card action', () => { describe('when the explanation modal is shown and the user closes it', () => { it('should not set the item in the local storage to show the modal again later', () => { - return expectSaga(itemSaga, getIdentity) + return expectSaga(itemSaga) .provide([ [ call( @@ -197,7 +195,7 @@ describe('when handling the buy items with card action', () => { describe('when opening Transak Widget fails', () => { it('should dispatch an action signaling the failure of the action handling', () => { - return expectSaga(itemSaga, getIdentity) + return expectSaga(itemSaga) .provide([[call(buyAssetWithCard, item), Promise.reject(anError)]]) .put(buyItemWithCardFailure(anError.message)) .dispatch(buyItemWithCardRequest(item)) @@ -207,7 +205,7 @@ describe('when handling the buy items with card action', () => { describe('when Transak widget is opened succesfully', () => { it('should dispatch the success action', () => { - return expectSaga(itemSaga, getIdentity) + return expectSaga(itemSaga) .provide([[call(buyAssetWithCard, item), Promise.resolve()]]) .dispatch(buyItemWithCardRequest(item)) .run({ silenceTimeout: true }) @@ -221,7 +219,7 @@ describe('when handling the buy items with card action', () => { describe('when handling the set purchase action', () => { describe('when it is a MANA purchase', () => { it('should not put any new action', () => { - return expectSaga(itemSaga, getIdentity) + return expectSaga(itemSaga) .dispatch(setPurchase(manaPurchase)) .run({ silenceTimeout: true }) .then(({ effects }) => { @@ -233,7 +231,7 @@ describe('when handling the set purchase action', () => { describe('when it is an NFT purchase', () => { describe('when it is a secondary market purchase', () => { it('should not put any new action', () => { - return expectSaga(itemSaga, getIdentity) + return expectSaga(itemSaga) .dispatch( setPurchase({ ...nftPurchase, @@ -254,7 +252,7 @@ describe('when handling the set purchase action', () => { describe('when the purchase is incomplete', () => { it('should not put any new action', () => { - return expectSaga(itemSaga, getIdentity) + return expectSaga(itemSaga) .dispatch(setPurchase(nftPurchase)) .run({ silenceTimeout: true }) .then(({ effects }) => { @@ -265,7 +263,7 @@ describe('when handling the set purchase action', () => { describe('when it is complete without a txHash', () => { it('should not put any new action', () => { - return expectSaga(itemSaga, getIdentity) + return expectSaga(itemSaga) .dispatch( setPurchase({ ...nftPurchase, @@ -285,7 +283,7 @@ describe('when handling the set purchase action', () => { describe('when the item does not yet exist in the store', () => { it('should put the action signaling the fetch item request', () => { - return expectSaga(itemSaga, getIdentity) + return expectSaga(itemSaga) .provide([ [select(getItems), {}], [ @@ -311,7 +309,7 @@ describe('when handling the set purchase action', () => { describe('when the action of fetching the item has been dispatched', () => { describe('when the fetch item request fails', () => { it('should put an action signaling the failure of the buy item with card request', () => { - return expectSaga(itemSaga, getIdentity) + return expectSaga(itemSaga) .provide([ [select(getItems), {}], [ @@ -341,7 +339,7 @@ describe('when handling the set purchase action', () => { const items = { anItemId: item } it('should put an action signaling the success of the buy item with card request', () => { - return expectSaga(itemSaga, getIdentity) + return expectSaga(itemSaga) .provide([ [select(getItems), items], [call(getItem, contractAddress, itemId!, items), item] @@ -371,7 +369,7 @@ describe('when handling the fetch collections items request action', () => { const fetchResult = { data: [item] } it('should dispatch a successful action with the fetched items', () => { - return expectSaga(itemSaga, getIdentity) + return expectSaga(itemSaga) .provide([[matchers.call.fn(ItemAPI.prototype.get), fetchResult]]) .call.like({ fn: ItemAPI.prototype.get, @@ -387,7 +385,7 @@ describe('when handling the fetch collections items request action', () => { describe('when the request fails', () => { it('should dispatch a failing action with the error and the options', () => { - return expectSaga(itemSaga, getIdentity) + return expectSaga(itemSaga) .provide([ [matchers.call.fn(ItemAPI.prototype.get), Promise.reject(anError)] ]) @@ -434,7 +432,7 @@ describe('when handling the fetch items request action', () => { }) it('should dispatch a successful action with the fetched items and cancel the ongoing one', () => { - return expectSaga(itemSaga, getIdentity) + return expectSaga(itemSaga) .provide([ [ matchers.call.fn( @@ -493,7 +491,7 @@ describe('when handling the fetch items request action', () => { describe('and there is no wallet connected', () => { it('should dispatch a successful action with the fetched items and cancel the ongoing one', () => { - return expectSaga(itemSaga, getIdentity) + return expectSaga(itemSaga) .provide([ [ matchers.call.fn( @@ -557,7 +555,7 @@ describe('when handling the fetch items request action', () => { pathname = locations.root() }) it('should dispatch a successful action with the fetched items', () => { - return expectSaga(itemSaga, getIdentity) + return expectSaga(itemSaga) .provide([ [matchers.call.fn(CatalogAPI.prototype.get), fetchResult], [ @@ -585,7 +583,7 @@ describe('when handling the fetch items request action', () => { describe('when the request fails', () => { it('should dispatch a failing action with the error and the options', () => { - return expectSaga(itemSaga, getIdentity) + return expectSaga(itemSaga) .provide([ [select(getLocation), { pathname: '' }], [select(getWallet), undefined], @@ -607,7 +605,7 @@ describe('when handling the fetch items request action', () => { describe('when handling the fetch item request action', () => { describe('when the request is successful', () => { it('should dispatch a successful action with the fetched items', () => { - return expectSaga(itemSaga, getIdentity) + return expectSaga(itemSaga) .provide([ [matchers.call.fn(ItemAPI.prototype.getOne), item], [ @@ -624,7 +622,7 @@ describe('when handling the fetch items request action', () => { describe('when the request fails', () => { it('should dispatching a failing action with the contract address, the token id and the error message', () => { - return expectSaga(itemSaga, getIdentity) + return expectSaga(itemSaga) .provide([ [ matchers.call.fn(ItemAPI.prototype.getOne), @@ -663,7 +661,7 @@ describe('when handling the fetch trending items request action', () => { }) it('should dispatch a successful action with the fetched trending items', () => { - return expectSaga(itemSaga, getIdentity) + return expectSaga(itemSaga) .provide([ [select(getIsMarketplaceServerEnabled), true], [matchers.call.fn(ItemAPI.prototype.getTrendings), fetchResult], @@ -683,7 +681,7 @@ describe('when handling the fetch trending items request action', () => { const fetchResult = { data: [], total: 0 } it('should dispatch a successful action with the fetched trending items', () => { - return expectSaga(itemSaga, getIdentity) + return expectSaga(itemSaga) .provide([ // [select(getIsMarketplaceServerEnabled), true], [matchers.call.fn(ItemAPI.prototype.getTrendings), fetchResult], @@ -701,7 +699,7 @@ describe('when handling the fetch trending items request action', () => { describe('when the request fails', () => { it('should dispatch a failing action with the error and the options', () => { - return expectSaga(itemSaga, getIdentity) + return expectSaga(itemSaga) .provide([ [ matchers.call.fn(ItemAPI.prototype.getTrendings), diff --git a/webapp/src/modules/nft/sagas.spec.ts b/webapp/src/modules/nft/sagas.spec.ts index f525c20ca9..6681bf66a9 100644 --- a/webapp/src/modules/nft/sagas.spec.ts +++ b/webapp/src/modules/nft/sagas.spec.ts @@ -71,7 +71,7 @@ describe('when handling the fetch NFTs request action', () => { } const error = 'someError' - return expectSaga(nftSaga, getIdentity) + return expectSaga(nftSaga) .provide([ [select(getContracts), []], [ @@ -96,7 +96,7 @@ describe('when handling the fetch NFTs request action', () => { const vendor = VendorFactory.build(options.vendor, API_OPTS) const error = { message: 'someError' } - return expectSaga(nftSaga, getIdentity) + return expectSaga(nftSaga) .provide([ [select(getContracts), []], [call(VendorFactory.build, options.vendor, API_OPTS), vendor], @@ -129,7 +129,7 @@ describe('when handling the fetch NFTs request action', () => { const rentals = [{ id: 'aRentalId' }] as RentalListing[] const count = 1 - return expectSaga(nftSaga, getIdentity) + return expectSaga(nftSaga) .provide([ [call(VendorFactory.build, options.vendor, API_OPTS), vendor], [ @@ -170,7 +170,7 @@ describe('when handling the fetch NFT request action', () => { const order = { id: 'id' } as Order const rental = { id: 'id' } as RentalListing - return expectSaga(nftSaga, getIdentity) + return expectSaga(nftSaga) .provide([ [select(getLoading), []], [select(getContracts), []], @@ -207,7 +207,7 @@ describe('when handling the fetch NFT request action', () => { const tokenId = 'aTokenId' const error = `Couldn't find a valid vendor for contract ${contractAddress}` - return expectSaga(nftSaga, getIdentity) + return expectSaga(nftSaga) .provide([ [select(getLoading), []], [select(getContracts), []], @@ -232,7 +232,7 @@ describe('when handling the fetch NFT request action', () => { const tokenId = 'aTokenId' const error = `Couldn't find a valid vendor for contract ${contractAddress}` - return expectSaga(nftSaga, getIdentity) + return expectSaga(nftSaga) .provide([ [select(getLoading), []], [select(getContracts), []], @@ -262,7 +262,7 @@ describe('when handling the fetch NFT request action', () => { const vendor = VendorFactory.build(VendorName.DECENTRALAND, API_OPTS) const error = { message: 'someError' } - return expectSaga(nftSaga, getIdentity) + return expectSaga(nftSaga) .provide([ [select(getLoading), []], [select(getContracts), []], @@ -300,7 +300,7 @@ describe('when handling the fetch NFT request action', () => { const order = { id: 'anId' } as Order const rental = { id: 'aRentalId' } as RentalListing - return expectSaga(nftSaga, getIdentity) + return expectSaga(nftSaga) .provide([ [select(getLoading), []], [select(getContracts), []], @@ -337,7 +337,7 @@ describe('when handling the transfer NFT request action', () => { const address = 'anAddress' const error = 'someError' - return expectSaga(nftSaga, getIdentity) + return expectSaga(nftSaga) .provide([ [call(VendorFactory.build, nft.vendor), throwError(new Error(error))] ]) @@ -355,7 +355,7 @@ describe('when handling the transfer NFT request action', () => { const address = 'anAddress' const error = 'A wallet is needed to perform a NFT transfer request' - return expectSaga(nftSaga, getIdentity) + return expectSaga(nftSaga) .provide([ [ call(VendorFactory.build, nft.vendor), @@ -379,7 +379,7 @@ describe('when handling the transfer NFT request action', () => { const vendor = VendorFactory.build(nft.vendor) const error = { message: 'anError' } - return expectSaga(nftSaga, getIdentity) + return expectSaga(nftSaga) .provide([ [call(VendorFactory.build, nft.vendor), vendor], [select(getWallet), wallet], @@ -421,7 +421,7 @@ describe('when handling the transfer NFT request action', () => { } as RentalListing }) it('should dispatch an action signaling the success of the action handling and cancel an existing rental listing', () => { - return expectSaga(nftSaga, getIdentity) + return expectSaga(nftSaga) .provide([ [call(VendorFactory.build, nft.vendor), vendor], [select(getWallet), wallet], @@ -448,7 +448,7 @@ describe('when handling the transfer NFT request action', () => { nft.openRentalId = null }) it('should dispatch an action signaling the success of the action handling', () => { - return expectSaga(nftSaga, getIdentity) + return expectSaga(nftSaga) .provide([ [call(VendorFactory.build, nft.vendor), vendor], [select(getWallet), wallet], @@ -467,7 +467,7 @@ describe('when handling the transfer NFT request action', () => { }) describe('and the transaction gets reverted', () => { it('should put the action to notify that the transaction was submitted and the claim LAND failure action with an error', () => { - return expectSaga(nftSaga, getIdentity) + return expectSaga(nftSaga) .provide([ [call(VendorFactory.build, nft.vendor), vendor], [select(getWallet), wallet], diff --git a/webapp/src/modules/nft/sagas.ts b/webapp/src/modules/nft/sagas.ts index 661ed081ca..c13bb52f9e 100644 --- a/webapp/src/modules/nft/sagas.ts +++ b/webapp/src/modules/nft/sagas.ts @@ -2,7 +2,6 @@ import { takeEvery, call, put, select } from 'redux-saga/effects' import { RentalListing, RentalStatus } from '@dcl/schemas' import { ErrorCode } from 'decentraland-transactions' import { waitForTx } from 'decentraland-dapps/dist/modules/transaction/utils' -import { AuthIdentity } from 'decentraland-crypto-fetch' import { t } from 'decentraland-dapps/dist/modules/translation/utils' import { isErrorWithMessage } from '../../lib/error' import { getWallet } from '../wallet/selectors' diff --git a/webapp/src/modules/rental/sagas.spec.ts b/webapp/src/modules/rental/sagas.spec.ts index 49f660daac..e32426204f 100644 --- a/webapp/src/modules/rental/sagas.spec.ts +++ b/webapp/src/modules/rental/sagas.spec.ts @@ -12,6 +12,7 @@ import { getConnectedProvider } from 'decentraland-dapps/dist/lib/eth' import { waitForTx } from 'decentraland-dapps/dist/modules/transaction/utils' import { sendTransaction } from 'decentraland-dapps/dist/modules/wallet/utils' import { closeModal } from 'decentraland-dapps/dist/modules/modal/actions' +import { getIdentityOrRedirect } from 'decentraland-dapps/dist/modules/identity/sagas' import { ContractData, ContractName, @@ -21,7 +22,6 @@ import { ethers } from 'ethers' import { expectSaga } from 'redux-saga-test-plan' import { throwError } from 'redux-saga-test-plan/providers' import { delay, take } from 'redux-saga/effects' -import { getCurrentIdentity } from '../identity/selectors' import { FETCH_NFT_SUCCESS } from '../nft/actions' import { getCurrentNFT } from '../nft/selectors' import { NFT } from '../nft/types' @@ -190,7 +190,7 @@ describe('when handling the request action to upsert a rental listing', () => { ), signature ], - [select(getCurrentIdentity), identity], + [call(getIdentityOrRedirect), identity], [ call( [rentalsAPI, 'createRentalListing'], @@ -264,7 +264,7 @@ describe('when handling the request action to upsert a rental listing', () => { ), signature ], - [select(getCurrentIdentity), identity], + [call(getIdentityOrRedirect), identity], [ call( [rentalsAPI, 'createRentalListing'], @@ -438,7 +438,7 @@ describe('when handling the request action to upsert a rental listing', () => { ), signatureWithWrongV ], - [select(getCurrentIdentity), identity], + [call(getIdentityOrRedirect), identity], [ call( [rentalsAPI, 'createRentalListing'], diff --git a/webapp/src/modules/rental/sagas.ts b/webapp/src/modules/rental/sagas.ts index 8bee5e6325..109aa4b596 100644 --- a/webapp/src/modules/rental/sagas.ts +++ b/webapp/src/modules/rental/sagas.ts @@ -13,10 +13,10 @@ import { getContract, Provider } from 'decentraland-transactions' -import { getIdentity } from '@dcl/single-sign-on-client' import { getConnectedProvider } from 'decentraland-dapps/dist/lib/eth' import { waitForTx } from 'decentraland-dapps/dist/modules/transaction/utils' import { sendTransaction } from 'decentraland-dapps/dist/modules/wallet/utils' +import { getIdentityOrRedirect } from 'decentraland-dapps/dist/modules/identity/sagas' import { CloseModalAction, CLOSE_MODAL @@ -124,16 +124,17 @@ function* handleCreateOrEditRentalRequest(action: UpsertRentalRequestAction) { target: ethers.constants.AddressZero // For now, all rent listing will be "public", for all addresses to use. } - console.log('check redirect2') - const identity: AuthIdentity = yield getIdentity(address) + const identity: AuthIdentity | null = yield call(getIdentityOrRedirect) - const rental: RentalListing = yield call( - [rentalsAPI, 'createRentalListing'], - rentalListingCreation, - identity - ) + if (identity) { + const rental: RentalListing = yield call( + [rentalsAPI, 'createRentalListing'], + rentalListingCreation, + identity + ) - yield put(upsertRentalSuccess(nft, rental, operationType)) + yield put(upsertRentalSuccess(nft, rental, operationType)) + } } catch (error) { yield put( upsertRentalFailure( diff --git a/webapp/src/modules/sagas.ts b/webapp/src/modules/sagas.ts index 6bbf1316a1..15b324fc74 100644 --- a/webapp/src/modules/sagas.ts +++ b/webapp/src/modules/sagas.ts @@ -42,7 +42,8 @@ import { loginSaga } from './login/sagas' import { ensSaga } from './ens/sagas' const analyticsSaga = createAnalyticsSaga() -const profileSaga = () => createProfileSaga({ peerUrl }) +const profileSaga = () => + createProfileSaga({ peerUrl, getIdentity: () => undefined }) // TODO, update profile Saga to read from LS const lambdasClient = createLambdasClient({ url: `${peerUrl}/lambdas`, fetcher: createFetchComponent() diff --git a/webapp/src/modules/store/sagas.spec.ts b/webapp/src/modules/store/sagas.spec.ts index 1d4af1a823..a0931e1243 100644 --- a/webapp/src/modules/store/sagas.spec.ts +++ b/webapp/src/modules/store/sagas.spec.ts @@ -5,6 +5,7 @@ import { ContentClient } from 'dcl-catalyst-client/dist/client/ContentClient' import { createFetchComponent } from '@well-known-components/fetch-component' +import { getIdentityOrRedirect } from 'decentraland-dapps/dist/modules/identity/sagas' import { expectSaga } from 'redux-saga-test-plan' import { call, select } from 'redux-saga/effects' import { getAddress } from '../wallet/selectors' @@ -120,7 +121,7 @@ describe('when handling the update of a store', () => { const identity = {} as AuthIdentity return expectSaga(storeSaga, mockClient) .provide([ - [call(getIdentity), identity], + [call(getIdentityOrRedirect), identity], [select(getAddress), mockAddress], [call(deployStoreEntity, mockClient, identity, mockStore), {}] ]) From 114d9f781ecbb42bfea79b98b11297892d8e3404 Mon Sep 17 00:00:00 2001 From: Juanma Hidalgo Date: Tue, 23 Jan 2024 18:19:46 +0100 Subject: [PATCH 3/8] chore: remove old code --- webapp/package.json | 2 +- webapp/src/modules/favorites/sagas.ts | 8 +------- webapp/src/modules/store/sagas.ts | 1 - webapp/src/utils/tests.tsx | 1 - 4 files changed, 2 insertions(+), 10 deletions(-) diff --git a/webapp/package.json b/webapp/package.json index 98280575da..2774c97c45 100644 --- a/webapp/package.json +++ b/webapp/package.json @@ -124,4 +124,4 @@ "@walletconnect/core": "2.9.2", "@walletconnect/keyvaluestorage": "1.0.0" } -} \ No newline at end of file +} diff --git a/webapp/src/modules/favorites/sagas.ts b/webapp/src/modules/favorites/sagas.ts index fefe6f90c8..b58c22cca4 100644 --- a/webapp/src/modules/favorites/sagas.ts +++ b/webapp/src/modules/favorites/sagas.ts @@ -6,6 +6,7 @@ import { CONNECT_WALLET_FAILURE, CONNECT_WALLET_SUCCESS } from 'decentraland-dapps/dist/modules/wallet/actions' +import { getIdentityOrRedirect } from 'decentraland-dapps/dist/modules/identity/sagas' import { isErrorWithMessage } from '../../lib/error' import { ItemBrowseOptions } from '../item/types' import { @@ -82,7 +83,6 @@ import { convertListsBrowseSortByIntoApiSortBy } from './utils' import { List } from './types' import { getData as getItemsData } from '../item/selectors' import { getIsMarketplaceServerEnabled } from '../features/selectors' -import { getIdentityOrRedirect } from 'decentraland-dapps/dist/modules/identity/sagas' export function* favoritesSaga() { const API_OPTS = { @@ -153,7 +153,6 @@ export function* favoritesSaga() { try { const address: ReturnType = yield select(getAddress) // Force the user to have the signed identity - console.log('check redirect3') if (address) yield call(getIdentityOrRedirect) let items: Item[] = [] @@ -216,7 +215,6 @@ export function* favoritesSaga() { try { // Force the user to have the signed identity - console.log('check redirect4') yield call(getIdentityOrRedirect) let sortBy: ListsSortBy | undefined let sortDirection: SortDirection | undefined @@ -282,7 +280,6 @@ export function* favoritesSaga() { try { // Force the user to have the signed identity - console.log('check redirect4') yield call(getIdentityOrRedirect) yield call([favoritesAPI, 'deleteList'], list.id) yield put(deleteListSuccess(list)) @@ -343,7 +340,6 @@ export function* favoritesSaga() { try { const { pathname } = yield select(getLocation) // Force the user to have the signed identity - console.log('check redirect4') yield call(getIdentityOrRedirect) const list: Awaited Date: Wed, 24 Jan 2024 12:00:04 +0100 Subject: [PATCH 4/8] feat: bump dapps --- webapp/package-lock.json | 10 ++++++++++ webapp/package.json | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/webapp/package-lock.json b/webapp/package-lock.json index 0920e3ed6a..f48387e527 100644 --- a/webapp/package-lock.json +++ b/webapp/package-lock.json @@ -336,6 +336,16 @@ "node": ">=0.10.0" } }, + "node_modules/@aashutoshrathi/word-wrap": { + "version": "1.2.6", + "resolved": "https://registry.npmjs.org/@aashutoshrathi/word-wrap/-/word-wrap-1.2.6.tgz", + "integrity": "sha512-1Yjs2SvM8TflER/OD3cOjhWWOZb58A2t7wpE2S9XfBYTiIl+XFhQG2bjy4Pu1I+EAlCNUzRDYDdFwFYUKvXcIA==", + "dev": true, + "peer": true, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/@adobe/css-tools": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/@adobe/css-tools/-/css-tools-4.1.0.tgz", diff --git a/webapp/package.json b/webapp/package.json index 2774c97c45..98280575da 100644 --- a/webapp/package.json +++ b/webapp/package.json @@ -124,4 +124,4 @@ "@walletconnect/core": "2.9.2", "@walletconnect/keyvaluestorage": "1.0.0" } -} +} \ No newline at end of file From e72a6ea92e9e58dafa90b9a2d0a7a28d0982524a Mon Sep 17 00:00:00 2001 From: Juanma Hidalgo Date: Wed, 24 Jan 2024 13:28:50 +0100 Subject: [PATCH 5/8] feat: put back the getIdentity fn to stores --- webapp/src/modules/favorites/sagas.spec.ts | 98 +++++++++++----------- webapp/src/modules/favorites/sagas.ts | 6 +- webapp/src/modules/item/sagas.spec.ts | 52 ++++++------ webapp/src/modules/item/sagas.ts | 6 +- webapp/src/modules/nft/sagas.spec.ts | 30 +++---- webapp/src/modules/nft/sagas.ts | 6 +- webapp/src/modules/sagas.ts | 14 ++-- webapp/src/modules/store.ts | 18 +++- webapp/src/utils/tests.tsx | 2 +- 9 files changed, 128 insertions(+), 104 deletions(-) diff --git a/webapp/src/modules/favorites/sagas.spec.ts b/webapp/src/modules/favorites/sagas.spec.ts index 0cf78e6fc1..061269d586 100644 --- a/webapp/src/modules/favorites/sagas.spec.ts +++ b/webapp/src/modules/favorites/sagas.spec.ts @@ -80,6 +80,8 @@ let item: Item let address: string let error: Error +const getIdentity = () => undefined + beforeEach(() => { error = new Error('error') item = { id: 'anAddress-itemId', itemId: 'itemId' } as Item @@ -100,7 +102,7 @@ describe('when handling the request for fetching favorited items', () => { describe('and getting the address fails', () => { it('should dispatch an action signaling the failure of the handled action', () => { - return expectSaga(favoritesSaga) + return expectSaga(favoritesSaga, getIdentity) .provide([ [select(getListId), listId], [select(getAddress), Promise.reject(error)], @@ -114,7 +116,7 @@ describe('when handling the request for fetching favorited items', () => { describe('and getting the identity fails', () => { it('should dispatch an action signaling the failure of the handled action', () => { - return expectSaga(favoritesSaga) + return expectSaga(favoritesSaga, getIdentity) .provide([ [select(getListId), listId], [select(getAddress), address], @@ -130,7 +132,7 @@ describe('when handling the request for fetching favorited items', () => { describe('and the user is logged in', () => { describe('and the call to the favorites api fails', () => { it('should dispatch an action signaling the failure of the handled action', () => { - return expectSaga(favoritesSaga) + return expectSaga(favoritesSaga, getIdentity) .provide([ [select(getListId), listId], [select(getAddress), address], @@ -170,7 +172,7 @@ describe('when handling the request for fetching favorited items', () => { }) describe('and the call to the items api fails', () => { it('should dispatch an action signaling the failure of the handled action', () => { - return expectSaga(favoritesSaga) + return expectSaga(favoritesSaga, getIdentity) .provide([ [select(getListId), listId], [select(getIsMarketplaceServerEnabled), isMarketplaceFFOn], @@ -208,7 +210,7 @@ describe('when handling the request for fetching favorited items', () => { }) describe('and the call to the items api fails', () => { it('should dispatch an action signaling the failure of the handled action', () => { - return expectSaga(favoritesSaga) + return expectSaga(favoritesSaga, getIdentity) .provide([ [select(getListId), listId], [select(getIsMarketplaceServerEnabled), isMarketplaceFFOn], @@ -249,7 +251,7 @@ describe('when handling the request for fetching favorited items', () => { }) it('should dispatch an action signaling the success of the handled action and the request of the retrieved items', () => { - return expectSaga(favoritesSaga) + return expectSaga(favoritesSaga, getIdentity) .provide([ [select(getListId), listId], [select(getAddress), address], @@ -304,7 +306,7 @@ describe('when handling the request for fetching favorited items', () => { }) it('should dispatch an action signaling the success of the handled action', () => { - return expectSaga(favoritesSaga) + return expectSaga(favoritesSaga, getIdentity) .provide([ [select(getListId), listId], [select(getAddress), address], @@ -345,7 +347,7 @@ describe('when handling the request for fetching favorited items', () => { describe('and the user is not logged in', () => { describe('and the call to the favorites api fails', () => { it('should dispatch an action signaling the failure of the handled action', () => { - return expectSaga(favoritesSaga) + return expectSaga(favoritesSaga, getIdentity) .provide([ [select(getListId), listId], [select(getAddress), null], @@ -379,7 +381,7 @@ describe('when handling the request for fetching favorited items', () => { describe('and the call to the items api fails', () => { it('should dispatch an action signaling the failure of the handled action', () => { - return expectSaga(favoritesSaga) + return expectSaga(favoritesSaga, getIdentity) .provide([ [select(getListId), listId], [select(getAddress), null], @@ -418,7 +420,7 @@ describe('when handling the request for fetching favorited items', () => { }) it('should dispatch an action signaling the success of the handled action and the request of the retrieved items', () => { - return expectSaga(favoritesSaga) + return expectSaga(favoritesSaga, getIdentity) .provide([ [select(getListId), listId], [select(getAddress), null], @@ -472,7 +474,7 @@ describe('when handling the request for fetching favorited items', () => { }) it('should dispatch an action signaling the success of the handled action', () => { - return expectSaga(favoritesSaga) + return expectSaga(favoritesSaga, getIdentity) .provide([ [select(getListId), listId], [select(getAddress), null], @@ -522,7 +524,7 @@ describe('when handling the request for fetching lists', () => { describe('and getting the identity fails', () => { it('should dispatch an action signaling the failure of the handled action', () => { - return expectSaga(favoritesSaga) + return expectSaga(favoritesSaga, getIdentity) .provide([[call(getIdentityOrRedirect), Promise.reject(error)]]) .put(fetchListsFailure(error.message)) .dispatch(fetchListsRequest(options)) @@ -532,7 +534,7 @@ describe('when handling the request for fetching lists', () => { describe('and the call to the favorites api fails', () => { it('should dispatch an action signaling the failure of the handled action', () => { - return expectSaga(favoritesSaga) + return expectSaga(favoritesSaga, getIdentity) .provide([ [call(getIdentityOrRedirect), Promise.resolve()], [ @@ -572,7 +574,7 @@ describe('when handling the request for fetching lists', () => { }) it('should convert the sort by options and call the api with the sortBy and sortDirection options', () => { - return expectSaga(favoritesSaga) + return expectSaga(favoritesSaga, getIdentity) .provide([ [call(getIdentityOrRedirect), Promise.resolve()], [ @@ -609,7 +611,7 @@ describe('when handling the request for fetching lists', () => { }) it('should call the api with the skip option', () => { - return expectSaga(favoritesSaga) + return expectSaga(favoritesSaga, getIdentity) .provide([ [call(getIdentityOrRedirect), Promise.resolve()], [ @@ -670,7 +672,7 @@ describe('when handling the request for fetching lists', () => { describe('and there are no items in the state', () => { it('should dispatch an action signaling the success of the handled action', () => { - return expectSaga(favoritesSaga) + return expectSaga(favoritesSaga, getIdentity) .provide([ [call(getIdentityOrRedirect), Promise.resolve()], [select(getIsMarketplaceServerEnabled), true], @@ -715,7 +717,7 @@ describe('when handling the request for fetching lists', () => { describe('and there are already some items in the sate', () => { it('should dispatch an action signaling the success of the handled action', () => { - return expectSaga(favoritesSaga) + return expectSaga(favoritesSaga, getIdentity) .provide([ [call(getIdentityOrRedirect), Promise.resolve()], [select(getIsMarketplaceServerEnabled), true], @@ -757,7 +759,7 @@ describe('when handling the request for fetching lists', () => { describe('and there are already all the items in the state', () => { it('should dispatch an action signaling the success of the handled action without fetching the catalog items', () => { - return expectSaga(favoritesSaga) + return expectSaga(favoritesSaga, getIdentity) .provide([ [call(getIdentityOrRedirect), Promise.resolve()], [ @@ -813,7 +815,7 @@ describe('when handling the request for fetching lists', () => { }) it('should dispatch an action signaling the success of the handled action', () => { - return expectSaga(favoritesSaga) + return expectSaga(favoritesSaga, getIdentity) .provide([ [call(getIdentityOrRedirect), Promise.resolve()], [select(getIsMarketplaceServerEnabled), true], @@ -861,7 +863,7 @@ describe('when handling the request for fetching lists', () => { describe('and the call to the catalog api fails', () => { it('should dispatch an action signaling the failure of the handled action', () => { - return expectSaga(favoritesSaga) + return expectSaga(favoritesSaga, getIdentity) .provide([ [call(getIdentityOrRedirect), Promise.resolve()], [select(getIsMarketplaceServerEnabled), true], @@ -922,7 +924,7 @@ describe('when handling the start for deleting a list', () => { }) it('should only dispatch an action to open the delete list confirmation modal', () => { - return expectSaga(favoritesSaga) + return expectSaga(favoritesSaga, getIdentity) .put(openModal('ConfirmDeleteListModal', { list })) .not.put(deleteListRequest(list)) .dispatch(deleteListStart(list)) @@ -936,7 +938,7 @@ describe('when handling the start for deleting a list', () => { }) it('should only dispatch an action to start the deletion of the list', () => { - return expectSaga(favoritesSaga) + return expectSaga(favoritesSaga, getIdentity) .provide([[deleteListRequest(list), undefined]]) .put(deleteListRequest(list)) .not.put(openModal('ConfirmDeleteListModal', { list })) @@ -961,7 +963,7 @@ describe('when handling the request for deleting a list', () => { describe('and getting the identity fails', () => { it('should dispatch an action signaling the failure of the handled action', () => { - return expectSaga(favoritesSaga) + return expectSaga(favoritesSaga, getIdentity) .provide([[call(getIdentityOrRedirect), Promise.reject(error)]]) .put(deleteListFailure(list, error.message)) .dispatch(deleteListRequest(list)) @@ -971,7 +973,7 @@ describe('when handling the request for deleting a list', () => { describe('and the call to the favorites api fails', () => { it('should dispatch an action signaling the failure of the handled action', () => { - return expectSaga(favoritesSaga) + return expectSaga(favoritesSaga, getIdentity) .provide([ [call(getIdentityOrRedirect), Promise.resolve()], [ @@ -991,7 +993,7 @@ describe('when handling the request for deleting a list', () => { describe('and the call to the favorites api succeeds', () => { it('should dispatch an action signaling the success of the handled action', () => { - return expectSaga(favoritesSaga) + return expectSaga(favoritesSaga, getIdentity) .provide([ [call(getIdentityOrRedirect), Promise.resolve()], [ @@ -1019,7 +1021,7 @@ describe('when handling the success deletion of a list', () => { describe('and the user performed the action from the list detail page', () => { it('should dispatch an action to redirect the user to the My Lists tab', () => { - return expectSaga(favoritesSaga) + return expectSaga(favoritesSaga, getIdentity) .provide([[select(getLocation), { pathname: locations.list(list.id) }]]) .put(push(locations.lists())) .dispatch(deleteListSuccess(list)) @@ -1029,7 +1031,7 @@ describe('when handling the success deletion of a list', () => { describe('and the user performed the action from the My Lists tab', () => { it('should not dispatch the action signaling the redirection', () => { - return expectSaga(favoritesSaga) + return expectSaga(favoritesSaga, getIdentity) .provide([[select(getLocation), { pathname: locations.lists() }]]) .not.put(push(locations.lists())) .dispatch(deleteListSuccess(list)) @@ -1058,7 +1060,7 @@ describe('when handling the request for getting a list', () => { describe('and the call to the favorites api fails', () => { it('should dispatch an action signaling the failure of the handled action', () => { - return expectSaga(favoritesSaga) + return expectSaga(favoritesSaga, getIdentity) .provide([ [ matchers.call.fn(FavoritesAPI.prototype.getList), @@ -1089,7 +1091,7 @@ describe('when handling the request for getting a list', () => { describe('and non of the preview items are already in the state', () => { it('should dispatch an action signaling the success of the handled action with the received list and items', () => { - return expectSaga(favoritesSaga) + return expectSaga(favoritesSaga, getIdentity) .provide([ [ matchers.call.fn(FavoritesAPI.prototype.getList), @@ -1134,7 +1136,7 @@ describe('when handling the request for getting a list', () => { }) it('should dispatch an action signaling the success of the handled action with the received list and the items that are not in the state', () => { - return expectSaga(favoritesSaga) + return expectSaga(favoritesSaga, getIdentity) .provide([ [ matchers.call.fn(FavoritesAPI.prototype.getList), @@ -1193,7 +1195,7 @@ describe('when handling the request for updating a list', () => { describe('and the call to the favorites api fails', () => { it('should dispatch an action signaling the failure of the handled action', () => { - return expectSaga(favoritesSaga) + return expectSaga(favoritesSaga, getIdentity) .provide([ [ matchers.call.fn(FavoritesAPI.prototype.updateList), @@ -1212,7 +1214,7 @@ describe('when handling the request for updating a list', () => { describe('and the call to the favorites api succeeds', () => { it('should dispatch an action signaling the success of the handled action', () => { - return expectSaga(favoritesSaga) + return expectSaga(favoritesSaga, getIdentity) .provide([ [ matchers.call.fn(FavoritesAPI.prototype.updateList), @@ -1255,7 +1257,7 @@ describe('when handling the request for creating a list', () => { describe('and getting the identity fails', () => { it('should dispatch an action signaling the failure of the handled action', () => { - return expectSaga(favoritesSaga) + return expectSaga(favoritesSaga, getIdentity) .provide([ [select(getLocation), { pathname: locations.lists() }], [call(getIdentityOrRedirect), Promise.reject(error)] @@ -1268,7 +1270,7 @@ describe('when handling the request for creating a list', () => { describe('and the call to the favorites api fails', () => { it('should dispatch an action signaling the failure of the handled action', () => { - return expectSaga(favoritesSaga) + return expectSaga(favoritesSaga, getIdentity) .provide([ [select(getLocation), { pathname: locations.lists() }], [call(getIdentityOrRedirect), Promise.resolve()], @@ -1290,7 +1292,7 @@ describe('when handling the request for creating a list', () => { describe('and the call to the favorites api succeeds', () => { describe('and the current path is the lists one', () => { it('should dispatch an action signaling the success of the handled action and a push to the created list page', () => { - return expectSaga(favoritesSaga) + return expectSaga(favoritesSaga, getIdentity) .provide([ [select(getLocation), { pathname: locations.lists() }], [call(getIdentityOrRedirect), Promise.resolve()], @@ -1312,7 +1314,7 @@ describe('when handling the request for creating a list', () => { describe('and the current path is not the lists one', () => { it('should dispatch an action signaling the success of the handled action without a push to the created list page', () => { - return expectSaga(favoritesSaga) + return expectSaga(favoritesSaga, getIdentity) .provide([ [select(getLocation), { pathname: locations.browse() }], [call(getIdentityOrRedirect), Promise.resolve()], @@ -1349,7 +1351,7 @@ describe('when handling the request to start the picks and unpicks in bulk proce describe('and getting the address fails', () => { it('should dispatch an action signaling the failure of the handled action', () => { - return expectSaga(favoritesSaga) + return expectSaga(favoritesSaga, getIdentity) .provide([[select(getAddress), throwError(error)]]) .put(bulkPickUnpickCancel(item, error.message)) .dispatch(bulkPickUnpickStart(item)) @@ -1361,7 +1363,7 @@ describe('when handling the request to start the picks and unpicks in bulk proce describe('and the user is not connected', () => { describe('and the user succeeds to connect the wallet', () => { it('should close the login modal after the success', () => { - return expectSaga(favoritesSaga) + return expectSaga(favoritesSaga, getIdentity) .provide([ [select(getAddress), undefined], [take(CONNECT_WALLET_SUCCESS), {}], @@ -1377,7 +1379,7 @@ describe('when handling the request to start the picks and unpicks in bulk proce describe('and the user closes the login modal', () => { it('should finish the saga', () => { - return expectSaga(favoritesSaga) + return expectSaga(favoritesSaga, getIdentity) .provide([ [select(getAddress), undefined], [take(CLOSE_MODAL), {}] @@ -1396,7 +1398,7 @@ describe('when handling the request to start the picks and unpicks in bulk proce describe('and getting the identity fails', () => { it('should dispatch an action signaling the failure of the handled action', () => { - return expectSaga(favoritesSaga) + return expectSaga(favoritesSaga, getIdentity) .provide([ [select(getAddress), address], [call(getIdentityOrRedirect), Promise.reject(error)] @@ -1409,7 +1411,7 @@ describe('when handling the request to start the picks and unpicks in bulk proce describe('and the user picks or unpicks in bulk without trying to create a new list', () => { it('should end the saga without dispatching a bulk request', () => { - return expectSaga(favoritesSaga) + return expectSaga(favoritesSaga, getIdentity) .provide([ [select(getAddress), address], [call(getIdentityOrRedirect), Promise.resolve()], @@ -1426,7 +1428,7 @@ describe('when handling the request to start the picks and unpicks in bulk proce describe('and the user tries to create a new list', () => { describe('and the creation of the list succeeds', () => { it('should dispatch an action signaling the pick item in bulk request for the created list', () => { - return expectSaga(favoritesSaga) + return expectSaga(favoritesSaga, getIdentity) .provide([ [select(getAddress), address], [call(getIdentityOrRedirect), Promise.resolve()], @@ -1444,7 +1446,7 @@ describe('when handling the request to start the picks and unpicks in bulk proce describe('and the user closes the creation list modal', () => { it('should dispatch an action signaling the cancel of the pick item in bulk process', () => { - return expectSaga(favoritesSaga) + return expectSaga(favoritesSaga, getIdentity) .provide([ [select(getAddress), address], [call(getIdentityOrRedirect), Promise.resolve()], @@ -1483,7 +1485,7 @@ describe('when handling the request to perform picks and unpicks in bulk', () => describe('and getting the identity fails', () => { it('should dispatch an action signaling the failure of the handled action', () => { - return expectSaga(favoritesSaga) + return expectSaga(favoritesSaga, getIdentity) .provide([[call(getIdentityOrRedirect), Promise.reject(error)]]) .put(bulkPickUnpickFailure(item, [fstList], [sndList], error.message)) .dispatch(bulkPickUnpickRequest(item, [fstList], [sndList])) @@ -1493,7 +1495,7 @@ describe('when handling the request to perform picks and unpicks in bulk', () => describe('and the call to the favorites api fails', () => { it('should dispatch an action signaling the failure of the handled action', () => { - return expectSaga(favoritesSaga) + return expectSaga(favoritesSaga, getIdentity) .provide([ [call(getIdentityOrRedirect), Promise.resolve()], [ @@ -1513,7 +1515,7 @@ describe('when handling the request to perform picks and unpicks in bulk', () => describe('and call to the favorites api succeeds', () => { it('should dispatch an action signaling the success of the handled action', () => { - return expectSaga(favoritesSaga) + return expectSaga(favoritesSaga, getIdentity) .provide([ [call(getIdentityOrRedirect), Promise.resolve()], [select(isOwnerUnpickingFromCurrentList, [sndList]), true], @@ -1555,7 +1557,7 @@ describe('when handling the success of the bulk pick and unpick process', () => }) it('should dispatch a pick success action and an unpick success action for each picked or unpicked lists', () => { - return expectSaga(favoritesSaga) + return expectSaga(favoritesSaga, getIdentity) .put(pickItemSuccess(item, fstList.id)) .put(unpickItemSuccess(item, sndList.id)) .dispatch(bulkPickUnpickSuccess(item, [fstList], [sndList], true, true)) @@ -1587,7 +1589,7 @@ describe('when handling the failure of the bulk pick and unpick process', () => }) it('should dispatch a pick failure action and an unpick success action for each picked or unpicked lists', () => { - return expectSaga(favoritesSaga) + return expectSaga(favoritesSaga, getIdentity) .put(pickItemFailure(item, fstList.id, error)) .put(unpickItemFailure(item, sndList.id, error)) .dispatch(bulkPickUnpickFailure(item, [fstList], [sndList], error)) diff --git a/webapp/src/modules/favorites/sagas.ts b/webapp/src/modules/favorites/sagas.ts index b58c22cca4..601989659c 100644 --- a/webapp/src/modules/favorites/sagas.ts +++ b/webapp/src/modules/favorites/sagas.ts @@ -1,5 +1,6 @@ import { getLocation, push } from 'connected-react-router' import { call, put, race, select, take, takeEvery } from 'redux-saga/effects' +import { AuthIdentity } from '@dcl/crypto' import { CatalogFilters, Item } from '@dcl/schemas' import { ConnectWalletSuccessAction, @@ -84,10 +85,11 @@ import { List } from './types' import { getData as getItemsData } from '../item/selectors' import { getIsMarketplaceServerEnabled } from '../features/selectors' -export function* favoritesSaga() { +export function* favoritesSaga(getIdentity: () => AuthIdentity | undefined) { const API_OPTS = { retries: retryParams.attempts, - retryDelay: retryParams.delay + retryDelay: retryParams.delay, + identity: getIdentity } const favoritesAPI = new FavoritesAPI( MARKETPLACE_FAVORITES_SERVER_URL, diff --git a/webapp/src/modules/item/sagas.spec.ts b/webapp/src/modules/item/sagas.spec.ts index 5eb043cc51..b47ffa1db8 100644 --- a/webapp/src/modules/item/sagas.spec.ts +++ b/webapp/src/modules/item/sagas.spec.ts @@ -102,10 +102,12 @@ const nftPurchase: NFTPurchase = { } } +const getIdentity = () => undefined + describe('when handling the buy items request action', () => { describe("when there's no wallet loaded in the state", () => { it('should dispatch an action signaling the failure of the action handling', () => { - return expectSaga(itemSaga) + return expectSaga(itemSaga, getIdentity) .provide([[select(getWallet), null]]) .put(buyItemFailure('A defined wallet is required to buy an item')) .dispatch(buyItemRequest(item)) @@ -115,7 +117,7 @@ describe('when handling the buy items request action', () => { describe('when sending the meta transaction fails', () => { it('should dispatch an action signaling the failure of the action handling', () => { - return expectSaga(itemSaga) + return expectSaga(itemSaga, getIdentity) .provide([ [select(getWallet), wallet], [matchers.call.fn(sendTransaction), Promise.reject(anError)] @@ -128,7 +130,7 @@ describe('when handling the buy items request action', () => { describe('when the meta transaction is sent succesfully', () => { it('should send a meta transaction to the collection store contract living in the chain provided by the item and dispatch the success action', () => { - return expectSaga(itemSaga) + return expectSaga(itemSaga, getIdentity) .provide([ [select(getWallet), wallet], [matchers.call.fn(sendTransaction), Promise.resolve(txHash)] @@ -151,7 +153,7 @@ describe('when handling the buy items with card action', () => { describe('when the explanation modal has already been shown', () => { it('should open Transak widget', () => { - return expectSaga(itemSaga) + return expectSaga(itemSaga, getIdentity) .provide([ [ call( @@ -173,7 +175,7 @@ describe('when handling the buy items with card action', () => { describe('when the explanation modal is shown and the user closes it', () => { it('should not set the item in the local storage to show the modal again later', () => { - return expectSaga(itemSaga) + return expectSaga(itemSaga, getIdentity) .provide([ [ call( @@ -195,7 +197,7 @@ describe('when handling the buy items with card action', () => { describe('when opening Transak Widget fails', () => { it('should dispatch an action signaling the failure of the action handling', () => { - return expectSaga(itemSaga) + return expectSaga(itemSaga, getIdentity) .provide([[call(buyAssetWithCard, item), Promise.reject(anError)]]) .put(buyItemWithCardFailure(anError.message)) .dispatch(buyItemWithCardRequest(item)) @@ -205,7 +207,7 @@ describe('when handling the buy items with card action', () => { describe('when Transak widget is opened succesfully', () => { it('should dispatch the success action', () => { - return expectSaga(itemSaga) + return expectSaga(itemSaga, getIdentity) .provide([[call(buyAssetWithCard, item), Promise.resolve()]]) .dispatch(buyItemWithCardRequest(item)) .run({ silenceTimeout: true }) @@ -219,7 +221,7 @@ describe('when handling the buy items with card action', () => { describe('when handling the set purchase action', () => { describe('when it is a MANA purchase', () => { it('should not put any new action', () => { - return expectSaga(itemSaga) + return expectSaga(itemSaga, getIdentity) .dispatch(setPurchase(manaPurchase)) .run({ silenceTimeout: true }) .then(({ effects }) => { @@ -231,7 +233,7 @@ describe('when handling the set purchase action', () => { describe('when it is an NFT purchase', () => { describe('when it is a secondary market purchase', () => { it('should not put any new action', () => { - return expectSaga(itemSaga) + return expectSaga(itemSaga, getIdentity) .dispatch( setPurchase({ ...nftPurchase, @@ -252,7 +254,7 @@ describe('when handling the set purchase action', () => { describe('when the purchase is incomplete', () => { it('should not put any new action', () => { - return expectSaga(itemSaga) + return expectSaga(itemSaga, getIdentity) .dispatch(setPurchase(nftPurchase)) .run({ silenceTimeout: true }) .then(({ effects }) => { @@ -263,7 +265,7 @@ describe('when handling the set purchase action', () => { describe('when it is complete without a txHash', () => { it('should not put any new action', () => { - return expectSaga(itemSaga) + return expectSaga(itemSaga, getIdentity) .dispatch( setPurchase({ ...nftPurchase, @@ -283,7 +285,7 @@ describe('when handling the set purchase action', () => { describe('when the item does not yet exist in the store', () => { it('should put the action signaling the fetch item request', () => { - return expectSaga(itemSaga) + return expectSaga(itemSaga, getIdentity) .provide([ [select(getItems), {}], [ @@ -309,7 +311,7 @@ describe('when handling the set purchase action', () => { describe('when the action of fetching the item has been dispatched', () => { describe('when the fetch item request fails', () => { it('should put an action signaling the failure of the buy item with card request', () => { - return expectSaga(itemSaga) + return expectSaga(itemSaga, getIdentity) .provide([ [select(getItems), {}], [ @@ -339,7 +341,7 @@ describe('when handling the set purchase action', () => { const items = { anItemId: item } it('should put an action signaling the success of the buy item with card request', () => { - return expectSaga(itemSaga) + return expectSaga(itemSaga, getIdentity) .provide([ [select(getItems), items], [call(getItem, contractAddress, itemId!, items), item] @@ -369,7 +371,7 @@ describe('when handling the fetch collections items request action', () => { const fetchResult = { data: [item] } it('should dispatch a successful action with the fetched items', () => { - return expectSaga(itemSaga) + return expectSaga(itemSaga, getIdentity) .provide([[matchers.call.fn(ItemAPI.prototype.get), fetchResult]]) .call.like({ fn: ItemAPI.prototype.get, @@ -385,7 +387,7 @@ describe('when handling the fetch collections items request action', () => { describe('when the request fails', () => { it('should dispatch a failing action with the error and the options', () => { - return expectSaga(itemSaga) + return expectSaga(itemSaga, getIdentity) .provide([ [matchers.call.fn(ItemAPI.prototype.get), Promise.reject(anError)] ]) @@ -432,7 +434,7 @@ describe('when handling the fetch items request action', () => { }) it('should dispatch a successful action with the fetched items and cancel the ongoing one', () => { - return expectSaga(itemSaga) + return expectSaga(itemSaga, getIdentity) .provide([ [ matchers.call.fn( @@ -491,7 +493,7 @@ describe('when handling the fetch items request action', () => { describe('and there is no wallet connected', () => { it('should dispatch a successful action with the fetched items and cancel the ongoing one', () => { - return expectSaga(itemSaga) + return expectSaga(itemSaga, getIdentity) .provide([ [ matchers.call.fn( @@ -555,7 +557,7 @@ describe('when handling the fetch items request action', () => { pathname = locations.root() }) it('should dispatch a successful action with the fetched items', () => { - return expectSaga(itemSaga) + return expectSaga(itemSaga, getIdentity) .provide([ [matchers.call.fn(CatalogAPI.prototype.get), fetchResult], [ @@ -583,7 +585,7 @@ describe('when handling the fetch items request action', () => { describe('when the request fails', () => { it('should dispatch a failing action with the error and the options', () => { - return expectSaga(itemSaga) + return expectSaga(itemSaga, getIdentity) .provide([ [select(getLocation), { pathname: '' }], [select(getWallet), undefined], @@ -605,7 +607,7 @@ describe('when handling the fetch items request action', () => { describe('when handling the fetch item request action', () => { describe('when the request is successful', () => { it('should dispatch a successful action with the fetched items', () => { - return expectSaga(itemSaga) + return expectSaga(itemSaga, getIdentity) .provide([ [matchers.call.fn(ItemAPI.prototype.getOne), item], [ @@ -622,7 +624,7 @@ describe('when handling the fetch items request action', () => { describe('when the request fails', () => { it('should dispatching a failing action with the contract address, the token id and the error message', () => { - return expectSaga(itemSaga) + return expectSaga(itemSaga, getIdentity) .provide([ [ matchers.call.fn(ItemAPI.prototype.getOne), @@ -661,7 +663,7 @@ describe('when handling the fetch trending items request action', () => { }) it('should dispatch a successful action with the fetched trending items', () => { - return expectSaga(itemSaga) + return expectSaga(itemSaga, getIdentity) .provide([ [select(getIsMarketplaceServerEnabled), true], [matchers.call.fn(ItemAPI.prototype.getTrendings), fetchResult], @@ -681,7 +683,7 @@ describe('when handling the fetch trending items request action', () => { const fetchResult = { data: [], total: 0 } it('should dispatch a successful action with the fetched trending items', () => { - return expectSaga(itemSaga) + return expectSaga(itemSaga, getIdentity) .provide([ // [select(getIsMarketplaceServerEnabled), true], [matchers.call.fn(ItemAPI.prototype.getTrendings), fetchResult], @@ -699,7 +701,7 @@ describe('when handling the fetch trending items request action', () => { describe('when the request fails', () => { it('should dispatch a failing action with the error and the options', () => { - return expectSaga(itemSaga) + return expectSaga(itemSaga, getIdentity) .provide([ [ matchers.call.fn(ItemAPI.prototype.getTrendings), diff --git a/webapp/src/modules/item/sagas.ts b/webapp/src/modules/item/sagas.ts index 0a8b79526c..fd7cc7c585 100644 --- a/webapp/src/modules/item/sagas.ts +++ b/webapp/src/modules/item/sagas.ts @@ -1,4 +1,5 @@ import { matchPath } from 'react-router-dom' +import { AuthIdentity } from '@dcl/crypto' import { getLocation } from 'connected-react-router' import { SagaIterator } from 'redux-saga' import { put, takeEvery } from '@redux-saga/core/effects' @@ -81,10 +82,11 @@ import { getItem } from './utils' export const NFT_SERVER_URL = config.get('NFT_SERVER_URL')! export const CANCEL_FETCH_ITEMS = 'CANCEL_FETCH_ITEMS' -export function* itemSaga() { +export function* itemSaga(getIdentity: () => AuthIdentity | undefined) { const API_OPTS = { retries: retryParams.attempts, - retryDelay: retryParams.delay + retryDelay: retryParams.delay, + identity: getIdentity } const itemAPI = new ItemAPI(NFT_SERVER_URL, API_OPTS) const marketplaceServerCatalogAPI = new CatalogAPI( diff --git a/webapp/src/modules/nft/sagas.spec.ts b/webapp/src/modules/nft/sagas.spec.ts index 6681bf66a9..2c330a8333 100644 --- a/webapp/src/modules/nft/sagas.spec.ts +++ b/webapp/src/modules/nft/sagas.spec.ts @@ -35,8 +35,8 @@ import { upsertContracts } from '../contract/actions' import { getStubMaticCollectionContract } from '../contract/utils' import { waitUntilRentalChangesStatus } from '../rental/utils' import { getRentalById } from '../rental/selectors' -import { retryParams } from '../vendor/decentraland/utils' import { fetchSmartWearableRequiredPermissionsRequest } from '../asset/actions' +import { retryParams } from '../vendor/decentraland/utils' jest.mock('decentraland-dapps/dist/lib/eth') @@ -71,7 +71,7 @@ describe('when handling the fetch NFTs request action', () => { } const error = 'someError' - return expectSaga(nftSaga) + return expectSaga(nftSaga, getIdentity) .provide([ [select(getContracts), []], [ @@ -96,7 +96,7 @@ describe('when handling the fetch NFTs request action', () => { const vendor = VendorFactory.build(options.vendor, API_OPTS) const error = { message: 'someError' } - return expectSaga(nftSaga) + return expectSaga(nftSaga, getIdentity) .provide([ [select(getContracts), []], [call(VendorFactory.build, options.vendor, API_OPTS), vendor], @@ -129,7 +129,7 @@ describe('when handling the fetch NFTs request action', () => { const rentals = [{ id: 'aRentalId' }] as RentalListing[] const count = 1 - return expectSaga(nftSaga) + return expectSaga(nftSaga, getIdentity) .provide([ [call(VendorFactory.build, options.vendor, API_OPTS), vendor], [ @@ -170,7 +170,7 @@ describe('when handling the fetch NFT request action', () => { const order = { id: 'id' } as Order const rental = { id: 'id' } as RentalListing - return expectSaga(nftSaga) + return expectSaga(nftSaga, getIdentity) .provide([ [select(getLoading), []], [select(getContracts), []], @@ -207,7 +207,7 @@ describe('when handling the fetch NFT request action', () => { const tokenId = 'aTokenId' const error = `Couldn't find a valid vendor for contract ${contractAddress}` - return expectSaga(nftSaga) + return expectSaga(nftSaga, getIdentity) .provide([ [select(getLoading), []], [select(getContracts), []], @@ -232,7 +232,7 @@ describe('when handling the fetch NFT request action', () => { const tokenId = 'aTokenId' const error = `Couldn't find a valid vendor for contract ${contractAddress}` - return expectSaga(nftSaga) + return expectSaga(nftSaga, getIdentity) .provide([ [select(getLoading), []], [select(getContracts), []], @@ -262,7 +262,7 @@ describe('when handling the fetch NFT request action', () => { const vendor = VendorFactory.build(VendorName.DECENTRALAND, API_OPTS) const error = { message: 'someError' } - return expectSaga(nftSaga) + return expectSaga(nftSaga, getIdentity) .provide([ [select(getLoading), []], [select(getContracts), []], @@ -300,7 +300,7 @@ describe('when handling the fetch NFT request action', () => { const order = { id: 'anId' } as Order const rental = { id: 'aRentalId' } as RentalListing - return expectSaga(nftSaga) + return expectSaga(nftSaga, getIdentity) .provide([ [select(getLoading), []], [select(getContracts), []], @@ -337,7 +337,7 @@ describe('when handling the transfer NFT request action', () => { const address = 'anAddress' const error = 'someError' - return expectSaga(nftSaga) + return expectSaga(nftSaga, getIdentity) .provide([ [call(VendorFactory.build, nft.vendor), throwError(new Error(error))] ]) @@ -355,7 +355,7 @@ describe('when handling the transfer NFT request action', () => { const address = 'anAddress' const error = 'A wallet is needed to perform a NFT transfer request' - return expectSaga(nftSaga) + return expectSaga(nftSaga, getIdentity) .provide([ [ call(VendorFactory.build, nft.vendor), @@ -379,7 +379,7 @@ describe('when handling the transfer NFT request action', () => { const vendor = VendorFactory.build(nft.vendor) const error = { message: 'anError' } - return expectSaga(nftSaga) + return expectSaga(nftSaga, getIdentity) .provide([ [call(VendorFactory.build, nft.vendor), vendor], [select(getWallet), wallet], @@ -421,7 +421,7 @@ describe('when handling the transfer NFT request action', () => { } as RentalListing }) it('should dispatch an action signaling the success of the action handling and cancel an existing rental listing', () => { - return expectSaga(nftSaga) + return expectSaga(nftSaga, getIdentity) .provide([ [call(VendorFactory.build, nft.vendor), vendor], [select(getWallet), wallet], @@ -448,7 +448,7 @@ describe('when handling the transfer NFT request action', () => { nft.openRentalId = null }) it('should dispatch an action signaling the success of the action handling', () => { - return expectSaga(nftSaga) + return expectSaga(nftSaga, getIdentity) .provide([ [call(VendorFactory.build, nft.vendor), vendor], [select(getWallet), wallet], @@ -467,7 +467,7 @@ describe('when handling the transfer NFT request action', () => { }) describe('and the transaction gets reverted', () => { it('should put the action to notify that the transaction was submitted and the claim LAND failure action with an error', () => { - return expectSaga(nftSaga) + return expectSaga(nftSaga, getIdentity) .provide([ [call(VendorFactory.build, nft.vendor), vendor], [select(getWallet), wallet], diff --git a/webapp/src/modules/nft/sagas.ts b/webapp/src/modules/nft/sagas.ts index c13bb52f9e..1dcba7e146 100644 --- a/webapp/src/modules/nft/sagas.ts +++ b/webapp/src/modules/nft/sagas.ts @@ -1,4 +1,5 @@ import { takeEvery, call, put, select } from 'redux-saga/effects' +import { AuthIdentity } from '@dcl/crypto' import { RentalListing, RentalStatus } from '@dcl/schemas' import { ErrorCode } from 'decentraland-transactions' import { waitForTx } from 'decentraland-dapps/dist/modules/transaction/utils' @@ -41,10 +42,11 @@ import { } from './actions' import { NFT } from './types' -export function* nftSaga() { +export function* nftSaga(getIdentity: () => AuthIdentity | undefined) { const API_OPTS = { retries: retryParams.attempts, - retryDelay: retryParams.delay + retryDelay: retryParams.delay, + identity: getIdentity } yield takeEvery(FETCH_NFTS_REQUEST, handleFetchNFTsRequest) diff --git a/webapp/src/modules/sagas.ts b/webapp/src/modules/sagas.ts index 15b324fc74..85b50d23ce 100644 --- a/webapp/src/modules/sagas.ts +++ b/webapp/src/modules/sagas.ts @@ -1,4 +1,5 @@ import { all } from 'redux-saga/effects' +import { AuthIdentity } from '@dcl/crypto' import { ApplicationName } from 'decentraland-dapps/dist/modules/features/types' import { authorizationSaga } from 'decentraland-dapps/dist/modules/authorization/sagas' import { FiatGateway } from 'decentraland-dapps/dist/modules/gateway/types' @@ -42,8 +43,7 @@ import { loginSaga } from './login/sagas' import { ensSaga } from './ens/sagas' const analyticsSaga = createAnalyticsSaga() -const profileSaga = () => - createProfileSaga({ peerUrl, getIdentity: () => undefined }) // TODO, update profile Saga to read from LS + const lambdasClient = createLambdasClient({ url: `${peerUrl}/lambdas`, fetcher: createFetchComponent() @@ -80,16 +80,16 @@ const gatewaySaga = createGatewaySaga({ } }) -export function* rootSaga() { +export function* rootSaga(getIdentity: () => AuthIdentity | undefined) { yield all([ analyticsSaga(), assetSaga(), authorizationSaga(), bidSaga(), - itemSaga(), - nftSaga(), + itemSaga(getIdentity), + nftSaga(getIdentity), orderSaga(), - profileSaga()(), + createProfileSaga({ peerUrl, getIdentity }), proximitySaga(), routingSaga(), tileSaga(), @@ -118,7 +118,7 @@ export function* rootSaga() { gatewaySaga(), locationSaga(), transakSaga(), - favoritesSaga(), + favoritesSaga(getIdentity), loginSaga(), ensSaga(), newIdentitySaga() diff --git a/webapp/src/modules/store.ts b/webapp/src/modules/store.ts index d574dbe5c0..59ab450efd 100644 --- a/webapp/src/modules/store.ts +++ b/webapp/src/modules/store.ts @@ -1,3 +1,5 @@ +import { localStorageGetIdentity } from '@dcl/single-sign-on-client' +import { getWallet } from './wallet/selectors' import { createMemoryHistory, createBrowserHistory, History } from 'history' import { applyMiddleware, compose, createStore } from 'redux' import createSagasMiddleware from 'redux-saga' @@ -72,8 +74,14 @@ export function initStore(history: History) { (rootReducer as unknown) as ReturnType, enhancer ) + const getIdentity = () => { + const wallet = getWallet(store.getState() as RootState) + return wallet + ? localStorageGetIdentity(wallet.address) || undefined + : undefined + } - sagasMiddleware.run(rootSaga) + sagasMiddleware.run(rootSaga, getIdentity) loadStorageMiddleware(store) if (isDev) { @@ -110,7 +118,13 @@ export function initTestStore(preloadedState = {}) { ) const enhancer = compose(middleware) const store = createStore(rootReducer, preloadedState, enhancer) - sagasMiddleware.run(rootSaga) + const getIdentity = () => { + const wallet = getWallet(store.getState() as RootState) + return wallet + ? localStorageGetIdentity(wallet.address) || undefined + : undefined + } + sagasMiddleware.run(rootSaga, getIdentity) loadStorageMiddleware(store) store.dispatch(fetchTilesRequest()) diff --git a/webapp/src/utils/tests.tsx b/webapp/src/utils/tests.tsx index b94d29b214..7453f3371c 100644 --- a/webapp/src/utils/tests.tsx +++ b/webapp/src/utils/tests.tsx @@ -49,7 +49,7 @@ export function initTestStore(preloadedState = {}) { const enhancer = compose(middleware) const store = createStore(rootReducer, preloadedState, enhancer) - sagasMiddleware.run(rootSaga) + sagasMiddleware.run(rootSaga, () => undefined) loadStorageMiddleware(store) store.dispatch(fetchTilesRequest()) From dff1808ff6134b07fd03342738884f190555ab7e Mon Sep 17 00:00:00 2001 From: Juanma Hidalgo Date: Wed, 24 Jan 2024 14:18:02 +0100 Subject: [PATCH 6/8] test: fix tests --- .../components/Modals/FavoritesModal/FavoritesModal.spec.tsx | 4 ++++ .../Modals/SaveToListModal/SaveToListModal.spec.tsx | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/webapp/src/components/Modals/FavoritesModal/FavoritesModal.spec.tsx b/webapp/src/components/Modals/FavoritesModal/FavoritesModal.spec.tsx index 1e28db6639..4a281f8a8d 100644 --- a/webapp/src/components/Modals/FavoritesModal/FavoritesModal.spec.tsx +++ b/webapp/src/components/Modals/FavoritesModal/FavoritesModal.spec.tsx @@ -5,6 +5,10 @@ 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 { diff --git a/webapp/src/components/Modals/SaveToListModal/SaveToListModal.spec.tsx b/webapp/src/components/Modals/SaveToListModal/SaveToListModal.spec.tsx index 1fba73214c..c11e4f03e1 100644 --- a/webapp/src/components/Modals/SaveToListModal/SaveToListModal.spec.tsx +++ b/webapp/src/components/Modals/SaveToListModal/SaveToListModal.spec.tsx @@ -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, From 2616302f36bdcb50a30bcac6d6e5beeb42e55080 Mon Sep 17 00:00:00 2001 From: Juanma Hidalgo Date: Wed, 24 Jan 2024 15:12:16 +0100 Subject: [PATCH 7/8] fix: fix the waitForWalletConnectionAndIdentityIfConnecting waiting for the success on the identity --- webapp/src/modules/wallet/utils.ts | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/webapp/src/modules/wallet/utils.ts b/webapp/src/modules/wallet/utils.ts index 158882ba58..032cbbbca0 100644 --- a/webapp/src/modules/wallet/utils.ts +++ b/webapp/src/modules/wallet/utils.ts @@ -1,16 +1,14 @@ import { ethers } from 'ethers' -import { race, select, take } from 'redux-saga/effects' +import { call, race, select, take } from 'redux-saga/effects' import { Provider } from 'decentraland-dapps/dist/modules/wallet/types' import { CONNECT_WALLET_FAILURE, - CONNECT_WALLET_SUCCESS + CONNECT_WALLET_SUCCESS, + ConnectWalletSuccessAction } from 'decentraland-dapps/dist/modules/wallet/actions' +import { getIdentityOrRedirect } from 'decentraland-dapps/dist/modules/identity/sagas' import { getConnectedProvider } from 'decentraland-dapps/dist/lib/eth' import { isConnecting } from 'decentraland-dapps/dist/modules/wallet/selectors' -import { - GENERATE_IDENTITY_FAILURE, - GENERATE_IDENTITY_SUCCESS -} from 'decentraland-dapps/dist/modules/identity/actions' import { config } from '../../config' export const TRANSACTIONS_API_URL = config.get('TRANSACTIONS_API_URL') @@ -53,17 +51,13 @@ export function formatBalance(balance: number) { export function* waitForWalletConnectionAndIdentityIfConnecting() { const isConnectingToWallet: boolean = yield select(isConnecting) - console.log('isConnectingToWallet: ', isConnectingToWallet); if (isConnectingToWallet) { - const { success } = yield race({ + const { success }: { success: ConnectWalletSuccessAction } = yield race({ success: take(CONNECT_WALLET_SUCCESS), failure: take(CONNECT_WALLET_FAILURE) }) if (success) { - yield race({ - success: take(GENERATE_IDENTITY_SUCCESS), - failure: take(GENERATE_IDENTITY_FAILURE) - }) + yield call(getIdentityOrRedirect) } } } From adf2e5ed7dd12ff647031892e32bc8df0f8e19ac Mon Sep 17 00:00:00 2001 From: Juanma Hidalgo Date: Tue, 30 Jan 2024 11:52:54 +0100 Subject: [PATCH 8/8] feat: remove extra newIdentitySaga --- webapp/src/modules/sagas.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/webapp/src/modules/sagas.ts b/webapp/src/modules/sagas.ts index 85b50d23ce..2494ad66d2 100644 --- a/webapp/src/modules/sagas.ts +++ b/webapp/src/modules/sagas.ts @@ -53,10 +53,6 @@ const contentClient = createContentClient({ fetcher: createFetchComponent() }) -const newIdentitySaga = createIdentitySaga({ - authURL: config.get('AUTH_URL') -}) - const gatewaySaga = createGatewaySaga({ [FiatGateway.WERT]: { marketplaceServerURL: config.get('MARKETPLACE_SERVER_URL'), @@ -103,7 +99,9 @@ export function* rootSaga(getIdentity: () => AuthIdentity | undefined) { accountSaga(lambdasClient), collectionSaga(), storeSaga(contentClient), - newIdentitySaga(), + createIdentitySaga({ + authURL: config.get('AUTH_URL') + }), marketplaceAnalyticsSagas(), featuresSaga({ polling: { @@ -120,7 +118,6 @@ export function* rootSaga(getIdentity: () => AuthIdentity | undefined) { transakSaga(), favoritesSaga(getIdentity), loginSaga(), - ensSaga(), - newIdentitySaga() + ensSaga() ]) }