mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-20 06:08:34 +02:00
* feat(zcash): initial commit - initial work on cw_zcash - use single .db for everything zcash to speed up sync and scanning - implement silent autoshielding of non-orchard funds - use FFI for everything to fetch the data - add support for passphrase by adding extra word to seed phrase - enforce lints on CI for cw_zcash directory - use correct zcash name, and call transparent zcash tZEC - minor cleanups outsite of cw_zcash - gitmodules, gitignore - db debug - fix broken addressPageType in WalletInfo - enable debug options in kDebugMode and kProfileMode * feat: T address rotation (and cache) wip: minor fixes * wip: shield tx list * fix fiat amounts fix derrivation of rotation account addresses screen for zcash block height fix T address shields improvements Amount in disposable T shields UI improvements show pending outgoing tx in tx history * fix null check on passphrase page fix tx showing as pending rename auto shield txs fixed send all to include fee use rotating address in addressForExchange wrap all calls of WarpApi.getLatestHeight in try catch to prevent leaking errors other minor fixes from notion * wallet group debug cache sent tx address wallet T address rotation fixes automatically pick the fee for auto-shield * fix T address cache deserialization fix autoshield icon fix autoshield text getCachedDestinationAddress fix send address cache * address comments from review * wip: iOS fix * fix swap * Allow cakepay payment from zcash wallet * fix: ios (I'm stupid) fix: reorder addresses to make orchard default fix: send all balance * 5.6.6 bump fix: ios apple review add transport error to ignored exceptions * fix: leaving dust behind when sweeping all * Change wallets order * fix: reflect balance of pending out txs fix: restore height support * linux support (disabled) * fix: date picker for zcash on restore screen fix: build script for linux match WarpApi.warpSync args with upstream * fix: linter script * ensure all exchange providers support ZEC (#2802) * ensure all exchange providers support ZEC * remove zaddr and tzec currencies and refactor providers * Update lib/exchange/provider/near_Intents_exchange_provider.dart * add back old zcash currencies for backward compatibility, thanks Czarek * minor fix [skip ci] --------- Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com> * Update android/app/src/main/AndroidManifestBase.xml [skip ci] * Update ios/Runner/InfoBase.plist [skip ci] * fix: remove unused code fix: macos fix: disable on linux and macos * update build numbers [skip ci] * Add zcash to birdpay --------- Co-authored-by: Czarek Nakamoto <cyjan@mrcyjanek.net> Co-authored-by: Serhii <borodenko.sv@gmail.com>
156 lines
4.3 KiB
Dart
156 lines
4.3 KiB
Dart
import 'dart:math';
|
|
|
|
import 'package:cake_wallet/utils/feature_flag.dart';
|
|
import 'package:cw_core/utils/print_verbose.dart';
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:cw_core/wallet_type.dart';
|
|
import 'package:mobx/mobx.dart';
|
|
import 'package:cw_core/wallet_base.dart';
|
|
import 'package:cake_wallet/evm/evm.dart';
|
|
import 'package:cake_wallet/reactions/wallet_connect.dart';
|
|
|
|
part 'wallet_seed_view_model.g.dart';
|
|
|
|
class WalletSeedViewModel = WalletSeedViewModelBase with _$WalletSeedViewModel;
|
|
|
|
abstract class WalletSeedViewModelBase with Store {
|
|
WalletSeedViewModelBase(WalletBase wallet)
|
|
: name = wallet.name,
|
|
seed = wallet.seed!,
|
|
walletType = _getWalletTypeName(wallet),
|
|
currentOptions = ObservableList<String>(),
|
|
verificationIndices = ObservableList<int>() {
|
|
setupSeedVerification();
|
|
}
|
|
|
|
static String _getWalletTypeName(WalletBase wallet) {
|
|
if (isEVMCompatibleChain(wallet.type)) {
|
|
final currentChain = evm!.getCurrentChain(wallet);
|
|
return currentChain?.name ?? walletTypeToString(wallet.type);
|
|
} else {
|
|
return walletTypeToString(wallet.type);
|
|
}
|
|
}
|
|
|
|
@observable
|
|
String name;
|
|
|
|
@observable
|
|
String seed;
|
|
|
|
@observable
|
|
String walletType;
|
|
|
|
/// The Regex split the words based on any whitespace character.
|
|
///
|
|
/// Either standard ASCII space (U+0020) or the full-width space character (U+3000) used by the Japanese.
|
|
List<String> get seedSplit => seed.split(RegExp(r'\s+'));
|
|
|
|
int get columnCount => seedSplit.length <= 16 ? 2 : 3;
|
|
|
|
double get columnAspectRatio => seedSplit.length <= 16 ? 1.8 : 2.8;
|
|
|
|
/// The indices of the seed to be verified.
|
|
ObservableList<int> verificationIndices;
|
|
|
|
/// The index of the word in verificationIndices being verified.
|
|
@observable
|
|
int currentStepIndex = 0;
|
|
|
|
/// The options to be displayed on the page for the current seed step.
|
|
///
|
|
/// The user has to choose from these.
|
|
ObservableList<String> currentOptions;
|
|
|
|
/// The number of words to be verified, linked to a Feature Flag so we can easily modify it.
|
|
int get verificationWordCount {
|
|
final shouldVerify = shouldPerformVerification();
|
|
|
|
return shouldVerify ? FeatureFlag.verificationWordsCount : 0;
|
|
}
|
|
|
|
/// Then number of wrong entries the user has selected;
|
|
///
|
|
/// Routes the view to the seed screen if it's up to two.
|
|
@observable
|
|
int wrongEntries = 0;
|
|
|
|
int get currentWordIndex => verificationIndices[currentStepIndex];
|
|
|
|
String get currentCorrectWord => seedSplit[currentWordIndex];
|
|
|
|
@observable
|
|
bool isVerificationComplete = false;
|
|
|
|
bool shouldPerformVerification() {
|
|
bool isCI = bool.fromEnvironment('CI_BUILD', defaultValue: false);
|
|
bool isDebug = kDebugMode || kProfileMode;
|
|
|
|
if (isDebug && !isCI) {
|
|
printV("Skipping verification in debug mode - $isDebug (and when it's not in CI - $isCI).");
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
void setupSeedVerification() {
|
|
if (verificationWordCount != 0) {
|
|
generateRandomIndices();
|
|
generateOptions();
|
|
}
|
|
}
|
|
|
|
/// Generate the indices of the seeds to be verified.
|
|
///
|
|
/// Structured to be as random as possible.
|
|
@action
|
|
void generateRandomIndices() {
|
|
verificationIndices.clear();
|
|
final random = Random();
|
|
final indices = <int>[];
|
|
while (indices.length < verificationWordCount) {
|
|
final i = random.nextInt(seedSplit.length);
|
|
if (!indices.contains(i)) {
|
|
indices.add(i);
|
|
}
|
|
}
|
|
|
|
verificationIndices.addAll(indices);
|
|
}
|
|
|
|
/// Generates the options for each index being verified.
|
|
@action
|
|
void generateOptions() {
|
|
currentOptions.clear();
|
|
|
|
final correctWord = currentCorrectWord;
|
|
final incorrectWords = seedSplit.where((word) => word != correctWord).toList();
|
|
incorrectWords.shuffle();
|
|
|
|
final options = [correctWord, ...incorrectWords.take(5)];
|
|
options.shuffle();
|
|
|
|
currentOptions.addAll(options);
|
|
}
|
|
|
|
bool isChosenWordCorrect(String chosenWord) {
|
|
if (chosenWord == currentCorrectWord) {
|
|
wrongEntries = 0;
|
|
|
|
if (currentStepIndex + 1 < verificationWordCount) {
|
|
currentStepIndex++;
|
|
generateOptions();
|
|
} else {
|
|
// All verification steps completed
|
|
isVerificationComplete = true;
|
|
}
|
|
|
|
return true;
|
|
} else {
|
|
wrongEntries++;
|
|
return false;
|
|
}
|
|
}
|
|
}
|