2022-07-14 11:48:59 +00:00
|
|
|
import 'package:cake_wallet/core/wallet_creation_service.dart';
|
2023-08-04 17:55:56 +00:00
|
|
|
import 'package:cake_wallet/di.dart';
|
|
|
|
import 'package:cake_wallet/entities/background_tasks.dart';
|
2023-04-21 18:36:47 +00:00
|
|
|
import 'package:cake_wallet/view_model/restore/restore_wallet.dart';
|
2020-07-06 20:09:03 +00:00
|
|
|
import 'package:hive/hive.dart';
|
2020-06-20 07:10:00 +00:00
|
|
|
import 'package:mobx/mobx.dart';
|
2020-09-21 11:50:26 +00:00
|
|
|
import 'package:cake_wallet/core/execution_state.dart';
|
2021-12-24 12:37:24 +00:00
|
|
|
import 'package:cw_core/wallet_base.dart';
|
|
|
|
import 'package:cw_core/wallet_credentials.dart';
|
|
|
|
import 'package:cw_core/pathForWallet.dart';
|
|
|
|
import 'package:cw_core/wallet_info.dart';
|
|
|
|
import 'package:cw_core/wallet_type.dart';
|
2020-09-21 11:50:26 +00:00
|
|
|
import 'package:cake_wallet/store/app_store.dart';
|
2020-10-22 18:24:24 +00:00
|
|
|
import 'package:cake_wallet/entities/generate_name.dart';
|
2020-06-20 07:10:00 +00:00
|
|
|
|
|
|
|
part 'wallet_creation_vm.g.dart';
|
|
|
|
|
|
|
|
class WalletCreationVM = WalletCreationVMBase with _$WalletCreationVM;
|
|
|
|
|
|
|
|
abstract class WalletCreationVMBase with Store {
|
2022-07-14 11:48:59 +00:00
|
|
|
WalletCreationVMBase(this._appStore, this._walletInfoSource, this.walletCreationService,
|
2022-10-12 17:09:57 +00:00
|
|
|
{required this.type, required this.isRecovery})
|
|
|
|
: state = InitialExecutionState(),
|
|
|
|
name = '';
|
2020-06-20 07:10:00 +00:00
|
|
|
|
Btc address types (#1263)
* inital migration changes
* feat: rest of changes
* minor fix [skip ci]
* fix: P2wshAddress & wallet address index
* fix: address review comments
* fix: address type restore
* feat: add testnet
* Fix review comments
Remove bitcoin_base from cw_core
* Fix address not matching selected type on start
* remove un-necessary parameter [skip ci]
* Remove bitcoin specific code from main lib
Fix possible runtime exception from list wrong access
* Minor fix
* fix: fixes for Testnet
* fix: bitcoin receive option dependency breaks monerocom
* Fix issues when building Monero.com
* feat: Transaction Builder changes
* fix: discover addresses, testnet restoring, duplicate unspent coins, and taproot address vs schnorr sig tweak
* fix: remove print
* feat: improve error when failed broadcast response
* feat: create fish shell env script
* fix: unmodifiable maps
* fix: build
* fix: build
* fix: computed observable side effect bug
* feat: add nix script for android build_all
* fix: wrong keypairs used for signing
* fix: wrong addresses when using fromScriptPubKey scripts
* fix(actual commit): testnet tx expanded + wrong addresses when using fromScriptPubKey scripts (update bitcoin_base deps)
* fix: self-send [skip ci]
* fix: p2wsh
* fix: testnet fees
* New versions
* Update macos build number
Minor UI fix
* fix: use new bitcoin_base ref, fix tx list wrong hex value & refactor hidden vs hd use
- if always use sideHd for isHidden, it is easier to simplify the functions instead of passing both which can be error prone
- (ps: now this could probably be changed, for example from isHidden to isChange since with address list we now see "hidden" addresses)
* Fix if condition to handle litecoin case
* fix: self-send, change address was always making direction incoming
* refactor: improve estimation function, add more inputs if balance missing
* fix: new bitcoin_base update, fixes script issues
* Update evm chain wallet service arguments
* Fix translation [skip ci]
* Fix translation [skip ci]
* Update strings_fr.arb [skip ci]
* fix: async isChange function not being awaited, refactor to reduce looping into a single place
* fix: _address vs address, missing p2sh
* fix: minor mistake in storing p2sh page type [skip ci]
* refactor: use already matched addresses property
* feat: improved perfomance for fetching transaction histories
* feat: continue perfomance change, improve address discovery only to last address by type with history
* fix: make sure transaction list is sorted by date
* refactor: isTestnet only for bitcoin
* fix: walletInfo type null case
* fix: deprecated p2pk
* refactor: make condition more readable
* refactor: remove unnecessary Str variant
* refactor: make condition more readable
* fix: infinite loop possible
* Revert removing isTestnet from other wallets [skip ci]
* refactor: rename addresses when matched by receive type
* Make the beta build [skip ci]
Remove app_env.fish
---------
Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
2024-02-23 16:13:30 +00:00
|
|
|
@observable
|
|
|
|
bool _useTestnet = false;
|
|
|
|
|
|
|
|
@computed
|
|
|
|
bool get useTestnet => _useTestnet;
|
|
|
|
|
2020-06-20 07:10:00 +00:00
|
|
|
@observable
|
|
|
|
String name;
|
|
|
|
|
|
|
|
@observable
|
2020-09-21 11:50:26 +00:00
|
|
|
ExecutionState state;
|
2020-06-20 07:10:00 +00:00
|
|
|
|
2020-11-12 16:31:53 +00:00
|
|
|
WalletType type;
|
2020-07-06 20:09:03 +00:00
|
|
|
final bool isRecovery;
|
2022-07-14 11:48:59 +00:00
|
|
|
final WalletCreationService walletCreationService;
|
2020-09-10 14:51:59 +00:00
|
|
|
final Box<WalletInfo> _walletInfoSource;
|
2020-09-21 11:50:26 +00:00
|
|
|
final AppStore _appStore;
|
2020-06-20 07:10:00 +00:00
|
|
|
|
2023-10-05 01:09:07 +00:00
|
|
|
bool nameExists(String name) => walletCreationService.exists(name);
|
2022-06-29 17:21:21 +00:00
|
|
|
|
2023-10-05 01:09:07 +00:00
|
|
|
bool typeExists(WalletType type) => walletCreationService.typeExists(type);
|
2022-08-30 18:03:02 +00:00
|
|
|
|
2023-04-21 18:36:47 +00:00
|
|
|
Future<void> create({dynamic options, RestoredWallet? restoreWallet}) async {
|
|
|
|
final type = restoreWallet?.type ?? this.type;
|
2020-06-20 07:10:00 +00:00
|
|
|
try {
|
2020-09-21 11:50:26 +00:00
|
|
|
state = IsExecutingState();
|
2022-10-12 17:09:57 +00:00
|
|
|
if (name.isEmpty) {
|
2023-10-05 01:09:07 +00:00
|
|
|
name = await generateName();
|
2022-01-03 18:25:48 +00:00
|
|
|
}
|
2022-07-14 11:48:59 +00:00
|
|
|
|
|
|
|
walletCreationService.checkIfExists(name);
|
2020-09-21 11:50:26 +00:00
|
|
|
final dirPath = await pathForWalletDir(name: name, type: type);
|
|
|
|
final path = await pathForWallet(name: name, type: type);
|
2023-04-21 18:36:47 +00:00
|
|
|
final credentials = restoreWallet != null
|
|
|
|
? getCredentialsFromRestoredWallet(options, restoreWallet)
|
|
|
|
: getCredentials(options);
|
2023-10-05 01:09:07 +00:00
|
|
|
|
2020-09-15 20:35:49 +00:00
|
|
|
final walletInfo = WalletInfo.external(
|
2023-10-05 01:09:07 +00:00
|
|
|
id: WalletBase.idFor(name, type),
|
|
|
|
name: name,
|
|
|
|
type: type,
|
|
|
|
isRecovery: isRecovery,
|
|
|
|
restoreHeight: credentials.height ?? 0,
|
|
|
|
date: DateTime.now(),
|
|
|
|
path: path,
|
|
|
|
dirPath: dirPath,
|
|
|
|
address: '',
|
|
|
|
showIntroCakePayCard: (!walletCreationService.typeExists(type)) && type != WalletType.haven,
|
|
|
|
derivationPath: credentials.derivationPath,
|
|
|
|
derivationType: credentials.derivationType,
|
|
|
|
);
|
2020-09-15 20:35:49 +00:00
|
|
|
credentials.walletInfo = walletInfo;
|
2023-04-21 18:36:47 +00:00
|
|
|
final wallet = restoreWallet != null
|
|
|
|
? await processFromRestoredWallet(credentials, restoreWallet)
|
|
|
|
: await process(credentials);
|
2021-07-13 05:46:34 +00:00
|
|
|
walletInfo.address = wallet.walletAddresses.address;
|
2020-07-06 20:09:03 +00:00
|
|
|
await _walletInfoSource.add(walletInfo);
|
2023-12-28 01:37:36 +00:00
|
|
|
await _appStore.changeCurrentWallet(wallet);
|
2023-08-04 17:55:56 +00:00
|
|
|
getIt.get<BackgroundTasks>().registerSyncTask();
|
2020-09-21 11:50:26 +00:00
|
|
|
_appStore.authenticationStore.allowed();
|
|
|
|
state = ExecutedSuccessfullyState();
|
2020-06-20 07:10:00 +00:00
|
|
|
} catch (e) {
|
2020-09-21 11:50:26 +00:00
|
|
|
state = FailureState(e.toString());
|
2020-06-20 07:10:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-05 01:09:07 +00:00
|
|
|
WalletCredentials getCredentials(dynamic options) => throw UnimplementedError();
|
|
|
|
|
|
|
|
Future<WalletBase> process(WalletCredentials credentials) => throw UnimplementedError();
|
2023-04-21 18:36:47 +00:00
|
|
|
|
2023-10-05 01:09:07 +00:00
|
|
|
WalletCredentials getCredentialsFromRestoredWallet(
|
|
|
|
dynamic options, RestoredWallet restoreWallet) =>
|
2023-04-21 18:36:47 +00:00
|
|
|
throw UnimplementedError();
|
|
|
|
|
2023-10-05 01:09:07 +00:00
|
|
|
Future<WalletBase> processFromRestoredWallet(
|
|
|
|
WalletCredentials credentials, RestoredWallet restoreWallet) =>
|
2023-04-21 18:36:47 +00:00
|
|
|
throw UnimplementedError();
|
Btc address types (#1263)
* inital migration changes
* feat: rest of changes
* minor fix [skip ci]
* fix: P2wshAddress & wallet address index
* fix: address review comments
* fix: address type restore
* feat: add testnet
* Fix review comments
Remove bitcoin_base from cw_core
* Fix address not matching selected type on start
* remove un-necessary parameter [skip ci]
* Remove bitcoin specific code from main lib
Fix possible runtime exception from list wrong access
* Minor fix
* fix: fixes for Testnet
* fix: bitcoin receive option dependency breaks monerocom
* Fix issues when building Monero.com
* feat: Transaction Builder changes
* fix: discover addresses, testnet restoring, duplicate unspent coins, and taproot address vs schnorr sig tweak
* fix: remove print
* feat: improve error when failed broadcast response
* feat: create fish shell env script
* fix: unmodifiable maps
* fix: build
* fix: build
* fix: computed observable side effect bug
* feat: add nix script for android build_all
* fix: wrong keypairs used for signing
* fix: wrong addresses when using fromScriptPubKey scripts
* fix(actual commit): testnet tx expanded + wrong addresses when using fromScriptPubKey scripts (update bitcoin_base deps)
* fix: self-send [skip ci]
* fix: p2wsh
* fix: testnet fees
* New versions
* Update macos build number
Minor UI fix
* fix: use new bitcoin_base ref, fix tx list wrong hex value & refactor hidden vs hd use
- if always use sideHd for isHidden, it is easier to simplify the functions instead of passing both which can be error prone
- (ps: now this could probably be changed, for example from isHidden to isChange since with address list we now see "hidden" addresses)
* Fix if condition to handle litecoin case
* fix: self-send, change address was always making direction incoming
* refactor: improve estimation function, add more inputs if balance missing
* fix: new bitcoin_base update, fixes script issues
* Update evm chain wallet service arguments
* Fix translation [skip ci]
* Fix translation [skip ci]
* Update strings_fr.arb [skip ci]
* fix: async isChange function not being awaited, refactor to reduce looping into a single place
* fix: _address vs address, missing p2sh
* fix: minor mistake in storing p2sh page type [skip ci]
* refactor: use already matched addresses property
* feat: improved perfomance for fetching transaction histories
* feat: continue perfomance change, improve address discovery only to last address by type with history
* fix: make sure transaction list is sorted by date
* refactor: isTestnet only for bitcoin
* fix: walletInfo type null case
* fix: deprecated p2pk
* refactor: make condition more readable
* refactor: remove unnecessary Str variant
* refactor: make condition more readable
* fix: infinite loop possible
* Revert removing isTestnet from other wallets [skip ci]
* refactor: rename addresses when matched by receive type
* Make the beta build [skip ci]
Remove app_env.fish
---------
Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
2024-02-23 16:13:30 +00:00
|
|
|
|
|
|
|
@action
|
|
|
|
void toggleUseTestnet(bool? value) {
|
|
|
|
_useTestnet = value ?? !_useTestnet;
|
|
|
|
}
|
2020-06-20 07:10:00 +00:00
|
|
|
}
|