Skip to content

Commit

Permalink
fix: backup atKeys
Browse files Browse the repository at this point in the history
  • Loading branch information
XavierChanth committed Nov 22, 2024
1 parent 67a603f commit ba838e3
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
35 changes: 34 additions & 1 deletion packages/dart/npt_flutter/lib/widgets/custom_text_button.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import 'dart:convert';
import 'dart:io';
import 'dart:typed_data';

import 'package:at_backupkey_flutter/services/backupkey_service.dart';
import 'package:at_contacts_flutter/services/contact_service.dart';
import 'package:at_onboarding_flutter/at_onboarding_flutter.dart';
import 'package:at_onboarding_flutter/at_onboarding_services.dart';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
Expand Down Expand Up @@ -123,7 +129,34 @@ class CustomTextButton extends StatelessWidget {
// break;
case CustomListTileType.backupYourKey:
if (context.mounted) {
BackupKeyWidget(atsign: ContactService().currentAtsign).showBackupDialog(context);
var atsign = context.read<OnboardingCubit>().getAtSign();
// Build file data
var aesEncryptedKeys = await BackUpKeyService.getEncryptedKeys(atsign);
var keyString = jsonEncode(aesEncryptedKeys);
final List<int> codeUnits = keyString.codeUnits;
final Uint8List data = Uint8List.fromList(codeUnits);

// Get file path to write to
String? outputFile = await FilePicker.platform.saveFile(
dialogTitle: 'Please select a file to export to:',
fileName: '${atsign}_key.atKeys',
);
if (outputFile == null) return;
// Create and write the file
try {
var f = File(outputFile);
await f.create(recursive: true);
await f.writeAsBytes(data);
} catch (e) {
if (!context.mounted) return;
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
backgroundColor: Colors.red,
// TODO localize
content: Text("Failed to save the atKeys file: $e"),
),
);
}
}
break;
case CustomListTileType.resetAtsign:
Expand Down
6 changes: 3 additions & 3 deletions packages/dart/npt_flutter/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ packages:
source: hosted
version: "2.0.7"
at_backupkey_flutter:
dependency: transitive
dependency: "direct main"
description:
name: at_backupkey_flutter
sha256: "91425f34aabec7fc37f61259af690676aae6c1776c2feac7bfea5f7ea7fc3812"
sha256: "674d5ebf8443e0848c86cd14e25c326e33d7fef54a2a9732c4328a138f6c4fa5"
url: "https://pub.dev"
source: hosted
version: "4.0.15"
version: "4.0.16"
at_base2e15:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions packages/dart/npt_flutter/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ environment:
dependencies:
adaptive_theme: ^3.6.0
at_auth: ^2.0.7
at_backupkey_flutter: ^4.0.16
at_client_mobile: ^3.2.18
at_contact: ^3.0.8
at_contacts_flutter: ^4.0.15
Expand Down

0 comments on commit ba838e3

Please sign in to comment.