-
Notifications
You must be signed in to change notification settings - Fork 5
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 #12 from Giveth/9-add-dropdown-menu
add dropdown menu
- Loading branch information
Showing
14 changed files
with
248 additions
and
61 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
import React from 'react'; | ||
import styled from 'styled-components'; | ||
import { NETWORK_IDS } from '../lib/constants'; | ||
|
||
export const isDevelopment = process.env.NEXT_PUBLIC_ENV === 'development'; | ||
|
||
interface NetworkSelectProps { | ||
selectedNetwork?: number; | ||
onNetworkChange: (event: React.ChangeEvent<HTMLSelectElement>) => void; | ||
} | ||
|
||
function getCorrectNetworkIdBasedOnEnv(networkId: number) { | ||
switch (networkId) { | ||
case NETWORK_IDS.ARBITRUM_MAINNET: | ||
return isDevelopment | ||
? NETWORK_IDS.ARBITRUM_SEPOLIA | ||
: NETWORK_IDS.ARBITRUM_MAINNET; | ||
case NETWORK_IDS.OPTIMISTIC: | ||
return isDevelopment | ||
? NETWORK_IDS.OPTIMISM_SEPOLIA | ||
: NETWORK_IDS.OPTIMISTIC; | ||
case NETWORK_IDS.BASE_MAINNET: | ||
return isDevelopment | ||
? NETWORK_IDS.BASE_SEPOLIA | ||
: NETWORK_IDS.BASE_MAINNET; | ||
case NETWORK_IDS.ZKEVM_MAINNET: | ||
return isDevelopment | ||
? NETWORK_IDS.ZKEVM_CARDONA | ||
: NETWORK_IDS.ZKEVM_MAINNET; | ||
case NETWORK_IDS.CELO: | ||
return isDevelopment | ||
? NETWORK_IDS.CELO_ALFAJORES | ||
: NETWORK_IDS.CELO; | ||
case NETWORK_IDS.SOLANA_MAINNET: | ||
return isDevelopment | ||
? NETWORK_IDS.SOLANA_TESTNET | ||
: NETWORK_IDS.SOLANA_MAINNET; | ||
case NETWORK_IDS.ETC: | ||
return isDevelopment | ||
? NETWORK_IDS.MORDOR_ETC_TESTNET | ||
: NETWORK_IDS.ETC; | ||
default: | ||
return networkId; | ||
} | ||
} | ||
|
||
const NetworkSelect: React.FC<NetworkSelectProps> = ({ | ||
selectedNetwork, | ||
onNetworkChange, | ||
}) => { | ||
return ( | ||
<> | ||
<label>Select Network: </label> | ||
<SelectStyled | ||
id='network-select' | ||
value={selectedNetwork !== undefined ? selectedNetwork : ''} | ||
onChange={onNetworkChange} | ||
> | ||
<option value=''>All Networks</option> | ||
<option | ||
value={getCorrectNetworkIdBasedOnEnv(NETWORK_IDS.MAIN_NET)} | ||
> | ||
Mainnet | ||
</option> | ||
<option value={getCorrectNetworkIdBasedOnEnv(NETWORK_IDS.XDAI)}> | ||
Gnosis Chain | ||
</option> | ||
<option | ||
value={getCorrectNetworkIdBasedOnEnv( | ||
NETWORK_IDS.OPTIMISTIC, | ||
)} | ||
> | ||
Optimism | ||
</option> | ||
<option | ||
value={getCorrectNetworkIdBasedOnEnv(NETWORK_IDS.POLYGON)} | ||
> | ||
Polygon | ||
</option> | ||
<option | ||
value={getCorrectNetworkIdBasedOnEnv( | ||
NETWORK_IDS.ZKEVM_MAINNET, | ||
)} | ||
> | ||
Polygon zkEVM | ||
</option> | ||
<option value={getCorrectNetworkIdBasedOnEnv(NETWORK_IDS.ETC)}> | ||
Ethereum Classic | ||
</option> | ||
<option | ||
value={getCorrectNetworkIdBasedOnEnv( | ||
NETWORK_IDS.SOLANA_MAINNET, | ||
)} | ||
> | ||
Solana | ||
</option> | ||
<option | ||
value={getCorrectNetworkIdBasedOnEnv( | ||
NETWORK_IDS.ARBITRUM_MAINNET, | ||
)} | ||
> | ||
Arbitrum | ||
</option> | ||
<option | ||
value={getCorrectNetworkIdBasedOnEnv( | ||
NETWORK_IDS.BASE_MAINNET, | ||
)} | ||
> | ||
Base | ||
</option> | ||
<option value={getCorrectNetworkIdBasedOnEnv(NETWORK_IDS.CELO)}> | ||
Celo | ||
</option> | ||
</SelectStyled> | ||
</> | ||
); | ||
}; | ||
|
||
const SelectStyled = styled.select` | ||
padding: 10px; | ||
font-size: 16px; | ||
border: 1px solid #ccc; | ||
border-radius: 4px; | ||
background-color: #fff; | ||
color: #333; | ||
margin-right: 10px; | ||
&:focus { | ||
border-color: #007bff; | ||
box-shadow: 0 0 5px rgba(0, 123, 255, 0.5); | ||
outline: none; | ||
} | ||
`; | ||
|
||
export default NetworkSelect; |
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
Oops, something went wrong.