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)); String formattedAmount = bitcoinAmountFormat.format(cryptoAmountToDouble(amount: amount, divider: lightningAmountDivider));
return formattedAmount.substring(0, formattedAmount.length - 2); 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 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 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 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 = 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 min = (snapshot.data as List<String>)[1];
String max = (snapshot.data as List<String>)[2]; String max = (snapshot.data as List<String>)[2];
String fee = (snapshot.data as List<String>)[3]; String fee = (snapshot.data as List<String>)[3];
min = bitcoinAmountToLightningString(amount: int.parse(min) ~/ 1000); min = satsToLightningString(double.parse(min));
max = bitcoinAmountToLightningString(amount: int.parse(min) ~/ 1000); max = satsToLightningString(double.parse(max));
fee = bitcoinAmountToLightningString(amount: int.parse(min) ~/ 1000); fee = satsToLightningString(double.parse(fee));
return Expanded( return Expanded(
child: Text( child: Text(
// S.of(context).lightning_receive_limits(min, max, fee), // S.of(context).lightning_receive_limits(min, max, fee),
"Needs fixing!: $min, $max, $fee", "Needs fixing!: min: $min max: $max fee: $fee",
maxLines: 10, maxLines: 10,
style: TextStyle( style: TextStyle(
fontSize: 14, fontSize: 14,

View file

@ -23,6 +23,7 @@ class AnonpayCurrencyInputField extends StatelessWidget {
final String maxAmount; final String maxAmount;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
bool hasDecimals = selectedCurrency.name != "Sats";
final arrowBottomPurple = Image.asset( final arrowBottomPurple = Image.asset(
'assets/images/arrow_bottom_purple_icon.png', 'assets/images/arrow_bottom_purple_icon.png',
color: Colors.white, color: Colors.white,
@ -114,12 +115,13 @@ class AnonpayCurrencyInputField extends StatelessWidget {
textInputAction: TextInputAction.next, textInputAction: TextInputAction.next,
enabled: true, enabled: true,
textAlign: TextAlign.left, textAlign: TextAlign.left,
keyboardType: keyboardType: TextInputType.numberWithOptions(
TextInputType.numberWithOptions(signed: false, decimal: true), signed: false, decimal: hasDecimals),
inputFormatters: [ inputFormatters: [
FilteringTextInputFormatter.deny(RegExp('[\\-|\\ ]')) FilteringTextInputFormatter.deny(RegExp('[\\-|\\ ]')),
if (!hasDecimals) FilteringTextInputFormatter.deny(RegExp('[\.,]')),
], ],
hintText: '0.0000', hintText: hasDecimals ? '0.0000' : '0',
borderColor: Colors.transparent, borderColor: Colors.transparent,
//widget.borderColor, //widget.borderColor,
textStyle: TextStyle( 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/themes/extensions/exchange_page_theme.dart';
import 'package:cake_wallet/typography.dart'; import 'package:cake_wallet/typography.dart';
import 'package:cake_wallet/view_model/lightning_invoice_page_view_model.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:cw_core/crypto_currency.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_mobx/flutter_mobx.dart'; import 'package:flutter_mobx/flutter_mobx.dart';
@ -44,8 +45,8 @@ class LightningInvoiceForm extends StatelessWidget {
controller: amountController, controller: amountController,
focusNode: depositAmountFocus, focusNode: depositAmountFocus,
maxAmount: '', maxAmount: '',
minAmount: lightningInvoicePageViewModel.minimum?.toString() ?? '...', minAmount: (lightningInvoicePageViewModel.minimum != null) ? satsToLightningString(lightningInvoicePageViewModel.minimum!) : '...',
selectedCurrency: CryptoCurrency.btc, selectedCurrency: CryptoCurrency.satoshis,
); );
}), }),
SizedBox( 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/receive_page_option.dart';
import 'package:cw_core/wallet_base.dart'; import 'package:cw_core/wallet_base.dart';
import 'package:cw_core/wallet_type.dart'; import 'package:cw_core/wallet_type.dart';
import 'package:cw_lightning/lightning_receive_page_option.dart';
import 'package:mobx/mobx.dart'; import 'package:mobx/mobx.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
@ -114,8 +113,9 @@ abstract class LightningInvoicePageViewModelBase with Store {
Future<void> _fetchLimits() async { Future<void> _fetchLimits() async {
List<String> limits = await lightningViewModel.invoiceLimitsSats(); List<String> limits = await lightningViewModel.invoiceLimitsSats();
minimum = bitcoinAmountToDouble(amount: int.parse(limits[0]) ~/ 1000); minimum = double.parse(limits[0]);
maximum = bitcoinAmountToDouble(amount: int.parse(limits[1]) ~/ 1000); maximum = double.parse(limits[1]);
print(minimum);
} }
@action @action

View file

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