@bsv/expo-wallet-toolbox 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/core/walletDbRegistry.ts +18 -4
- package/package.json +1 -1
package/core/walletDbRegistry.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import AsyncStorage from '@react-native-async-storage/async-storage'
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* Wallet database filename registry.
|
|
5
3
|
*
|
|
@@ -81,6 +79,22 @@ export function selectLatestDb(filenames: string[]): string {
|
|
|
81
79
|
|
|
82
80
|
// ── AsyncStorage-backed registry ────────────────────────────────────────────
|
|
83
81
|
|
|
82
|
+
// Required lazily, on first call, rather than imported statically — this
|
|
83
|
+
// file is barrel-exported from the package root, and a static top-level
|
|
84
|
+
// `import` of a native module gets eagerly evaluated for every consumer of
|
|
85
|
+
// the barrel, which breaks a plain `jest` host that never touches the
|
|
86
|
+
// registry (no native module to resolve). Same class of issue documented on
|
|
87
|
+
// useHaptics.ts and services/vault/driver.ts/random.ts's lazy requires.
|
|
88
|
+
type AsyncStorageModule = typeof import('@react-native-async-storage/async-storage')['default']
|
|
89
|
+
let asyncStorage: AsyncStorageModule | undefined
|
|
90
|
+
function getAsyncStorage(): AsyncStorageModule {
|
|
91
|
+
if (!asyncStorage) {
|
|
92
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
93
|
+
asyncStorage = require('@react-native-async-storage/async-storage').default as AsyncStorageModule
|
|
94
|
+
}
|
|
95
|
+
return asyncStorage
|
|
96
|
+
}
|
|
97
|
+
|
|
84
98
|
function registryKey(keySuffix: string, chain: string): string {
|
|
85
99
|
return `walletDbs-${keySuffix}-${chain}net`
|
|
86
100
|
}
|
|
@@ -89,7 +103,7 @@ function registryKey(keySuffix: string, chain: string): string {
|
|
|
89
103
|
* Return all registered wallet DB filenames for the given identity + chain.
|
|
90
104
|
*/
|
|
91
105
|
export async function getRegisteredDbs(keySuffix: string, chain: string): Promise<string[]> {
|
|
92
|
-
const raw = await
|
|
106
|
+
const raw = await getAsyncStorage().getItem(registryKey(keySuffix, chain))
|
|
93
107
|
if (!raw) return []
|
|
94
108
|
try {
|
|
95
109
|
const arr = JSON.parse(raw)
|
|
@@ -106,5 +120,5 @@ export async function registerDb(keySuffix: string, chain: string, filename: str
|
|
|
106
120
|
const existing = await getRegisteredDbs(keySuffix, chain)
|
|
107
121
|
if (existing.includes(filename)) return
|
|
108
122
|
existing.push(filename)
|
|
109
|
-
await
|
|
123
|
+
await getAsyncStorage().setItem(registryKey(keySuffix, chain), JSON.stringify(existing))
|
|
110
124
|
}
|
package/package.json
CHANGED