2024-03-19 22:44:00 +00:00
|
|
|
import 'package:cake_wallet/entities/contact.dart';
|
2022-11-23 17:06:41 +00:00
|
|
|
import 'package:cake_wallet/entities/priority_for_wallet_type.dart';
|
2020-11-06 18:54:00 +00:00
|
|
|
import 'package:cake_wallet/entities/transaction_description.dart';
|
2023-10-05 01:09:07 +00:00
|
|
|
import 'package:cake_wallet/ethereum/ethereum.dart';
|
2024-03-28 12:41:11 +00:00
|
|
|
import 'package:cake_wallet/exchange/provider/exchange_provider.dart';
|
|
|
|
import 'package:cake_wallet/exchange/provider/thorchain_exchange.provider.dart';
|
2023-10-05 01:09:07 +00:00
|
|
|
import 'package:cake_wallet/nano/nano.dart';
|
|
|
|
import 'package:cake_wallet/core/wallet_change_listener_view_model.dart';
|
|
|
|
import 'package:cake_wallet/entities/contact_record.dart';
|
2023-08-04 13:49:26 +00:00
|
|
|
import 'package:cake_wallet/entities/wallet_contact.dart';
|
2023-12-02 02:26:43 +00:00
|
|
|
import 'package:cake_wallet/polygon/polygon.dart';
|
|
|
|
import 'package:cake_wallet/reactions/wallet_connect.dart';
|
CW-555-Add-Solana-Wallet (#1272)
* chore: Create cw_solana package and clean up files
* feat: Add Solana Wallet - Create, Restore form seed, restore from Key, Restore from QR, Send, Receive, transaction history, spl tokens
* fix: Make transactions file specific to solana only for solana transactions
* chore: Revert inject app details script
* fix: Fix issue with node and switch current node to main beta instead of testnet
* fix: Fix merge conflicts and adjust migration version
* fix: Fetch spl token error
Signed-off-by: Blazebrain <davidadegoke16@gmail.com>
* fix: Diplay and activate spl tokens bug
* fix: Review and fixes
* fix: reverted formatting for cryptocurrency class
* fix: Review comments, split sending flow into signing and sending separately, fix issues
* fix: Revert throwing unimplenented error
* chore: Fix comment
* chore: Fix comment
* fix: Errors in flow
* Update provider_types.dart [skip ci]
* fix: Issues with solana wallet
* Update solana_wallet.dart [skip ci]
* fix: Review comments
* fix: Date time config
* fix: Revert bash script for app details
* fix: Error with balance, displaying fees, fixing sent or received identifier bug, displaying token symbol with token transaction item in transactions list
* fix: Issues with address validation when sending spl tokens and walletconnect initial setup
* fix: Issues with sending, fetching transactions history, almost wrapping up walletconnect
* fix: Adjust imports that would affect monerocom building successfully
* fix: Refine transaction direction and continue work on walletconnect
* feat: Display SPL token transfers in the transaction history and finally settle the transaction direction
* fix: Delay in transactions history dispaly, show native token transactions first, then process spl token transactions
* feat: Switch node and revert solana chain id to previous id
* fix: Remove print statement
* fix: Remove await for transactions, fetch all transaction histories instantly and adjust solana send success message
* chore: Code refactoring and streamlined wallet type check for solana send success message
* fix: Make timeout error for node silent and add spl token images
---------
Signed-off-by: Blazebrain <davidadegoke16@gmail.com>
Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
2024-02-23 13:39:19 +00:00
|
|
|
import 'package:cake_wallet/solana/solana.dart';
|
2023-10-05 01:09:07 +00:00
|
|
|
import 'package:cake_wallet/store/app_store.dart';
|
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 18:00:05 +00:00
|
|
|
import 'package:cake_wallet/tron/tron.dart';
|
2023-08-04 13:49:26 +00:00
|
|
|
import 'package:cake_wallet/view_model/contact_list/contact_list_view_model.dart';
|
2022-04-22 15:00:28 +00:00
|
|
|
import 'package:cake_wallet/view_model/dashboard/balance_view_model.dart';
|
2024-05-05 01:44:50 +00:00
|
|
|
import 'package:cake_wallet/view_model/hardware_wallet/ledger_view_model.dart';
|
2024-03-29 18:51:34 +00:00
|
|
|
import 'package:cw_core/exceptions.dart';
|
2021-12-24 12:37:24 +00:00
|
|
|
import 'package:cw_core/transaction_priority.dart';
|
2021-08-10 14:52:35 +00:00
|
|
|
import 'package:cake_wallet/view_model/send/output.dart';
|
2021-07-16 09:32:36 +00:00
|
|
|
import 'package:cake_wallet/view_model/send/send_template_view_model.dart';
|
2020-11-06 18:54:00 +00:00
|
|
|
import 'package:hive/hive.dart';
|
2024-05-05 01:44:50 +00:00
|
|
|
import 'package:ledger_flutter/ledger_flutter.dart';
|
2020-10-30 16:32:21 +00:00
|
|
|
import 'package:mobx/mobx.dart';
|
2020-10-07 05:58:22 +00:00
|
|
|
import 'package:cake_wallet/entities/template.dart';
|
2020-08-25 16:32:40 +00:00
|
|
|
import 'package:cake_wallet/core/address_validator.dart';
|
|
|
|
import 'package:cake_wallet/core/amount_validator.dart';
|
2021-12-24 12:37:24 +00:00
|
|
|
import 'package:cw_core/pending_transaction.dart';
|
2020-08-25 16:32:40 +00:00
|
|
|
import 'package:cake_wallet/core/validator.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:cake_wallet/monero/monero.dart';
|
|
|
|
import 'package:cw_core/sync_status.dart';
|
|
|
|
import 'package:cw_core/crypto_currency.dart';
|
2020-09-21 11:50:26 +00:00
|
|
|
import 'package:cake_wallet/entities/fiat_currency.dart';
|
|
|
|
import 'package:cake_wallet/entities/calculate_fiat_amount.dart';
|
2021-12-24 12:37:24 +00:00
|
|
|
import 'package:cw_core/wallet_type.dart';
|
2020-09-21 11:50:26 +00:00
|
|
|
import 'package:cake_wallet/store/dashboard/fiat_conversion_store.dart';
|
2020-08-25 16:32:40 +00:00
|
|
|
import 'package:cake_wallet/store/settings_store.dart';
|
|
|
|
import 'package:cake_wallet/view_model/send/send_view_model_state.dart';
|
2021-11-02 09:17:24 +00:00
|
|
|
import 'package:cake_wallet/entities/parsed_address.dart';
|
2021-12-24 12:37:24 +00:00
|
|
|
import 'package:cake_wallet/bitcoin/bitcoin.dart';
|
2022-03-30 15:57:04 +00:00
|
|
|
import 'package:cake_wallet/haven/haven.dart';
|
2023-09-25 12:20:11 +00:00
|
|
|
import 'package:cake_wallet/generated/i18n.dart';
|
2024-04-08 14:54:58 +00:00
|
|
|
import 'package:collection/collection.dart';
|
2020-08-25 16:32:40 +00:00
|
|
|
|
|
|
|
part 'send_view_model.g.dart';
|
|
|
|
|
|
|
|
class SendViewModel = SendViewModelBase with _$SendViewModel;
|
|
|
|
|
2023-09-01 15:06:18 +00:00
|
|
|
abstract class SendViewModelBase extends WalletChangeListenerViewModel with Store {
|
|
|
|
@override
|
|
|
|
void onWalletChange(wallet) {
|
|
|
|
currencies = wallet.balance.keys.toList();
|
|
|
|
selectedCryptoCurrency = wallet.currency;
|
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 18:00:05 +00:00
|
|
|
hasMultipleTokens = isEVMCompatibleChain(wallet.type) ||
|
|
|
|
wallet.type == WalletType.solana ||
|
|
|
|
wallet.type == WalletType.tron;
|
2023-09-01 15:06:18 +00:00
|
|
|
}
|
|
|
|
|
2022-01-25 14:43:19 +00:00
|
|
|
SendViewModelBase(
|
2023-09-01 15:06:18 +00:00
|
|
|
AppStore appStore,
|
|
|
|
this.sendTemplateViewModel,
|
|
|
|
this._fiatConversationStore,
|
|
|
|
this.balanceViewModel,
|
|
|
|
this.contactListViewModel,
|
|
|
|
this.transactionDescriptionBox,
|
2024-05-05 01:44:50 +00:00
|
|
|
this.ledgerViewModel,
|
2023-09-01 15:06:18 +00:00
|
|
|
) : state = InitialExecutionState(),
|
|
|
|
currencies = appStore.wallet!.balance.keys.toList(),
|
|
|
|
selectedCryptoCurrency = appStore.wallet!.currency,
|
CW-555-Add-Solana-Wallet (#1272)
* chore: Create cw_solana package and clean up files
* feat: Add Solana Wallet - Create, Restore form seed, restore from Key, Restore from QR, Send, Receive, transaction history, spl tokens
* fix: Make transactions file specific to solana only for solana transactions
* chore: Revert inject app details script
* fix: Fix issue with node and switch current node to main beta instead of testnet
* fix: Fix merge conflicts and adjust migration version
* fix: Fetch spl token error
Signed-off-by: Blazebrain <davidadegoke16@gmail.com>
* fix: Diplay and activate spl tokens bug
* fix: Review and fixes
* fix: reverted formatting for cryptocurrency class
* fix: Review comments, split sending flow into signing and sending separately, fix issues
* fix: Revert throwing unimplenented error
* chore: Fix comment
* chore: Fix comment
* fix: Errors in flow
* Update provider_types.dart [skip ci]
* fix: Issues with solana wallet
* Update solana_wallet.dart [skip ci]
* fix: Review comments
* fix: Date time config
* fix: Revert bash script for app details
* fix: Error with balance, displaying fees, fixing sent or received identifier bug, displaying token symbol with token transaction item in transactions list
* fix: Issues with address validation when sending spl tokens and walletconnect initial setup
* fix: Issues with sending, fetching transactions history, almost wrapping up walletconnect
* fix: Adjust imports that would affect monerocom building successfully
* fix: Refine transaction direction and continue work on walletconnect
* feat: Display SPL token transfers in the transaction history and finally settle the transaction direction
* fix: Delay in transactions history dispaly, show native token transactions first, then process spl token transactions
* feat: Switch node and revert solana chain id to previous id
* fix: Remove print statement
* fix: Remove await for transactions, fetch all transaction histories instantly and adjust solana send success message
* chore: Code refactoring and streamlined wallet type check for solana send success message
* fix: Make timeout error for node silent and add spl token images
---------
Signed-off-by: Blazebrain <davidadegoke16@gmail.com>
Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
2024-02-23 13:39:19 +00:00
|
|
|
hasMultipleTokens = isEVMCompatibleChain(appStore.wallet!.type) ||
|
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 18:00:05 +00:00
|
|
|
appStore.wallet!.type == WalletType.solana ||
|
|
|
|
appStore.wallet!.type == WalletType.tron,
|
2022-11-25 20:51:07 +00:00
|
|
|
outputs = ObservableList<Output>(),
|
2023-09-01 15:06:18 +00:00
|
|
|
_settingsStore = appStore.settingsStore,
|
|
|
|
fiatFromSettings = appStore.settingsStore.fiatCurrency,
|
|
|
|
super(appStore: appStore) {
|
2024-04-08 14:54:58 +00:00
|
|
|
if (wallet.type == WalletType.bitcoin &&
|
|
|
|
_settingsStore.priority[wallet.type] == bitcoinTransactionPriorityCustom) {
|
|
|
|
setTransactionPriority(bitcoinTransactionPriorityMedium);
|
|
|
|
}
|
2023-09-01 15:06:18 +00:00
|
|
|
final priority = _settingsStore.priority[wallet.type];
|
|
|
|
final priorities = priorityForWalletType(wallet.type);
|
2023-10-05 01:09:07 +00:00
|
|
|
if (!priorityForWalletType(wallet.type).contains(priority) && priorities.isNotEmpty) {
|
2023-09-01 15:06:18 +00:00
|
|
|
_settingsStore.priority[wallet.type] = priorities.first;
|
2021-01-06 08:42:21 +00:00
|
|
|
}
|
2023-08-04 13:49:26 +00:00
|
|
|
|
|
|
|
outputs
|
2023-09-01 15:06:18 +00:00
|
|
|
.add(Output(wallet, _settingsStore, _fiatConversationStore, () => selectedCryptoCurrency));
|
2020-09-21 11:50:26 +00:00
|
|
|
}
|
2020-08-25 16:32:40 +00:00
|
|
|
|
|
|
|
@observable
|
2020-09-21 11:50:26 +00:00
|
|
|
ExecutionState state;
|
2020-08-25 16:32:40 +00:00
|
|
|
|
2021-08-10 14:52:35 +00:00
|
|
|
ObservableList<Output> outputs;
|
2020-08-25 16:32:40 +00:00
|
|
|
|
2021-07-16 09:32:36 +00:00
|
|
|
@action
|
2021-08-10 14:52:35 +00:00
|
|
|
void addOutput() {
|
2023-08-04 13:49:26 +00:00
|
|
|
outputs
|
2023-09-01 15:06:18 +00:00
|
|
|
.add(Output(wallet, _settingsStore, _fiatConversationStore, () => selectedCryptoCurrency));
|
2021-07-16 09:32:36 +00:00
|
|
|
}
|
2021-01-27 13:51:51 +00:00
|
|
|
|
2021-07-16 09:32:36 +00:00
|
|
|
@action
|
2021-08-10 14:52:35 +00:00
|
|
|
void removeOutput(Output output) {
|
2021-08-12 14:56:34 +00:00
|
|
|
if (isBatchSending) {
|
|
|
|
outputs.remove(output);
|
|
|
|
}
|
2021-07-16 09:32:36 +00:00
|
|
|
}
|
2021-01-27 13:51:51 +00:00
|
|
|
|
2021-07-16 09:32:36 +00:00
|
|
|
@action
|
2021-08-10 14:52:35 +00:00
|
|
|
void clearOutputs() {
|
|
|
|
outputs.clear();
|
|
|
|
addOutput();
|
2021-01-27 13:51:51 +00:00
|
|
|
}
|
2020-09-30 18:23:15 +00:00
|
|
|
|
2020-12-29 18:48:57 +00:00
|
|
|
@computed
|
2021-08-10 14:52:35 +00:00
|
|
|
bool get isBatchSending => outputs.length > 1;
|
2020-12-29 18:48:57 +00:00
|
|
|
|
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 18:00:05 +00:00
|
|
|
bool get shouldDisplaySendALL => walletType != WalletType.solana || walletType != WalletType.tron;
|
|
|
|
|
2020-12-29 18:48:57 +00:00
|
|
|
@computed
|
|
|
|
String get pendingTransactionFiatAmount {
|
2023-10-05 01:09:07 +00:00
|
|
|
if (pendingTransaction == null) {
|
|
|
|
return '0.00';
|
|
|
|
}
|
|
|
|
|
2020-12-29 18:48:57 +00:00
|
|
|
try {
|
2023-10-05 01:09:07 +00:00
|
|
|
final fiat = calculateFiatAmount(
|
|
|
|
price: _fiatConversationStore.prices[selectedCryptoCurrency]!,
|
|
|
|
cryptoAmount: pendingTransaction!.amountFormatted);
|
|
|
|
return fiat;
|
2020-12-29 18:48:57 +00:00
|
|
|
} catch (_) {
|
|
|
|
return '0.00';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-30 14:54:55 +00:00
|
|
|
@computed
|
|
|
|
String get pendingTransactionFeeFiatAmount {
|
|
|
|
try {
|
|
|
|
if (pendingTransaction != null) {
|
2024-05-28 13:32:36 +00:00
|
|
|
final currency = pendingTransactionFeeCurrency(walletType);
|
2020-12-30 14:54:55 +00:00
|
|
|
final fiat = calculateFiatAmount(
|
2023-08-04 17:01:49 +00:00
|
|
|
price: _fiatConversationStore.prices[currency]!,
|
2022-10-12 17:09:57 +00:00
|
|
|
cryptoAmount: pendingTransaction!.feeFormatted);
|
2020-12-30 14:54:55 +00:00
|
|
|
return fiat;
|
|
|
|
} else {
|
|
|
|
return '0.00';
|
|
|
|
}
|
|
|
|
} catch (_) {
|
|
|
|
return '0.00';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-28 13:32:36 +00:00
|
|
|
CryptoCurrency pendingTransactionFeeCurrency(WalletType type) {
|
|
|
|
switch (type) {
|
|
|
|
case WalletType.ethereum:
|
|
|
|
case WalletType.polygon:
|
|
|
|
case WalletType.tron:
|
|
|
|
case WalletType.solana:
|
|
|
|
return wallet.currency;
|
|
|
|
default:
|
|
|
|
return selectedCryptoCurrency;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-25 16:32:40 +00:00
|
|
|
FiatCurrency get fiat => _settingsStore.fiatCurrency;
|
|
|
|
|
2022-10-12 17:09:57 +00:00
|
|
|
TransactionPriority get transactionPriority {
|
2023-09-01 15:06:18 +00:00
|
|
|
final priority = _settingsStore.priority[wallet.type];
|
2022-10-12 17:09:57 +00:00
|
|
|
|
|
|
|
if (priority == null) {
|
2023-09-01 15:06:18 +00:00
|
|
|
throw Exception('Unexpected type ${wallet.type}');
|
2022-10-12 17:09:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return priority;
|
|
|
|
}
|
2020-08-25 16:32:40 +00:00
|
|
|
|
2024-04-08 14:54:58 +00:00
|
|
|
int? getCustomPriorityIndex(List<TransactionPriority> priorities) {
|
|
|
|
if (wallet.type == WalletType.bitcoin) {
|
2024-04-12 14:01:21 +00:00
|
|
|
final customItem = priorities
|
|
|
|
.firstWhereOrNull((element) => element == bitcoin!.getBitcoinTransactionPriorityCustom());
|
2024-04-08 14:54:58 +00:00
|
|
|
|
|
|
|
return customItem != null ? priorities.indexOf(customItem) : null;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2024-04-25 16:28:18 +00:00
|
|
|
int? get maxCustomFeeRate {
|
|
|
|
if (wallet.type == WalletType.bitcoin) {
|
|
|
|
return bitcoin!.getMaxCustomFeeRate(wallet);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2024-04-08 14:54:58 +00:00
|
|
|
@computed
|
|
|
|
int get customBitcoinFeeRate => _settingsStore.customBitcoinFeeRate;
|
|
|
|
|
|
|
|
void set customBitcoinFeeRate(int value) => _settingsStore.customBitcoinFeeRate = value;
|
|
|
|
|
2023-09-01 15:06:18 +00:00
|
|
|
CryptoCurrency get currency => wallet.currency;
|
2020-08-25 16:32:40 +00:00
|
|
|
|
2023-08-04 17:01:49 +00:00
|
|
|
Validator<String> get amountValidator =>
|
2023-09-01 15:06:18 +00:00
|
|
|
AmountValidator(currency: walletTypeToCryptoCurrency(wallet.type));
|
2020-08-25 16:32:40 +00:00
|
|
|
|
2023-08-04 17:01:49 +00:00
|
|
|
Validator<String> get allAmountValidator => AllAmountValidator();
|
2020-10-09 07:41:29 +00:00
|
|
|
|
2023-08-04 17:01:49 +00:00
|
|
|
Validator<String> get addressValidator => AddressValidator(type: selectedCryptoCurrency);
|
2020-08-25 16:32:40 +00:00
|
|
|
|
2023-08-04 17:01:49 +00:00
|
|
|
Validator<String> get textValidator => TextValidator();
|
2021-09-22 13:47:10 +00:00
|
|
|
|
2022-11-25 20:51:07 +00:00
|
|
|
final FiatCurrency fiatFromSettings;
|
|
|
|
|
2021-01-29 20:18:07 +00:00
|
|
|
@observable
|
2022-10-12 17:09:57 +00:00
|
|
|
PendingTransaction? pendingTransaction;
|
2020-08-25 16:32:40 +00:00
|
|
|
|
|
|
|
@computed
|
2023-09-01 15:06:18 +00:00
|
|
|
String get balance => wallet.balance[selectedCryptoCurrency]!.formattedAvailableBalance;
|
2020-08-25 16:32:40 +00:00
|
|
|
|
2022-12-07 20:07:32 +00:00
|
|
|
@computed
|
|
|
|
bool get isFiatDisabled => balanceViewModel.isFiatDisabled;
|
|
|
|
|
2022-11-22 17:33:24 +00:00
|
|
|
@computed
|
|
|
|
String get pendingTransactionFiatAmountFormatted =>
|
2023-08-04 13:49:26 +00:00
|
|
|
isFiatDisabled ? '' : pendingTransactionFiatAmount + ' ' + fiat.title;
|
2022-11-22 17:33:24 +00:00
|
|
|
|
|
|
|
@computed
|
|
|
|
String get pendingTransactionFeeFiatAmountFormatted =>
|
2023-08-04 13:49:26 +00:00
|
|
|
isFiatDisabled ? '' : pendingTransactionFeeFiatAmount + ' ' + fiat.title;
|
2022-11-22 17:33:24 +00:00
|
|
|
|
2020-08-25 16:32:40 +00:00
|
|
|
@computed
|
2024-05-09 20:06:39 +00:00
|
|
|
bool get isReadyForSend =>
|
|
|
|
wallet.syncStatus is SyncedSyncStatus ||
|
|
|
|
// If silent payments scanning, can still send payments
|
|
|
|
(wallet.type == WalletType.bitcoin && wallet.syncStatus is SyncingSyncStatus);
|
2020-08-25 16:32:40 +00:00
|
|
|
|
2020-10-07 05:58:22 +00:00
|
|
|
@computed
|
2022-01-26 16:11:32 +00:00
|
|
|
List<Template> get templates => sendTemplateViewModel.templates
|
2022-01-31 12:54:24 +00:00
|
|
|
.where((template) => _isEqualCurrency(template.cryptoCurrency))
|
2022-01-26 16:11:32 +00:00
|
|
|
.toList();
|
2020-10-07 05:58:22 +00:00
|
|
|
|
2023-08-24 13:54:05 +00:00
|
|
|
@computed
|
|
|
|
bool get hasCoinControl =>
|
2023-09-01 15:06:18 +00:00
|
|
|
wallet.type == WalletType.bitcoin ||
|
2023-10-17 15:59:41 +00:00
|
|
|
wallet.type == WalletType.litecoin ||
|
|
|
|
wallet.type == WalletType.monero ||
|
|
|
|
wallet.type == WalletType.bitcoinCash;
|
2023-08-24 13:54:05 +00:00
|
|
|
|
2021-07-20 15:03:49 +00:00
|
|
|
@computed
|
2022-01-25 14:43:19 +00:00
|
|
|
bool get isElectrumWallet =>
|
2023-10-12 22:50:16 +00:00
|
|
|
wallet.type == WalletType.bitcoin ||
|
2023-10-17 15:59:41 +00:00
|
|
|
wallet.type == WalletType.litecoin ||
|
|
|
|
wallet.type == WalletType.bitcoinCash;
|
2021-07-20 15:03:49 +00:00
|
|
|
|
2023-10-05 01:09:07 +00:00
|
|
|
@computed
|
|
|
|
bool get hasFees => wallet.type != WalletType.nano && wallet.type != WalletType.banano;
|
|
|
|
|
2024-03-29 18:55:29 +00:00
|
|
|
@computed
|
|
|
|
bool get hasFeesPriority =>
|
|
|
|
wallet.type != WalletType.nano &&
|
|
|
|
wallet.type != WalletType.banano &&
|
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 18:00:05 +00:00
|
|
|
wallet.type != WalletType.solana &&
|
|
|
|
wallet.type != WalletType.tron;
|
2024-05-06 19:11:18 +00:00
|
|
|
|
2022-03-30 15:57:04 +00:00
|
|
|
@observable
|
|
|
|
CryptoCurrency selectedCryptoCurrency;
|
|
|
|
|
|
|
|
List<CryptoCurrency> currencies;
|
|
|
|
|
2023-09-01 15:06:18 +00:00
|
|
|
bool get hasYat => outputs
|
|
|
|
.any((out) => out.isParsedAddress && out.parsedAddress.parseFrom == ParseFrom.yatRecord);
|
2021-11-02 09:17:24 +00:00
|
|
|
|
2023-09-01 15:06:18 +00:00
|
|
|
WalletType get walletType => wallet.type;
|
2022-03-30 15:57:04 +00:00
|
|
|
|
2023-09-01 15:06:18 +00:00
|
|
|
String? get walletCurrencyName => wallet.currency.fullName?.toLowerCase() ?? wallet.currency.name;
|
2022-08-09 15:06:21 +00:00
|
|
|
|
2022-03-30 15:57:04 +00:00
|
|
|
bool get hasCurrecyChanger => walletType == WalletType.haven;
|
|
|
|
|
2022-11-25 20:51:07 +00:00
|
|
|
@computed
|
|
|
|
FiatCurrency get fiatCurrency => _settingsStore.fiatCurrency;
|
|
|
|
|
2020-08-25 16:32:40 +00:00
|
|
|
final SettingsStore _settingsStore;
|
2021-07-16 09:32:36 +00:00
|
|
|
final SendTemplateViewModel sendTemplateViewModel;
|
2022-04-22 15:00:28 +00:00
|
|
|
final BalanceViewModel balanceViewModel;
|
2023-08-04 13:49:26 +00:00
|
|
|
final ContactListViewModel contactListViewModel;
|
2024-05-22 01:18:04 +00:00
|
|
|
final LedgerViewModel? ledgerViewModel;
|
2020-09-21 11:50:26 +00:00
|
|
|
final FiatConversionStore _fiatConversationStore;
|
2020-11-06 18:54:00 +00:00
|
|
|
final Box<TransactionDescription> transactionDescriptionBox;
|
2023-09-01 15:06:18 +00:00
|
|
|
|
|
|
|
@observable
|
|
|
|
bool hasMultipleTokens;
|
2020-08-25 16:32:40 +00:00
|
|
|
|
2023-08-04 13:49:26 +00:00
|
|
|
@computed
|
|
|
|
List<ContactRecord> get contactsToShow => contactListViewModel.contacts
|
2023-08-24 13:54:05 +00:00
|
|
|
.where((element) => element.type == selectedCryptoCurrency)
|
2023-08-04 13:49:26 +00:00
|
|
|
.toList();
|
|
|
|
|
|
|
|
@computed
|
|
|
|
List<WalletContact> get walletContactsToShow => contactListViewModel.walletContacts
|
2023-08-24 13:54:05 +00:00
|
|
|
.where((element) => element.type == selectedCryptoCurrency)
|
2023-08-04 13:49:26 +00:00
|
|
|
.toList();
|
|
|
|
|
|
|
|
@action
|
|
|
|
bool checkIfAddressIsAContact(String address) {
|
|
|
|
final contactList = contactsToShow.where((element) => element.address == address).toList();
|
|
|
|
|
|
|
|
return contactList.isNotEmpty;
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
bool checkIfWalletIsAnInternalWallet(String address) {
|
|
|
|
final walletContactList =
|
|
|
|
walletContactsToShow.where((element) => element.address == address).toList();
|
|
|
|
|
|
|
|
return walletContactList.isNotEmpty;
|
|
|
|
}
|
|
|
|
|
|
|
|
@computed
|
|
|
|
bool get shouldDisplayTOTP2FAForContact => _settingsStore.shouldRequireTOTP2FAForSendsToContact;
|
|
|
|
|
|
|
|
@computed
|
|
|
|
bool get shouldDisplayTOTP2FAForNonContact =>
|
|
|
|
_settingsStore.shouldRequireTOTP2FAForSendsToNonContact;
|
|
|
|
|
|
|
|
@computed
|
|
|
|
bool get shouldDisplayTOTP2FAForSendsToInternalWallet =>
|
|
|
|
_settingsStore.shouldRequireTOTP2FAForSendsToInternalWallets;
|
|
|
|
|
|
|
|
//* Still open to further optimize these checks
|
|
|
|
//* It works but can be made better
|
|
|
|
@action
|
|
|
|
bool checkThroughChecksToDisplayTOTP(String address) {
|
|
|
|
final isContact = checkIfAddressIsAContact(address);
|
|
|
|
final isInternalWallet = checkIfWalletIsAnInternalWallet(address);
|
|
|
|
|
|
|
|
if (isContact) {
|
|
|
|
return shouldDisplayTOTP2FAForContact;
|
|
|
|
} else if (isInternalWallet) {
|
|
|
|
return shouldDisplayTOTP2FAForSendsToInternalWallet;
|
|
|
|
} else {
|
|
|
|
return shouldDisplayTOTP2FAForNonContact;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool shouldDisplayTotp() {
|
|
|
|
List<bool> conditionsList = [];
|
|
|
|
|
|
|
|
for (var output in outputs) {
|
2023-10-09 15:18:59 +00:00
|
|
|
final show = checkThroughChecksToDisplayTOTP(output.extractedAddress);
|
2023-08-04 13:49:26 +00:00
|
|
|
conditionsList.add(show);
|
|
|
|
}
|
|
|
|
|
|
|
|
return conditionsList.contains(true);
|
|
|
|
}
|
|
|
|
|
2020-08-25 16:32:40 +00:00
|
|
|
@action
|
2024-03-28 12:41:11 +00:00
|
|
|
Future<PendingTransaction?> createTransaction({ExchangeProvider? provider}) async {
|
2020-08-25 16:32:40 +00:00
|
|
|
try {
|
2020-09-21 11:50:26 +00:00
|
|
|
state = IsExecutingState();
|
2024-04-25 01:14:11 +00:00
|
|
|
|
2024-05-05 01:44:50 +00:00
|
|
|
if (wallet.isHardwareWallet) state = IsAwaitingDeviceResponseState();
|
|
|
|
|
2023-09-01 15:06:18 +00:00
|
|
|
pendingTransaction = await wallet.createTransaction(_credentials());
|
2024-05-05 01:44:50 +00:00
|
|
|
|
2024-03-28 12:41:11 +00:00
|
|
|
if (provider is ThorChainExchangeProvider) {
|
|
|
|
final outputCount = pendingTransaction?.outputCount ?? 0;
|
2024-04-01 13:31:14 +00:00
|
|
|
if (outputCount > 10) {
|
2024-04-25 01:14:11 +00:00
|
|
|
throw Exception("THORChain does not support more than 10 outputs");
|
2024-04-01 13:31:14 +00:00
|
|
|
}
|
2024-04-25 01:14:11 +00:00
|
|
|
|
2024-04-01 13:31:14 +00:00
|
|
|
if (_hasTaprootInput(pendingTransaction)) {
|
2024-04-25 01:14:11 +00:00
|
|
|
throw Exception("THORChain does not support Taproot addresses");
|
2024-04-01 13:31:14 +00:00
|
|
|
}
|
2024-03-28 12:41:11 +00:00
|
|
|
}
|
2020-09-21 11:50:26 +00:00
|
|
|
state = ExecutedSuccessfullyState();
|
2024-03-28 12:41:11 +00:00
|
|
|
return pendingTransaction;
|
2020-08-25 16:32:40 +00:00
|
|
|
} catch (e) {
|
2024-05-05 01:44:50 +00:00
|
|
|
if (e is LedgerException) {
|
|
|
|
final errorCode = e.errorCode.toRadixString(16);
|
2024-05-06 19:11:18 +00:00
|
|
|
final fallbackMsg =
|
|
|
|
e.message.isNotEmpty ? e.message : "Unexpected Ledger Error Code: $errorCode";
|
2024-05-22 01:18:04 +00:00
|
|
|
final errorMsg = ledgerViewModel!.interpretErrorCode(errorCode) ?? fallbackMsg;
|
2024-05-05 01:44:50 +00:00
|
|
|
|
|
|
|
state = FailureState(errorMsg);
|
|
|
|
} else {
|
|
|
|
state = FailureState(translateErrorMessage(e, wallet.type, wallet.currency));
|
|
|
|
}
|
2020-08-25 16:32:40 +00:00
|
|
|
}
|
2024-04-01 13:31:14 +00:00
|
|
|
return null;
|
2020-08-25 16:32:40 +00:00
|
|
|
}
|
|
|
|
|
2024-04-08 14:54:58 +00:00
|
|
|
@action
|
|
|
|
Future<void> replaceByFee(String txId, String newFee) async {
|
|
|
|
state = IsExecutingState();
|
|
|
|
|
|
|
|
final isSufficient = await bitcoin!.isChangeSufficientForFee(wallet, txId, newFee);
|
|
|
|
|
|
|
|
if (!isSufficient) {
|
|
|
|
state = AwaitingConfirmationState(
|
|
|
|
title: S.current.confirm_fee_deduction,
|
|
|
|
message: S.current.confirm_fee_deduction_content,
|
|
|
|
onConfirm: () async {
|
|
|
|
pendingTransaction = await bitcoin!.replaceByFee(wallet, txId, newFee);
|
|
|
|
state = ExecutedSuccessfullyState();
|
|
|
|
},
|
|
|
|
onCancel: () {
|
|
|
|
state = FailureState('Insufficient change for fee');
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
pendingTransaction = await bitcoin!.replaceByFee(wallet, txId, newFee);
|
|
|
|
state = ExecutedSuccessfullyState();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-25 16:32:40 +00:00
|
|
|
@action
|
|
|
|
Future<void> commitTransaction() async {
|
2022-10-12 17:09:57 +00:00
|
|
|
if (pendingTransaction == null) {
|
|
|
|
throw Exception("Pending transaction doesn't exist. It should not be happened.");
|
|
|
|
}
|
|
|
|
|
2021-08-10 14:52:35 +00:00
|
|
|
String address = outputs.fold('', (acc, value) {
|
2021-10-04 14:25:27 +00:00
|
|
|
return value.isParsedAddress
|
2024-05-05 01:44:50 +00:00
|
|
|
? '$acc${value.address}\n${value.extractedAddress}\n\n'
|
|
|
|
: '$acc${value.address}\n\n';
|
2021-07-20 15:03:49 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
address = address.trim();
|
|
|
|
|
2024-05-05 01:44:50 +00:00
|
|
|
String note = outputs.fold('', (acc, value) => '$acc${value.note}\n');
|
2021-07-20 15:03:49 +00:00
|
|
|
|
|
|
|
note = note.trim();
|
|
|
|
|
2020-08-25 16:32:40 +00:00
|
|
|
try {
|
|
|
|
state = TransactionCommitting();
|
2022-10-12 17:09:57 +00:00
|
|
|
await pendingTransaction!.commit();
|
2020-11-06 18:54:00 +00:00
|
|
|
|
2023-10-05 01:09:07 +00:00
|
|
|
if (walletType == WalletType.nano) {
|
|
|
|
nano!.updateTransactions(wallet);
|
|
|
|
}
|
|
|
|
|
2022-11-25 20:51:07 +00:00
|
|
|
if (pendingTransaction!.id.isNotEmpty) {
|
2020-12-24 10:04:23 +00:00
|
|
|
_settingsStore.shouldSaveRecipientAddress
|
2021-01-11 17:15:27 +00:00
|
|
|
? await transactionDescriptionBox.add(TransactionDescription(
|
2023-08-04 13:49:26 +00:00
|
|
|
id: pendingTransaction!.id, recipientAddress: address, transactionNote: note))
|
|
|
|
: await transactionDescriptionBox
|
|
|
|
.add(TransactionDescription(id: pendingTransaction!.id, transactionNote: note));
|
2020-11-06 18:54:00 +00:00
|
|
|
}
|
|
|
|
|
2020-08-25 16:32:40 +00:00
|
|
|
state = TransactionCommitted();
|
|
|
|
} catch (e) {
|
2024-03-29 18:51:34 +00:00
|
|
|
state = FailureState(translateErrorMessage(e, wallet.type, wallet.currency));
|
2020-08-25 16:32:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-30 18:23:15 +00:00
|
|
|
@action
|
|
|
|
void setTransactionPriority(TransactionPriority priority) =>
|
2023-09-01 15:06:18 +00:00
|
|
|
_settingsStore.priority[wallet.type] = priority;
|
2020-09-30 18:23:15 +00:00
|
|
|
|
2020-08-25 16:32:40 +00:00
|
|
|
Object _credentials() {
|
2023-10-12 22:50:16 +00:00
|
|
|
final priority = _settingsStore.priority[wallet.type];
|
2020-09-21 11:50:26 +00:00
|
|
|
|
2024-05-06 19:11:18 +00:00
|
|
|
if (priority == null &&
|
|
|
|
wallet.type != WalletType.nano &&
|
|
|
|
wallet.type != WalletType.banano &&
|
|
|
|
wallet.type != WalletType.solana &&
|
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 18:00:05 +00:00
|
|
|
wallet.type != WalletType.tron) {
|
2023-10-17 15:59:41 +00:00
|
|
|
throw Exception('Priority is null for wallet type: ${wallet.type}');
|
|
|
|
}
|
2022-10-12 17:09:57 +00:00
|
|
|
|
2023-10-12 22:50:16 +00:00
|
|
|
switch (wallet.type) {
|
|
|
|
case WalletType.bitcoin:
|
2021-05-07 07:36:38 +00:00
|
|
|
case WalletType.litecoin:
|
2023-10-12 22:50:16 +00:00
|
|
|
case WalletType.bitcoinCash:
|
2024-04-08 14:54:58 +00:00
|
|
|
return bitcoin!.createBitcoinTransactionCredentials(outputs,
|
|
|
|
priority: priority!, feeRate: customBitcoinFeeRate);
|
2022-10-12 17:09:57 +00:00
|
|
|
|
2023-10-12 22:50:16 +00:00
|
|
|
case WalletType.monero:
|
2023-08-04 13:49:26 +00:00
|
|
|
return monero!
|
2023-10-17 15:59:41 +00:00
|
|
|
.createMoneroTransactionCreationCredentials(outputs: outputs, priority: priority!);
|
2023-08-04 13:49:26 +00:00
|
|
|
|
2023-10-12 22:50:16 +00:00
|
|
|
case WalletType.haven:
|
2022-10-12 17:09:57 +00:00
|
|
|
return haven!.createHavenTransactionCreationCredentials(
|
2023-10-17 15:59:41 +00:00
|
|
|
outputs: outputs, priority: priority!, assetType: selectedCryptoCurrency.title);
|
2023-10-12 22:50:16 +00:00
|
|
|
|
2023-08-04 17:01:49 +00:00
|
|
|
case WalletType.ethereum:
|
2023-09-01 15:06:18 +00:00
|
|
|
return ethereum!.createEthereumTransactionCredentials(outputs,
|
2023-10-17 15:59:41 +00:00
|
|
|
priority: priority!, currency: selectedCryptoCurrency);
|
2023-10-05 01:09:07 +00:00
|
|
|
case WalletType.nano:
|
2023-10-12 22:50:16 +00:00
|
|
|
return nano!.createNanoTransactionCredentials(outputs);
|
2023-12-02 02:26:43 +00:00
|
|
|
case WalletType.polygon:
|
|
|
|
return polygon!.createPolygonTransactionCredentials(outputs,
|
|
|
|
priority: priority!, currency: selectedCryptoCurrency);
|
CW-555-Add-Solana-Wallet (#1272)
* chore: Create cw_solana package and clean up files
* feat: Add Solana Wallet - Create, Restore form seed, restore from Key, Restore from QR, Send, Receive, transaction history, spl tokens
* fix: Make transactions file specific to solana only for solana transactions
* chore: Revert inject app details script
* fix: Fix issue with node and switch current node to main beta instead of testnet
* fix: Fix merge conflicts and adjust migration version
* fix: Fetch spl token error
Signed-off-by: Blazebrain <davidadegoke16@gmail.com>
* fix: Diplay and activate spl tokens bug
* fix: Review and fixes
* fix: reverted formatting for cryptocurrency class
* fix: Review comments, split sending flow into signing and sending separately, fix issues
* fix: Revert throwing unimplenented error
* chore: Fix comment
* chore: Fix comment
* fix: Errors in flow
* Update provider_types.dart [skip ci]
* fix: Issues with solana wallet
* Update solana_wallet.dart [skip ci]
* fix: Review comments
* fix: Date time config
* fix: Revert bash script for app details
* fix: Error with balance, displaying fees, fixing sent or received identifier bug, displaying token symbol with token transaction item in transactions list
* fix: Issues with address validation when sending spl tokens and walletconnect initial setup
* fix: Issues with sending, fetching transactions history, almost wrapping up walletconnect
* fix: Adjust imports that would affect monerocom building successfully
* fix: Refine transaction direction and continue work on walletconnect
* feat: Display SPL token transfers in the transaction history and finally settle the transaction direction
* fix: Delay in transactions history dispaly, show native token transactions first, then process spl token transactions
* feat: Switch node and revert solana chain id to previous id
* fix: Remove print statement
* fix: Remove await for transactions, fetch all transaction histories instantly and adjust solana send success message
* chore: Code refactoring and streamlined wallet type check for solana send success message
* fix: Make timeout error for node silent and add spl token images
---------
Signed-off-by: Blazebrain <davidadegoke16@gmail.com>
Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
2024-02-23 13:39:19 +00:00
|
|
|
case WalletType.solana:
|
|
|
|
return solana!
|
|
|
|
.createSolanaTransactionCredentials(outputs, currency: selectedCryptoCurrency);
|
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 18:00:05 +00:00
|
|
|
case WalletType.tron:
|
|
|
|
return tron!.createTronTransactionCredentials(outputs, currency: selectedCryptoCurrency);
|
2020-08-25 16:32:40 +00:00
|
|
|
default:
|
2023-09-01 15:06:18 +00:00
|
|
|
throw Exception('Unexpected wallet type: ${wallet.type}');
|
2021-07-20 15:03:49 +00:00
|
|
|
}
|
2020-09-21 11:50:26 +00:00
|
|
|
}
|
2020-10-07 05:58:22 +00:00
|
|
|
|
2024-04-08 14:54:58 +00:00
|
|
|
String displayFeeRate(dynamic priority, int? customValue) {
|
2021-02-12 22:38:34 +00:00
|
|
|
final _priority = priority as TransactionPriority;
|
|
|
|
|
2024-04-08 14:54:58 +00:00
|
|
|
if (walletType == WalletType.bitcoin) {
|
|
|
|
final rate = bitcoin!.getFeeRate(wallet, _priority);
|
|
|
|
return bitcoin!.bitcoinTransactionPriorityWithLabel(_priority, rate, customRate: customValue);
|
|
|
|
}
|
|
|
|
|
2021-12-24 12:37:24 +00:00
|
|
|
if (isElectrumWallet) {
|
2022-10-12 17:09:57 +00:00
|
|
|
final rate = bitcoin!.getFeeRate(wallet, _priority);
|
2022-10-28 22:09:27 +00:00
|
|
|
return bitcoin!.bitcoinTransactionPriorityWithLabel(_priority, rate);
|
2021-02-12 22:38:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return priority.toString();
|
|
|
|
}
|
2022-01-31 12:54:24 +00:00
|
|
|
|
2023-08-04 13:49:26 +00:00
|
|
|
bool _isEqualCurrency(String currency) =>
|
2023-09-01 15:06:18 +00:00
|
|
|
wallet.balance.keys.any((e) => currency.toLowerCase() == e.title.toLowerCase());
|
2022-11-25 20:51:07 +00:00
|
|
|
|
2024-04-08 14:54:58 +00:00
|
|
|
TransactionPriority get bitcoinTransactionPriorityCustom =>
|
|
|
|
bitcoin!.getBitcoinTransactionPriorityCustom();
|
|
|
|
|
|
|
|
TransactionPriority get bitcoinTransactionPriorityMedium =>
|
|
|
|
bitcoin!.getBitcoinTransactionPriorityMedium();
|
|
|
|
|
2022-11-25 20:51:07 +00:00
|
|
|
@action
|
2023-08-04 13:49:26 +00:00
|
|
|
void onClose() => _settingsStore.fiatCurrency = fiatFromSettings;
|
2022-12-12 13:41:16 +00:00
|
|
|
|
2022-11-25 20:51:07 +00:00
|
|
|
@action
|
2023-09-01 15:06:18 +00:00
|
|
|
void setFiatCurrency(FiatCurrency fiat) => _settingsStore.fiatCurrency = fiat;
|
2023-08-04 17:01:49 +00:00
|
|
|
|
|
|
|
@action
|
|
|
|
void setSelectedCryptoCurrency(String cryptoCurrency) {
|
|
|
|
try {
|
2023-09-01 15:06:18 +00:00
|
|
|
selectedCryptoCurrency = wallet.balance.keys
|
2023-08-04 17:01:49 +00:00
|
|
|
.firstWhere((e) => cryptoCurrency.toLowerCase() == e.title.toLowerCase());
|
|
|
|
} catch (e) {
|
2023-09-01 15:06:18 +00:00
|
|
|
selectedCryptoCurrency = wallet.currency;
|
2023-08-04 17:01:49 +00:00
|
|
|
}
|
|
|
|
}
|
2023-09-25 12:20:11 +00:00
|
|
|
|
2024-03-29 18:51:34 +00:00
|
|
|
ContactRecord? newContactAddress() {
|
2024-03-19 22:44:00 +00:00
|
|
|
final Set<String> contactAddresses =
|
2024-03-29 18:51:34 +00:00
|
|
|
Set.from(contactListViewModel.contacts.map((contact) => contact.address))
|
|
|
|
..addAll(contactListViewModel.walletContacts.map((contact) => contact.address));
|
2024-03-19 22:44:00 +00:00
|
|
|
|
|
|
|
for (var output in outputs) {
|
|
|
|
String address;
|
|
|
|
if (output.isParsedAddress) {
|
|
|
|
address = output.parsedAddress.addresses.first;
|
|
|
|
} else {
|
|
|
|
address = output.address;
|
|
|
|
}
|
|
|
|
|
2024-04-12 14:01:21 +00:00
|
|
|
if (address.isNotEmpty &&
|
|
|
|
!contactAddresses.contains(address) &&
|
|
|
|
selectedCryptoCurrency.raw != -1) {
|
2024-03-19 22:44:00 +00:00
|
|
|
return ContactRecord(
|
|
|
|
contactListViewModel.contactSource,
|
|
|
|
Contact(
|
|
|
|
name: '',
|
|
|
|
address: address,
|
|
|
|
type: selectedCryptoCurrency,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2023-10-09 15:18:59 +00:00
|
|
|
String translateErrorMessage(
|
2024-03-29 18:51:34 +00:00
|
|
|
Object error,
|
2023-10-09 15:18:59 +00:00
|
|
|
WalletType walletType,
|
|
|
|
CryptoCurrency currency,
|
|
|
|
) {
|
2024-03-29 18:51:34 +00:00
|
|
|
String errorMessage = error.toString();
|
|
|
|
|
2023-12-02 02:26:43 +00:00
|
|
|
if (walletType == WalletType.ethereum ||
|
|
|
|
walletType == WalletType.polygon ||
|
2024-03-10 02:02:30 +00:00
|
|
|
walletType == WalletType.solana ||
|
2023-12-02 02:26:43 +00:00
|
|
|
walletType == WalletType.haven) {
|
2024-03-29 18:51:34 +00:00
|
|
|
if (errorMessage.contains('gas required exceeds allowance') ||
|
|
|
|
errorMessage.contains('insufficient funds')) {
|
2023-09-25 12:20:11 +00:00
|
|
|
return S.current.do_not_have_enough_gas_asset(currency.toString());
|
|
|
|
}
|
2023-12-02 02:26:43 +00:00
|
|
|
|
2024-03-29 18:51:34 +00:00
|
|
|
return errorMessage;
|
|
|
|
}
|
|
|
|
|
2024-05-06 19:11:18 +00:00
|
|
|
if (walletType == WalletType.tron) {
|
|
|
|
if (errorMessage.contains('balance is not sufficient')) {
|
|
|
|
return S.current.do_not_have_enough_gas_asset(currency.toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (errorMessage.contains('Transaction expired')) {
|
2024-05-10 18:34:28 +00:00
|
|
|
return 'An error occurred while processing the transaction. Please retry the transaction';
|
2024-05-06 19:11:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-29 18:51:34 +00:00
|
|
|
if (walletType == WalletType.bitcoin ||
|
|
|
|
walletType == WalletType.litecoin ||
|
|
|
|
walletType == WalletType.bitcoinCash) {
|
|
|
|
if (error is TransactionWrongBalanceException) {
|
2024-04-18 13:38:18 +00:00
|
|
|
if (error.amount != null)
|
|
|
|
return S.current
|
|
|
|
.tx_wrong_balance_with_amount_exception(currency.toString(), error.amount.toString());
|
|
|
|
|
2024-03-29 18:51:34 +00:00
|
|
|
return S.current.tx_wrong_balance_exception(currency.toString());
|
|
|
|
}
|
|
|
|
if (error is TransactionNoInputsException) {
|
|
|
|
return S.current.tx_not_enough_inputs_exception;
|
|
|
|
}
|
|
|
|
if (error is TransactionNoFeeException) {
|
|
|
|
return S.current.tx_zero_fee_exception;
|
|
|
|
}
|
|
|
|
if (error is TransactionNoDustException) {
|
|
|
|
return S.current.tx_no_dust_exception;
|
|
|
|
}
|
|
|
|
if (error is TransactionCommitFailed) {
|
2024-04-26 19:29:31 +00:00
|
|
|
return "${S.current.tx_commit_failed}${error.errorMessage != null ? "\n\n${error.errorMessage}" : ""}";
|
2024-03-29 18:51:34 +00:00
|
|
|
}
|
|
|
|
if (error is TransactionCommitFailedDustChange) {
|
|
|
|
return S.current.tx_rejected_dust_change;
|
|
|
|
}
|
|
|
|
if (error is TransactionCommitFailedDustOutput) {
|
|
|
|
return S.current.tx_rejected_dust_output;
|
|
|
|
}
|
|
|
|
if (error is TransactionCommitFailedDustOutputSendAll) {
|
|
|
|
return S.current.tx_rejected_dust_output_send_all;
|
|
|
|
}
|
|
|
|
if (error is TransactionCommitFailedVoutNegative) {
|
|
|
|
return S.current.tx_rejected_vout_negative;
|
|
|
|
}
|
2024-04-17 19:35:11 +00:00
|
|
|
if (error is TransactionCommitFailedBIP68Final) {
|
|
|
|
return S.current.tx_rejected_bip68_final;
|
|
|
|
}
|
2024-03-29 18:51:34 +00:00
|
|
|
if (error is TransactionNoDustOnChangeException) {
|
|
|
|
return S.current.tx_commit_exception_no_dust_on_change(error.min, error.max);
|
|
|
|
}
|
2024-04-17 19:35:11 +00:00
|
|
|
if (error is TransactionInputNotSupported) {
|
|
|
|
return S.current.tx_invalid_input;
|
|
|
|
}
|
2023-09-25 12:20:11 +00:00
|
|
|
}
|
|
|
|
|
2024-03-29 18:51:34 +00:00
|
|
|
return errorMessage;
|
2023-09-25 12:20:11 +00:00
|
|
|
}
|
2024-04-01 13:31:14 +00:00
|
|
|
|
|
|
|
bool _hasTaprootInput(PendingTransaction? pendingTransaction) {
|
|
|
|
if (walletType == WalletType.bitcoin && pendingTransaction != null) {
|
|
|
|
return bitcoin!.hasTaprootInput(pendingTransaction);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2020-08-25 16:32:40 +00:00
|
|
|
}
|