Add primary receive address extracted from private key

This commit is contained in:
OmarHatem 2023-01-05 20:03:55 +02:00
parent 713ea83229
commit 73680a96e2
4 changed files with 42 additions and 9 deletions

View file

@ -40,6 +40,7 @@ abstract class EthereumWalletBase
super(walletInfo) {
this.walletInfo = walletInfo;
transactionHistory = EthereumTransactionHistory();
walletAddresses.address = EthPrivateKey.fromHex(privateKey).address.toString();
}
final String mnemonic;

View file

@ -11,6 +11,9 @@ class CWEthereum extends Ethereum {
WalletCredentials createEthereumNewWalletCredentials({
required String name,
WalletInfo? walletInfo,
}) =>
EthereumNewWalletCredentials(name: name, walletInfo: walletInfo);
}) {
return EthereumNewWalletCredentials(name: name, walletInfo: walletInfo);
}
String getAddress(WalletBase wallet) => (wallet as EthereumWallet).walletAddresses.address;
}

View file

@ -1,5 +1,5 @@
import 'package:cake_wallet/ethereum/ethereum.dart';
import 'package:cake_wallet/store/yat/yat_store.dart';
import 'package:flutter/foundation.dart';
import 'package:mobx/mobx.dart';
import 'package:cw_core/wallet_base.dart';
import 'package:cake_wallet/utils/list_item.dart';
@ -11,9 +11,7 @@ import 'package:cake_wallet/bitcoin/bitcoin.dart';
import 'package:cw_core/transaction_history.dart';
import 'package:cw_core/balance.dart';
import 'package:cw_core/transaction_info.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:cake_wallet/store/app_store.dart';
import 'dart:async';
import 'package:cake_wallet/monero/monero.dart';
import 'package:cake_wallet/haven/haven.dart';
@ -41,7 +39,7 @@ class MoneroURI extends PaymentURI {
String toString() {
var base = 'monero:' + address;
if (amount?.isNotEmpty ?? false) {
if (amount.isNotEmpty) {
base += '?tx_amount=${amount.replaceAll(',', '.')}';
}
@ -59,7 +57,7 @@ class HavenURI extends PaymentURI {
String toString() {
var base = 'haven:' + address;
if (amount?.isNotEmpty ?? false) {
if (amount.isNotEmpty) {
base += '?tx_amount=${amount.replaceAll(',', '.')}';
}
@ -77,7 +75,7 @@ class BitcoinURI extends PaymentURI {
String toString() {
var base = 'bitcoin:' + address;
if (amount?.isNotEmpty ?? false) {
if (amount.isNotEmpty) {
base += '?amount=${amount.replaceAll(',', '.')}';
}
@ -95,7 +93,25 @@ class LitecoinURI extends PaymentURI {
String toString() {
var base = 'litecoin:' + address;
if (amount?.isNotEmpty ?? false) {
if (amount.isNotEmpty) {
base += '?amount=${amount.replaceAll(',', '.')}';
}
return base;
}
}
class EthereumURI extends PaymentURI {
EthereumURI({
required String amount,
required String address})
: super(amount: amount, address: address);
@override
String toString() {
var base = 'ethereum:' + address;
if (amount.isNotEmpty) {
base += '?amount=${amount.replaceAll(',', '.')}';
}
@ -152,6 +168,10 @@ abstract class WalletAddressListViewModelBase with Store {
return LitecoinURI(amount: amount, address: address.address);
}
if (_wallet.type == WalletType.ethereum) {
return EthereumURI(amount: amount, address: address.address);
}
throw Exception('Unexpected type: ${type.toString()}');
}
@ -209,6 +229,12 @@ abstract class WalletAddressListViewModelBase with Store {
addressList.addAll(bitcoinAddresses);
}
if (wallet.type == WalletType.ethereum) {
final primaryAddress = ethereum!.getAddress(wallet);
addressList.add(WalletAddressListItem(isPrimary: true, name: null, address: primaryAddress));
}
return addressList;
}

View file

@ -477,10 +477,12 @@ Future<void> generateEthereum(bool hasImplementation) async {
const ethereumCommonHeaders = """
""";
const ethereumCWHeaders = """
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:cw_ethereum/ethereum_mnemonics.dart';
import 'package:cw_ethereum/ethereum_wallet.dart';
import 'package:cw_ethereum/ethereum_wallet_creation_credentials.dart';
import 'package:cw_ethereum/ethereum_wallet_service.dart';
import 'package:hive/hive.dart';
@ -491,6 +493,7 @@ abstract class Ethereum {
List<String> getEthereumWordList(String language);
WalletService createEthereumWalletService(Box<WalletInfo> walletInfoSource);
WalletCredentials createEthereumNewWalletCredentials({required String name, WalletInfo? walletInfo});
String getAddress(WalletBase wallet);
}
""";