Skip to content

Commit

Permalink
feat: Automatically assign the user wallet address and wallet type to…
Browse files Browse the repository at this point in the history
… the intercom Instance
  • Loading branch information
LautaroPetaccio committed Nov 29, 2024
1 parent 9809b6d commit 2051e4a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
12 changes: 9 additions & 3 deletions webapp/src/components/Routes/Routes.container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@ import { Dispatch } from 'redux'
import { closeAllModals } from 'decentraland-dapps/dist/modules/modal/actions'
import { getIsMaintenanceEnabled } from '../../modules/features/selectors'
import { RootState } from '../../modules/reducer'
import { getWallet } from '../../modules/wallet/selectors'
import Routes from './Routes'
import { MapDispatchProps, MapStateProps } from './Routes.types'

const mapState = (state: RootState): MapStateProps => ({
inMaintenance: getIsMaintenanceEnabled(state)
})
const mapState = (state: RootState): MapStateProps => {
const wallet = getWallet(state)
return {
inMaintenance: getIsMaintenanceEnabled(state),
userWalletAddress: wallet?.address.toLowerCase() ?? null,
userWalletType: wallet?.providerType ?? null
}
}

const mapDispatch = (dispatch: Dispatch): MapDispatchProps => ({
onLocationChanged: () => dispatch(closeAllModals())
Expand Down
11 changes: 8 additions & 3 deletions webapp/src/components/Routes/Routes.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCallback, useEffect } from 'react'
import { useCallback, useEffect, useMemo } from 'react'
import { Switch, Route, Redirect, RouteComponentProps, useLocation } from 'react-router-dom'
import Intercom from 'decentraland-dapps/dist/components/Intercom'
import useManaFiatGatewayPurchase from 'decentraland-dapps/dist/hooks/useManaFiatGatewayPurchase'
Expand Down Expand Up @@ -34,7 +34,7 @@ import { SuccessPage } from '../SuccessPage'
import { TransferPage } from '../TransferPage'
import { Props } from './Routes.types'

const Routes = ({ inMaintenance, onLocationChanged }: Props) => {
const Routes = ({ inMaintenance, onLocationChanged, userWalletAddress, userWalletType }: Props) => {
usePageTracking()
useManaFiatGatewayPurchase()
const location = useLocation()
Expand All @@ -43,6 +43,11 @@ const Routes = ({ inMaintenance, onLocationChanged }: Props) => {
onLocationChanged()
}, [location])

const intercomData = useMemo(
() => (userWalletType && userWalletAddress ? { Wallet: userWalletAddress, 'Wallet type': userWalletType } : undefined),
[userWalletAddress, userWalletType]
)

const APP_ID = config.get('INTERCOM_APP_ID')
const renderItemAssetPage = useCallback(() => <AssetPage type={AssetType.ITEM} />, [])

Expand Down Expand Up @@ -99,7 +104,7 @@ const Routes = ({ inMaintenance, onLocationChanged }: Props) => {
<Redirect from="/browse" to={locations.browse() + window.location.search} push />
<Redirect to={locations.root()} />
</Switch>
{APP_ID ? <Intercom appId={APP_ID} settings={{ alignment: 'right' }} /> : null}
{APP_ID ? <Intercom appId={APP_ID} data={intercomData} settings={{ alignment: 'right' }} /> : null}
</>
)
}
Expand Down
5 changes: 4 additions & 1 deletion webapp/src/components/Routes/Routes.types.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { RouteComponentProps } from 'react-router-dom'
import { ProviderType } from '@dcl/schemas'
import { closeAllModals } from 'decentraland-dapps/dist/modules/modal/actions'

export type Props = RouteComponentProps & {
inMaintenance: boolean
userWalletAddress: string | null
userWalletType: ProviderType | null
onLocationChanged: typeof closeAllModals
}

export type MapStateProps = Pick<Props, 'inMaintenance'>
export type MapStateProps = Pick<Props, 'inMaintenance' | 'userWalletAddress' | 'userWalletType'>
export type MapDispatchProps = Pick<Props, 'onLocationChanged'>

export type State = {
Expand Down

0 comments on commit 2051e4a

Please sign in to comment.