dev
dart 170 lines 5.02 KB
Raw
1 part of 'tron.dart';
2
3 class CWTron extends Tron {
4 @override
5 List<String> getTronWordList(String language) => EVMChainMnemonics.englishWordlist;
6
7 @override
8 WalletService createTronWalletService(bool isDirect) =>
9 TronWalletService(client: TronClient(), isDirect: isDirect);
10
11 @override
12 WalletCredentials createTronNewWalletCredentials({
13 required String name,
14 WalletInfo? walletInfo,
15 String? password,
16 String? mnemonic,
17 String? passphrase,
18 }) =>
19 TronNewWalletCredentials(
20 name: name,
21 walletInfo: walletInfo,
22 password: password,
23 mnemonic: mnemonic,
24 passphrase: passphrase,
25 );
26
27 @override
28 WalletCredentials createTronRestoreWalletFromSeedCredentials({
29 required String name,
30 required String mnemonic,
31 required String password,
32 String? passphrase,
33 }) =>
34 TronRestoreWalletFromSeedCredentials(
35 name: name,
36 password: password,
37 mnemonic: mnemonic,
38 passphrase: passphrase,
39 );
40
41 @override
42 WalletCredentials createTronRestoreWalletFromPrivateKey({
43 required String name,
44 required String privateKey,
45 required String password,
46 }) =>
47 TronRestoreWalletFromPrivateKey(name: name, password: password, privateKey: privateKey);
48
49 @override
50 String getAddress(WalletBase wallet) => (wallet as TronWallet).walletAddresses.address;
51
52 Object createTronTransactionCredentials(
53 List<Output> outputs, {
54 required CryptoCurrency currency,
55 }) =>
56 TronTransactionCredentials(
57 outputs
58 .map(
59 (out) => OutputInfo(
60 fiatAmount: out.fiatAmount,
61 cryptoAmount: out.cryptoAmountMoney,
62 address: out.address,
63 note: out.note,
64 sendAll: out.sendAll,
65 extractedAddress: out.extractedAddress,
66 isParsedAddress: out.isParsedAddress,
67 ),
68 )
69 .toList(),
70 currency: currency,
71 );
72
73 @override
74 List<TronToken> getTronTokenCurrencies(WalletBase wallet) =>
75 (wallet as TronWallet).tronTokenCurrencies;
76
77 @override
78 Future<void> addTronToken(WalletBase wallet, CryptoCurrency token, String contractAddress) async {
79 final tronToken = TronToken(
80 name: token.name,
81 symbol: token.title,
82 contractAddress: contractAddress,
83 decimal: token.decimals,
84 enabled: token.enabled,
85 iconPath: token.iconPath,
86 isPotentialScam: token.isPotentialScam,
87 );
88 await (wallet as TronWallet).addTronToken(tronToken);
89 }
90
91 @override
92 Future<void> deleteTronToken(WalletBase wallet, CryptoCurrency token) async =>
93 await (wallet as TronWallet).deleteTronToken(token as TronToken);
94
95 @override
96 Future<TronToken?> getTronToken(WalletBase wallet, String contractAddress) async =>
97 (wallet as TronWallet).getTronToken(contractAddress);
98
99 @override
100 CryptoCurrency assetOfTransaction(WalletBase wallet, TransactionInfo transaction) {
101 transaction as TronTransactionInfo;
102 if (transaction.amount.currency.symbol == CryptoCurrency.trx.title) {
103 return CryptoCurrency.trx;
104 }
105
106 wallet as TronWallet;
107 return wallet.tronTokenCurrencies.firstWhere((element) =>
108 transaction.amount.currency.symbol.toLowerCase() == element.symbol.toLowerCase());
109 }
110
111 @override
112 String getTokenAddress(CryptoCurrency asset) => (asset as TronToken).contractAddress;
113
114 @override
115 String getTronBase58Address(String hexAddress, WalletBase wallet) =>
116 (wallet as TronWallet).getTronBase58AddressFromHex(hexAddress);
117
118 @override
119 Money? getTronNativeEstimatedFee(WalletBase wallet) =>
120 (wallet as TronWallet).nativeTxEstimatedFee;
121
122 @override
123 Money? getTronTRC20EstimatedFee(WalletBase wallet) => (wallet as TronWallet).trc20EstimatedFee;
124
125 @override
126 void updateTronGridUsageState(WalletBase wallet, bool isEnabled) {
127 (wallet as TronWallet).updateScanProviderUsageState(isEnabled);
128 }
129
130 @override
131 List<TronToken> getDefaultTronTokens() => DefaultTronTokens().initialTronTokens;
132
133 @override
134 List<String> getDefaultTokenContractAddresses() {
135 return DefaultTronTokens().initialTronTokens.map((e) => e.contractAddress).toList();
136 }
137
138 @override
139 List<String> getDefaultTokenSymbols() {
140 return DefaultTronTokens().initialTronTokens.map((e) => e.symbol.toUpperCase()).toList();
141 }
142
143 @override
144 bool isTokenAlreadyAdded(WalletBase wallet, String contractAddress) {
145 final tronWallet = wallet as TronWallet;
146 return tronWallet.tronTokenCurrencies
147 .any((element) => element.contractAddress == contractAddress);
148 }
149
150 @override
151 TransactionInfo getTransactionInfo({
152 required String id,
153 required Money amount,
154 Money? fee,
155 required TransactionDirection direction,
156 required DateTime blockTime,
157 String? to,
158 String? from,
159 required bool isPending,
160 }) =>
161 TronTransactionInfo(
162 id: id,
163 amount: amount,
164 fee: fee,
165 direction: direction,
166 blockTime: blockTime,
167 to: to,
168 from: from,
169 isPending: isPending);
170 }