forked from BlueWallet/BlueWallet
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master'
- Loading branch information
Showing
20 changed files
with
235 additions
and
164 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
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
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,49 @@ | ||
import AsyncStorage from '@react-native-async-storage/async-storage'; | ||
import DefaultPreference from 'react-native-default-preference'; | ||
import { BlueApp } from '../class'; | ||
import { GROUP_IO_BLUEWALLET } from '../blue_modules/currency'; | ||
|
||
// Function to get the value from DefaultPreference first, then fallback to AsyncStorage | ||
// as DefaultPreference uses truly native storage. | ||
// If found in AsyncStorage, migrate it to DefaultPreference and remove it from AsyncStorage. | ||
export const getLNDHub = async (): Promise<string | undefined> => { | ||
try { | ||
await DefaultPreference.setName(GROUP_IO_BLUEWALLET); | ||
let value = await DefaultPreference.get(BlueApp.LNDHUB); | ||
|
||
// If not found, check AsyncStorage and migrate it to DefaultPreference | ||
if (!value) { | ||
value = await AsyncStorage.getItem(BlueApp.LNDHUB); | ||
|
||
if (value) { | ||
await DefaultPreference.set(BlueApp.LNDHUB, value); | ||
await AsyncStorage.removeItem(BlueApp.LNDHUB); | ||
console.log('Migrated LNDHub value from AsyncStorage to DefaultPreference'); | ||
} | ||
} | ||
|
||
return value ?? undefined; | ||
} catch (error) { | ||
console.error('Error getting LNDHub preference:', (error as Error).message); | ||
return undefined; | ||
} | ||
}; | ||
|
||
export const setLNDHub = async (value: string): Promise<void> => { | ||
try { | ||
await DefaultPreference.setName(GROUP_IO_BLUEWALLET); | ||
await DefaultPreference.set(BlueApp.LNDHUB, value); | ||
} catch (error) { | ||
console.error('Error setting LNDHub preference:', error); | ||
} | ||
}; | ||
|
||
export const clearLNDHub = async (): Promise<void> => { | ||
try { | ||
await DefaultPreference.setName(GROUP_IO_BLUEWALLET); | ||
await DefaultPreference.clear(BlueApp.LNDHUB); | ||
await AsyncStorage.removeItem(BlueApp.LNDHUB); | ||
} catch (error) { | ||
console.error('Error clearing LNDHub preference:', error); | ||
} | ||
}; |
Oops, something went wrong.