mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-19 05:58:50 +02:00
v6.0.2 Release candidate (#3080)
* v6.0.2 Release candidate * v6.0.2 Release candidate * move btc ln up in the currency picker * disable bsc for swapsxyz * minor [skip ci] * hide dex/rate selection on swap screen * temp fix for evm tokens swaps icons until hive migration is done * minor [skip ci] * disable force dex providers for existing users and let them pick it from settings preference * Show bitcoin address types in swap picker (#3096) * Show bitcoin address types in swap picker * remove wrong conversion to bolt11 [skip ci] * feat: add Lightning invoice resolution and address normalization * automatically select contact wallet address based on the selected swap currency (whether it's bitcoin or lightning) * minor [skip ci] * default to bolt11 invoice for lightning swaps --------- Co-authored-by: Konstantin Ullrich <konstantinullrich12@gmail.com> --------- Co-authored-by: Konstantin Ullrich <konstantinullrich12@gmail.com>
This commit is contained in:
co-authored by
Konstantin Ullrich
parent
82982ae5af
commit
db00a0214a
@@ -9,6 +9,8 @@ import 'package:cake_wallet/bitcoin/bitcoin.dart';
|
||||
import 'package:cake_wallet/core/amount_parsing_proxy.dart';
|
||||
import 'package:cake_wallet/core/create_trade_result.dart';
|
||||
import 'package:cake_wallet/core/fiat_conversion_service.dart';
|
||||
import 'package:cake_wallet/core/lightning_invoice_service.dart';
|
||||
import 'package:cake_wallet/core/utilities.dart';
|
||||
import 'package:cake_wallet/core/wallet_change_listener_view_model.dart';
|
||||
import 'package:cake_wallet/entities/calculate_fiat_amount.dart';
|
||||
import 'package:cake_wallet/entities/exchange_api_mode.dart';
|
||||
@@ -420,7 +422,7 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
|
||||
return await WalletInfo.selectList("type = ?", [type!.index]);
|
||||
}
|
||||
|
||||
Future<List<WalletInfoAddressInfo>> addressesForWallet(WalletInfo wallet) async {
|
||||
Future<List<WalletInfoAddressInfo>> addressesForAccountsWallet(WalletInfo wallet) async {
|
||||
final List<WalletInfoAddressInfo> ret = [];
|
||||
final addresses = await wallet.getAddressInfos();
|
||||
for (var list in addresses.values) {
|
||||
@@ -554,6 +556,8 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
|
||||
calculateForcedProviderRate();
|
||||
}
|
||||
|
||||
WalletInfo? selectedAddressBookWallet;
|
||||
|
||||
@observable
|
||||
double forcedProviderRate = 0.0;
|
||||
|
||||
@@ -964,22 +968,6 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
|
||||
}
|
||||
}
|
||||
|
||||
if (depositCurrency == CryptoCurrency.btcln &&
|
||||
depositAddress == wallet.walletAddresses.addressForExchange) {
|
||||
final invoice = await bitcoin!.getLightningInvoice(wallet, BigInt.zero);
|
||||
if (invoice != null) {
|
||||
depositAddress = invoice;
|
||||
}
|
||||
}
|
||||
|
||||
if (receiveCurrency == CryptoCurrency.btcln &&
|
||||
receiveAddress == wallet.walletAddresses.addressForExchange) {
|
||||
final invoice = await bitcoin!.getLightningInvoice(wallet, BigInt.zero);
|
||||
if (invoice != null) {
|
||||
receiveAddress = invoice;
|
||||
}
|
||||
}
|
||||
|
||||
late final Map<double, ExchangeProvider> providers;
|
||||
if (forcedProvider != null) {
|
||||
providers = {forcedProviderRate: forcedProvider!};
|
||||
@@ -1000,6 +988,32 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
|
||||
}
|
||||
|
||||
try {
|
||||
if (selectedAddressBookWallet?.type == WalletType.bitcoin) {
|
||||
final _walletAddresses = await selectedAddressBookWallet!.getAddresses();
|
||||
|
||||
// if receive currency is lightning pick the lightning address
|
||||
// if normal bitcoin, then pick the segwit address
|
||||
if (receiveCurrency == CryptoCurrency.btcln) {
|
||||
final lightningAddressOfWallet =
|
||||
_walletAddresses.entries.firstWhereOrNull((e) => e.value.contains("LN"))?.key;
|
||||
if (lightningAddressOfWallet != null) {
|
||||
receiveAddress = lightningAddressOfWallet;
|
||||
}
|
||||
}
|
||||
if (receiveCurrency == CryptoCurrency.btc) {
|
||||
final segwitAddressOfWallet =
|
||||
_walletAddresses.entries.firstWhereOrNull((e) => e.value.contains("P2WPKH"))?.key;
|
||||
if (segwitAddressOfWallet != null) {
|
||||
receiveAddress = segwitAddressOfWallet;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// parse Lightning address to bolt11 invoice
|
||||
if (receiveAddress.contains("@")) {
|
||||
receiveAddress = await getBolt11FromLightingAddress(receiveAddress) ?? receiveAddress;
|
||||
}
|
||||
|
||||
// snapshot of providers to avoid concurrent modification issues
|
||||
final providersSnapshot = providers.values.toList();
|
||||
final ratesSnapshot = providers.keys.toList();
|
||||
|
||||
@@ -109,7 +109,7 @@ abstract class OutputBase with Store {
|
||||
if (fiatAmount.split(".").last.length <= digits) {
|
||||
return fiatAmount;
|
||||
}
|
||||
return double.parse(fiatAmount.replaceAll(",", "")).toStringAsPrecision(digits);
|
||||
return double.tryParse(fiatAmount.replaceAll(",", ""))?.toStringAsPrecision(digits) ?? '0.0';
|
||||
}
|
||||
|
||||
@observable
|
||||
|
||||
Reference in New Issue
Block a user