-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #121 from multiversx/development
Development
- Loading branch information
Showing
71 changed files
with
1,523 additions
and
145 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
import React, { useState } from 'react'; | ||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; | ||
import classNames from 'classnames'; | ||
import { Collapse } from 'react-bootstrap'; | ||
import { useSelector } from 'react-redux'; | ||
|
||
import { CUSTOM_NETWORK_ID } from 'appConstants'; | ||
import { CollapsibleArrows, CopyButton } from 'components'; | ||
import { networks } from 'config'; | ||
import { storage, scrollToElement } from 'helpers'; | ||
import { useGetNetworkChangeLink } from 'hooks'; | ||
import { faTrash, faCheck } from 'icons/regular'; | ||
import { activeNetworkSelector } from 'redux/selectors'; | ||
import { WithClassnameType } from 'types'; | ||
|
||
export interface NetworkDetailUIType { | ||
title: string; | ||
description: React.ReactNode; | ||
} | ||
|
||
const NetworkDetail = ({ title, description }: NetworkDetailUIType) => { | ||
return ( | ||
<div className='d-flex flex-wrap align-items-center gap-1'> | ||
<div>{title}:</div> | ||
<div className='text-neutral-100 text-strong'>{description}</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export const CustomNetworkDetails = ({ className }: WithClassnameType) => { | ||
const getNetworkChangeLink = useGetNetworkChangeLink(); | ||
const activeNetwork = useSelector(activeNetworkSelector); | ||
const { isCustom: activeNetworkIsCustom } = activeNetwork; | ||
|
||
const configCustomNetwork = networks.filter((network) => network.isCustom)[0]; | ||
const existingCustomNetwork = activeNetworkIsCustom | ||
? activeNetwork | ||
: configCustomNetwork; | ||
|
||
const [open, setOpen] = useState(false); | ||
|
||
const isSavedCustomNetworkActive = | ||
configCustomNetwork?.id === activeNetwork?.id; | ||
const defaultNetwork = networks.find((network) => Boolean(network.default)); | ||
const defaultNetworkId = defaultNetwork?.id ?? networks[0]?.id; | ||
|
||
const removeNetwork = () => { | ||
storage.removeFromLocal(CUSTOM_NETWORK_ID); | ||
window.location.href = getNetworkChangeLink({ | ||
networkId: defaultNetworkId | ||
}); | ||
}; | ||
|
||
const applyNetwork = () => { | ||
window.location.href = getNetworkChangeLink({ | ||
networkId: CUSTOM_NETWORK_ID | ||
}); | ||
}; | ||
|
||
if (!existingCustomNetwork) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div className={classNames('custom-network-details', className)}> | ||
<button | ||
type='button' | ||
onClick={() => { | ||
setOpen(!open); | ||
}} | ||
aria-controls='custom-network-details' | ||
aria-expanded={open} | ||
className='btn-unstyled d-flex align-items-center justify-content-between' | ||
> | ||
Network Details | ||
<CollapsibleArrows expanded={open} className='ms-2' /> | ||
</button> | ||
<Collapse | ||
in={open} | ||
onEntered={() => { | ||
scrollToElement('.custom-network-details', 50); | ||
}} | ||
> | ||
<div id='custom-network-details' className='mx-n2'> | ||
<div className='bg-neutral-850 rounded d-flex flex-column gap-2 mt-2 p-2'> | ||
{!isSavedCustomNetworkActive && ( | ||
<> | ||
<div>Saved Custom Network Config</div> | ||
<NetworkDetail | ||
title='Active' | ||
description={<code className='text-warning'>false</code>} | ||
/> | ||
</> | ||
)} | ||
{existingCustomNetwork.name && ( | ||
<NetworkDetail | ||
title='Name' | ||
description={existingCustomNetwork.name} | ||
/> | ||
)} | ||
{existingCustomNetwork.apiAddress && ( | ||
<NetworkDetail | ||
title='API Address' | ||
description={ | ||
<div className='bg-neutral-950 rounded p-1'> | ||
<code>{existingCustomNetwork.apiAddress}</code>{' '} | ||
<CopyButton | ||
text={existingCustomNetwork.apiAddress} | ||
className='copy-button' | ||
/> | ||
</div> | ||
} | ||
/> | ||
)} | ||
{existingCustomNetwork.chainId && ( | ||
<NetworkDetail | ||
title='Chain Id' | ||
description={ | ||
<span className='badge badge-sm'> | ||
{existingCustomNetwork.chainId} | ||
</span> | ||
} | ||
/> | ||
)} | ||
{existingCustomNetwork.egldLabel && ( | ||
<NetworkDetail | ||
title='Default Token Label' | ||
description={existingCustomNetwork.egldLabel} | ||
/> | ||
)} | ||
<div className='d-flex gap-3 align-items-center'> | ||
{!isSavedCustomNetworkActive && ( | ||
<button | ||
type='button' | ||
onClick={(e) => { | ||
e.preventDefault(); | ||
applyNetwork(); | ||
}} | ||
className='btn btn-sm btn-primary align-items-center justify-content-center d-flex flex-grow-1' | ||
> | ||
<FontAwesomeIcon icon={faCheck} className='me-2' /> | ||
Apply | ||
</button> | ||
)} | ||
<button | ||
type='button' | ||
onClick={(e) => { | ||
e.preventDefault(); | ||
removeNetwork(); | ||
}} | ||
className='btn btn-sm btn-dark-alt align-items-center justify-content-center d-flex flex-grow-1' | ||
> | ||
<FontAwesomeIcon icon={faTrash} className='me-2' /> | ||
Remove | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
</Collapse> | ||
</div> | ||
); | ||
}; |
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,100 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; | ||
import classNames from 'classnames'; | ||
import { useSelector } from 'react-redux'; | ||
|
||
import { networks } from 'config'; | ||
import { useCustomNetwork } from 'hooks'; | ||
import { faCircleNotch } from 'icons/regular'; | ||
import { faCheck } from 'icons/solid'; | ||
import { activeNetworkSelector } from 'redux/selectors'; | ||
import { WithClassnameType } from 'types'; | ||
|
||
export const CustomNetworkInput = ({ className }: WithClassnameType) => { | ||
const activeNetwork = useSelector(activeNetworkSelector); | ||
const { isCustom: activeNetworkIsCustom } = activeNetwork; | ||
|
||
const configCustomNetwork = networks.filter((network) => network.isCustom)[0]; | ||
const existingCustomNetwork = activeNetworkIsCustom | ||
? activeNetwork | ||
: configCustomNetwork; | ||
|
||
const [customNetworkUrl, setcustomNetworkUrl] = useState<string>( | ||
existingCustomNetwork?.apiAddress ?? '' | ||
); | ||
const [generalError, setGeneralError] = useState(''); | ||
const { setCustomNetwork, isSaving, errors } = | ||
useCustomNetwork(customNetworkUrl); | ||
|
||
const handleKeyDown = (e: React.KeyboardEvent) => { | ||
if (e.key === 'Enter') { | ||
e.preventDefault(); | ||
setCustomNetwork(); | ||
} | ||
}; | ||
|
||
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
setGeneralError(''); | ||
setcustomNetworkUrl(e.target.value); | ||
}; | ||
|
||
useEffect(() => { | ||
if (errors?.apiAddress) { | ||
setGeneralError(errors.apiAddress); | ||
} | ||
}, [errors]); | ||
|
||
return ( | ||
<form | ||
className={classNames( | ||
'custom-network-input input-group-black w-100 d-flex', | ||
className | ||
)} | ||
> | ||
<div className='input-group input-group-sm input-group-seamless has-validation'> | ||
<input | ||
type='text' | ||
className='form-control text-truncate' | ||
placeholder='API Address' | ||
name='requestType' | ||
data-testid='customNetwork' | ||
required | ||
value={customNetworkUrl} | ||
onChange={handleChange} | ||
onKeyDown={handleKeyDown} | ||
disabled={isSaving} | ||
aria-label='API Address' | ||
aria-describedby='customNetwork-addon' | ||
/> | ||
<button | ||
type='submit' | ||
className='input-group-text' | ||
onClick={(e) => { | ||
e.preventDefault(); | ||
setCustomNetwork(); | ||
}} | ||
data-testid='customNetworkButton' | ||
aria-label='customNetwork' | ||
> | ||
{isSaving ? ( | ||
<FontAwesomeIcon | ||
icon={faCircleNotch} | ||
spin | ||
className='me-1 text-primary' | ||
/> | ||
) : ( | ||
<FontAwesomeIcon | ||
icon={faCheck} | ||
className={classNames('me-1', { | ||
'text-primary': activeNetworkIsCustom | ||
})} | ||
/> | ||
)} | ||
</button> | ||
{generalError && ( | ||
<div className='invalid-feedback d-block'>{generalError}</div> | ||
)} | ||
</div> | ||
</form> | ||
); | ||
}; |
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,25 @@ | ||
import { forwardRef } from 'react'; | ||
import classNames from 'classnames'; | ||
import { Dropdown } from 'react-bootstrap'; | ||
|
||
import { CustomNetworkInput, CustomNetworkDetails } from 'components'; | ||
|
||
export const CustomNetworkMenu = forwardRef( | ||
({ children, className, style }: any, ref: any) => { | ||
return ( | ||
<div | ||
ref={ref} | ||
className={classNames('custom-network-menu', className)} | ||
style={style} | ||
> | ||
{children} | ||
<Dropdown.Divider /> | ||
<div className='d-flex flex-column gap-2 px-3 pb-2'> | ||
Custom Network API Address | ||
<CustomNetworkInput /> | ||
<CustomNetworkDetails /> | ||
</div> | ||
</div> | ||
); | ||
} | ||
); |
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,9 @@ | ||
.custom-network-menu { | ||
width: 15rem; | ||
--dropdown-divider-bg: var(--neutral-700); | ||
.input-group-seamless { | ||
.form-control { | ||
padding-right: 2.5rem; | ||
} | ||
} | ||
} |
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 @@ | ||
export * from './CustomNetworkDetails'; | ||
export * from './CustomNetworkInput'; | ||
export * from './CustomNetworkMenu'; |
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.