-
Notifications
You must be signed in to change notification settings - Fork 684
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3e5aeb3
commit e85f7d3
Showing
35 changed files
with
4,313 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
webapp/src/components/NamesPage/MintName/MintNamePage.container.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { connect } from 'react-redux' | ||
import { push } from 'connected-react-router' | ||
import { Network } from '@dcl/schemas' | ||
import { getMana } from '../../../modules/wallet/selectors' | ||
import { locations } from '../../../modules/routing/locations' | ||
import { Section } from '../../../modules/vendor/decentraland' | ||
import { | ||
MapDispatch, | ||
MapDispatchProps, | ||
MapStateProps | ||
} from './MintNamePage.types' | ||
import { RootState } from '../../../modules/reducer' | ||
import MintNamePage from './MintNamePage' | ||
|
||
const mapState = (state: RootState): MapStateProps => ({ | ||
currentMana: getMana(state, Network.ETHEREUM) | ||
}) | ||
|
||
const mapDispatch = (dispatch: MapDispatch): MapDispatchProps => ({ | ||
onBrowse: () => dispatch(push(locations.names({ section: Section.ENS }))) | ||
}) | ||
|
||
export default connect(mapState, mapDispatch)(MintNamePage) |
26 changes: 26 additions & 0 deletions
26
webapp/src/components/NamesPage/MintName/MintNamePage.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
.mintNamePageContainer { | ||
display: flex; | ||
flex-direction: column; | ||
height: 100%; | ||
} | ||
|
||
.mintNamePage { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
flex: 1; | ||
} | ||
|
||
.mintNamePage .buttons { | ||
display: flex; | ||
flex-direction: column; | ||
margin-top: 12px; | ||
} | ||
|
||
.mintNamePage .buttons :global(.button) { | ||
margin-bottom: 12px; | ||
} | ||
|
||
.mintNamePage .buttons :global(.ui.button + .ui.button) { | ||
margin-left: 0; | ||
} |
186 changes: 186 additions & 0 deletions
186
webapp/src/components/NamesPage/MintName/MintNamePage.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
import React, { useCallback, useEffect, useMemo, useState } from 'react' | ||
import { Button, Field, Form, Popup, Row, Section } from 'decentraland-ui' | ||
import { t } from 'decentraland-dapps/dist/modules/translation/utils' | ||
import NetworkButton from 'decentraland-dapps/dist/containers/NetworkButton' | ||
import { NavigationTab } from '../../Navigation/Navigation.types' | ||
import { builderUrl } from '../../../lib/environment' | ||
import { Navbar } from '../../Navbar' | ||
import { Footer } from '../../Footer' | ||
import { Navigation } from '../../Navigation' | ||
import { Props } from './MintNamePage.types' | ||
import styles from './MintNamePage.module.css' | ||
import { | ||
MAX_NAME_SIZE, | ||
PRICE, | ||
hasNameMinLength, | ||
isEnoughClaimMana, | ||
isNameAvailable, | ||
isNameValid | ||
} from '../../../modules/ens/utils' | ||
import { Mana } from '../../Mana' | ||
import { useInput } from '../../../lib/input' | ||
import { Network } from '@dcl/schemas' | ||
|
||
const MintNamePage = (props: Props) => { | ||
const { onBrowse, currentMana } = props | ||
const [showMintFlow, setShowMintFlow] = useState(false) | ||
const [isError, setIsError] = useState(false) | ||
const [isLoading, setIsLoading] = useState(false) | ||
|
||
const handleNameChange = useCallback(async text => { | ||
try { | ||
console.log('checking if available') | ||
console.log('text: ', text) | ||
const isAvailable = await isNameAvailable(text) | ||
console.log('isAvailable result: ', isAvailable) | ||
setIsAvailable(isAvailable) | ||
} catch (error) { | ||
console.log('error: ', error) | ||
setIsError(true) | ||
} | ||
}, []) | ||
|
||
const [name, setName] = useInput('', handleNameChange, 1000) | ||
console.log('name: ', name) | ||
|
||
const [isAvailable, setIsAvailable] = useState(false) | ||
console.log('isAvailable: ', isAvailable) | ||
|
||
useEffect(() => { | ||
;(async () => {})() | ||
}, [name]) | ||
|
||
const handleClaim = useCallback(() => { | ||
setIsLoading(true) | ||
}, []) | ||
|
||
const isEnoughMana = useMemo(() => { | ||
return currentMana && isEnoughClaimMana(currentMana) | ||
}, [currentMana]) | ||
console.log('isEnoughMana: ', isEnoughMana) | ||
|
||
const isValid = useMemo(() => { | ||
return isNameValid(name) | ||
}, [name]) | ||
|
||
const isDisabled = !isValid || !isAvailable || !isEnoughMana | ||
|
||
const renderMintFlow = useCallback(() => { | ||
let message = '' | ||
if (isError) { | ||
message = t('names_page.error_message') | ||
} else if (!isAvailable) { | ||
message = t('names_page.repeated_message') | ||
} else if (name.length <= 2) { | ||
message = '' | ||
} else if (!isValid) { | ||
message = t('names_page.name_message') | ||
} | ||
|
||
return ( | ||
<Form onSubmit={handleClaim}> | ||
<Section className={name.length === MAX_NAME_SIZE ? 'red' : ''}> | ||
<Field | ||
label={t('names_page.name_label')} | ||
value={name} | ||
message={message} | ||
placeholder={t('names_page.name_placeholder')} | ||
action={`${name.length}/${MAX_NAME_SIZE}`} | ||
error={ | ||
isError || (hasNameMinLength(name) && !isValid) || !isAvailable | ||
} | ||
onChange={(_event: React.ChangeEvent<HTMLInputElement>) => | ||
setName(_event) | ||
} | ||
/> | ||
</Section> | ||
<Row className="actions"> | ||
<Button | ||
className="cancel" | ||
onClick={() => setShowMintFlow(false)} | ||
type="button" | ||
> | ||
{t('global.cancel')} | ||
</Button> | ||
{!isLoading && !isEnoughMana ? ( | ||
<Popup | ||
className="modal-tooltip" | ||
content={t('claim_ens_page.not_enough_mana')} | ||
position="top center" | ||
trigger={ | ||
<div className="popup-button"> | ||
<NetworkButton | ||
type="submit" | ||
primary | ||
disabled={isDisabled} | ||
loading={isLoading} | ||
network={Network.ETHEREUM} | ||
> | ||
{t('names_page.claim_button')}{' '} | ||
<Mana inline>{PRICE.toLocaleString()}</Mana> | ||
</NetworkButton> | ||
</div> | ||
} | ||
hideOnScroll={true} | ||
on="hover" | ||
inverted | ||
/> | ||
) : ( | ||
<NetworkButton | ||
type="submit" | ||
primary | ||
disabled={isDisabled} | ||
loading={isLoading} | ||
network={Network.ETHEREUM} | ||
> | ||
{t('claim_ens_page.claim_button')}{' '} | ||
<Mana inline>{PRICE.toLocaleString()}</Mana> | ||
</NetworkButton> | ||
)} | ||
</Row> | ||
</Form> | ||
) | ||
}, [ | ||
handleClaim, | ||
isAvailable, | ||
isDisabled, | ||
isEnoughMana, | ||
isError, | ||
isLoading, | ||
isValid, | ||
name, | ||
setName | ||
]) | ||
|
||
return ( | ||
<div className={styles.mintNamePageContainer}> | ||
<Navbar isFullscreen /> | ||
<Navigation activeTab={NavigationTab.NAMES} /> | ||
<div className={styles.mintNamePage}> | ||
{showMintFlow ? ( | ||
renderMintFlow() | ||
) : ( | ||
<> | ||
<h2>{t('names_page.title')}</h2> | ||
<span>{t('names_page.subtitle')}</span> | ||
<div className={styles.buttons}> | ||
<Button primary onClick={() => setShowMintFlow(true)}> | ||
{t('names_page.claim_a_name')} | ||
</Button> | ||
<Button onClick={() => onBrowse()}> | ||
{t('names_page.browse_names_being_resold')} | ||
</Button> | ||
<Button inverted as={'a'} href={`${builderUrl}/claim-name`}> | ||
{t('names_page.manage_your_names')} | ||
</Button> | ||
</div> | ||
</> | ||
)} | ||
</div> | ||
|
||
<Footer isFullscreen /> | ||
</div> | ||
) | ||
} | ||
|
||
export default React.memo(MintNamePage) |
13 changes: 13 additions & 0 deletions
13
webapp/src/components/NamesPage/MintName/MintNamePage.types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Dispatch } from 'react' | ||
import { CallHistoryMethodAction } from 'connected-react-router' | ||
|
||
export type Props = { | ||
currentMana: number | undefined | ||
onBrowse: () => void | ||
} | ||
|
||
export type MapStateProps = Pick<Props, 'currentMana'> | ||
|
||
export type MapDispatchProps = Pick<Props, 'onBrowse'> | ||
|
||
export type MapDispatch = Dispatch<CallHistoryMethodAction> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import MintNamePage from './MintNamePage.container' | ||
export { MintNamePage } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.namesPageContainer { | ||
display: flex; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React from 'react' | ||
import { VendorName } from '../../modules/vendor/types' | ||
import { View } from '../../modules/ui/types' | ||
import { NavigationTab } from '../Navigation/Navigation.types' | ||
import { Section } from '../../modules/vendor/decentraland' | ||
import { Navbar } from '../Navbar' | ||
import { Footer } from '../Footer' | ||
import { Navigation } from '../Navigation' | ||
import { AssetBrowse } from '../AssetBrowse' | ||
import { Props } from './NamesPage.types' | ||
import styles from './NamesPage.module.css' | ||
|
||
const NamesPage = (props: Props) => { | ||
const { isFullscreen } = props | ||
return ( | ||
<div className={styles.namesPageContainer}> | ||
<Navbar isFullscreen /> | ||
<Navigation activeTab={NavigationTab.NAMES} /> | ||
<AssetBrowse | ||
vendor={VendorName.DECENTRALAND} | ||
view={View.MARKET} | ||
section={Section.ENS} | ||
sections={[Section.ENS]} | ||
/> | ||
<Footer isFullscreen={isFullscreen} /> | ||
</div> | ||
) | ||
} | ||
|
||
export default React.memo(NamesPage) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export type Props = { | ||
isFullscreen: boolean | ||
isMap: boolean | ||
onBrowse: () => void | ||
} | ||
|
||
export type MapStateProps = Pick<Props, 'isMap' | 'isFullscreen'> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import NamesPage from './NamesPage' | ||
export { NamesPage } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.