-
Notifications
You must be signed in to change notification settings - Fork 345
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
33 additions
and
63 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
11 changes: 2 additions & 9 deletions
11
apps/ledger-live-mobile/src/newArch/features/Web3Hub/constants.ts
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,4 @@ | ||
import type { Web3HubDB } from "./types"; | ||
|
||
export const URL_ORIGIN = "https://live-app-catalog.ledger.com"; | ||
|
||
export const WEB3HUB_STORE_KEY = "web3hub"; | ||
|
||
export const INITIAL_WEB3HUB_STATE: Web3HubDB = { | ||
recentlyUsed: [], | ||
dismissedManifests: {}, | ||
// localLiveApp: [], | ||
}; | ||
export const RECENTLY_USED_KEY = "WEB3HUB_RECENTLY_USED"; | ||
export const DISSMISSED_MANIFETS_KEY = "WEB3HUB_DISSMISSED_MANIFETS"; |
39 changes: 9 additions & 30 deletions
39
apps/ledger-live-mobile/src/newArch/features/Web3Hub/db.ts
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,36 +1,15 @@ | ||
import AsyncStorage from "@react-native-async-storage/async-storage"; | ||
import { useAtom } from "jotai"; | ||
import { createJSONStorage } from "jotai/utils"; | ||
import { useCallback, useMemo } from "react"; | ||
import { Web3HubDB } from "LLM/features/Web3Hub/types"; | ||
import { atomWithStorage } from "jotai/utils"; | ||
import { INITIAL_WEB3HUB_STATE, WEB3HUB_STORE_KEY } from "./constants"; | ||
import { atomWithStorage, createJSONStorage } from "jotai/utils"; | ||
import { DISSMISSED_MANIFETS_KEY, RECENTLY_USED_KEY } from "./constants"; | ||
|
||
export const storage = createJSONStorage<Web3HubDB>(() => AsyncStorage); | ||
const emptyRecentlyUsed: Web3HubDB["recentlyUsed"] = []; | ||
export const recentlyUseAtom = storedAtom(RECENTLY_USED_KEY, emptyRecentlyUsed); | ||
|
||
export const web3hubAtom = atomWithStorage<Web3HubDB>( | ||
WEB3HUB_STORE_KEY, | ||
INITIAL_WEB3HUB_STATE, | ||
storage, | ||
); | ||
const emptyDismissedManifests: Web3HubDB["dismissedManifests"] = {}; | ||
export const dismissedManifestsAtom = storedAtom(DISSMISSED_MANIFETS_KEY, emptyDismissedManifests); | ||
|
||
type NewState = Web3HubDB | ((s: Web3HubDB) => Web3HubDB); | ||
|
||
export function useWeb3HubDB<Selected>( | ||
selector: (state: Web3HubDB) => Selected, | ||
): [Selected, (v: NewState) => void] { | ||
const [state, setState] = useAtom(web3hubAtom); | ||
|
||
const setter = useCallback( | ||
(newState: NewState) => { | ||
const val = typeof newState === "function" ? newState(state) : newState; | ||
|
||
setState(val); | ||
}, | ||
// eslint-disable-next-line | ||
[state], | ||
); | ||
|
||
const result = useMemo(() => selector(state), [state, selector]); | ||
return [result, setter]; | ||
export function storedAtom<T = unknown>(key: string, defaultValue: T) { | ||
const storage = createJSONStorage<T>(() => AsyncStorage); | ||
return atomWithStorage<T>(key, defaultValue, storage); | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.