This commit is contained in:
fosse 2024-02-27 16:50:26 -05:00
parent 5c5eb5965f
commit cd8ad676f5
7 changed files with 29 additions and 17 deletions

View file

@ -30,3 +30,8 @@ String bitcoinAmountToLightningString({required int amount}) {
String formattedAmount = bitcoinAmountFormat.format(cryptoAmountToDouble(amount: amount, divider: lightningAmountDivider));
return formattedAmount.substring(0, formattedAmount.length - 2);
}
String satsToLightningString(double sats) {
String formattedAmount = bitcoinAmountFormat.format(sats);
return formattedAmount.substring(0, formattedAmount.length - 2);
}

View file

@ -216,6 +216,8 @@ class CryptoCurrency extends EnumerableItem<int> with Serializable<int> implemen
static const kaspa = CryptoCurrency(title: 'KAS', fullName: 'Kaspa', raw: 89, name: 'kas', iconPath: 'assets/images/kaspa_icon.png', decimals: 8);
static const digibyte = CryptoCurrency(title: 'DGB', fullName: 'DigiByte', raw: 90, name: 'dgb', iconPath: 'assets/images/digibyte.png', decimals: 8);
static const usdtSol = CryptoCurrency(title: 'USDT', tag: 'SOL', fullName: 'USDT Tether', raw: 90, name: 'usdtsol', iconPath: 'assets/images/usdt_icon.png', decimals: 6);
static const satoshis = CryptoCurrency(title: 'Sats', fullName: 'Satoshis', raw: 91, name: 'sats', iconPath: 'assets/images/btc.png', decimals: 0);
static final Map<int, CryptoCurrency> _rawCurrencyMap =

View file

@ -209,13 +209,13 @@ class LightningReceiveOnchainPage extends BasePage {
String min = (snapshot.data as List<String>)[1];
String max = (snapshot.data as List<String>)[2];
String fee = (snapshot.data as List<String>)[3];
min = bitcoinAmountToLightningString(amount: int.parse(min) ~/ 1000);
max = bitcoinAmountToLightningString(amount: int.parse(min) ~/ 1000);
fee = bitcoinAmountToLightningString(amount: int.parse(min) ~/ 1000);
min = satsToLightningString(double.parse(min));
max = satsToLightningString(double.parse(max));
fee = satsToLightningString(double.parse(fee));
return Expanded(
child: Text(
// S.of(context).lightning_receive_limits(min, max, fee),
"Needs fixing!: $min, $max, $fee",
"Needs fixing!: min: $min max: $max fee: $fee",
maxLines: 10,
style: TextStyle(
fontSize: 14,

View file

@ -23,6 +23,7 @@ class AnonpayCurrencyInputField extends StatelessWidget {
final String maxAmount;
@override
Widget build(BuildContext context) {
bool hasDecimals = selectedCurrency.name != "Sats";
final arrowBottomPurple = Image.asset(
'assets/images/arrow_bottom_purple_icon.png',
color: Colors.white,
@ -114,12 +115,13 @@ class AnonpayCurrencyInputField extends StatelessWidget {
textInputAction: TextInputAction.next,
enabled: true,
textAlign: TextAlign.left,
keyboardType:
TextInputType.numberWithOptions(signed: false, decimal: true),
keyboardType: TextInputType.numberWithOptions(
signed: false, decimal: hasDecimals),
inputFormatters: [
FilteringTextInputFormatter.deny(RegExp('[\\-|\\ ]'))
FilteringTextInputFormatter.deny(RegExp('[\\-|\\ ]')),
if (!hasDecimals) FilteringTextInputFormatter.deny(RegExp('[\.,]')),
],
hintText: '0.0000',
hintText: hasDecimals ? '0.0000' : '0',
borderColor: Colors.transparent,
//widget.borderColor,
textStyle: TextStyle(

View file

@ -4,6 +4,7 @@ import 'package:cake_wallet/src/widgets/base_text_form_field.dart';
import 'package:cake_wallet/themes/extensions/exchange_page_theme.dart';
import 'package:cake_wallet/typography.dart';
import 'package:cake_wallet/view_model/lightning_invoice_page_view_model.dart';
import 'package:cw_bitcoin/bitcoin_amount_format.dart';
import 'package:cw_core/crypto_currency.dart';
import 'package:flutter/material.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
@ -44,8 +45,8 @@ class LightningInvoiceForm extends StatelessWidget {
controller: amountController,
focusNode: depositAmountFocus,
maxAmount: '',
minAmount: lightningInvoicePageViewModel.minimum?.toString() ?? '...',
selectedCurrency: CryptoCurrency.btc,
minAmount: (lightningInvoicePageViewModel.minimum != null) ? satsToLightningString(lightningInvoicePageViewModel.minimum!) : '...',
selectedCurrency: CryptoCurrency.satoshis,
);
}),
SizedBox(

View file

@ -8,7 +8,6 @@ import 'package:cw_core/currency.dart';
import 'package:cw_core/receive_page_option.dart';
import 'package:cw_core/wallet_base.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:cw_lightning/lightning_receive_page_option.dart';
import 'package:mobx/mobx.dart';
import 'package:shared_preferences/shared_preferences.dart';
@ -114,8 +113,9 @@ abstract class LightningInvoicePageViewModelBase with Store {
Future<void> _fetchLimits() async {
List<String> limits = await lightningViewModel.invoiceLimitsSats();
minimum = bitcoinAmountToDouble(amount: int.parse(limits[0]) ~/ 1000);
maximum = bitcoinAmountToDouble(amount: int.parse(limits[1]) ~/ 1000);
minimum = double.parse(limits[0]);
maximum = double.parse(limits[1]);
print(minimum);
}
@action

View file

@ -17,18 +17,20 @@ abstract class LightningViewModelBase with Store {
SwapInfo swapInfo = await sdk.receiveOnchain(req: req);
print("Minimum amount allowed to deposit in sats: ${swapInfo.minAllowedDeposit}");
print("Maximum amount allowed to deposit in sats: ${swapInfo.maxAllowedDeposit}");
int fee = swapInfo.channelOpeningFees?.minMsat ?? 2000;
fee = fee ~/ 1000;
return [
swapInfo.bitcoinAddress,
swapInfo.minAllowedDeposit.toString(),
swapInfo.maxAllowedDeposit.toString(),
swapInfo.channelOpeningFees?.minMsat.toString() ?? "2000",
fee.toString(),
];
}
Future<String> createInvoice({required String amount, String? description}) async {
final sdk = await BreezSDK();
final req = ReceivePaymentRequest(
amountMsat: (double.parse(amount) * 100000000).round(),
amountMsat: (double.parse(amount) * 1000).round(),
description: description ?? '',
);
final res = await sdk.receivePayment(req: req);
@ -38,11 +40,11 @@ abstract class LightningViewModelBase with Store {
Future<List<String>> invoiceLimitsSats() async {
final sdk = await BreezSDK();
final req = ReceivePaymentRequest(
amountMsat: 3000 * 1000,
amountMsat: 3000 * 1000,// 3000 sats
description: "limits",
);
final res = await sdk.receivePayment(req: req);
int min = (res.openingFeeMsat ?? (2500 * 1000));
int min = (res.openingFeeMsat ?? (2500 * 1000)) ~/ 1000;
int max = 1000000000 * 1000 * 10;// 10 BTC
return [min.toString(), max.toString()];
}