type Props = StackScreenProps<WalletStackParamList, "SelfCredential">
const RecoverWallet = ({ navigation }: Props) => {
useLayoutEffect(() => {
navigation.setOptions({
title: "Recover Wallet",
})
}, [navigation])
const [importedFileName, setImportedFileName] = useState<string | null>(null)
const pickDocument = async () => {
try {
const response = await DocumentPicker.pick({
type: [DocumentPicker.types.allFiles],
copyTo: "documentDirectory", // Save the selected file to the app's document directory
})
const selectedFile = response[0] // Assume the user picked only one file
setImportedFileName(selectedFile.name)
console.log(`${selectedFile.name} file picked`)
handleImport(selectedFile)
} catch (err) {
if (!DocumentPicker.isCancel(err)) {
console.error("Error picking document:", err)
Alert.alert("Error", "An error occurred while picking the document.")
}
}
}
const handleImport = async (selectedFile: DocumentPickerResponse | null) => {
try {
if (!selectedFile) {
console.log("No file selected")
return
}
const uniqueIdentifier = `${Date.now()}_${Math.floor(
Math.random() * 1000
)}`
const walletName = `imported_wallet_${uniqueIdentifier}`
const localFilePath = `${RNFS.DocumentDirectoryPath}/${selectedFile.name}`
await RNFS.moveFile(selectedFile.uri, localFilePath)
const walletConfig: WalletConfig = config.walletConfig || {}
const walletCredentials = { key: walletConfig.key || "" }
// Check if the wallet already exists
const existingWalletPath = `${RNFS.DocumentDirectoryPath}/.indy_client/wallet/${walletName}`
const walletExists = await RNFS.exists(existingWalletPath)
// Delete existing wallet if it exists
if (walletExists) {
await RNFS.unlink(existingWalletPath)
console.log("Deleted existing wallet:", walletName)
}
// Import the wallet
await IndySdk.importWallet(walletConfig, walletCredentials, {
path: localFilePath,
key: walletName,
})
console.log("Imported Wallet Successfully")
Alert.alert("Success", "Wallet imported successfully!")
} catch (error) {
console.error("Error during import:", error)
Alert.alert("Error", "An error occurred during wallet import.")
}
}
ERROR Error during import: {"indyBacktrace": "", "indyCode": 203, "indyMessage": "Error: Wallet with this name already exists Caused by: Wallet database file already exists: "/storage/emulated/0/Android/data/com.anonymous.xpoafj/files/.indy_client/wallet/sainopal-wallet/sqlite.db" ", "indyName": "WalletAlreadyExistsError", "message": "WalletAlreadyExistsError", "name": "IndyError"}
the export is work and the file is selected for import. It mention cannot use back the wallet, but from what i tested the lissi app import backup file is using the same wallet and add on the backup data. Why is that I could not use back my wallet "sainopal-wallet" and import the indy exported file?
issus: I use back my own wallet to import.
solve: create another with different id "wa" for import. Then Login that different id "wa" account only work.