React Native IndySdk在尝试导入时出现原因错误此名称的Wallet已经存在原因:Wallet数据库文件已经存在

67up9zun  于 6个月前  发布在  React
关注(0)|答案(1)|浏览(60)
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导入过程中出错:{“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”:“WalletAlreadyError”,“message”:“WalletAlreadyError”,“name”:“IndyError”}
导出是工作和文件被选择用于导入.它提到不能使用回钱包,但从我测试的lissi应用程序导入备份文件是使用相同的钱包和添加备份数据.为什么我不能使用回我的钱包“sainopal钱包”和导入indy导出的文件?

dbf7pr2w

dbf7pr2w1#

const configNew: InitConfig = {
    label: "SainoPal Mobile Wallet",
    walletConfig: {
      id: "wa",
      key: "testkey0090000000000000000000001",
    },
    logger: new ConsoleLogger(LogLevel.trace),
  }

  const walletConfig: WalletConfig = configNew.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)

  console.log("localFilePath  ", localFilePath)

  // Delete existing wallet if it exists
  if (walletExists) {
    await RNFS.unlink(existingWalletPath)
    console.log("Deleted existing wallet:", walletName)
  }

  await IndySdk.importWallet(walletConfig, walletCredentials, {
    path: localFilePath,
    key: "123456",
  })

字符串
问题:我用我自己的钱包进口。
解决方法:创建另一个不同id“wa”导入。2然后登录不同id“wa”帐户才有效。

相关问题