mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-12-02 12:14:09 +01: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
This commit is contained in:
+94
-2
@@ -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';
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import 'utils/utils.dart';
|
||||
const configPath = 'tool/.secrets-config.json';
|
||||
const evmChainsConfigPath = 'tool/.evm-secrets-config.json';
|
||||
const solanaConfigPath = 'tool/.solana-secrets-config.json';
|
||||
const tronConfigPath = 'tool/.tron-secrets-config.json';
|
||||
|
||||
Future<void> main(List<String> args) async => generateSecretsConfig(args);
|
||||
|
||||
@@ -20,9 +21,10 @@ Future<void> generateSecretsConfig(List<String> args) async {
|
||||
final configFile = File(configPath);
|
||||
final evmChainsConfigFile = File(evmChainsConfigPath);
|
||||
final solanaConfigFile = File(solanaConfigPath);
|
||||
final tronConfigFile = File(tronConfigPath);
|
||||
|
||||
final secrets = <String, dynamic>{};
|
||||
|
||||
|
||||
secrets.addAll(extraInfo);
|
||||
secrets.removeWhere((key, dynamic value) {
|
||||
if (key.contains('--')) {
|
||||
@@ -78,4 +80,18 @@ Future<void> generateSecretsConfig(List<String> args) async {
|
||||
secretsJson = JsonEncoder.withIndent(' ').convert(secrets);
|
||||
|
||||
await solanaConfigFile.writeAsString(secretsJson);
|
||||
|
||||
secrets.clear();
|
||||
|
||||
SecretKey.tronSecrets.forEach((sec) {
|
||||
if (secrets[sec.name] != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
secrets[sec.name] = sec.generate();
|
||||
});
|
||||
|
||||
secretsJson = JsonEncoder.withIndent(' ').convert(secrets);
|
||||
|
||||
await tronConfigFile.writeAsString(secretsJson);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,9 @@ const evmChainsOutputPath = 'cw_evm/lib/.secrets.g.dart';
|
||||
|
||||
const solanaConfigPath = 'tool/.solana-secrets-config.json';
|
||||
const solanaOutputPath = 'cw_solana/lib/.secrets.g.dart';
|
||||
|
||||
const tronConfigPath = 'tool/.tron-secrets-config.json';
|
||||
const tronOutputPath = 'cw_tron/lib/.secrets.g.dart';
|
||||
Future<void> main(List<String> args) async => importSecretsConfig();
|
||||
|
||||
Future<void> importSecretsConfig() async {
|
||||
@@ -29,6 +32,11 @@ Future<void> importSecretsConfig() async {
|
||||
final solanaOutput =
|
||||
solanaInput.keys.fold('', (String acc, String val) => acc + generateConst(val, solanaInput));
|
||||
|
||||
final tronOutputFile = File(tronOutputPath);
|
||||
final tronInput = json.decode(File(tronConfigPath).readAsStringSync()) as Map<String, dynamic>;
|
||||
final tronOutput =
|
||||
tronInput.keys.fold('', (String acc, String val) => acc + generateConst(val, tronInput));
|
||||
|
||||
if (outputFile.existsSync()) {
|
||||
await outputFile.delete();
|
||||
}
|
||||
@@ -46,4 +54,10 @@ Future<void> importSecretsConfig() async {
|
||||
}
|
||||
|
||||
await solanaOutputFile.writeAsString(solanaOutput);
|
||||
|
||||
if (tronOutputFile.existsSync()) {
|
||||
await tronOutputFile.delete();
|
||||
}
|
||||
|
||||
await tronOutputFile.writeAsString(tronOutput);
|
||||
}
|
||||
|
||||
@@ -50,6 +50,10 @@ class SecretKey {
|
||||
SecretKey('ankrApiKey', () => ''),
|
||||
];
|
||||
|
||||
static final tronSecrets = [
|
||||
SecretKey('tronGridApiKey', () => ''),
|
||||
];
|
||||
|
||||
final String name;
|
||||
final String Function() generate;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user