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
This commit is contained in:
Adegoke David
2024-05-03 21:00:05 +03:00
committed by GitHub
parent e4fd534949
commit d1870ba8b8
82 changed files with 3660 additions and 62 deletions
+2
View File
@@ -294,6 +294,8 @@ class AddressValidator extends TextValidator {
'|([^0-9a-zA-Z]|^)q[0-9a-zA-Z]{42}([^0-9a-zA-Z]|\$)';
case CryptoCurrency.sol:
return '([^0-9a-zA-Z]|^)[1-9A-HJ-NP-Za-km-z]{43,44}([^0-9a-zA-Z]|\$)';
case CryptoCurrency.trx:
return '^(T|t)[1-9A-HJ-NP-Za-km-z]{33}\$';
default:
if (type.tag == CryptoCurrency.eth.title) {
return '0x[0-9a-zA-Z]{42}';
+3
View File
@@ -5,6 +5,7 @@ import 'package:cake_wallet/core/validator.dart';
import 'package:cake_wallet/entities/mnemonic_item.dart';
import 'package:cake_wallet/polygon/polygon.dart';
import 'package:cake_wallet/solana/solana.dart';
import 'package:cake_wallet/tron/tron.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:cake_wallet/monero/monero.dart';
import 'package:cake_wallet/nano/nano.dart';
@@ -40,6 +41,8 @@ class SeedValidator extends Validator<MnemonicItem> {
return polygon!.getPolygonWordList(language);
case WalletType.solana:
return solana!.getSolanaWordList(language);
case WalletType.tron:
return tron!.getTronWordList(language);
default:
return [];
}
+3
View File
@@ -13,6 +13,7 @@ import 'package:cake_wallet/core/yat_service.dart';
import 'package:cake_wallet/entities/background_tasks.dart';
import 'package:cake_wallet/entities/exchange_api_mode.dart';
import 'package:cake_wallet/entities/parse_address_from_domain.dart';
import 'package:cake_wallet/tron/tron.dart';
import 'package:cake_wallet/src/screens/transaction_details/rbf_details_page.dart';
import 'package:cw_core/receive_page_option.dart';
import 'package:cake_wallet/ethereum/ethereum.dart';
@@ -873,6 +874,8 @@ Future<void> setup({
return polygon!.createPolygonWalletService(_walletInfoSource);
case WalletType.solana:
return solana!.createSolanaWalletService(_walletInfoSource);
case WalletType.tron:
return tron!.createTronWalletService(_walletInfoSource);
default:
throw Exception('Unexpected token: ${param1.toString()} for generating of WalletService');
}
+36 -5
View File
@@ -36,6 +36,7 @@ const cakeWalletBitcoinCashDefaultNodeUri = 'bitcoincash.stackwallet.com:50002';
const nanoDefaultNodeUri = 'rpc.nano.to';
const nanoDefaultPowNodeUri = 'rpc.nano.to';
const solanaDefaultNodeUri = 'rpc.ankr.com';
const tronDefaultNodeUri = 'api.trongrid.io';
const newCakeWalletBitcoinUri = 'btc-electrum.cakewallet.com:50002';
Future<void> defaultSettingsMigration(
@@ -207,23 +208,22 @@ Future<void> defaultSettingsMigration(
case 28:
await _updateMoneroPriority(sharedPreferences);
break;
case 29:
await changeDefaultBitcoinNode(nodes, sharedPreferences);
break;
case 30:
await disableServiceStatusFiatDisabled(sharedPreferences);
break;
case 31:
await updateNanoNodeList(nodes: nodes);
break;
case 32:
await updateBtcNanoWalletInfos(walletInfoSource);
break;
case 33:
await addTronNodeList(nodes: nodes);
await changeTronCurrentNodeToDefault(sharedPreferences: sharedPreferences, nodes: nodes);
break;
default:
break;
}
@@ -478,6 +478,11 @@ Node? getSolanaDefaultNode({required Box<Node> nodes}) {
nodes.values.firstWhereOrNull((node) => node.type == WalletType.solana);
}
Node? getTronDefaultNode({required Box<Node> nodes}) {
return nodes.values.firstWhereOrNull((Node node) => node.uriRaw == tronDefaultNodeUri) ??
nodes.values.firstWhereOrNull((node) => node.type == WalletType.tron);
}
Future<void> insecureStorageMigration({
required SharedPreferences sharedPreferences,
required FlutterSecureStorage secureStorage,
@@ -809,6 +814,7 @@ Future<void> checkCurrentNodes(
final currentBitcoinCashNodeId =
sharedPreferences.getInt(PreferencesKey.currentBitcoinCashNodeIdKey);
final currentSolanaNodeId = sharedPreferences.getInt(PreferencesKey.currentSolanaNodeIdKey);
final currentTronNodeId = sharedPreferences.getInt(PreferencesKey.currentTronNodeIdKey);
final currentMoneroNode =
nodeSource.values.firstWhereOrNull((node) => node.key == currentMoneroNodeId);
final currentBitcoinElectrumServer =
@@ -829,6 +835,8 @@ Future<void> checkCurrentNodes(
nodeSource.values.firstWhereOrNull((node) => node.key == currentBitcoinCashNodeId);
final currentSolanaNodeServer =
nodeSource.values.firstWhereOrNull((node) => node.key == currentSolanaNodeId);
final currentTronNodeServer =
nodeSource.values.firstWhereOrNull((node) => node.key == currentTronNodeId);
if (currentMoneroNode == null) {
final newCakeWalletNode = Node(uri: newCakeWalletMoneroUri, type: WalletType.monero);
await nodeSource.add(newCakeWalletNode);
@@ -894,6 +902,12 @@ Future<void> checkCurrentNodes(
await nodeSource.add(node);
await sharedPreferences.setInt(PreferencesKey.currentSolanaNodeIdKey, node.key as int);
}
if (currentTronNodeServer == null) {
final node = Node(uri: tronDefaultNodeUri, type: WalletType.tron);
await nodeSource.add(node);
await sharedPreferences.setInt(PreferencesKey.currentTronNodeIdKey, node.key as int);
}
}
Future<void> resetBitcoinElectrumServer(
@@ -1022,3 +1036,20 @@ Future<void> changeSolanaCurrentNodeToDefault(
await sharedPreferences.setInt(PreferencesKey.currentSolanaNodeIdKey, nodeId);
}
Future<void> addTronNodeList({required Box<Node> nodes}) async {
final nodeList = await loadDefaultTronNodes();
for (var node in nodeList) {
if (nodes.values.firstWhereOrNull((element) => element.uriRaw == node.uriRaw) == null) {
await nodes.add(node);
}
}
}
Future<void> changeTronCurrentNodeToDefault(
{required SharedPreferences sharedPreferences, required Box<Node> nodes}) async {
final node = getTronDefaultNode(nodes: nodes);
final nodeId = node?.key as int? ?? 0;
await sharedPreferences.setInt(PreferencesKey.currentTronNodeIdKey, nodeId);
}
+19 -1
View File
@@ -166,6 +166,23 @@ Future<List<Node>> loadDefaultSolanaNodes() async {
return nodes;
}
Future<List<Node>> loadDefaultTronNodes() async {
final nodesRaw = await rootBundle.loadString('assets/tron_node_list.yml');
final loadedNodes = loadYaml(nodesRaw) as YamlList;
final nodes = <Node>[];
for (final raw in loadedNodes) {
if (raw is Map) {
final node = Node.fromMap(Map<String, Object>.from(raw));
node.type = WalletType.tron;
nodes.add(node);
}
}
return nodes;
}
Future<void> resetToDefault(Box<Node> nodeSource) async {
final moneroNodes = await loadDefaultNodes();
final bitcoinElectrumServerList = await loadBitcoinElectrumServerList();
@@ -176,6 +193,7 @@ Future<void> resetToDefault(Box<Node> nodeSource) async {
final nanoNodes = await loadDefaultNanoNodes();
final polygonNodes = await loadDefaultPolygonNodes();
final solanaNodes = await loadDefaultSolanaNodes();
final tronNodes = await loadDefaultTronNodes();
final nodes = moneroNodes +
bitcoinElectrumServerList +
@@ -185,7 +203,7 @@ Future<void> resetToDefault(Box<Node> nodeSource) async {
bitcoinCashElectrumServerList +
nanoNodes +
polygonNodes +
solanaNodes;
solanaNodes + tronNodes;
await nodeSource.clear();
await nodeSource.addAll(nodes);
+1
View File
@@ -14,6 +14,7 @@ class PreferencesKey {
static const currentFiatCurrencyKey = 'current_fiat_currency';
static const currentBitcoinCashNodeIdKey = 'current_node_id_bch';
static const currentSolanaNodeIdKey = 'current_node_id_sol';
static const currentTronNodeIdKey = 'current_node_id_trx';
static const currentTransactionPriorityKeyLegacy = 'current_fee_priority';
static const currentBalanceDisplayModeKey = 'current_balance_display_mode';
static const shouldSaveRecipientAddressKey = 'save_recipient_address';
+2 -1
View File
@@ -23,10 +23,11 @@ List<TransactionPriority> priorityForWalletType(WalletType type) {
return bitcoinCash!.getTransactionPriorities();
case WalletType.polygon:
return polygon!.getTransactionPriorities();
// no such thing for nano/banano/solana:
// no such thing for nano/banano/solana/tron:
case WalletType.nano:
case WalletType.banano:
case WalletType.solana:
case WalletType.tron:
return [];
default:
return [];
+13
View File
@@ -69,6 +69,13 @@ class ProvidersHelper {
return [ProviderType.askEachTime, ProviderType.onramper, ProviderType.robinhood, ProviderType.moonpay];
case WalletType.solana:
return [ProviderType.askEachTime, ProviderType.onramper, ProviderType.robinhood];
case WalletType.tron:
return [
ProviderType.askEachTime,
ProviderType.onramper,
ProviderType.robinhood,
ProviderType.moonpay,
];
case WalletType.none:
case WalletType.haven:
return [];
@@ -96,6 +103,12 @@ class ProvidersHelper {
ProviderType.robinhood,
ProviderType.moonpay,
];
case WalletType.tron:
return [
ProviderType.askEachTime,
ProviderType.robinhood,
ProviderType.moonpay,
];
case WalletType.monero:
case WalletType.nano:
case WalletType.banano:
+1 -1
View File
@@ -167,7 +167,7 @@ Future<void> initializeAppConfigs() async {
transactionDescriptions: transactionDescriptions,
secureStorage: secureStorage,
anonpayInvoiceInfo: anonpayInvoiceInfo,
initialMigrationVersion: 32,
initialMigrationVersion: 33,
);
}
+6
View File
@@ -8,6 +8,7 @@ import 'package:cake_wallet/solana/solana.dart';
import 'package:cake_wallet/store/app_store.dart';
import 'package:cake_wallet/store/dashboard/fiat_conversion_store.dart';
import 'package:cake_wallet/store/settings_store.dart';
import 'package:cake_wallet/tron/tron.dart';
import 'package:cw_core/crypto_currency.dart';
import 'package:cw_core/erc20_token.dart';
import 'package:cw_core/wallet_type.dart';
@@ -53,6 +54,11 @@ Future<void> startFiatRateUpdate(
solana!.getSPLTokenCurrencies(appStore.wallet!).where((element) => element.enabled);
}
if (appStore.wallet!.type == WalletType.tron) {
currencies =
tron!.getTronTokenCurrencies(appStore.wallet!).where((element) => element.enabled);
}
if (currencies != null) {
for (final currency in currencies) {
+10 -4
View File
@@ -4,8 +4,8 @@ import 'package:cake_wallet/entities/update_haven_rate.dart';
import 'package:cake_wallet/ethereum/ethereum.dart';
import 'package:cake_wallet/polygon/polygon.dart';
import 'package:cake_wallet/solana/solana.dart';
import 'package:cake_wallet/tron/tron.dart';
import 'package:cw_core/crypto_currency.dart';
import 'package:cw_core/erc20_token.dart';
import 'package:cw_core/transaction_history.dart';
import 'package:cw_core/balance.dart';
import 'package:cw_core/transaction_info.dart';
@@ -70,8 +70,10 @@ void startCurrentWalletChangeReaction(
.get<SharedPreferences>()
.setInt(PreferencesKey.currentWalletType, serializeToInt(wallet.type));
if (wallet.type == WalletType.monero || wallet.type == WalletType.bitcoin ||
wallet.type == WalletType.litecoin || wallet.type == WalletType.bitcoinCash ) {
if (wallet.type == WalletType.monero ||
wallet.type == WalletType.bitcoin ||
wallet.type == WalletType.litecoin ||
wallet.type == WalletType.bitcoinCash) {
_setAutoGenerateSubaddressStatus(wallet, settingsStore);
}
@@ -124,7 +126,11 @@ void startCurrentWalletChangeReaction(
currencies =
solana!.getSPLTokenCurrencies(appStore.wallet!).where((element) => element.enabled);
}
if (wallet.type == WalletType.tron) {
currencies =
tron!.getTronTokenCurrencies(appStore.wallet!).where((element) => element.enabled);
}
if (currencies != null) {
for (final currency in currencies) {
() async {
@@ -38,6 +38,7 @@ class _DesktopWalletSelectionDropDownState extends State<DesktopWalletSelectionD
final nanoIcon = Image.asset('assets/images/nano_icon.png', height: 24, width: 24);
final bananoIcon = Image.asset('assets/images/nano_icon.png', height: 24, width: 24);
final solanaIcon = Image.asset('assets/images/sol_icon.png', height: 24, width: 24);
final tronIcon = Image.asset('assets/images/trx_icon.png', height: 24, width: 24);
final nonWalletTypeIcon = Image.asset('assets/images/close.png', height: 24, width: 24);
Image _newWalletImage(BuildContext context) => Image.asset(
@@ -156,6 +157,8 @@ class _DesktopWalletSelectionDropDownState extends State<DesktopWalletSelectionD
return polygonIcon;
case WalletType.solana:
return solanaIcon;
case WalletType.tron:
return tronIcon;
default:
return nonWalletTypeIcon;
}
@@ -82,21 +82,27 @@ class TransactionsPage extends StatelessWidget {
}
if (item is TransactionListItem) {
if (item.hasTokens && item.assetOfTransaction == null) {
return Container();
}
final transaction = item.transaction;
return Observer(
builder: (_) => TransactionRow(
onTap: () => Navigator.of(context)
.pushNamed(Routes.transactionDetails, arguments: transaction),
direction: transaction.direction,
formattedDate: DateFormat('HH:mm').format(transaction.date),
formattedAmount: item.formattedCryptoAmount,
formattedFiatAmount:
dashboardViewModel.balanceViewModel.isFiatDisabled
? ''
: item.formattedFiatAmount,
isPending: transaction.isPending,
title: item.formattedTitle + item.formattedStatus));
builder: (_) => TransactionRow(
onTap: () => Navigator.of(context)
.pushNamed(Routes.transactionDetails, arguments: transaction),
direction: transaction.direction,
formattedDate: DateFormat('HH:mm').format(transaction.date),
formattedAmount: item.formattedCryptoAmount,
formattedFiatAmount:
dashboardViewModel.balanceViewModel.isFiatDisabled
? ''
: item.formattedFiatAmount,
isPending: transaction.isPending,
title: item.formattedTitle + item.formattedStatus,
),
);
}
if (item is AnonpayTransactionListItem) {
@@ -34,7 +34,8 @@ class MenuWidgetState extends State<MenuWidget> {
this.bananoIcon = Image.asset('assets/images/nano_icon.png'),
this.bitcoinCashIcon = Image.asset('assets/images/bch_icon.png'),
this.polygonIcon = Image.asset('assets/images/matic_icon.png'),
this.solanaIcon = Image.asset('assets/images/sol_icon.png');
this.solanaIcon = Image.asset('assets/images/sol_icon.png'),
this.tronIcon = Image.asset('assets/images/trx_icon.png');
final largeScreen = 731;
@@ -57,6 +58,7 @@ class MenuWidgetState extends State<MenuWidget> {
Image bananoIcon;
Image polygonIcon;
Image solanaIcon;
Image tronIcon;
@override
void initState() {
@@ -226,6 +228,8 @@ class MenuWidgetState extends State<MenuWidget> {
return polygonIcon;
case WalletType.solana:
return solanaIcon;
case WalletType.tron:
return tronIcon;
default:
throw Exception('No icon for ${type.toString()}');
}
@@ -104,6 +104,7 @@ class WalletListBodyState extends State<WalletListBody> {
final nanoIcon = Image.asset('assets/images/nano_icon.png', height: 24, width: 24);
final polygonIcon = Image.asset('assets/images/matic_icon.png', height: 24, width: 24);
final solanaIcon = Image.asset('assets/images/sol_icon.png', height: 24, width: 24);
final tronIcon = Image.asset('assets/images/trx_icon.png', height: 24, width: 24);
final scrollController = ScrollController();
final double tileHeight = 60;
Flushbar<void>? _progressBar;
@@ -316,6 +317,8 @@ class WalletListBodyState extends State<WalletListBody> {
return polygonIcon;
case WalletType.solana:
return solanaIcon;
case WalletType.tron:
return tronIcon;
default:
return nonWalletTypeIcon;
}
+15
View File
@@ -872,6 +872,7 @@ abstract class SettingsStoreBase with Store {
final nanoNodeId = sharedPreferences.getInt(PreferencesKey.currentNanoNodeIdKey);
final nanoPowNodeId = sharedPreferences.getInt(PreferencesKey.currentNanoPowNodeIdKey);
final solanaNodeId = sharedPreferences.getInt(PreferencesKey.currentSolanaNodeIdKey);
final tronNodeId = sharedPreferences.getInt(PreferencesKey.currentTronNodeIdKey);
final moneroNode = nodeSource.get(nodeId);
final bitcoinElectrumServer = nodeSource.get(bitcoinElectrumServerId);
final litecoinElectrumServer = nodeSource.get(litecoinElectrumServerId);
@@ -882,6 +883,7 @@ abstract class SettingsStoreBase with Store {
final nanoNode = nodeSource.get(nanoNodeId);
final nanoPowNode = powNodeSource.get(nanoPowNodeId);
final solanaNode = nodeSource.get(solanaNodeId);
final tronNode = nodeSource.get(tronNodeId);
final packageInfo = await PackageInfo.fromPlatform();
final deviceName = await _getDeviceName() ?? '';
final shouldShowYatPopup = sharedPreferences.getBool(PreferencesKey.shouldShowYatPopup) ?? true;
@@ -944,6 +946,10 @@ abstract class SettingsStoreBase with Store {
nodes[WalletType.solana] = solanaNode;
}
if (tronNode != null) {
nodes[WalletType.tron] = tronNode;
}
final savedSyncMode = SyncMode.all.firstWhere((element) {
return element.type.index == (sharedPreferences.getInt(PreferencesKey.syncModeKey) ?? 0);
});
@@ -1238,6 +1244,7 @@ abstract class SettingsStoreBase with Store {
final polygonNodeId = sharedPreferences.getInt(PreferencesKey.currentPolygonNodeIdKey);
final nanoNodeId = sharedPreferences.getInt(PreferencesKey.currentNanoNodeIdKey);
final solanaNodeId = sharedPreferences.getInt(PreferencesKey.currentSolanaNodeIdKey);
final tronNodeId = sharedPreferences.getInt(PreferencesKey.currentTronNodeIdKey);
final moneroNode = nodeSource.get(nodeId);
final bitcoinElectrumServer = nodeSource.get(bitcoinElectrumServerId);
final litecoinElectrumServer = nodeSource.get(litecoinElectrumServerId);
@@ -1247,6 +1254,7 @@ abstract class SettingsStoreBase with Store {
final bitcoinCashNode = nodeSource.get(bitcoinCashElectrumServerId);
final nanoNode = nodeSource.get(nanoNodeId);
final solanaNode = nodeSource.get(solanaNodeId);
final tronNode = nodeSource.get(tronNodeId);
if (moneroNode != null) {
nodes[WalletType.monero] = moneroNode;
}
@@ -1283,6 +1291,10 @@ abstract class SettingsStoreBase with Store {
nodes[WalletType.solana] = solanaNode;
}
if (tronNode != null) {
nodes[WalletType.tron] = tronNode;
}
// MIGRATED:
useTOTP2FA = await SecureKey.getBool(
@@ -1413,6 +1425,9 @@ abstract class SettingsStoreBase with Store {
case WalletType.solana:
await _sharedPreferences.setInt(PreferencesKey.currentSolanaNodeIdKey, node.key as int);
break;
case WalletType.tron:
await _sharedPreferences.setInt(PreferencesKey.currentTronNodeIdKey, node.key as int);
break;
default:
break;
}
+114
View File
@@ -0,0 +1,114 @@
part of 'tron.dart';
class CWTron extends Tron {
@override
List<String> getTronWordList(String language) => EVMChainMnemonics.englishWordlist;
WalletService createTronWalletService(Box<WalletInfo> walletInfoSource) =>
TronWalletService(walletInfoSource, client: TronClient());
@override
WalletCredentials createTronNewWalletCredentials({
required String name,
WalletInfo? walletInfo,
}) =>
TronNewWalletCredentials(name: name, walletInfo: walletInfo);
@override
WalletCredentials createTronRestoreWalletFromSeedCredentials({
required String name,
required String mnemonic,
required String password,
}) =>
TronRestoreWalletFromSeedCredentials(name: name, password: password, mnemonic: mnemonic);
@override
WalletCredentials createTronRestoreWalletFromPrivateKey({
required String name,
required String privateKey,
required String password,
}) =>
TronRestoreWalletFromPrivateKey(name: name, password: password, privateKey: privateKey);
@override
String getAddress(WalletBase wallet) => (wallet as TronWallet).walletAddresses.address;
Object createTronTransactionCredentials(
List<Output> outputs, {
required CryptoCurrency currency,
}) =>
TronTransactionCredentials(
outputs
.map(
(out) => OutputInfo(
fiatAmount: out.fiatAmount,
cryptoAmount: out.cryptoAmount,
address: out.address,
note: out.note,
sendAll: out.sendAll,
extractedAddress: out.extractedAddress,
isParsedAddress: out.isParsedAddress,
formattedCryptoAmount: out.formattedCryptoAmount,
),
)
.toList(),
currency: currency,
);
@override
List<TronToken> getTronTokenCurrencies(WalletBase wallet) =>
(wallet as TronWallet).tronTokenCurrencies;
@override
Future<void> addTronToken(WalletBase wallet, CryptoCurrency token, String contractAddress) async {
final tronToken = TronToken(
name: token.name,
symbol: token.title,
contractAddress: contractAddress,
decimal: token.decimals,
enabled: token.enabled,
iconPath: token.iconPath,
);
await (wallet as TronWallet).addTronToken(tronToken);
}
@override
Future<void> deleteTronToken(WalletBase wallet, CryptoCurrency token) async =>
await (wallet as TronWallet).deleteTronToken(token as TronToken);
@override
Future<TronToken?> getTronToken(WalletBase wallet, String contractAddress) async =>
(wallet as TronWallet).getTronToken(contractAddress);
@override
double getTransactionAmountRaw(TransactionInfo transactionInfo) {
final amount = (transactionInfo as TronTransactionInfo).rawTronAmount();
return double.parse(amount);
}
@override
CryptoCurrency assetOfTransaction(WalletBase wallet, TransactionInfo transaction) {
transaction as TronTransactionInfo;
if (transaction.tokenSymbol == CryptoCurrency.trx.title) {
return CryptoCurrency.trx;
}
wallet as TronWallet;
return wallet.tronTokenCurrencies.firstWhere(
(element) => transaction.tokenSymbol.toLowerCase() == element.symbol.toLowerCase());
}
@override
String getTokenAddress(CryptoCurrency asset) => (asset as TronToken).contractAddress;
@override
String getTronBase58Address(String hexAddress, WalletBase wallet) =>
(wallet as TronWallet).getTronBase58AddressFromHex(hexAddress);
@override
String? getTronNativeEstimatedFee(WalletBase wallet) =>
(wallet as TronWallet).nativeTxEstimatedFee;
@override
String? getTronTRC20EstimatedFee(WalletBase wallet) => (wallet as TronWallet).trc20EstimatedFee;
}
@@ -38,6 +38,7 @@ abstract class AdvancedPrivacySettingsViewModelBase with Store {
case WalletType.bitcoinCash:
case WalletType.polygon:
case WalletType.solana:
case WalletType.tron:
return true;
case WalletType.monero:
case WalletType.none:
@@ -80,7 +80,9 @@ abstract class BalanceViewModelBase with Store {
@computed
bool get isHomeScreenSettingsEnabled =>
isEVMCompatibleChain(wallet.type) || wallet.type == WalletType.solana;
isEVMCompatibleChain(wallet.type) ||
wallet.type == WalletType.solana ||
wallet.type == WalletType.tron;
@computed
bool get hasAccounts => wallet.type == WalletType.monero;
@@ -126,6 +128,7 @@ abstract class BalanceViewModelBase with Store {
case WalletType.nano:
case WalletType.banano:
case WalletType.solana:
case WalletType.tron:
return S.current.xmr_available_balance;
default:
return S.current.confirmed;
@@ -140,6 +143,7 @@ abstract class BalanceViewModelBase with Store {
case WalletType.ethereum:
case WalletType.polygon:
case WalletType.solana:
case WalletType.tron:
return S.current.xmr_full_balance;
case WalletType.nano:
case WalletType.banano:
@@ -287,6 +291,7 @@ abstract class BalanceViewModelBase with Store {
case WalletType.ethereum:
case WalletType.polygon:
case WalletType.solana:
case WalletType.tron:
return false;
default:
return true;
@@ -5,6 +5,7 @@ import 'package:cake_wallet/ethereum/ethereum.dart';
import 'package:cake_wallet/polygon/polygon.dart';
import 'package:cake_wallet/solana/solana.dart';
import 'package:cake_wallet/store/settings_store.dart';
import 'package:cake_wallet/tron/tron.dart';
import 'package:cake_wallet/view_model/dashboard/balance_view_model.dart';
import 'package:cw_core/crypto_currency.dart';
import 'package:cw_core/erc20_token.dart';
@@ -79,6 +80,10 @@ abstract class HomeSettingsViewModelBase with Store {
);
}
if (_balanceViewModel.wallet.type == WalletType.tron) {
await tron!.addTronToken(_balanceViewModel.wallet, token, contractAddress);
}
_updateTokensList();
_updateFiatPrices(token);
}
@@ -96,6 +101,9 @@ abstract class HomeSettingsViewModelBase with Store {
await solana!.deleteSPLToken(_balanceViewModel.wallet, token);
}
if (_balanceViewModel.wallet.type == WalletType.tron) {
await tron!.deleteTronToken(_balanceViewModel.wallet, token);
}
_updateTokensList();
}
@@ -112,6 +120,10 @@ abstract class HomeSettingsViewModelBase with Store {
return await solana!.getSPLToken(_balanceViewModel.wallet, contractAddress);
}
if (_balanceViewModel.wallet.type == WalletType.tron) {
return await tron!.getTronToken(_balanceViewModel.wallet, contractAddress);
}
return null;
}
@@ -143,6 +155,11 @@ abstract class HomeSettingsViewModelBase with Store {
solana!.addSPLToken(_balanceViewModel.wallet, token, address);
}
if (_balanceViewModel.wallet.type == WalletType.tron) {
final address = tron!.getTokenAddress(token);
tron!.addTronToken(_balanceViewModel.wallet, token, address);
}
_refreshTokensList();
}
@@ -189,6 +206,14 @@ abstract class HomeSettingsViewModelBase with Store {
.toList()
..sort(_sortFunc));
}
if (_balanceViewModel.wallet.type == WalletType.tron) {
tokens.addAll(tron!
.getTronTokenCurrencies(_balanceViewModel.wallet)
.where((element) => _matchesSearchText(element))
.toList()
..sort(_sortFunc));
}
}
@action
@@ -207,7 +232,7 @@ abstract class HomeSettingsViewModelBase with Store {
bool _matchesSearchText(CryptoCurrency asset) {
final address = getTokenAddressBasedOnWallet(asset);
// The homes settings would only be displayed for either of Ethereum, Polygon or Solana Wallets.
// The homes settings would only be displayed for either of Tron, Ethereum, Polygon or Solana Wallets.
if (address == null) return false;
return searchText.isEmpty ||
@@ -217,6 +242,10 @@ abstract class HomeSettingsViewModelBase with Store {
}
String? getTokenAddressBasedOnWallet(CryptoCurrency asset) {
if (_balanceViewModel.wallet.type == WalletType.tron) {
return tron!.getTokenAddress(asset);
}
if (_balanceViewModel.wallet.type == WalletType.solana) {
return solana!.getTokenAddress(asset);
}
@@ -229,7 +258,7 @@ abstract class HomeSettingsViewModelBase with Store {
return polygon!.getTokenAddress(asset);
}
// We return null if it's neither Polygin, Ethereum or Solana wallet (which is actually impossible because we only display home settings for either of these three wallets).
// We return null if it's neither Tron, Polygon, Ethereum or Solana wallet (which is actually impossible because we only display home settings for either of these three wallets).
return null;
}
}
@@ -4,7 +4,10 @@ import 'package:cake_wallet/ethereum/ethereum.dart';
import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/nano/nano.dart';
import 'package:cake_wallet/polygon/polygon.dart';
import 'package:cake_wallet/reactions/wallet_connect.dart';
import 'package:cake_wallet/solana/solana.dart';
import 'package:cake_wallet/tron/tron.dart';
import 'package:cw_core/crypto_currency.dart';
import 'package:cw_core/transaction_direction.dart';
import 'package:cw_core/transaction_info.dart';
import 'package:cake_wallet/store/settings_store.dart';
@@ -34,6 +37,11 @@ class TransactionListItem extends ActionListItem with Keyable {
@override
dynamic get keyIndex => transaction.id;
bool get hasTokens =>
isEVMCompatibleChain(balanceViewModel.wallet.type) ||
balanceViewModel.wallet.type == WalletType.solana ||
balanceViewModel.wallet.type == WalletType.tron;
String get formattedCryptoAmount {
return displayMode == BalanceDisplayMode.hiddenBalance ? '---' : transaction.amountFormatted();
}
@@ -63,6 +71,34 @@ class TransactionListItem extends ActionListItem with Keyable {
return transaction.isPending ? S.current.pending : '';
}
CryptoCurrency? get assetOfTransaction {
try {
if (balanceViewModel.wallet.type == WalletType.ethereum) {
final asset = ethereum!.assetOfTransaction(balanceViewModel.wallet, transaction);
return asset;
}
if (balanceViewModel.wallet.type == WalletType.polygon) {
final asset = polygon!.assetOfTransaction(balanceViewModel.wallet, transaction);
return asset;
}
if (balanceViewModel.wallet.type == WalletType.solana) {
final asset = solana!.assetOfTransaction(balanceViewModel.wallet, transaction);
return asset;
}
if (balanceViewModel.wallet.type == WalletType.tron) {
final asset = tron!.assetOfTransaction(balanceViewModel.wallet, transaction);
return asset;
}
} catch (e) {
return null;
}
return null;
}
String get formattedFiatAmount {
var amount = '';
@@ -114,6 +150,16 @@ class TransactionListItem extends ActionListItem with Keyable {
price: price,
);
break;
case WalletType.tron:
final asset = tron!.assetOfTransaction(balanceViewModel.wallet, transaction);
final price = balanceViewModel.fiatConvertationStore.prices[asset];
final cryptoAmount = tron!.getTransactionAmountRaw(transaction);
amount = calculateFiatAmountRaw(
cryptoAmount: cryptoAmount,
price: price,
);
break;
default:
break;
}
@@ -178,6 +178,10 @@ abstract class ExchangeTradeViewModelBase with Store {
wallet.currency == CryptoCurrency.maticpoly &&
tradesStore.trade!.from.tag == CryptoCurrency.maticpoly.tag;
bool _isTronToken() =>
wallet.currency == CryptoCurrency.trx &&
tradesStore.trade!.from.tag == CryptoCurrency.trx.title;
bool _isSplToken() =>
wallet.currency == CryptoCurrency.sol &&
tradesStore.trade!.from.tag == CryptoCurrency.sol.title;
@@ -186,6 +190,7 @@ abstract class ExchangeTradeViewModelBase with Store {
tradesStore.trade!.provider == ExchangeProviderDescription.xmrto ||
_isEthToken() ||
_isPolygonToken() ||
_isSplToken();
_isSplToken() ||
_isTronToken();
}
}
@@ -676,6 +676,10 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
depositCurrency = CryptoCurrency.sol;
receiveCurrency = CryptoCurrency.xmr;
break;
case WalletType.tron:
depositCurrency = CryptoCurrency.trx;
receiveCurrency = CryptoCurrency.xmr;
break;
default:
break;
}
@@ -76,6 +76,7 @@ abstract class NodeCreateOrEditViewModelBase with Store {
case WalletType.solana:
case WalletType.banano:
case WalletType.nano:
case WalletType.tron:
return true;
case WalletType.none:
case WalletType.monero:
@@ -82,6 +82,9 @@ abstract class NodeListViewModelBase with Store {
case WalletType.solana:
node = getSolanaDefaultNode(nodes: _nodeSource)!;
break;
case WalletType.tron:
node = getTronDefaultNode(nodes: _nodeSource)!;
break;
default:
throw Exception('Unexpected wallet type: ${_appStore.wallet!.type}');
}
@@ -4,13 +4,14 @@ import 'package:cake_wallet/ethereum/ethereum.dart';
import 'package:cake_wallet/nano/nano.dart';
import 'package:cake_wallet/polygon/polygon.dart';
import 'package:cake_wallet/solana/solana.dart';
import 'package:cake_wallet/tron/tron.dart';
import 'package:cake_wallet/view_model/restore/restore_mode.dart';
import 'package:cake_wallet/view_model/restore/restore_wallet.dart';
import 'package:hive/hive.dart';
import 'package:mobx/mobx.dart';
import 'package:cake_wallet/monero/monero.dart';
import 'package:cake_wallet/store/app_store.dart';
import 'package:cw_core/wallet_base.dart';
import 'package:cw_core/wallet_base.dart';
import 'package:cake_wallet/core/generate_wallet_password.dart';
import 'package:cake_wallet/core/wallet_creation_service.dart';
import 'package:cw_core/wallet_credentials.dart';
@@ -86,6 +87,9 @@ abstract class WalletRestorationFromQRVMBase extends WalletCreationVM with Store
case WalletType.solana:
return solana!.createSolanaRestoreWalletFromPrivateKey(
name: name, password: password, privateKey: restoreWallet.privateKey!);
case WalletType.tron:
return tron!.createTronRestoreWalletFromPrivateKey(
name: name, password: password, privateKey: restoreWallet.privateKey!);
default:
throw Exception('Unexpected type: ${restoreWallet.type.toString()}');
}
@@ -130,6 +134,9 @@ abstract class WalletRestorationFromQRVMBase extends WalletCreationVM with Store
case WalletType.solana:
return solana!.createSolanaRestoreWalletFromSeedCredentials(
name: name, mnemonic: restoreWallet.mnemonicSeed ?? '', password: password);
case WalletType.tron:
return tron!.createTronRestoreWalletFromSeedCredentials(
name: name, mnemonic: restoreWallet.mnemonicSeed ?? '', password: password);
default:
throw Exception('Unexpected type: ${type.toString()}');
}
@@ -33,6 +33,9 @@ class WalletRestoreFromQRCode {
'bitcoincash-wallet': WalletType.bitcoinCash,
'bitcoincash_wallet': WalletType.bitcoinCash,
'solana-wallet': WalletType.solana,
'tron': WalletType.tron,
'tron-wallet': WalletType.tron,
'tron_wallet': WalletType.tron,
};
static bool _containsAssetSpecifier(String code) => _extractWalletType(code) != null;
@@ -184,6 +187,14 @@ class WalletRestoreFromQRCode {
return WalletRestoreMode.keys;
}
if (type == WalletType.tron && credentials.containsKey('private_key')) {
final privateKey = credentials['private_key'] as String;
if (privateKey.isEmpty) {
throw Exception('Unexpected restore mode: private_key');
}
return WalletRestoreMode.keys;
}
throw Exception('Unexpected restore mode: restore params are invalid');
}
}
+20 -2
View File
@@ -8,6 +8,7 @@ import 'package:cake_wallet/polygon/polygon.dart';
import 'package:cake_wallet/reactions/wallet_connect.dart';
import 'package:cake_wallet/solana/solana.dart';
import 'package:cake_wallet/src/screens/send/widgets/extract_address_from_parsed.dart';
import 'package:cake_wallet/tron/tron.dart';
import 'package:cw_core/crypto_currency.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
@@ -117,6 +118,17 @@ abstract class OutputBase with Store {
@computed
double get estimatedFee {
try {
if (_wallet.type == WalletType.tron) {
if (cryptoCurrencyHandler() == CryptoCurrency.trx) {
final nativeEstimatedFee = tron!.getTronNativeEstimatedFee(_wallet) ?? 0;
return double.parse(nativeEstimatedFee.toString());
} else {
final trc20EstimatedFee = tron!.getTronTRC20EstimatedFee(_wallet) ?? 0;
return double.parse(trc20EstimatedFee.toString());
}
}
if (_wallet.type == WalletType.solana) {
return solana!.getEstimateFees(_wallet) ?? 0.0;
}
@@ -163,8 +175,11 @@ abstract class OutputBase with Store {
@computed
String get estimatedFeeFiatAmount {
try {
final currency =
isEVMCompatibleChain(_wallet.type) ? _wallet.currency : cryptoCurrencyHandler();
final currency = (isEVMCompatibleChain(_wallet.type) ||
_wallet.type == WalletType.solana ||
_wallet.type == WalletType.tron)
? _wallet.currency
: cryptoCurrencyHandler();
final fiat = calculateFiatAmountRaw(
price: _fiatConversationStore.prices[currency]!, cryptoAmount: estimatedFee);
return fiat;
@@ -269,6 +284,9 @@ abstract class OutputBase with Store {
case WalletType.solana:
maximumFractionDigits = 12;
break;
case WalletType.tron:
maximumFractionDigits = 12;
break;
default:
break;
}
@@ -53,7 +53,8 @@ abstract class SendTemplateViewModelBase with Store {
_wallet.type != WalletType.haven &&
_wallet.type != WalletType.ethereum &&
_wallet.type != WalletType.polygon &&
_wallet.type != WalletType.solana;
_wallet.type != WalletType.solana &&
_wallet.type != WalletType.tron;
@computed
CryptoCurrency get cryptoCurrency => _wallet.currency;
+15 -4
View File
@@ -12,6 +12,7 @@ import 'package:cake_wallet/polygon/polygon.dart';
import 'package:cake_wallet/reactions/wallet_connect.dart';
import 'package:cake_wallet/solana/solana.dart';
import 'package:cake_wallet/store/app_store.dart';
import 'package:cake_wallet/tron/tron.dart';
import 'package:cake_wallet/view_model/contact_list/contact_list_view_model.dart';
import 'package:cake_wallet/view_model/dashboard/balance_view_model.dart';
import 'package:cw_core/exceptions.dart';
@@ -50,7 +51,9 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor
void onWalletChange(wallet) {
currencies = wallet.balance.keys.toList();
selectedCryptoCurrency = wallet.currency;
hasMultipleTokens = isEVMCompatibleChain(wallet.type) || wallet.type == WalletType.solana;
hasMultipleTokens = isEVMCompatibleChain(wallet.type) ||
wallet.type == WalletType.solana ||
wallet.type == WalletType.tron;
}
SendViewModelBase(
@@ -64,7 +67,8 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor
currencies = appStore.wallet!.balance.keys.toList(),
selectedCryptoCurrency = appStore.wallet!.currency,
hasMultipleTokens = isEVMCompatibleChain(appStore.wallet!.type) ||
appStore.wallet!.type == WalletType.solana,
appStore.wallet!.type == WalletType.solana ||
appStore.wallet!.type == WalletType.tron,
outputs = ObservableList<Output>(),
_settingsStore = appStore.settingsStore,
fiatFromSettings = appStore.settingsStore.fiatCurrency,
@@ -110,6 +114,8 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor
@computed
bool get isBatchSending => outputs.length > 1;
bool get shouldDisplaySendALL => walletType != WalletType.solana || walletType != WalletType.tron;
@computed
String get pendingTransactionFiatAmount {
if (pendingTransaction == null) {
@@ -236,7 +242,9 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor
bool get hasFeesPriority =>
wallet.type != WalletType.nano &&
wallet.type != WalletType.banano &&
wallet.type != WalletType.solana;
wallet.type != WalletType.solana &&
wallet.type != WalletType.tron;
@observable
CryptoCurrency selectedCryptoCurrency;
@@ -423,7 +431,8 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor
Object _credentials() {
final priority = _settingsStore.priority[wallet.type];
if (priority == null && wallet.type != WalletType.nano && wallet.type != WalletType.banano && wallet.type != WalletType.solana) {
if (priority == null && wallet.type != WalletType.nano && wallet.type != WalletType.banano && wallet.type != WalletType.solana &&
wallet.type != WalletType.tron) {
throw Exception('Priority is null for wallet type: ${wallet.type}');
}
@@ -453,6 +462,8 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor
case WalletType.solana:
return solana!
.createSolanaTransactionCredentials(outputs, currency: selectedCryptoCurrency);
case WalletType.tron:
return tron!.createTronTransactionCredentials(outputs, currency: selectedCryptoCurrency);
default:
throw Exception('Unexpected wallet type: ${wallet.type}');
}
@@ -56,8 +56,9 @@ abstract class OtherSettingsViewModelBase with Store {
_wallet.type == WalletType.nano || _wallet.type == WalletType.banano;
@computed
bool get displayTransactionPriority =>
!(changeRepresentativeEnabled || _wallet.type == WalletType.solana);
bool get displayTransactionPriority => !(changeRepresentativeEnabled ||
_wallet.type == WalletType.solana ||
_wallet.type == WalletType.tron);
@computed
bool get isEnabledBuyAction => !_settingsStore.disableBuy && _wallet.type != WalletType.haven;
@@ -1,3 +1,7 @@
import 'package:cake_wallet/tron/tron.dart';
import 'package:cw_core/wallet_base.dart';
import 'package:cw_core/transaction_info.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:cake_wallet/bitcoin/bitcoin.dart';
import 'package:cake_wallet/entities/priority_for_wallet_type.dart';
import 'package:cake_wallet/entities/transaction_description.dart';
@@ -14,10 +18,7 @@ import 'package:cake_wallet/utils/date_formatter.dart';
import 'package:cake_wallet/view_model/send/send_view_model.dart';
import 'package:collection/collection.dart';
import 'package:cw_core/transaction_direction.dart';
import 'package:cw_core/transaction_info.dart';
import 'package:cw_core/transaction_priority.dart';
import 'package:cw_core/wallet_base.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:hive/hive.dart';
import 'package:intl/src/intl/date_format.dart';
import 'package:mobx/mobx.dart';
@@ -71,6 +72,9 @@ abstract class TransactionDetailsViewModelBase with Store {
case WalletType.solana:
_addSolanaListItems(tx, dateFormat);
break;
case WalletType.tron:
_addTronListItems(tx, dateFormat);
break;
default:
break;
}
@@ -160,6 +164,8 @@ abstract class TransactionDetailsViewModelBase with Store {
return 'https://polygonscan.com/tx/${txId}';
case WalletType.solana:
return 'https://solscan.io/tx/${txId}';
case WalletType.tron:
return 'https://tronscan.org/#/transaction/${txId}';
default:
return '';
}
@@ -186,6 +192,8 @@ abstract class TransactionDetailsViewModelBase with Store {
return S.current.view_transaction_on + 'polygonscan.com';
case WalletType.solana:
return S.current.view_transaction_on + 'solscan.io';
case WalletType.tron:
return S.current.view_transaction_on + 'tronscan.org';
default:
return '';
}
@@ -339,20 +347,19 @@ abstract class TransactionDetailsViewModelBase with Store {
transactionInfo.inputAddresses?.length ?? 1,
transactionInfo.outputAddresses?.length ?? 1);
RBFListItems.add(StandartListItem(
title: S.current.old_fee,
value: tx.feeFormatted() ?? '0.0'));
RBFListItems.add(StandartListItem(title: S.current.old_fee, value: tx.feeFormatted() ?? '0.0'));
final priorities = priorityForWalletType(wallet.type);
final selectedItem = priorities.indexOf(sendViewModel.transactionPriority);
final customItem = priorities.firstWhereOrNull(
(element) => element == sendViewModel.bitcoinTransactionPriorityCustom);
final customItem = priorities
.firstWhereOrNull((element) => element == sendViewModel.bitcoinTransactionPriorityCustom);
final customItemIndex = customItem != null ? priorities.indexOf(customItem) : null;
final maxCustomFeeRate = sendViewModel.maxCustomFeeRate?.toDouble();
RBFListItems.add(StandardPickerListItem(
title: S.current.estimated_new_fee,
value: bitcoin!.formatterBitcoinAmountToString(amount: newFee) + ' ${walletTypeToCryptoCurrency(wallet.type)}',
value: bitcoin!.formatterBitcoinAmountToString(amount: newFee) +
' ${walletTypeToCryptoCurrency(wallet.type)}',
items: priorityForWalletType(wallet.type),
customValue: settingsStore.customBitcoinFeeRate.toDouble(),
maxValue: maxCustomFeeRate,
@@ -378,6 +385,27 @@ abstract class TransactionDetailsViewModelBase with Store {
}
}
void _addTronListItems(TransactionInfo tx, DateFormat dateFormat) {
final _items = [
StandartListItem(title: S.current.transaction_details_transaction_id, value: tx.id),
StandartListItem(
title: S.current.transaction_details_date, value: dateFormat.format(tx.date)),
StandartListItem(title: S.current.transaction_details_amount, value: tx.amountFormatted()),
if (tx.feeFormatted()?.isNotEmpty ?? false)
StandartListItem(title: S.current.transaction_details_fee, value: tx.feeFormatted()!),
if (showRecipientAddress && tx.to != null)
StandartListItem(
title: S.current.transaction_details_recipient_address,
value: tron!.getTronBase58Address(tx.to!, wallet)),
if (tx.from != null)
StandartListItem(
title: S.current.transaction_details_source_address,
value: tron!.getTronBase58Address(tx.from!, wallet)),
];
items.addAll(_items);
}
@action
Future<void> _checkForRBF() async {
if (wallet.type == WalletType.bitcoin &&
@@ -392,10 +420,10 @@ abstract class TransactionDetailsViewModelBase with Store {
newFee = priority == bitcoin!.getBitcoinTransactionPriorityCustom() && value != null
? bitcoin!.getEstimatedFeeWithFeeRate(wallet, value.round(), transactionInfo.amount)
: bitcoin!.getFeeAmountForPriority(
wallet,
priority,
transactionInfo.inputAddresses?.length ?? 1,
transactionInfo.outputAddresses?.length ?? 1);
wallet,
priority,
transactionInfo.inputAddresses?.length ?? 1,
transactionInfo.outputAddresses?.length ?? 1);
return bitcoin!.formatterBitcoinAmountToString(amount: newFee);
}
@@ -12,6 +12,7 @@ import 'package:cake_wallet/store/app_store.dart';
import 'package:cake_wallet/store/dashboard/fiat_conversion_store.dart';
import 'package:cake_wallet/store/settings_store.dart';
import 'package:cake_wallet/store/yat/yat_store.dart';
import 'package:cake_wallet/tron/tron.dart';
import 'package:cake_wallet/utils/list_item.dart';
import 'package:cake_wallet/view_model/wallet_address_list/wallet_account_list_header.dart';
import 'package:cake_wallet/view_model/wallet_address_list/wallet_address_list_header.dart';
@@ -175,6 +176,21 @@ class SolanaURI extends PaymentURI {
}
}
class TronURI extends PaymentURI {
TronURI({required String amount, required String address})
: super(amount: amount, address: address);
@override
String toString() {
var base = 'tron:' + address;
if (amount.isNotEmpty) {
base += '?amount=${amount.replaceAll(',', '.')}';
}
return base;
}
}
abstract class WalletAddressListViewModelBase extends WalletChangeListenerViewModel with Store {
WalletAddressListViewModelBase({
required AppStore appStore,
@@ -273,6 +289,10 @@ abstract class WalletAddressListViewModelBase extends WalletChangeListenerViewMo
return SolanaURI(amount: amount, address: address.address);
}
if (wallet.type == WalletType.tron) {
return TronURI(amount: amount, address: address.address);
}
throw Exception('Unexpected type: ${type.toString()}');
}
@@ -348,6 +368,12 @@ abstract class WalletAddressListViewModelBase extends WalletChangeListenerViewMo
addressList.add(WalletAddressListItem(isPrimary: true, name: null, address: primaryAddress));
}
if (wallet.type == WalletType.tron) {
final primaryAddress = tron!.getAddress(wallet);
addressList.add(WalletAddressListItem(isPrimary: true, name: null, address: primaryAddress));
}
if (searchText.isNotEmpty) {
return ObservableList.of(addressList.where((item) {
if (item is WalletAddressListItem) {
+4 -1
View File
@@ -118,7 +118,8 @@ abstract class WalletKeysViewModelBase with Store {
}
if (isEVMCompatibleChain(_appStore.wallet!.type) ||
_appStore.wallet!.type == WalletType.solana) {
_appStore.wallet!.type == WalletType.solana ||
_appStore.wallet!.type == WalletType.tron) {
items.addAll([
if (_appStore.wallet!.privateKey != null)
StandartListItem(title: S.current.private_key, value: _appStore.wallet!.privateKey!),
@@ -175,6 +176,8 @@ abstract class WalletKeysViewModelBase with Store {
return 'polygon-wallet';
case WalletType.solana:
return 'solana-wallet';
case WalletType.tron:
return 'tron-wallet';
default:
throw Exception('Unexpected wallet type: ${_appStore.wallet!.toString()}');
}
+4
View File
@@ -1,6 +1,7 @@
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';
@@ -43,6 +44,7 @@ abstract class WalletNewVMBase extends WalletCreationVM with Store {
return 16;
}
return 25;
case WalletType.tron:
case WalletType.solana:
case WalletType.polygon:
case WalletType.ethereum:
@@ -79,6 +81,8 @@ abstract class WalletNewVMBase extends WalletCreationVM with Store {
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()}');
}
+16 -1
View File
@@ -6,6 +6,7 @@ import 'package:cw_core/nano_account_info_response.dart';
import 'package:cake_wallet/bitcoin_cash/bitcoin_cash.dart';
import 'package:cake_wallet/polygon/polygon.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/store/app_store.dart';
@@ -34,7 +35,8 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store {
type == WalletType.polygon ||
type == WalletType.nano ||
type == WalletType.banano ||
type == WalletType.solana,
type == WalletType.solana ||
type == WalletType.tron,
isButtonEnabled = false,
mode = WalletRestoreMode.seed,
super(appStore, walletInfoSource, walletCreationService, type: type, isRecovery: true) {
@@ -48,6 +50,7 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store {
case WalletType.nano:
case WalletType.banano:
case WalletType.solana:
case WalletType.tron:
availableModes = [WalletRestoreMode.seed, WalletRestoreMode.keys];
break;
default:
@@ -127,6 +130,12 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store {
mnemonic: seed,
password: password,
);
case WalletType.tron:
return tron!.createTronRestoreWalletFromSeedCredentials(
name: name,
mnemonic: seed,
password: password,
);
default:
break;
}
@@ -185,6 +194,12 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store {
password: password,
privateKey: options['private_key'] as String,
);
case WalletType.tron:
return tron!.createTronRestoreWalletFromPrivateKey(
name: name,
password: password,
privateKey: options['private_key'] as String,
);
default:
break;
}