cake_wallet/lib/view_model/wallet_new_vm.dart
Adegoke David d1870ba8b8
CW-525-Add-Tron-Wallet (#1327)
* chore: Initial setup for Tron Wallet

* feat: Create Tron Wallet base flow implemented, keys, address, receive, restore and proxy classes all setup

* feat: Display seed and key within the app

* feat: Activate restore from key and seed for Tron wallet

* feat: Add icon for tron wallet in wallet listing page

* feat: Activate display of receive address for tron

* feat: Fetch and display tron balance, sending transaction flow setup, fee limit calculation setup

* feat: Implement sending of native tron, setup sending of trc20 tokens

* chore: Rename function

* Delete lib/tron/tron.dart

* feat: Activate exchange for tron and its tokens, implement balance display for trc20 tokens and setup secrets configuration for tron

* feat: Implement tron token management, add, remove, delete, and get tokens in home settings view, also minor cleanup

* feat: Activate buy and sell for tron

* feat: Implement restore from QR, transactions history listing for both native transactions and trc20 transactions

* feat: Activate send all and do some minor cleanups

* chore: Fix some lint infos and warnings

* chore: Adjust configurations

* ci: Modify CI to create and add secrets for node

* fix: Fixes made while self reviewing the PR for this feature

* feat: Add guide for adding new wallet types, and add fixes to requested changes

* fix: Handle exceptions gracefully

* fix: Alternative for trc20 estimated fee

* fix: Fixes to display of amount and fee, removing clashes

* fix: Fee calculation WIP

* fix: Fix issue with handling of send all flow and display of amount and fee values before broadcasting transaction

* fix: PR review fixes and fix merge conflicts

* fix: Modify fetching assetOfTransaction [skip ci]

* fix: Move tron settings migration to 33
2024-05-03 21:00:05 +03:00

96 lines
3.6 KiB
Dart

import 'package:cake_wallet/ethereum/ethereum.dart';
import 'package:cake_wallet/bitcoin_cash/bitcoin_cash.dart';
import 'package:cake_wallet/solana/solana.dart';
import 'package:cake_wallet/tron/tron.dart';
import 'package:hive/hive.dart';
import 'package:mobx/mobx.dart';
import 'package:cake_wallet/monero/monero.dart';
import 'package:cake_wallet/nano/nano.dart';
import 'package:cake_wallet/store/app_store.dart';
import 'package:cw_core/wallet_base.dart';
import 'package:cake_wallet/core/wallet_creation_service.dart';
import 'package:cw_core/wallet_credentials.dart';
import 'package:cw_core/wallet_info.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:cake_wallet/view_model/wallet_creation_vm.dart';
import 'package:cake_wallet/bitcoin/bitcoin.dart';
import 'package:cake_wallet/haven/haven.dart';
import 'advanced_privacy_settings_view_model.dart';
import '../polygon/polygon.dart';
part 'wallet_new_vm.g.dart';
class WalletNewVM = WalletNewVMBase with _$WalletNewVM;
abstract class WalletNewVMBase extends WalletCreationVM with Store {
WalletNewVMBase(AppStore appStore, WalletCreationService walletCreationService,
Box<WalletInfo> walletInfoSource, this.advancedPrivacySettingsViewModel,
{required WalletType type})
: selectedMnemonicLanguage = '',
super(appStore, walletInfoSource, walletCreationService, type: type, isRecovery: false);
final AdvancedPrivacySettingsViewModel advancedPrivacySettingsViewModel;
@observable
String selectedMnemonicLanguage;
bool get hasLanguageSelector => type == WalletType.monero || type == WalletType.haven;
int get seedPhraseWordsLength {
switch (type) {
case WalletType.monero:
if (advancedPrivacySettingsViewModel.isPolySeed) {
return 16;
}
return 25;
case WalletType.tron:
case WalletType.solana:
case WalletType.polygon:
case WalletType.ethereum:
case WalletType.bitcoinCash:
return advancedPrivacySettingsViewModel.seedPhraseLength.value;
default:
return 24;
}
}
bool get hasSeedType => type == WalletType.monero;
@override
WalletCredentials getCredentials(dynamic _options) {
final options = _options as List<dynamic>?;
switch (type) {
case WalletType.monero:
return monero!.createMoneroNewWalletCredentials(
name: name, language: options!.first as String, isPolyseed: options.last as bool);
case WalletType.bitcoin:
return bitcoin!.createBitcoinNewWalletCredentials(name: name);
case WalletType.litecoin:
return bitcoin!.createBitcoinNewWalletCredentials(name: name);
case WalletType.haven:
return haven!
.createHavenNewWalletCredentials(name: name, language: options!.first as String);
case WalletType.ethereum:
return ethereum!.createEthereumNewWalletCredentials(name: name);
case WalletType.bitcoinCash:
return bitcoinCash!.createBitcoinCashNewWalletCredentials(name: name);
case WalletType.nano:
return nano!.createNanoNewWalletCredentials(name: name);
case WalletType.polygon:
return polygon!.createPolygonNewWalletCredentials(name: name);
case WalletType.solana:
return solana!.createSolanaNewWalletCredentials(name: name);
case WalletType.tron:
return tron!.createTronNewWalletCredentials(name: name);
default:
throw Exception('Unexpected type: ${type.toString()}');
}
}
@override
Future<WalletBase> process(WalletCredentials credentials) async {
walletCreationService.changeWalletType(type: type);
return walletCreationService.create(credentials, isTestnet: useTestnet);
}
}