react-native-ldk icon indicating copy to clipboard operation
react-native-ldk copied to clipboard

Native wipeLdkStorage call

Open limpbrains opened this issue 7 months ago • 1 comments

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.

limpbrains avatar Jul 12 '24 11:07 limpbrains