-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: local storage and query param chain
- Loading branch information
Showing
4 changed files
with
77 additions
and
37 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 |
---|---|---|
@@ -1,13 +1,40 @@ | ||
import React from "react"; | ||
|
||
export function MvxSolSwitch({ toggleState, setToggleState}: { toggleState: boolean, setToggleState: any }) { | ||
console.log(toggleState); | ||
return ( | ||
<label className="inline-flex items-center cursor-pointer m-3"> | ||
<span className="me-3 text-sm font-medium text-gray-900 dark:text-gray-300">MultiversX</span> | ||
<input type="checkbox" value="" className="sr-only peer" onChange={setToggleState}/> | ||
<div className="relative w-11 h-6 bg-gray-200 peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-blue-300 dark:peer-focus:ring-blue-800 rounded-full peer dark:bg-gray-700 peer-checked:after:translate-x-full rtl:peer-checked:after:-translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:start-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all dark:border-gray-600 peer-checked:bg-blue-600"></div> | ||
<span className="ms-3 text-sm font-medium text-gray-900 dark:text-gray-300">Solana</span> | ||
</label> | ||
import React, { useEffect } from "react"; | ||
import { useSearchParams } from "react-router-dom"; | ||
import { useLocalStorageStore } from "store/LocalStorageStore.ts"; | ||
|
||
export function MvxSolSwitch() { | ||
const [searchParams, setSearchParams] = useSearchParams(); | ||
|
||
const defaultChain = useLocalStorageStore((state) => state.defaultChain); | ||
const setDefaultChain = useLocalStorageStore((state) => state.setDefaultChain); | ||
|
||
function handleChainChange() { | ||
setDefaultChain(defaultChain === "solana" ? "multiversx" : "solana"); | ||
} | ||
|
||
useEffect(() => { | ||
const chainParam = searchParams.get("chain"); | ||
if (chainParam === "solana") { | ||
setDefaultChain("solana"); | ||
} else if (chainParam === "multiversx") { | ||
setDefaultChain("multiversx"); | ||
} | ||
}, []); | ||
|
||
return ( | ||
<label className="inline-flex items-center cursor-pointer m-3"> | ||
<span className="me-3 text-xl font-medium text-gray-900 dark:text-gray-300">MultiversX</span> | ||
<input | ||
type="checkbox" | ||
checked={defaultChain === "solana" ? true : false} | ||
value="" | ||
className="sr-only peer" | ||
onChange={() => { | ||
handleChainChange(); | ||
}} | ||
/> | ||
<div className="relative w-11 h-6 bg-gray-200 peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-blue-300 dark:peer-focus:ring-blue-800 rounded-full peer dark:bg-gray-700 peer-checked:after:translate-x-full rtl:peer-checked:after:-translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:start-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all dark:border-gray-600 peer-checked:bg-blue-600"></div> | ||
<span className="ms-3 text-xl font-medium text-gray-900 dark:text-gray-300">Solana</span> | ||
</label> | ||
); | ||
} |
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 |
---|---|---|
@@ -1,11 +1,18 @@ | ||
import { create } from "zustand"; | ||
|
||
interface LocalStorageStore { | ||
appVersion: string | undefined; | ||
setAppVersion: (newAppVersion: string | undefined) => void; | ||
} | ||
|
||
export const useLocalStorageStore = create<LocalStorageStore>((set) => ({ | ||
appVersion: import.meta.env.VITE_APP_VERSION, | ||
setAppVersion: (newAppVersion) => set({ appVersion: newAppVersion }), | ||
})); | ||
import { create } from "zustand"; | ||
|
||
interface LocalStorageStore { | ||
appVersion: string | undefined; | ||
setAppVersion: (newAppVersion: string | undefined) => void; | ||
defaultChain: string; | ||
setDefaultChain: (newDefaultChain: string) => void; | ||
} | ||
|
||
export const useLocalStorageStore = create<LocalStorageStore>((set) => ({ | ||
appVersion: import.meta.env.VITE_APP_VERSION, | ||
setAppVersion: (newAppVersion) => set({ appVersion: newAppVersion }), | ||
defaultChain: localStorage.getItem("defaultChain") ?? "multiversx", | ||
setDefaultChain: (newDefaultChain) => { | ||
localStorage.setItem("defaultChain", newDefaultChain); | ||
set({ defaultChain: newDefaultChain }); | ||
}, | ||
})); |