mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-12-05 12:44:09 +01:00
Reworked electrum wallet. Added Litecoin wallet.
This commit is contained in:
@@ -72,7 +72,7 @@ class AddressValidator extends TextValidator {
|
||||
case CryptoCurrency.eth:
|
||||
return [42];
|
||||
case CryptoCurrency.ltc:
|
||||
return [34];
|
||||
return [34, 43];
|
||||
case CryptoCurrency.nano:
|
||||
return [64, 65];
|
||||
case CryptoCurrency.trx:
|
||||
|
||||
@@ -8,7 +8,6 @@ import 'package:path_provider/path_provider.dart';
|
||||
import 'package:cryptography/cryptography.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:archive/archive_io.dart';
|
||||
import 'package:cake_wallet/core/auth_service.dart';
|
||||
import 'package:cake_wallet/core/key_service.dart';
|
||||
import 'package:cake_wallet/entities/encrypt.dart';
|
||||
import 'package:cake_wallet/entities/preferences_key.dart';
|
||||
|
||||
@@ -3,7 +3,6 @@ import 'package:cake_wallet/entities/fiat_currency.dart';
|
||||
import 'dart:convert';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:http/http.dart';
|
||||
import 'package:cake_wallet/entities/currency_formatter.dart';
|
||||
|
||||
const fiatApiAuthority = 'fiat-api.cakewallet.com';
|
||||
const fiatApiPath = '/v1/rates';
|
||||
@@ -15,9 +14,8 @@ Future<double> _fetchPrice(Map<String, dynamic> args) async {
|
||||
|
||||
try {
|
||||
final fiatStringified = fiat.toString();
|
||||
final uri =
|
||||
Uri.https(fiatApiAuthority, fiatApiPath,
|
||||
<String, String> {'convert': fiatStringified});
|
||||
final uri = Uri.https(fiatApiAuthority, fiatApiPath,
|
||||
<String, String>{'convert': fiatStringified});
|
||||
final response = await get(uri.toString());
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
@@ -28,7 +26,7 @@ Future<double> _fetchPrice(Map<String, dynamic> args) async {
|
||||
final data = responseJSON['data'] as List<dynamic>;
|
||||
|
||||
for (final item in data) {
|
||||
if (item['symbol'] == cryptoToString(crypto)) {
|
||||
if (item['symbol'] == crypto.title) {
|
||||
price = item['quote'][fiatStringified]['price'] as double;
|
||||
break;
|
||||
}
|
||||
@@ -45,6 +43,7 @@ Future<double> _fetchPriceAsync(
|
||||
compute(_fetchPrice, {'fiat': fiat, 'crypto': crypto});
|
||||
|
||||
class FiatConversionService {
|
||||
static Future<double> fetchPrice(CryptoCurrency crypto, FiatCurrency fiat) async =>
|
||||
static Future<double> fetchPrice(
|
||||
CryptoCurrency crypto, FiatCurrency fiat) async =>
|
||||
await _fetchPriceAsync(crypto, fiat);
|
||||
}
|
||||
|
||||
@@ -4,9 +4,9 @@ import 'package:cake_wallet/entities/wallet_type.dart';
|
||||
|
||||
String generateWalletPassword(WalletType type) {
|
||||
switch (type) {
|
||||
case WalletType.bitcoin:
|
||||
return generateKey();
|
||||
default:
|
||||
case WalletType.monero:
|
||||
return Uuid().v4();
|
||||
default:
|
||||
return generateKey();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:cake_wallet/generated/i18n.dart';
|
||||
import 'package:cake_wallet/core/validator.dart';
|
||||
|
||||
|
||||
@@ -3,43 +3,50 @@ import 'package:mobx/mobx.dart';
|
||||
import 'package:cake_wallet/entities/transaction_info.dart';
|
||||
|
||||
abstract class TransactionHistoryBase<TransactionType extends TransactionInfo> {
|
||||
TransactionHistoryBase() : _isUpdating = false;
|
||||
TransactionHistoryBase();
|
||||
// : _isUpdating = false;
|
||||
|
||||
@observable
|
||||
ObservableMap<String, TransactionType> transactions;
|
||||
|
||||
bool _isUpdating;
|
||||
Future<void> save();
|
||||
|
||||
@action
|
||||
Future<void> update() async {
|
||||
if (_isUpdating) {
|
||||
return;
|
||||
}
|
||||
void addOne(TransactionType transaction);
|
||||
|
||||
try {
|
||||
_isUpdating = true;
|
||||
final _transactions = await fetchTransactions();
|
||||
transactions.keys
|
||||
.toSet()
|
||||
.difference(_transactions.keys.toSet())
|
||||
.forEach((k) => transactions.remove(k));
|
||||
_transactions.forEach((key, value) => transactions[key] = value);
|
||||
_isUpdating = false;
|
||||
} catch (e) {
|
||||
_isUpdating = false;
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
void addMany(Map<String, TransactionType> transactions);
|
||||
|
||||
void updateAsync({void Function() onFinished}) {
|
||||
fetchTransactionsAsync(
|
||||
(transaction) => transactions[transaction.id] = transaction,
|
||||
onFinished: onFinished);
|
||||
}
|
||||
// bool _isUpdating;
|
||||
|
||||
void fetchTransactionsAsync(
|
||||
void Function(TransactionType transaction) onTransactionLoaded,
|
||||
{void Function() onFinished});
|
||||
// @action
|
||||
// Future<void> update() async {
|
||||
// if (_isUpdating) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
Future<Map<String, TransactionType>> fetchTransactions();
|
||||
// try {
|
||||
// _isUpdating = true;
|
||||
// final _transactions = await fetchTransactions();
|
||||
// transactions.keys
|
||||
// .toSet()
|
||||
// .difference(_transactions.keys.toSet())
|
||||
// .forEach((k) => transactions.remove(k));
|
||||
// _transactions.forEach((key, value) => transactions[key] = value);
|
||||
// _isUpdating = false;
|
||||
// } catch (e) {
|
||||
// _isUpdating = false;
|
||||
// rethrow;
|
||||
// }
|
||||
// }
|
||||
|
||||
// void updateAsync({void Function() onFinished}) {
|
||||
// fetchTransactionsAsync(
|
||||
// (transaction) => transactions[transaction.id] = transaction,
|
||||
// onFinished: onFinished);
|
||||
// }
|
||||
|
||||
// void fetchTransactionsAsync(
|
||||
// void Function(TransactionType transaction) onTransactionLoaded,
|
||||
// {void Function() onFinished});
|
||||
|
||||
// Future<Map<String, TransactionType>> fetchTransactions();
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:cake_wallet/entities/balance.dart';
|
||||
import 'package:cake_wallet/entities/transaction_info.dart';
|
||||
import 'package:cake_wallet/entities/transaction_priority.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:cake_wallet/entities/wallet_info.dart';
|
||||
@@ -11,7 +12,10 @@ import 'package:cake_wallet/entities/sync_status.dart';
|
||||
import 'package:cake_wallet/entities/node.dart';
|
||||
import 'package:cake_wallet/entities/wallet_type.dart';
|
||||
|
||||
abstract class WalletBase<BalanceType extends Balance> {
|
||||
abstract class WalletBase<
|
||||
BalanceType extends Balance,
|
||||
HistoryType extends TransactionHistoryBase,
|
||||
TransactionType extends TransactionInfo> {
|
||||
WalletBase(this.walletInfo);
|
||||
|
||||
static String idFor(String name, WalletType type) =>
|
||||
@@ -41,7 +45,7 @@ abstract class WalletBase<BalanceType extends Balance> {
|
||||
|
||||
Object get keys;
|
||||
|
||||
TransactionHistoryBase transactionHistory;
|
||||
HistoryType transactionHistory;
|
||||
|
||||
Future<void> connectToNode({@required Node node});
|
||||
|
||||
@@ -51,6 +55,12 @@ abstract class WalletBase<BalanceType extends Balance> {
|
||||
|
||||
int calculateEstimatedFee(TransactionPriority priority, int amount);
|
||||
|
||||
// void fetchTransactionsAsync(
|
||||
// void Function(TransactionType transaction) onTransactionLoaded,
|
||||
// {void Function() onFinished});
|
||||
|
||||
Future<Map<String, TransactionType>> fetchTransactions();
|
||||
|
||||
Future<void> save();
|
||||
|
||||
Future<void> rescan({int height});
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import 'package:cake_wallet/core/wallet_base.dart';
|
||||
import 'package:cake_wallet/core/wallet_credentials.dart';
|
||||
import 'package:cake_wallet/entities/wallet_type.dart';
|
||||
|
||||
abstract class WalletService<N extends WalletCredentials,
|
||||
RFS extends WalletCredentials, RFK extends WalletCredentials> {
|
||||
WalletType getType();
|
||||
|
||||
Future<WalletBase> create(N credentials);
|
||||
|
||||
Future<WalletBase> restoreFromSeed(RFS credentials);
|
||||
|
||||
Reference in New Issue
Block a user