This repository has been archived by the owner on Jan 7, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1k
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 #204 from HaresMahmood/network-switcher-component
Add Network Switcher component.
- Loading branch information
Showing
6 changed files
with
73 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { FC } from 'react'; | ||
import dynamic from 'next/dynamic'; | ||
import { useNetworkConfiguration } from '../contexts/NetworkConfigurationProvider'; | ||
|
||
const NetworkSwitcher: FC = () => { | ||
const { networkConfiguration, setNetworkConfiguration } = useNetworkConfiguration(); | ||
|
||
console.log(networkConfiguration); | ||
|
||
return ( | ||
<label className="cursor-pointer label"> | ||
<a>Network</a> | ||
<select | ||
value={networkConfiguration} | ||
onChange={(e) => setNetworkConfiguration(e.target.value)} | ||
className="select max-w-xs" | ||
> | ||
<option value="mainnet-beta">main</option> | ||
<option value="devnet">dev</option> | ||
<option value="testnet">test</option> | ||
</select> | ||
</label> | ||
); | ||
}; | ||
|
||
export default dynamic(() => Promise.resolve(NetworkSwitcher), { | ||
ssr: false | ||
}) |
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,22 @@ | ||
import { useLocalStorage } from '@solana/wallet-adapter-react'; | ||
import { createContext, FC, ReactNode, useContext } from 'react'; | ||
|
||
|
||
export interface NetworkConfigurationState { | ||
networkConfiguration: string; | ||
setNetworkConfiguration(networkConfiguration: string): void; | ||
} | ||
|
||
export const NetworkConfigurationContext = createContext<NetworkConfigurationState>({} as NetworkConfigurationState); | ||
|
||
export function useNetworkConfiguration(): NetworkConfigurationState { | ||
return useContext(NetworkConfigurationContext); | ||
} | ||
|
||
export const NetworkConfigurationProvider: FC<{ children: ReactNode }> = ({ children }) => { | ||
const [networkConfiguration, setNetworkConfiguration] = useLocalStorage("network", "devnet"); | ||
|
||
return ( | ||
<NetworkConfigurationContext.Provider value={{ networkConfiguration, setNetworkConfiguration }}>{children}</NetworkConfigurationContext.Provider> | ||
); | ||
}; |