-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* show/hide networks * rewards feedback * remove deposited/withdrawn --------- Co-authored-by: jmzwar <[email protected]>
- Loading branch information
Showing
8 changed files
with
110 additions
and
59 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './useLocalStorage'; |
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,36 @@ | ||
import { useState } from 'react'; | ||
|
||
export const set = (key: string, value: any) => { | ||
if (typeof window !== 'undefined') { | ||
window.localStorage.setItem(key, JSON.stringify(value)); | ||
} | ||
}; | ||
|
||
export function get<T>(key: string): T | null { | ||
if (typeof window !== 'undefined') { | ||
const item = window.localStorage.getItem(key); | ||
try { | ||
if (item != null) { | ||
return JSON.parse(item); | ||
} | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
export function useLocalStorage<T>(key: string, initialValue: T) { | ||
const [storedValue, setStoredValue] = useState<T>(() => { | ||
const item = get<T>(key); | ||
return item != null ? item : initialValue; | ||
}); | ||
|
||
const setValue = (value: T) => { | ||
const valueToStore = value instanceof Function ? value(storedValue) : value; | ||
setStoredValue(valueToStore); | ||
set(key, valueToStore); | ||
}; | ||
|
||
return [storedValue, setValue] as const; | ||
} |
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,3 @@ | ||
export const LOCAL_STORAGE_KEYS = { | ||
SHOW_TESTNETS: 'SHOW_TESTNETS', | ||
}; |
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