diff --git a/lib/encrypt/crypter.dart b/lib/encrypt/crypter.dart index 2df9f8b6..91d4f0c9 100644 --- a/lib/encrypt/crypter.dart +++ b/lib/encrypt/crypter.dart @@ -1,7 +1,7 @@ +import 'dart:convert'; import 'dart:math'; import 'dart:typed_data'; -import '../utils.dart'; import 'aes/aes_cbcpkcs7.dart'; import 'kdf/kdf.dart'; import 'kdf/sha256_kdf.dart'; @@ -11,16 +11,9 @@ import 'model/keyiv.dart'; class NanoCrypt { /// Decrypts a value with a password using AES/CBC/PKCS7 /// KDF is Sha256KDF if not specified - static Uint8List decrypt(dynamic value, String password, {KDF? kdf}) { + static Uint8List decrypt(Uint8List value, String password, {KDF? kdf}) { kdf = kdf ?? Sha256KDF(); - Uint8List valBytes; - if (value is String) { - valBytes = hexToBytes(value); - } else if (value is Uint8List) { - valBytes = value; - } else { - throw Exception('Value should be a string or a byte array'); - } + Uint8List valBytes = Uint8List.fromList(value); Uint8List salt = valBytes.sublist(8, 16); KeyIV key = kdf.deriveKey(password, salt: salt); @@ -35,20 +28,13 @@ class NanoCrypt { /// KDF is Sha256KDF if not specified static Uint8List encrypt(dynamic value, String password, {KDF? kdf}) { kdf = kdf ?? Sha256KDF(); - Uint8List valBytes; - if (value is String) { - valBytes = hexToBytes(value); - } else if (value is Uint8List) { - valBytes = value; - } else { - throw Exception('Seed should be a string or uint8list'); - } + Uint8List valBytes = Uint8List.fromList(value); // Generate a random salt Uint8List salt = Uint8List(8); Random rng = Random.secure(); for (int i = 0; i < 8; i++) { - salt[i] = rng.nextInt(255); + salt[i] = rng.nextInt(256); } KeyIV keyInfo = kdf.deriveKey(password, salt: salt); @@ -56,7 +42,6 @@ class NanoCrypt { Uint8List seedEncrypted = AesCbcPkcs7.encrypt(valBytes, key: keyInfo.key, iv: keyInfo.iv); - return Uint8List.fromList( - stringToBytesUtf8("Salted__") + salt + seedEncrypted); + return Uint8List.fromList(utf8.encode('Salted__') + salt + seedEncrypted); } } diff --git a/lib/encrypt/kdf/pbkdf2_kdf.dart b/lib/encrypt/kdf/pbkdf2_kdf.dart index 7bc2d9df..f8c482d5 100644 --- a/lib/encrypt/kdf/pbkdf2_kdf.dart +++ b/lib/encrypt/kdf/pbkdf2_kdf.dart @@ -1,8 +1,8 @@ +import 'dart:convert'; import 'dart:typed_data'; import 'package:pointycastle/export.dart'; -import '../../utils.dart'; import '../model/keyiv.dart'; import 'kdf.dart'; @@ -12,7 +12,7 @@ class PBKDF2 extends KDF { /// Expects password to be a utf-8 string /// If salt is not provided, a random 8-byte one will be generated KeyIV deriveKey(String password, {Uint8List? salt}) { - Uint8List pwBytes = stringToBytesUtf8(password); + Uint8List pwBytes = utf8.encode(password); Uint8List saltBytes = salt == null ? Uint8List(1) : salt; // Use pbkdf2 from pointycastle diff --git a/lib/encrypt/kdf/sha256_kdf.dart b/lib/encrypt/kdf/sha256_kdf.dart index 8cb528c0..11877bfe 100644 --- a/lib/encrypt/kdf/sha256_kdf.dart +++ b/lib/encrypt/kdf/sha256_kdf.dart @@ -1,6 +1,6 @@ +import 'dart:convert'; import 'dart:typed_data'; -import '../../utils.dart'; import '../model/keyiv.dart'; import '../sha.dart'; import 'kdf.dart'; @@ -12,7 +12,7 @@ import 'kdf.dart'; class Sha256KDF extends KDF { /// Gets the key and iv KeyIV deriveKey(String password, {Uint8List? salt}) { - Uint8List pwBytes = stringToBytesUtf8(password); + Uint8List pwBytes = utf8.encode(password); Uint8List saltBytes = salt == null ? Uint8List(1) : salt; // Key = sha256 (password + salt); diff --git a/lib/transfer/transfer_complete_sheet.dart b/lib/transfer/transfer_complete_sheet.dart deleted file mode 100644 index 6bb549e9..00000000 --- a/lib/transfer/transfer_complete_sheet.dart +++ /dev/null @@ -1,86 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import '../app_icons.dart'; -import '../app_providers.dart'; -import '../l10n/l10n.dart'; -import '../widgets/buttons/success_outline_button.dart'; - -class TransferCompleteSheet extends ConsumerWidget { - final String transferAmount; - const TransferCompleteSheet({ - Key? key, - required this.transferAmount, - }) : super(key: key); - - @override - Widget build(BuildContext context, WidgetRef ref) { - final theme = ref.watch(themeProvider); - final styles = ref.watch(stylesProvider); - final l10n = l10nOf(context); - - return SafeArea( - minimum: EdgeInsets.only( - bottom: MediaQuery.of(context).size.height * 0.035, - ), - child: Container( - width: double.infinity, - child: Column( - mainAxisSize: MainAxisSize.max, - children: [ - //A container for the paragraph and seed - Expanded( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - // Success tick (icon) - Container( - margin: const EdgeInsets.only(bottom: 30), - child: Icon( - AppIcons.success, - size: 100, - color: theme.success, - ), - ), - Container( - margin: EdgeInsets.only(bottom: 20), - constraints: BoxConstraints( - maxHeight: MediaQuery.of(context).size.height * 0.2, - maxWidth: MediaQuery.of(context).size.width * 0.6, - ), - child: Stack( - children: [], - ), - ), - Container( - alignment: AlignmentDirectional(-1, 0), - margin: EdgeInsets.symmetric(horizontal: 60), - child: Text( - l10n.transferComplete(transferAmount), - style: styles.textStyleParagraphSuccess, - textAlign: TextAlign.start, - ), - ), - Container( - alignment: AlignmentDirectional(-1, 0), - margin: EdgeInsets.symmetric(horizontal: 60), - child: Text( - l10n.transferClose, - style: styles.textStyleParagraph, - textAlign: TextAlign.start, - ), - ), - ], - ), - ), - SuccessOutlineButton( - title: l10n.close.toUpperCase(), - margin: const EdgeInsets.only(left: 28, right: 28, top: 8), - onPressed: () => Navigator.of(context).pop(), - ), - ], - ), - ), - ); - } -} diff --git a/lib/transfer/transfer_confirm_sheet.dart b/lib/transfer/transfer_confirm_sheet.dart deleted file mode 100755 index 6083b9bd..00000000 --- a/lib/transfer/transfer_confirm_sheet.dart +++ /dev/null @@ -1,271 +0,0 @@ -import 'dart:async'; - -import 'package:auto_size_text/auto_size_text.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import '../app_providers.dart'; -import '../karlsen/karlsen.dart'; -import '../l10n/l10n.dart'; -import '../util/numberutil.dart'; -import '../widgets/buttons/primary_button.dart'; -import '../widgets/buttons/primary_outline_button.dart'; -import '../widgets/dialog.dart'; - -class AppTransferConfirmSheet extends StatefulWidget { - final Map? privKeyBalanceMap; - final Function? errorCallback; - - AppTransferConfirmSheet({ - this.privKeyBalanceMap, - this.errorCallback, - }) : super(); - - _AppTransferConfirmSheetState createState() => - _AppTransferConfirmSheetState(); -} - -class _AppTransferConfirmSheetState extends State { - // Total amount there is to transfer - BigInt totalToTransfer = BigInt.zero; - String totalAsReadableAmount = ''; - // Need to be received by current account - //PendingResponse? accountPending; - // Whether animation overlay is open - bool animationOpen = false; - - @override - void initState() { - super.initState(); - - // widget.privKeyBalanceMap! - // .forEach((account, accountBalanceItem) { - // totalToTransfer += BigInt.parse(accountBalanceItem.balance!) + - // BigInt.parse(accountBalanceItem.pending!); - // }); - totalAsReadableAmount = NumberUtil.getStringFromRaw( - totalToTransfer, - 8, - ); - } - - @override - Widget build(BuildContext context) { - return Consumer( - builder: (context, ref, _) { - final styles = ref.watch(stylesProvider); - final l10n = l10nOf(context); - - return SafeArea( - minimum: EdgeInsets.only( - bottom: MediaQuery.of(context).size.height * 0.035, - ), - child: Container( - width: double.infinity, - child: Column( - mainAxisSize: MainAxisSize.max, - children: [ - //A container for the header - Container( - margin: const EdgeInsets.only(top: 30, left: 70, right: 70), - child: AutoSizeText( - l10n.transferHeader, - style: styles.textStyleHeader(context), - textAlign: TextAlign.center, - maxLines: 2, - stepGranularity: 0.1, - ), - ), - // A container for the paragraphs - Expanded( - child: Container( - margin: EdgeInsets.only( - top: MediaQuery.of(context).size.height * 0.1), - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Container( - margin: EdgeInsets.symmetric(horizontal: 60), - child: Text( - l10n.transferConfirmInfo(totalAsReadableAmount), - style: styles.textStyleParagraphPrimary, - textAlign: TextAlign.start, - )), - Container( - margin: EdgeInsets.symmetric(horizontal: 60), - child: Text( - l10n.transferConfirmInfoSecond, - style: styles.textStyleParagraph, - textAlign: TextAlign.start, - )), - Container( - margin: EdgeInsets.symmetric(horizontal: 60), - child: Text( - l10n.transferConfirmInfoThird, - style: styles.textStyleParagraph, - textAlign: TextAlign.start, - )), - ], - ), - ), - ), - Padding( - padding: const EdgeInsets.symmetric(horizontal: 28), - child: Column( - children: [ - PrimaryButton( - title: l10n.confirm, - onPressed: () async { - final theme = ref.read(themeProvider); - animationOpen = true; - Navigator.of(context).push(AnimationLoadingOverlay( - AnimationType.TRANSFER_TRANSFERRING, - theme.animationOverlayStrong, - theme.animationOverlayMedium, - onPoppedCallback: () { - animationOpen = false; - })); - await processWallets(); - }, - ), - const SizedBox(height: 16), - PrimaryOutlineButton( - title: l10n.cancel, - onPressed: () => Navigator.of(context).pop(), - ), - ], - ), - ), - ], - ), - ), - ); - }, - ); - } - - // Future _getPrivKey(int index) async { - // //final appState = context.read(appStateProvider); - // final encryptedSecret = context.read(encryptedSecretProvider); - // final vault = context.read(vaultProvider); - // String? seed; - // if (encryptedSecret != null) { - // final sessionKey = await vault.getSessionKey(); - // seed = KarlsenUtil.decryptHex(encryptedSecret, sessionKey); - // } else { - // seed = await vault.getSeed(); - // } - // return KarlsenUtil.seedToPrivate(seed!, index); - // } - - Future processWallets() async { - //BigInt totalTransferred = BigInt.zero; - return; - // try { - // final accountService = context.read(accountServiceProvider); - // state.lockCallback(); - // for (String account in widget.privKeyBalanceMap!.keys) { - // final balanceItem = widget.privKeyBalanceMap![account]!; - // // Get frontiers first - // AccountInfoResponse resp = await accountService.getAccountInfo(account); - // if (!resp.unopened) { - // balanceItem.frontier = resp.frontier; - // } - // // Receive pending blocks - // PendingResponse pr = await accountService.getPending(account, 20); - // Map pendingBlocks = pr.blocks!; - // for (String hash in pendingBlocks.keys) { - // PendingResponseItem? item = pendingBlocks[hash]; - // if (balanceItem.frontier != null) { - // ProcessResponse resp = await accountService.requestReceive( - // balanceItem.frontier, - // item!.amount, - // hash, - // account, - // balanceItem.privKey); - // if (resp.hash != null) { - // balanceItem.frontier = resp.hash; - // totalTransferred += BigInt.parse(item.amount!); - // } - // } else { - // ProcessResponse resp = await accountService.requestOpen( - // item!.amount, hash, account, balanceItem.privKey); - // if (resp.hash != null) { - // balanceItem.frontier = resp.hash; - // totalTransferred += BigInt.parse(item.amount!); - // } - // } - // // Hack that waits for blocks to be confirmed - // await Future.delayed(const Duration(milliseconds: 300)); - // } - // // Process send from this account - // resp = await accountService.getAccountInfo(account); - // ProcessResponse sendResp = await accountService.requestSend( - // resp.frontier, - // resp.balance, - // state.wallet!.address, - // account, - // balanceItem.privKey, - // max: true); - // if (sendResp.hash != null) { - // totalTransferred += BigInt.parse(balanceItem.balance!); - // } - // } - // } catch (e) { - // if (animationOpen) { - // Navigator.of(context).pop(); - // } - // widget.errorCallback!(); - // context.read(loggerProvider).e("Error processing wallet", e); - // return; - // } finally { - // state.unlockCallback(); - // } - // try { - // final accountService = context.read(accountServiceProvider); - // state.lockCallback(); - // // Receive all new blocks to our own account - // PendingResponse pr = await accountService - // .getPending(state.wallet!.address, 20, includeActive: true); - // Map pendingBlocks = pr.blocks!; - // for (String hash in pendingBlocks.keys) { - // PendingResponseItem? item = pendingBlocks[hash]; - // if (state.wallet!.openBlock != null) { - // ProcessResponse resp = await accountService.requestReceive( - // state.wallet!.frontier, - // item!.amount, - // hash, - // state.wallet!.address, - // await _getPrivKey(state.selectedAccount.index)); - // if (resp.hash != null) { - // state.wallet!.frontier = resp.hash; - // } - // } else { - // ProcessResponse resp = await accountService.requestOpen( - // item!.amount, - // hash, - // state.wallet!.address, - // await _getPrivKey(state.selectedAccount.index), - // ); - // if (resp.hash != null) { - // state.wallet!.frontier = resp.hash; - // state.wallet!.openBlock = resp.hash; - // } - // } - // } - // state.requestUpdate(); - // } catch (e) { - // // Less-important error - // context.read(loggerProvider).e("Error processing wallet", e); - // } finally { - // state.unlockCallback(); - // } - // EventTaxiImpl.singleton() - // .fire(TransferCompleteEvent(amount: totalTransferred)); - // if (animationOpen) { - // Navigator.of(context).pop(); - // } - // Navigator.of(context).pop(); - } -} diff --git a/lib/transfer/transfer_manual_entry_sheet.dart b/lib/transfer/transfer_manual_entry_sheet.dart deleted file mode 100755 index 9ae1fdf2..00000000 --- a/lib/transfer/transfer_manual_entry_sheet.dart +++ /dev/null @@ -1,174 +0,0 @@ -import 'package:auto_size_text/auto_size_text.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import '../app_icons.dart'; -import '../app_providers.dart'; -import '../app_styles.dart'; -import '../l10n/l10n.dart'; -import '../util/formatters.dart'; -import '../util/karlsen_util.dart'; -import '../util/user_data_util.dart'; -import '../widgets/app_text_field.dart'; -import '../widgets/buttons/primary_button.dart'; -import '../widgets/buttons/primary_outline_button.dart'; -import '../widgets/tap_outside_unfocus.dart'; - -class TransferManualEntrySheet extends ConsumerStatefulWidget { - final Function? validSeedCallback; - - const TransferManualEntrySheet({ - Key? key, - this.validSeedCallback, - }) : super(key: key); - - _TransferManualEntrySheetState createState() => - _TransferManualEntrySheetState(); -} - -class _TransferManualEntrySheetState - extends ConsumerState { - final _seedInputFocusNode = FocusNode(); - final _seedInputController = TextEditingController(); - - bool seedIsValid = false; - bool hasError = false; - - @override - Widget build(BuildContext context) { - final theme = ref.watch(themeProvider); - final styles = ref.watch(stylesProvider); - final l10n = l10nOf(context); - - return TapOutsideUnfocus( - child: SafeArea( - minimum: EdgeInsets.only( - bottom: MediaQuery.of(context).size.height * 0.035, - ), - child: Column( - children: [ - Container( - margin: const EdgeInsets.only(top: 30, left: 70, right: 70), - child: AutoSizeText( - l10n.transferHeader, - style: styles.textStyleHeader(context), - textAlign: TextAlign.center, - maxLines: 2, - stepGranularity: 0.1, - ), - ), - Expanded( - child: Container( - margin: EdgeInsets.only( - top: MediaQuery.of(context).size.height * 0.05, - ), - child: Column(children: [ - Container( - margin: EdgeInsets.symmetric( - horizontal: 60, - vertical: 10, - ), - alignment: Alignment.centerLeft, - child: Text( - l10n.transferManualHint, - style: styles.textStyleParagraph, - textAlign: TextAlign.start, - ), - ), - Expanded( - child: Column(children: [ - AppTextField( - focusNode: _seedInputFocusNode, - controller: _seedInputController, - inputFormatters: [ - LengthLimitingTextInputFormatter(128), - LowerCaseTextFormatter(), - ], - textInputAction: TextInputAction.done, - maxLines: null, - autocorrect: false, - suffixButton: TextFieldButton( - icon: AppIcons.paste, - onPressed: () async { - String? data = await UserDataUtil.getClipboardText( - DataType.SEED); - if (data != null) { - if (mounted) { - _seedInputController.text = data; - setState(() => seedIsValid = true); - } - } else { - if (mounted) { - setState(() => seedIsValid = false); - } - } - }, - ), - fadeSuffixOnCondition: true, - suffixShowFirstCondition: - !KarlsenUtil.isValidSeed(_seedInputController.text), - keyboardType: TextInputType.text, - style: seedIsValid - ? styles.textStyleSeed - : styles.textStyleSeedGray, - onChanged: (text) { - // Always reset the error message to be less annoying - setState(() => hasError = false); - // If valid seed, clear focus/close keyboard - if (KarlsenUtil.isValidSeed(text) && mounted) { - _seedInputFocusNode.unfocus(); - setState(() => seedIsValid = true); - } else if (mounted) { - setState(() => seedIsValid = false); - } - }, - ), - Container( - margin: const EdgeInsets.only(top: 5), - child: Text( - l10n.seedInvalid, - style: TextStyle( - fontSize: 14.0, - color: - hasError ? theme.primary : Colors.transparent, - fontFamily: kDefaultFontFamily, - fontWeight: FontWeight.w600, - ), - ), - ), - ]), - ), - ]), - ), - ), - Padding( - padding: const EdgeInsets.symmetric(horizontal: 28), - child: Column(children: [ - PrimaryButton( - title: l10n.transfer, - onPressed: () { - final seed = _seedInputController.text; - if (KarlsenUtil.isValidSeed(seed) && - widget.validSeedCallback != null) { - widget.validSeedCallback!(seed); - } else if (mounted) { - setState(() => hasError = true); - } - }, - ), - const SizedBox(height: 16), - PrimaryOutlineButton( - title: l10n.cancel, - onPressed: () { - Navigator.of(context).pop(); - }, - ), - ]), - ), - ], - ), - ), - ); - } -} diff --git a/lib/transfer/transfer_overview_sheet.dart b/lib/transfer/transfer_overview_sheet.dart deleted file mode 100755 index ad79f54d..00000000 --- a/lib/transfer/transfer_overview_sheet.dart +++ /dev/null @@ -1,253 +0,0 @@ -import 'dart:async'; - -import 'package:auto_size_text/auto_size_text.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import '../app_providers.dart'; -import '../karlsen/karlsen.dart'; -import '../l10n/l10n.dart'; -import '../util/ui_util.dart'; -import '../util/user_data_util.dart'; -import '../widgets/buttons.dart'; -import '../widgets/dialog.dart'; -import '../widgets/sheet_handle.dart'; -import '../widgets/sheet_util.dart'; -import 'transfer_manual_entry_sheet.dart'; - -class TransferOverviewSheet extends ConsumerStatefulWidget { - const TransferOverviewSheet({Key? key}) : super(key: key); - - @override - _TransferOverviewSheetState createState() => _TransferOverviewSheetState(); -} - -class _TransferOverviewSheetState extends ConsumerState { - // Number of accounts to sweep from a seed - static const int NUM_SWEEP = 15; - // accounts to private keys/account balances - Map privKeyBalanceMap = Map(); - - bool _animationOpen = false; - - @override - Widget build(BuildContext context) { - //final theme = ref.watch(themeProvider); - final styles = ref.watch(stylesProvider); - final l10n = l10nOf(context); - - return SafeArea( - minimum: EdgeInsets.only( - bottom: MediaQuery.of(context).size.height * 0.035, - ), - child: Container( - width: double.infinity, - child: Column( - mainAxisSize: MainAxisSize.max, - children: [ - // A container for the header - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - const SizedBox(height: 60, width: 60), - Column( - children: [ - const SheetHandle(), - // The header - Container( - margin: EdgeInsets.only(top: 15), - constraints: BoxConstraints( - maxWidth: MediaQuery.of(context).size.width - 140), - child: AutoSizeText( - l10n.transferHeader, - style: styles.textStyleHeader(context), - textAlign: TextAlign.center, - maxLines: 2, - stepGranularity: 0.1, - ), - ), - ], - ), - // Emtpy SizedBox - const SizedBox(height: 60, width: 60), - ], - ), - // A container for the illustration and paragraphs - Expanded( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Container( - constraints: BoxConstraints( - maxHeight: MediaQuery.of(context).size.height * 0.2, - maxWidth: MediaQuery.of(context).size.width * 0.6, - ), - child: Stack( - children: [ - // Center( - // child: SvgPicture.asset( - // 'assets/transferfunds_illustration_start_paperwalletonly.svg', - // color: theme.text45, - // width: MediaQuery.of(context).size.width, - // ), - // ), - // Center( - // child: SvgPicture.asset( - // 'assets/transferfunds_illustration_start_natriumwalletonly.svg', - // color: theme.primary, - // width: MediaQuery.of(context).size.width, - // ), - // ), - ], - ), - ), - Container( - alignment: AlignmentDirectional(-1, 0), - margin: EdgeInsets.symmetric( - horizontal: 50, - vertical: 20, - ), - child: AutoSizeText( - l10n.transferIntro(l10n.scanQrCode), - style: styles.textStyleParagraph, - textAlign: TextAlign.start, - maxLines: 6, - stepGranularity: 0.5, - ), - ), - ], - ), - ), - Padding( - padding: const EdgeInsets.symmetric(horizontal: 28), - child: Column(children: [ - PrimaryButton( - title: l10n.scanQrCode, - onPressed: () async { - // UIUtil.cancelLockEvent(); - final result = await UserDataUtil.scanQrCode(context); - - if (result != null && result.isNotEmpty) { - final seed = result; - startTransfer(seed); - } else { - UIUtil.showSnackbar('Invalid QR code data', context); - } - }, - ), - const SizedBox(height: 16), - PrimaryOutlineButton( - title: l10n.manualEntry, - onPressed: () { - Sheets.showAppHeightNineSheet( - context: context, - widget: TransferManualEntrySheet( - validSeedCallback: manualEntryCallback, - ), - theme: ref.read(themeProvider), - ); - }, - ), - ]), - ), - ], - ), - ), - ); - } - - void manualEntryCallback(WidgetRef ref, String seed) { - Navigator.of(context).pop(); - startTransfer(seed, manualEntry: true); - } - - Future startTransfer( - String seed, { - bool manualEntry = false, - }) async { - final theme = ref.read(themeProvider); - final l10n = l10nOf(context); - - // Show loading overlay - _animationOpen = true; - AnimationType animation = manualEntry - ? AnimationType.TRANSFER_SEARCHING_MANUAL - : AnimationType.TRANSFER_SEARCHING_QR; - Navigator.of(context).push(AnimationLoadingOverlay( - animation, theme.animationOverlayStrong, theme.animationOverlayMedium, - onPoppedCallback: () { - _animationOpen = false; - })); - // Get accounts from seed - //final accounts = await getAddressesFromSeed(context, seed); - try { - //final accountService = ref.read(accountServiceProvider); - //final resp = await accountService.accountInfoForAddresses(accounts); - if (_animationOpen) { - Navigator.of(context).pop(); - } - List accountsToRemove = []; - // resp.forEach((String account, AccountBalanceItem balItem) { - // BigInt balance = BigInt.parse(balItem.balance!); - // BigInt pending = BigInt.parse(balItem.pending!); - // if (balance + pending == BigInt.zero) { - // accountsToRemove.add(account); - // } else { - // // Update balance of this item - // privKeyBalanceMap[account]!.balance = balItem.balance; - // privKeyBalanceMap[account]!.pending = balItem.pending; - // } - // }); - accountsToRemove.forEach((String account) { - privKeyBalanceMap.remove(account); - }); - if (privKeyBalanceMap.length == 0) { - UIUtil.showSnackbar(l10n.transferNoFunds, context); - return; - } - // Go to confirmation screen - // EventTaxiImpl.singleton() - // .fire(TransferConfirmEvent(balMap: privKeyBalanceMap)); - Navigator.of(context).pop(); - } catch (e) { - ref.read(loggerProvider).e("error", error: e); - if (_animationOpen) { - Navigator.of(context).pop(); - } - UIUtil.showSnackbar(l10n.sendError, context); - } - } - - /// Get NUM_SWEEP accounts from seed to request balances for - Future> getAddressesFromSeed( - BuildContext context, - String seed, - ) async { - //final theme = context.read(themeProvider); - List
accountsToRequest = []; - //String privKey; - //Address address; - // Get NUM_SWEEP private keys + accounts from seed - for (int i = 0; i < NUM_SWEEP; i++) { - //privKey = KarlsenUtil.seedToPrivate(seed, i); - //address = KarlsenUtil.seedToAddress(seed, i); - // Don't add this if it is the currently logged in account - // if (address != appState.wallet!.address) { - // privKeyBalanceMap.putIfAbsent( - // address, () => AccountBalanceItem(privKey: privKey)); - // accountsToRequest.add(address); - // } - } - // Also treat this seed as a private key - // address = NanoAccounts.createAccount( - // NanoAccountType.KARLSEN, NanoKeys.createPublicKey(seed)); - // if (address != appState.wallet!.address) { - // privKeyBalanceMap.putIfAbsent( - // address, () => AccountBalanceItem(privKey: seed)); - // accountsToRequest.add(address); - // } - return accountsToRequest; - } -}