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 19:00:05 +01:00 committed by GitHub
parent e4fd534949
commit d1870ba8b8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
82 changed files with 3660 additions and 62 deletions

View file

@ -8,6 +8,7 @@ const bitcoinCashOutputPath = 'lib/bitcoin_cash/bitcoin_cash.dart';
const nanoOutputPath = 'lib/nano/nano.dart';
const polygonOutputPath = 'lib/polygon/polygon.dart';
const solanaOutputPath = 'lib/solana/solana.dart';
const tronOutputPath = 'lib/tron/tron.dart';
const walletTypesPath = 'lib/wallet_types.g.dart';
const pubspecDefaultPath = 'pubspec_default.yaml';
const pubspecOutputPath = 'pubspec.yaml';
@ -23,6 +24,7 @@ Future<void> main(List<String> args) async {
final hasBanano = args.contains('${prefix}banano');
final hasPolygon = args.contains('${prefix}polygon');
final hasSolana = args.contains('${prefix}solana');
final hasTron = args.contains('${prefix}tron');
await generateBitcoin(hasBitcoin);
await generateMonero(hasMonero);
@ -32,6 +34,7 @@ Future<void> main(List<String> args) async {
await generateNano(hasNano);
await generatePolygon(hasPolygon);
await generateSolana(hasSolana);
await generateTron(hasTron);
// await generateBanano(hasEthereum);
await generatePubspec(
@ -44,6 +47,7 @@ Future<void> main(List<String> args) async {
hasBitcoinCash: hasBitcoinCash,
hasPolygon: hasPolygon,
hasSolana: hasSolana,
hasTron: hasTron,
);
await generateWalletTypes(
hasMonero: hasMonero,
@ -55,6 +59,7 @@ Future<void> main(List<String> args) async {
hasBitcoinCash: hasBitcoinCash,
hasPolygon: hasPolygon,
hasSolana: hasSolana,
hasTron: hasTron,
);
}
@ -1024,6 +1029,79 @@ abstract class Solana {
await outputFile.writeAsString(output);
}
Future<void> generateTron(bool hasImplementation) async {
final outputFile = File(tronOutputPath);
const tronCommonHeaders = """
import 'package:cake_wallet/view_model/send/output.dart';
import 'package:cw_core/crypto_currency.dart';
import 'package:cw_core/output_info.dart';
import 'package:cw_core/transaction_info.dart';
import 'package:cw_core/wallet_base.dart';
import 'package:cw_core/wallet_credentials.dart';
import 'package:cw_core/wallet_info.dart';
import 'package:cw_core/wallet_service.dart';
import 'package:hive/hive.dart';
""";
const tronCWHeaders = """
import 'package:cw_evm/evm_chain_mnemonics.dart';
import 'package:cw_tron/tron_transaction_credentials.dart';
import 'package:cw_tron/tron_transaction_info.dart';
import 'package:cw_tron/tron_wallet_creation_credentials.dart';
import 'package:cw_tron/tron_client.dart';
import 'package:cw_tron/tron_token.dart';
import 'package:cw_tron/tron_wallet.dart';
import 'package:cw_tron/tron_wallet_service.dart';
""";
const tronCwPart = "part 'cw_tron.dart';";
const tronContent = """
abstract class Tron {
List<String> getTronWordList(String language);
WalletService createTronWalletService(Box<WalletInfo> walletInfoSource);
WalletCredentials createTronNewWalletCredentials({required String name, WalletInfo? walletInfo});
WalletCredentials createTronRestoreWalletFromSeedCredentials({required String name, required String mnemonic, required String password});
WalletCredentials createTronRestoreWalletFromPrivateKey({required String name, required String privateKey, required String password});
String getAddress(WalletBase wallet);
Object createTronTransactionCredentials(
List<Output> outputs, {
required CryptoCurrency currency,
});
List<CryptoCurrency> getTronTokenCurrencies(WalletBase wallet);
Future<void> addTronToken(WalletBase wallet, CryptoCurrency token, String contractAddress);
Future<void> deleteTronToken(WalletBase wallet, CryptoCurrency token);
Future<CryptoCurrency?> getTronToken(WalletBase wallet, String contractAddress);
double getTransactionAmountRaw(TransactionInfo transactionInfo);
CryptoCurrency assetOfTransaction(WalletBase wallet, TransactionInfo transaction);
String getTokenAddress(CryptoCurrency asset);
String getTronBase58Address(String hexAddress, WalletBase wallet);
String? getTronNativeEstimatedFee(WalletBase wallet);
String? getTronTRC20EstimatedFee(WalletBase wallet);
}
""";
const tronEmptyDefinition = 'Tron? tron;\n';
const tronCWDefinition = 'Tron? tron = CWTron();\n';
final output = '$tronCommonHeaders\n' +
(hasImplementation ? '$tronCWHeaders\n' : '\n') +
(hasImplementation ? '$tronCwPart\n\n' : '\n') +
(hasImplementation ? tronCWDefinition : tronEmptyDefinition) +
'\n' +
tronContent;
if (outputFile.existsSync()) {
await outputFile.delete();
}
await outputFile.writeAsString(output);
}
Future<void> generatePubspec(
{required bool hasMonero,
required bool hasBitcoin,
@ -1033,7 +1111,8 @@ Future<void> generatePubspec(
required bool hasBanano,
required bool hasBitcoinCash,
required bool hasPolygon,
required bool hasSolana}) async {
required bool hasSolana,
required bool hasTron}) async {
const cwCore = """
cw_core:
path: ./cw_core
@ -1082,6 +1161,10 @@ Future<void> generatePubspec(
cw_evm:
path: ./cw_evm
""";
const cwTron = """
cw_tron:
path: ./cw_tron
""";
final inputFile = File(pubspecOutputPath);
final inputText = await inputFile.readAsString();
final inputLines = inputText.split('\n');
@ -1121,6 +1204,10 @@ Future<void> generatePubspec(
output += '\n$cwSolana';
}
if (hasTron) {
output += '\n$cwTron';
}
if (hasHaven && !hasMonero) {
output += '\n$cwSharedExternal\n$cwHaven';
} else if (hasHaven) {
@ -1152,7 +1239,8 @@ Future<void> generateWalletTypes(
required bool hasBanano,
required bool hasBitcoinCash,
required bool hasPolygon,
required bool hasSolana}) async {
required bool hasSolana,
required bool hasTron}) async {
final walletTypesFile = File(walletTypesPath);
if (walletTypesFile.existsSync()) {
@ -1191,6 +1279,10 @@ Future<void> generateWalletTypes(
outputContent += '\tWalletType.solana,\n';
}
if (hasTron) {
outputContent += '\tWalletType.tron,\n';
}
if (hasNano) {
outputContent += '\tWalletType.nano,\n';
}