use sats in more places

This commit is contained in:
fosse 2024-02-26 14:46:05 -05:00
parent dd5b918d65
commit 617555b633
6 changed files with 40 additions and 45 deletions

View file

@ -1,3 +1,4 @@
import 'package:cake_wallet/bitcoin/bitcoin.dart';
import 'package:cake_wallet/src/screens/receive/widgets/lightning_input_form.dart';
import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart';
import 'package:cake_wallet/themes/extensions/dashboard_page_theme.dart';
@ -13,6 +14,7 @@ import 'package:cake_wallet/utils/show_bar.dart';
import 'package:cake_wallet/view_model/dashboard/receive_option_view_model.dart';
import 'package:cake_wallet/view_model/lightning_invoice_page_view_model.dart';
import 'package:cake_wallet/view_model/lightning_view_model.dart';
import 'package:cw_bitcoin/bitcoin_amount_format.dart';
import 'package:cw_core/receive_page_option.dart';
import 'package:cw_lightning/lightning_receive_page_option.dart';
import 'package:flutter/material.dart';
@ -135,21 +137,6 @@ class LightningInvoicePage extends BasePage {
bottomSection: Observer(builder: (_) {
return Column(
children: <Widget>[
// Padding(
// padding: EdgeInsets.only(bottom: 15),
// child: Center(
// child: Text(
// S.of(context).anonpay_description("an invoice", "pay"),
// textAlign: TextAlign.center,
// style: TextStyle(
// color: Theme.of(context)
// .extension<ExchangePageTheme>()!
// .receiveAmountColor,
// fontWeight: FontWeight.w500,
// fontSize: 12),
// ),
// ),
// ),
Container(
padding: const EdgeInsets.only(top: 12, bottom: 12, right: 6),
margin: const EdgeInsets.only(left: 24, right: 24, bottom: 48),
@ -170,16 +157,27 @@ class LightningInvoicePage extends BasePage {
margin: EdgeInsets.only(left: 12, bottom: 48, right: 12),
child: Image.asset("assets/images/warning.png"),
),
Expanded(
child: Text(
"A setup fee of 0.4% with a minimum of 2,079 sats will be applied upon receiving this invoice.",
maxLines: 3,
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w500,
color: Theme.of(context).extension<DashboardPageTheme>()!.textColor,
),
),
FutureBuilder(
future: lightningInvoicePageViewModel.lightningViewModel.invoiceLimitsSats(),
builder: (context, snapshot) {
if (snapshot.data == null) {
return SizedBox();
}
String min = (snapshot.data as List<String>)[0];
min = bitcoinAmountToLightningString(amount: int.parse(min) ~/ 1000);
return Expanded(
child: Text(
"A setup fee of 0.4% with a minimum of ${min} sats will be applied upon receiving this invoice.",
maxLines: 3,
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w500,
color:
Theme.of(context).extension<DashboardPageTheme>()!.textColor,
),
),
);
},
),
],
),

View file

@ -151,12 +151,14 @@ class AnonpayCurrencyInputField extends StatelessWidget {
height: 1.2,
color: Theme.of(context).extension<ExchangePageTheme>()!.hintTextColor),
),
SizedBox(width: 10),
Text(S.of(context).max_value(maxAmount, selectedCurrency.toString()),
style: TextStyle(
fontSize: 10,
height: 1.2,
color: Theme.of(context).extension<ExchangePageTheme>()!.hintTextColor)),
if (maxAmount.isNotEmpty) ...[
SizedBox(width: 10),
Text(S.of(context).max_value(maxAmount, selectedCurrency.toString()),
style: TextStyle(
fontSize: 10,
height: 1.2,
color: Theme.of(context).extension<ExchangePageTheme>()!.hintTextColor))
],
],
),
)

View file

@ -43,7 +43,7 @@ class LightningInvoiceForm extends StatelessWidget {
return AnonpayCurrencyInputField(
controller: amountController,
focusNode: depositAmountFocus,
maxAmount: lightningInvoicePageViewModel.maximum?.toString() ?? '...',
maxAmount: '',
minAmount: lightningInvoicePageViewModel.minimum?.toString() ?? '...',
selectedCurrency: CryptoCurrency.btc,
);

View file

@ -102,10 +102,6 @@ abstract class AnonInvoicePageViewModelBase with Store {
state = FailureState('Amount is too small');
return;
}
if (maximum != null && amountInCrypto > maximum!) {
state = FailureState('Amount is too big');
return;
}
}
final result = await anonPayApi.createInvoice(AnonPayRequest(
cryptoCurrency: cryptoCurrency,

View file

@ -2,6 +2,7 @@ import 'package:cake_wallet/core/execution_state.dart';
import 'package:cake_wallet/entities/fiat_currency.dart';
import 'package:cake_wallet/store/settings_store.dart';
import 'package:cake_wallet/view_model/lightning_view_model.dart';
import 'package:cw_bitcoin/bitcoin_amount_format.dart';
import 'package:cw_core/crypto_currency.dart';
import 'package:cw_core/currency.dart';
import 'package:cw_core/receive_page_option.dart';
@ -112,11 +113,9 @@ abstract class LightningInvoicePageViewModelBase with Store {
}
Future<void> _fetchLimits() async {
List<String> limits = await lightningViewModel.invoiceLimits();
minimum = double.tryParse(limits[0]) ?? 0;
maximum = double.tryParse(limits[1]) ?? (100000000 * 10);
minimum = minimum! / 100000000000;
maximum = maximum! / 100000000000;
List<String> limits = await lightningViewModel.invoiceLimitsSats();
minimum = bitcoinAmountToDouble(amount: int.parse(limits[0]) ~/ 1000);
maximum = bitcoinAmountToDouble(amount: int.parse(limits[1]) ~/ 1000);
}
@action

View file

@ -38,15 +38,15 @@ abstract class LightningViewModelBase with Store {
return res.lnInvoice.bolt11;
}
Future<List<String>> invoiceLimits() async {
Future<List<String>> invoiceLimitsSats() async {
final sdk = await BreezSDK();
final req = ReceivePaymentRequest(
amountMsat: 3000000,
amountMsat: 3000 * 1000,
description: "limits",
);
final res = await sdk.receivePayment(req: req);
int min = (res.openingFeeMsat ?? 2500000);
int max = 1000000000;
int min = (res.openingFeeMsat ?? (2500 * 1000));
int max = 1000000000 * 1000 * 10;// 10 BTC
return [min.toString(), max.toString()];
}
}