Merge pull request #1100 from cake-tech/CW-477-add-ens

Cw 477 add ens
This commit is contained in:
Matthew Fosse 2023-10-03 14:57:38 -04:00 committed by GitHub
commit 24fa84d6cc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 183 additions and 110 deletions

View file

@ -208,6 +208,10 @@ I/flutter ( 4474): Gas Used: 53000
} }
} }
Web3Client? getWeb3Client() {
return _client;
}
// Future<int> _getDecimalPlacesForContract(DeployedContract contract) async { // Future<int> _getDecimalPlacesForContract(DeployedContract contract) async {
// final String abi = await rootBundle.loadString("assets/abi_json/erc20_abi.json"); // final String abi = await rootBundle.loadString("assets/abi_json/erc20_abi.json");
// final contractAbi = ContractAbi.fromJson(abi, "ERC20"); // final contractAbi = ContractAbi.fromJson(abi, "ERC20");

View file

@ -510,4 +510,6 @@ abstract class EthereumWalletBase
@override @override
String signMessage(String message, {String? address = null}) => String signMessage(String message, {String? address = null}) =>
bytesToHex(_ethPrivateKey.signPersonalMessageToUint8List(ascii.encode(message))); bytesToHex(_ethPrivateKey.signPersonalMessageToUint8List(ascii.encode(message)));
Web3Client? getWeb3Client() => _client.getWeb3Client();
} }

View file

@ -267,4 +267,4 @@ class AddressValidator extends TextValidator {
return null; return null;
} }
} }
} }

View file

@ -912,7 +912,7 @@ Future<void> setup({
getIt.registerFactory(() => YatService()); getIt.registerFactory(() => YatService());
getIt.registerFactory(() => AddressResolver( getIt.registerFactory(() => AddressResolver(
yatService: getIt.get<YatService>(), walletType: getIt.get<AppStore>().wallet!.type)); yatService: getIt.get<YatService>(), wallet: getIt.get<AppStore>().wallet!));
getIt.registerFactoryParam<FullscreenQRPage, QrViewData, void>( getIt.registerFactoryParam<FullscreenQRPage, QrViewData, void>(
(QrViewData viewData, _) => FullscreenQRPage(qrViewData: viewData)); (QrViewData viewData, _) => FullscreenQRPage(qrViewData: viewData));

View file

@ -0,0 +1,46 @@
import 'package:cake_wallet/ethereum/ethereum.dart';
import 'package:cw_core/wallet_base.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:ens_dart/ens_dart.dart';
import 'package:http/http.dart';
import 'package:web3dart/web3dart.dart';
class EnsRecord {
static Future<String> fetchEnsAddress(String name, {WalletBase? wallet}) async {
Web3Client? _client;
if (wallet != null && wallet.type == WalletType.ethereum) {
_client = ethereum!.getWeb3Client(wallet);
}
if (_client == null) {
_client = Web3Client("https://ethereum.publicnode.com", Client());
}
try {
final ens = Ens(client: _client);
if (wallet != null) {
switch (wallet.type) {
case WalletType.monero:
return await ens.withName(name).getCoinAddress(CoinType.XMR);
case WalletType.bitcoin:
return await ens.withName(name).getCoinAddress(CoinType.BTC);
case WalletType.litecoin:
return await ens.withName(name).getCoinAddress(CoinType.LTC);
case WalletType.haven:
return await ens.withName(name).getCoinAddress(CoinType.XHV);
case WalletType.ethereum:
default:
return (await ens.withName(name).getAddress()).hex;
}
}
final addr = await ens.withName(name).getAddress();
return addr.hex;
} catch (e) {
print(e);
return "";
}
}
}

View file

@ -1,19 +1,22 @@
import 'package:cake_wallet/core/address_validator.dart'; import 'package:cake_wallet/core/address_validator.dart';
import 'package:cake_wallet/core/yat_service.dart'; import 'package:cake_wallet/core/yat_service.dart';
import 'package:cake_wallet/entities/ens_record.dart';
import 'package:cake_wallet/entities/openalias_record.dart'; import 'package:cake_wallet/entities/openalias_record.dart';
import 'package:cake_wallet/entities/parsed_address.dart'; import 'package:cake_wallet/entities/parsed_address.dart';
import 'package:cake_wallet/entities/unstoppable_domain_address.dart'; import 'package:cake_wallet/entities/unstoppable_domain_address.dart';
import 'package:cake_wallet/entities/emoji_string_extension.dart'; import 'package:cake_wallet/entities/emoji_string_extension.dart';
import 'package:cake_wallet/twitter/twitter_api.dart'; import 'package:cake_wallet/twitter/twitter_api.dart';
import 'package:cw_core/crypto_currency.dart'; import 'package:cw_core/crypto_currency.dart';
import 'package:cw_core/wallet_base.dart';
import 'package:cw_core/wallet_type.dart'; import 'package:cw_core/wallet_type.dart';
import 'package:cake_wallet/entities/fio_address_provider.dart'; import 'package:cake_wallet/entities/fio_address_provider.dart';
class AddressResolver { class AddressResolver {
AddressResolver({required this.yatService, required this.walletType}); AddressResolver({required this.yatService, required this.wallet}) : walletType = wallet.type;
final YatService yatService; final YatService yatService;
final WalletType walletType; final WalletType walletType;
final WalletBase wallet;
static const unstoppableDomains = [ static const unstoppableDomains = [
'crypto', 'crypto',
@ -63,7 +66,7 @@ class AddressResolver {
}); });
final userTweetsText = subString.toString(); final userTweetsText = subString.toString();
final addressFromPinnedTweet = final addressFromPinnedTweet =
extractAddressByType(raw: userTweetsText, type: CryptoCurrency.fromString(ticker)); extractAddressByType(raw: userTweetsText, type: CryptoCurrency.fromString(ticker));
if (addressFromPinnedTweet != null) { if (addressFromPinnedTweet != null) {
return ParsedAddress.fetchTwitterAddress(address: addressFromPinnedTweet, name: text); return ParsedAddress.fetchTwitterAddress(address: addressFromPinnedTweet, name: text);
@ -96,6 +99,13 @@ class AddressResolver {
return ParsedAddress.fetchUnstoppableDomainAddress(address: address, name: text); return ParsedAddress.fetchUnstoppableDomainAddress(address: address, name: text);
} }
if (text.endsWith(".eth")) {
final address = await EnsRecord.fetchEnsAddress(text, wallet: wallet);
if (address.isNotEmpty && address != "0x0000000000000000000000000000000000000000") {
return ParsedAddress.fetchEnsAddress(name: text, address: address);
}
}
if (formattedName.contains(".")) { if (formattedName.contains(".")) {
final txtRecord = await OpenaliasRecord.lookupOpenAliasRecord(formattedName); final txtRecord = await OpenaliasRecord.lookupOpenAliasRecord(formattedName);
if (txtRecord != null) { if (txtRecord != null) {

View file

@ -1,7 +1,7 @@
import 'package:cake_wallet/entities/openalias_record.dart'; import 'package:cake_wallet/entities/openalias_record.dart';
import 'package:cake_wallet/entities/yat_record.dart'; import 'package:cake_wallet/entities/yat_record.dart';
enum ParseFrom { unstoppableDomains, openAlias, yatRecord, fio, notParsed, twitter, contact } enum ParseFrom { unstoppableDomains, openAlias, yatRecord, fio, notParsed, twitter, ens, contact }
class ParsedAddress { class ParsedAddress {
ParsedAddress({ ParsedAddress({
@ -77,8 +77,17 @@ class ParsedAddress {
); );
} }
factory ParsedAddress.fetchEnsAddress({required String address, required String name}) {
return ParsedAddress(
addresses: [address],
name: name,
parseFrom: ParseFrom.ens,
);
}
final List<String> addresses; final List<String> addresses;
final String name; final String name;
final String description; final String description;
final ParseFrom parseFrom; final ParseFrom parseFrom;
} }

View file

@ -145,4 +145,9 @@ class CWEthereum extends Ethereum {
void updateEtherscanUsageState(WalletBase wallet, bool isEnabled) { void updateEtherscanUsageState(WalletBase wallet, bool isEnabled) {
(wallet as EthereumWallet).updateEtherscanUsageState(isEnabled); (wallet as EthereumWallet).updateEtherscanUsageState(isEnabled);
} }
@override
Web3Client? getWeb3Client(WalletBase wallet) {
return (wallet as EthereumWallet).getWeb3Client();
}
} }

View file

@ -66,9 +66,8 @@ class SendPage extends BasePage {
color: titleColor(context), color: titleColor(context),
size: 16, size: 16,
); );
final _closeButton = currentTheme.type == ThemeType.dark final _closeButton =
? closeButtonImageDarkTheme currentTheme.type == ThemeType.dark ? closeButtonImageDarkTheme : closeButtonImage;
: closeButtonImage;
bool isMobileView = ResponsiveLayoutUtil.instance.isMobile; bool isMobileView = ResponsiveLayoutUtil.instance.isMobile;
@ -79,13 +78,10 @@ class SendPage extends BasePage {
child: ButtonTheme( child: ButtonTheme(
minWidth: double.minPositive, minWidth: double.minPositive,
child: Semantics( child: Semantics(
label: !isMobileView label: !isMobileView ? S.of(context).close : S.of(context).seed_alert_back,
? S.of(context).close
: S.of(context).seed_alert_back,
child: TextButton( child: TextButton(
style: ButtonStyle( style: ButtonStyle(
overlayColor: MaterialStateColor.resolveWith( overlayColor: MaterialStateColor.resolveWith((states) => Colors.transparent),
(states) => Colors.transparent),
), ),
onPressed: () => onClose(context), onPressed: () => onClose(context),
child: !isMobileView ? _closeButton : _backButton, child: !isMobileView ? _closeButton : _backButton,
@ -123,8 +119,7 @@ class SendPage extends BasePage {
Padding( Padding(
padding: const EdgeInsets.only(right: 8.0), padding: const EdgeInsets.only(right: 8.0),
child: Observer( child: Observer(
builder: (_) => builder: (_) => SyncIndicatorIcon(isSynced: sendViewModel.isReadyForSend),
SyncIndicatorIcon(isSynced: sendViewModel.isReadyForSend),
), ),
), ),
if (supMiddle != null) supMiddle if (supMiddle != null) supMiddle
@ -158,10 +153,10 @@ class SendPage extends BasePage {
_setEffects(context); _setEffects(context);
return GestureDetector( return GestureDetector(
onLongPress: () => sendViewModel.balanceViewModel.isReversing = onLongPress: () =>
!sendViewModel.balanceViewModel.isReversing, sendViewModel.balanceViewModel.isReversing = !sendViewModel.balanceViewModel.isReversing,
onLongPressUp: () => sendViewModel.balanceViewModel.isReversing = onLongPressUp: () =>
!sendViewModel.balanceViewModel.isReversing, sendViewModel.balanceViewModel.isReversing = !sendViewModel.balanceViewModel.isReversing,
child: Form( child: Form(
key: _formKey, key: _formKey,
child: ScrollableWithBottomSection( child: ScrollableWithBottomSection(
@ -191,8 +186,7 @@ class SendPage extends BasePage {
}, },
)), )),
Padding( Padding(
padding: EdgeInsets.only( padding: EdgeInsets.only(top: 10, left: 24, right: 24, bottom: 10),
top: 10, left: 24, right: 24, bottom: 10),
child: Container( child: Container(
height: 10, height: 10,
child: Observer( child: Observer(
@ -208,8 +202,12 @@ class SendPage extends BasePage {
radius: 6.0, radius: 6.0,
dotWidth: 6.0, dotWidth: 6.0,
dotHeight: 6.0, dotHeight: 6.0,
dotColor: Theme.of(context).extension<SendPageTheme>()!.indicatorDotColor, dotColor: Theme.of(context)
activeDotColor: Theme.of(context).extension<SendPageTheme>()!.templateBackgroundColor), .extension<SendPageTheme>()!
.indicatorDotColor,
activeDotColor: Theme.of(context)
.extension<SendPageTheme>()!
.templateBackgroundColor),
) )
: Offstage(); : Offstage();
}, },
@ -230,8 +228,7 @@ class SendPage extends BasePage {
return Row( return Row(
children: <Widget>[ children: <Widget>[
AddTemplateButton( AddTemplateButton(
onTap: () => Navigator.of(context) onTap: () => Navigator.of(context).pushNamed(Routes.sendTemplate),
.pushNamed(Routes.sendTemplate),
currentTemplatesLength: templates.length, currentTemplatesLength: templates.length,
), ),
ListView.builder( ListView.builder(
@ -244,9 +241,8 @@ class SendPage extends BasePage {
return TemplateTile( return TemplateTile(
key: UniqueKey(), key: UniqueKey(),
to: template.name, to: template.name,
hasMultipleRecipients: hasMultipleRecipients: template.additionalRecipients != null &&
template.additionalRecipients != null && template.additionalRecipients!.length > 1,
template.additionalRecipients!.length > 1,
amount: template.isCurrencySelected amount: template.isCurrencySelected
? template.amount ? template.amount
: template.amountFiat, : template.amountFiat,
@ -257,7 +253,9 @@ class SendPage extends BasePage {
if (template.additionalRecipients?.isNotEmpty ?? false) { if (template.additionalRecipients?.isNotEmpty ?? false) {
sendViewModel.clearOutputs(); sendViewModel.clearOutputs();
for (int i = 0;i < template.additionalRecipients!.length;i++) { for (int i = 0;
i < template.additionalRecipients!.length;
i++) {
Output output; Output output;
try { try {
output = sendViewModel.outputs[i]; output = sendViewModel.outputs[i];
@ -286,26 +284,17 @@ class SendPage extends BasePage {
context: context, context: context,
builder: (dialogContext) { builder: (dialogContext) {
return AlertWithTwoActions( return AlertWithTwoActions(
alertTitle: alertTitle: S.of(context).template,
S.of(context).template, alertContent: S.of(context).confirm_delete_template,
alertContent: S rightButtonText: S.of(context).delete,
.of(context) leftButtonText: S.of(context).cancel,
.confirm_delete_template,
rightButtonText:
S.of(context).delete,
leftButtonText:
S.of(context).cancel,
actionRightButton: () { actionRightButton: () {
Navigator.of(dialogContext) Navigator.of(dialogContext).pop();
.pop(); sendViewModel.sendTemplateViewModel
sendViewModel .removeTemplate(template: template);
.sendTemplateViewModel
.removeTemplate(
template: template);
}, },
actionLeftButton: () => actionLeftButton: () =>
Navigator.of(dialogContext) Navigator.of(dialogContext).pop());
.pop());
}, },
); );
}, },
@ -321,8 +310,7 @@ class SendPage extends BasePage {
], ],
), ),
), ),
bottomSectionPadding: bottomSectionPadding: EdgeInsets.only(left: 24, right: 24, bottom: 24),
EdgeInsets.only(left: 24, right: 24, bottom: 24),
bottomSection: Column( bottomSection: Column(
children: [ children: [
if (sendViewModel.hasCurrecyChanger) if (sendViewModel.hasCurrecyChanger)
@ -331,10 +319,10 @@ class SendPage extends BasePage {
padding: EdgeInsets.only(bottom: 12), padding: EdgeInsets.only(bottom: 12),
child: PrimaryButton( child: PrimaryButton(
onPressed: () => presentCurrencyPicker(context), onPressed: () => presentCurrencyPicker(context),
text: text: 'Change your asset (${sendViewModel.selectedCryptoCurrency})',
'Change your asset (${sendViewModel.selectedCryptoCurrency})',
color: Colors.transparent, color: Colors.transparent,
textColor: Theme.of(context).extension<SeedWidgetTheme>()!.hintTextColor, textColor:
Theme.of(context).extension<SeedWidgetTheme>()!.hintTextColor,
))), ))),
if (sendViewModel.sendTemplateViewModel.hasMultiRecipient) if (sendViewModel.sendTemplateViewModel.hasMultiRecipient)
Padding( Padding(
@ -343,22 +331,21 @@ class SendPage extends BasePage {
onPressed: () { onPressed: () {
sendViewModel.addOutput(); sendViewModel.addOutput();
Future.delayed(const Duration(milliseconds: 250), () { Future.delayed(const Duration(milliseconds: 250), () {
controller controller.jumpToPage(sendViewModel.outputs.length - 1);
.jumpToPage(sendViewModel.outputs.length - 1);
}); });
}, },
text: S.of(context).add_receiver, text: S.of(context).add_receiver,
color: Colors.transparent, color: Colors.transparent,
textColor: Theme.of(context).extension<SeedWidgetTheme>()!.hintTextColor, textColor: Theme.of(context).extension<SeedWidgetTheme>()!.hintTextColor,
isDottedBorder: true, isDottedBorder: true,
borderColor: Theme.of(context).extension<SendPageTheme>()!.templateDottedBorderColor, borderColor:
Theme.of(context).extension<SendPageTheme>()!.templateDottedBorderColor,
)), )),
Observer( Observer(
builder: (_) { builder: (_) {
return LoadingPrimaryButton( return LoadingPrimaryButton(
onPressed: () async { onPressed: () async {
if (_formKey.currentState != null && if (_formKey.currentState != null && !_formKey.currentState!.validate()) {
!_formKey.currentState!.validate()) {
if (sendViewModel.outputs.length > 1) { if (sendViewModel.outputs.length > 1) {
showErrorValidationAlert(context); showErrorValidationAlert(context);
} }
@ -367,9 +354,7 @@ class SendPage extends BasePage {
} }
final notValidItems = sendViewModel.outputs final notValidItems = sendViewModel.outputs
.where((item) => .where((item) => item.address.isEmpty || item.cryptoAmount.isEmpty)
item.address.isEmpty ||
item.cryptoAmount.isEmpty)
.toList(); .toList();
if (notValidItems.isNotEmpty) { if (notValidItems.isNotEmpty) {
@ -389,8 +374,7 @@ class SendPage extends BasePage {
); );
}, },
text: S.of(context).send, text: S.of(context).send,
color: color: Theme.of(context).primaryColor,
Theme.of(context).primaryColor,
textColor: Colors.white, textColor: Colors.white,
isLoading: sendViewModel.state is IsExecutingState || isLoading: sendViewModel.state is IsExecutingState ||
sendViewModel.state is TransactionCommitting, sendViewModel.state is TransactionCommitting,
@ -433,14 +417,11 @@ class SendPage extends BasePage {
return ConfirmSendingAlert( return ConfirmSendingAlert(
alertTitle: S.of(context).confirm_sending, alertTitle: S.of(context).confirm_sending,
amount: S.of(context).send_amount, amount: S.of(context).send_amount,
amountValue: amountValue: sendViewModel.pendingTransaction!.amountFormatted,
sendViewModel.pendingTransaction!.amountFormatted, fiatAmountValue: sendViewModel.pendingTransactionFiatAmountFormatted,
fiatAmountValue:
sendViewModel.pendingTransactionFiatAmountFormatted,
fee: S.of(context).send_fee, fee: S.of(context).send_fee,
feeValue: sendViewModel.pendingTransaction!.feeFormatted, feeValue: sendViewModel.pendingTransaction!.feeFormatted,
feeFiatAmount: sendViewModel feeFiatAmount: sendViewModel.pendingTransactionFeeFiatAmountFormatted,
.pendingTransactionFeeFiatAmountFormatted,
outputs: sendViewModel.outputs, outputs: sendViewModel.outputs,
rightButtonText: S.of(context).ok, rightButtonText: S.of(context).ok,
leftButtonText: S.of(context).cancel, leftButtonText: S.of(context).cancel,
@ -461,8 +442,7 @@ class SendPage extends BasePage {
return AlertWithOneAction( return AlertWithOneAction(
alertTitle: '', alertTitle: '',
alertContent: S.of(context).send_success( alertContent: S.of(context).send_success(
sendViewModel.selectedCryptoCurrency sendViewModel.selectedCryptoCurrency.toString()),
.toString()),
buttonText: S.of(context).ok, buttonText: S.of(context).ok,
buttonAction: () { buttonAction: () {
Navigator.of(context).pop(); Navigator.of(context).pop();
@ -492,8 +472,8 @@ class SendPage extends BasePage {
Future<void> _setInputsFromTemplate(BuildContext context, Future<void> _setInputsFromTemplate(BuildContext context,
{required Output output, required Template template}) async { {required Output output, required Template template}) async {
final fiatFromTemplate = FiatCurrency.all final fiatFromTemplate =
.singleWhere((element) => element.title == template.fiatCurrency); FiatCurrency.all.singleWhere((element) => element.title == template.fiatCurrency);
output.address = template.address; output.address = template.address;
@ -534,12 +514,11 @@ class SendPage extends BasePage {
builder: (_) => Picker( builder: (_) => Picker(
items: sendViewModel.currencies, items: sendViewModel.currencies,
displayItem: (Object item) => item.toString(), displayItem: (Object item) => item.toString(),
selectedAtIndex: sendViewModel.currencies selectedAtIndex:
.indexOf(sendViewModel.selectedCryptoCurrency), sendViewModel.currencies.indexOf(sendViewModel.selectedCryptoCurrency),
title: S.of(context).please_select, title: S.of(context).please_select,
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
onItemSelected: (CryptoCurrency cur) => onItemSelected: (CryptoCurrency cur) => sendViewModel.selectedCryptoCurrency = cur,
sendViewModel.selectedCryptoCurrency = cur,
), ),
context: context); context: context);
} }

View file

@ -18,6 +18,11 @@ Future<String> extractAddressFromParsed(
content = S.of(context).address_from_domain(parsedAddress.name); content = S.of(context).address_from_domain(parsedAddress.name);
address = parsedAddress.addresses.first; address = parsedAddress.addresses.first;
break; break;
case ParseFrom.ens:
title = S.of(context).address_detected;
content = S.of(context).extracted_address_content('${parsedAddress.name} (ENS)');
address = parsedAddress.addresses.first;
break;
case ParseFrom.openAlias: case ParseFrom.openAlias:
title = S.of(context).address_detected; title = S.of(context).address_detected;
content = S.of(context).extracted_address_content('${parsedAddress.name} (OpenAlias)'); content = S.of(context).extracted_address_content('${parsedAddress.name} (OpenAlias)');

View file

@ -84,6 +84,10 @@ dependencies:
sensitive_clipboard: ^1.0.0 sensitive_clipboard: ^1.0.0
walletconnect_flutter_v2: ^2.1.4 walletconnect_flutter_v2: ^2.1.4
eth_sig_util: ^0.0.9 eth_sig_util: ^0.0.9
ens_dart:
git:
url: https://github.com/cake-tech/ens_dart.git
ref: main
bitcoin_flutter: bitcoin_flutter:
git: git:
url: https://github.com/cake-tech/bitcoin_flutter.git url: https://github.com/cake-tech/bitcoin_flutter.git

View file

@ -18,8 +18,10 @@ Future<void> main(List<String> args) async {
await generateMonero(hasMonero); await generateMonero(hasMonero);
await generateHaven(hasHaven); await generateHaven(hasHaven);
await generateEthereum(hasEthereum); await generateEthereum(hasEthereum);
await generatePubspec(hasMonero: hasMonero, hasBitcoin: hasBitcoin, hasHaven: hasHaven, hasEthereum: hasEthereum); await generatePubspec(
await generateWalletTypes(hasMonero: hasMonero, hasBitcoin: hasBitcoin, hasHaven: hasHaven, hasEthereum: hasEthereum); hasMonero: hasMonero, hasBitcoin: hasBitcoin, hasHaven: hasHaven, hasEthereum: hasEthereum);
await generateWalletTypes(
hasMonero: hasMonero, hasBitcoin: hasBitcoin, hasHaven: hasHaven, hasEthereum: hasEthereum);
} }
Future<void> generateBitcoin(bool hasImplementation) async { Future<void> generateBitcoin(bool hasImplementation) async {
@ -88,12 +90,12 @@ abstract class Bitcoin {
const bitcoinEmptyDefinition = 'Bitcoin? bitcoin;\n'; const bitcoinEmptyDefinition = 'Bitcoin? bitcoin;\n';
const bitcoinCWDefinition = 'Bitcoin? bitcoin = CWBitcoin();\n'; const bitcoinCWDefinition = 'Bitcoin? bitcoin = CWBitcoin();\n';
final output = '$bitcoinCommonHeaders\n' final output = '$bitcoinCommonHeaders\n' +
+ (hasImplementation ? '$bitcoinCWHeaders\n' : '\n') (hasImplementation ? '$bitcoinCWHeaders\n' : '\n') +
+ (hasImplementation ? '$bitcoinCwPart\n\n' : '\n') (hasImplementation ? '$bitcoinCwPart\n\n' : '\n') +
+ (hasImplementation ? bitcoinCWDefinition : bitcoinEmptyDefinition) (hasImplementation ? bitcoinCWDefinition : bitcoinEmptyDefinition) +
+ '\n' '\n' +
+ bitcoinContent; bitcoinContent;
if (outputFile.existsSync()) { if (outputFile.existsSync()) {
await outputFile.delete(); await outputFile.delete();
@ -268,12 +270,12 @@ abstract class MoneroAccountList {
const moneroEmptyDefinition = 'Monero? monero;\n'; const moneroEmptyDefinition = 'Monero? monero;\n';
const moneroCWDefinition = 'Monero? monero = CWMonero();\n'; const moneroCWDefinition = 'Monero? monero = CWMonero();\n';
final output = '$moneroCommonHeaders\n' final output = '$moneroCommonHeaders\n' +
+ (hasImplementation ? '$moneroCWHeaders\n' : '\n') (hasImplementation ? '$moneroCWHeaders\n' : '\n') +
+ (hasImplementation ? '$moneroCwPart\n\n' : '\n') (hasImplementation ? '$moneroCwPart\n\n' : '\n') +
+ (hasImplementation ? moneroCWDefinition : moneroEmptyDefinition) (hasImplementation ? moneroCWDefinition : moneroEmptyDefinition) +
+ '\n' '\n' +
+ moneroContent; moneroContent;
if (outputFile.existsSync()) { if (outputFile.existsSync()) {
await outputFile.delete(); await outputFile.delete();
@ -283,7 +285,6 @@ abstract class MoneroAccountList {
} }
Future<void> generateHaven(bool hasImplementation) async { Future<void> generateHaven(bool hasImplementation) async {
final outputFile = File(havenOutputPath); final outputFile = File(havenOutputPath);
const havenCommonHeaders = """ const havenCommonHeaders = """
import 'package:mobx/mobx.dart'; import 'package:mobx/mobx.dart';
@ -448,12 +449,12 @@ abstract class HavenAccountList {
const havenEmptyDefinition = 'Haven? haven;\n'; const havenEmptyDefinition = 'Haven? haven;\n';
const havenCWDefinition = 'Haven? haven = CWHaven();\n'; const havenCWDefinition = 'Haven? haven = CWHaven();\n';
final output = '$havenCommonHeaders\n' final output = '$havenCommonHeaders\n' +
+ (hasImplementation ? '$havenCWHeaders\n' : '\n') (hasImplementation ? '$havenCWHeaders\n' : '\n') +
+ (hasImplementation ? '$havenCwPart\n\n' : '\n') (hasImplementation ? '$havenCwPart\n\n' : '\n') +
+ (hasImplementation ? havenCWDefinition : havenEmptyDefinition) (hasImplementation ? havenCWDefinition : havenEmptyDefinition) +
+ '\n' '\n' +
+ havenContent; havenContent;
if (outputFile.existsSync()) { if (outputFile.existsSync()) {
await outputFile.delete(); await outputFile.delete();
@ -463,11 +464,9 @@ abstract class HavenAccountList {
} }
Future<void> generateEthereum(bool hasImplementation) async { Future<void> generateEthereum(bool hasImplementation) async {
final outputFile = File(ethereumOutputPath); final outputFile = File(ethereumOutputPath);
const ethereumCommonHeaders = """ const ethereumCommonHeaders = """
import 'package:cake_wallet/view_model/send/output.dart'; import 'package:cake_wallet/view_model/send/output.dart';
import 'package:cw_core/crypto_amount_format.dart';
import 'package:cw_core/crypto_currency.dart'; import 'package:cw_core/crypto_currency.dart';
import 'package:cw_core/erc20_token.dart'; import 'package:cw_core/erc20_token.dart';
import 'package:cw_core/output_info.dart'; import 'package:cw_core/output_info.dart';
@ -479,6 +478,7 @@ import 'package:cw_core/wallet_info.dart';
import 'package:cw_core/wallet_service.dart'; import 'package:cw_core/wallet_service.dart';
import 'package:eth_sig_util/util/utils.dart'; import 'package:eth_sig_util/util/utils.dart';
import 'package:hive/hive.dart'; import 'package:hive/hive.dart';
import 'package:web3dart/web3dart.dart';
"""; """;
const ethereumCWHeaders = """ const ethereumCWHeaders = """
import 'package:cw_ethereum/ethereum_formatter.dart'; import 'package:cw_ethereum/ethereum_formatter.dart';
@ -528,18 +528,19 @@ abstract class Ethereum {
CryptoCurrency assetOfTransaction(WalletBase wallet, TransactionInfo transaction); CryptoCurrency assetOfTransaction(WalletBase wallet, TransactionInfo transaction);
void updateEtherscanUsageState(WalletBase wallet, bool isEnabled); void updateEtherscanUsageState(WalletBase wallet, bool isEnabled);
Web3Client? getWeb3Client(WalletBase wallet);
} }
"""; """;
const ethereumEmptyDefinition = 'Ethereum? ethereum;\n'; const ethereumEmptyDefinition = 'Ethereum? ethereum;\n';
const ethereumCWDefinition = 'Ethereum? ethereum = CWEthereum();\n'; const ethereumCWDefinition = 'Ethereum? ethereum = CWEthereum();\n';
final output = '$ethereumCommonHeaders\n' final output = '$ethereumCommonHeaders\n' +
+ (hasImplementation ? '$ethereumCWHeaders\n' : '\n') (hasImplementation ? '$ethereumCWHeaders\n' : '\n') +
+ (hasImplementation ? '$ethereumCwPart\n\n' : '\n') (hasImplementation ? '$ethereumCwPart\n\n' : '\n') +
+ (hasImplementation ? ethereumCWDefinition : ethereumEmptyDefinition) (hasImplementation ? ethereumCWDefinition : ethereumEmptyDefinition) +
+ '\n' '\n' +
+ ethereumContent; ethereumContent;
if (outputFile.existsSync()) { if (outputFile.existsSync()) {
await outputFile.delete(); await outputFile.delete();
@ -548,8 +549,12 @@ abstract class Ethereum {
await outputFile.writeAsString(output); await outputFile.writeAsString(output);
} }
Future<void> generatePubspec({required bool hasMonero, required bool hasBitcoin, required bool hasHaven, required bool hasEthereum}) async { Future<void> generatePubspec(
const cwCore = """ {required bool hasMonero,
required bool hasBitcoin,
required bool hasHaven,
required bool hasEthereum}) async {
const cwCore = """
cw_core: cw_core:
path: ./cw_core path: ./cw_core
"""; """;
@ -601,7 +606,7 @@ Future<void> generatePubspec({required bool hasMonero, required bool hasBitcoin,
inputLines.insertAll(dependenciesIndex + 1, outputLines); inputLines.insertAll(dependenciesIndex + 1, outputLines);
final outputContent = inputLines.join('\n'); final outputContent = inputLines.join('\n');
final outputFile = File(pubspecOutputPath); final outputFile = File(pubspecOutputPath);
if (outputFile.existsSync()) { if (outputFile.existsSync()) {
await outputFile.delete(); await outputFile.delete();
} }
@ -609,9 +614,13 @@ Future<void> generatePubspec({required bool hasMonero, required bool hasBitcoin,
await outputFile.writeAsString(outputContent); await outputFile.writeAsString(outputContent);
} }
Future<void> generateWalletTypes({required bool hasMonero, required bool hasBitcoin, required bool hasHaven, required bool hasEthereum}) async { Future<void> generateWalletTypes(
{required bool hasMonero,
required bool hasBitcoin,
required bool hasHaven,
required bool hasEthereum}) async {
final walletTypesFile = File(walletTypesPath); final walletTypesFile = File(walletTypesPath);
if (walletTypesFile.existsSync()) { if (walletTypesFile.existsSync()) {
await walletTypesFile.delete(); await walletTypesFile.delete();
} }

View file

@ -1,6 +1,6 @@
const defaultLang = "en"; const defaultLang = "en";
const langs = [ const langs = [
"ar", "bg", "cs", "de", "en", "es", "fr", "ha", "hi", "hr", "id", "it", "ar", "bg", "cs", "de", "en", "es", "fr", "ha", "hi", "hr", "id", "it",
"ja", "ko", "my", "nl", "pl", "pt", "ru", "th", "tr", "uk", "ur", "yo", "ja", "ko", "my", "nl", "pl", "pt", "ru", "th", "tl", "tr", "uk", "ur", "yo",
"zh-cn" // zh, but Google Translate uses zh-cn for Chinese (Simplified) "zh-cn" // zh, but Google Translate uses zh-cn for Chinese (Simplified)
]; ];