react-native-ldk
react-native-ldk copied to clipboard
Native wipeLdkStorage call
Right now we are using custom function that cleans ldk storage in bitkit:
export const wipeLdkStorage = async ({
selectedWallet = getSelectedWallet(),
selectedNetwork = getSelectedNetwork(),
}: {
selectedWallet?: TWalletName;
selectedNetwork?: EAvailableNetwork;
}): Promise<Result<string>> => {
await ldk.stop();
const path = `${RNFS.DocumentDirectoryPath}/ldk/${lm.account.name}`;
const deleteAllFiles = async (dirpath: string): Promise<void> => {
const items = await RNFS.readDir(dirpath);
for (const item of items) {
if (item.isFile()) {
await RNFS.unlink(item.path);
} else {
await deleteAllFiles(item.path);
}
}
};
try {
// delete all files in the directory
// NOTE: this is a workaround for RNFS.unlink(folder) freezing the app
await deleteAllFiles(path);
} catch (e) {
return err(e);
}
return ok(`${selectedNetwork}'s LDK directory wiped for ${selectedWallet}`);
};
I think we should move this logic to native Kotlin/Swift code to make it more robust and handle corner cases, like LDK being running.