monero.com fixes

This commit is contained in:
Matthew Fosse 2024-03-05 09:51:20 -08:00
parent b763328354
commit c65d8c43bc
11 changed files with 76 additions and 71 deletions

View file

@ -8,8 +8,8 @@ final bitcoinAmountFormat = NumberFormat()
..maximumFractionDigits = bitcoinAmountLength ..maximumFractionDigits = bitcoinAmountLength
..minimumFractionDigits = 1; ..minimumFractionDigits = 1;
String bitcoinAmountToString({required int amount}) => bitcoinAmountFormat.format( String bitcoinAmountToString({required int amount}) =>
cryptoAmountToDouble(amount: amount, divider: bitcoinAmountDivider)); bitcoinAmountFormat.format(cryptoAmountToDouble(amount: amount, divider: bitcoinAmountDivider));
double bitcoinAmountToDouble({required int amount}) => double bitcoinAmountToDouble({required int amount}) =>
cryptoAmountToDouble(amount: amount, divider: bitcoinAmountDivider); cryptoAmountToDouble(amount: amount, divider: bitcoinAmountDivider);
@ -27,11 +27,7 @@ int stringDoubleToBitcoinAmount(String amount) {
} }
String bitcoinAmountToLightningString({required int amount}) { String bitcoinAmountToLightningString({required int amount}) {
String formattedAmount = bitcoinAmountFormat.format(cryptoAmountToDouble(amount: amount, divider: lightningAmountDivider)); String formattedAmount = bitcoinAmountFormat
return formattedAmount.substring(0, formattedAmount.length - 2); .format(cryptoAmountToDouble(amount: amount, divider: lightningAmountDivider));
}
String satsToLightningString(int sats) {
String formattedAmount = bitcoinAmountFormat.format(sats);
return formattedAmount.substring(0, formattedAmount.length - 2); return formattedAmount.substring(0, formattedAmount.length - 2);
} }

View file

@ -36,7 +36,7 @@ class LightningBalance extends ElectrumBalance {
@override @override
String get formattedUnAvailableBalance { String get formattedUnAvailableBalance {
final frozenFormatted = bitcoinAmountToString(amount: frozen); final frozenFormatted = bitcoinAmountToLightningString(amount: frozen);
return frozenFormatted == '0.0' ? '' : frozenFormatted; return frozenFormatted == '0.0' ? '' : frozenFormatted;
} }

View file

@ -1,19 +0,0 @@
import 'package:cw_core/receive_page_option.dart';
class LightningReceivePageOption implements ReceivePageOption {
static const lightningOnchain = LightningReceivePageOption._('lightningOnchain');
static const lightningInvoice = LightningReceivePageOption._('lightningInvoice');
const LightningReceivePageOption._(this.value);
final String value;
String toString() {
return value;
}
static const all = [
LightningReceivePageOption.lightningInvoice,
LightningReceivePageOption.lightningOnchain
];
}

View file

@ -1,10 +1,10 @@
import 'package:cake_wallet/generated/i18n.dart'; import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/lightning/lightning.dart';
import 'package:cake_wallet/routes.dart'; import 'package:cake_wallet/routes.dart';
import 'package:cake_wallet/src/widgets/alert_with_one_action.dart'; import 'package:cake_wallet/src/widgets/alert_with_one_action.dart';
import 'package:cake_wallet/utils/show_pop_up.dart'; import 'package:cake_wallet/utils/show_pop_up.dart';
import 'package:cake_wallet/view_model/dashboard/dashboard_view_model.dart'; import 'package:cake_wallet/view_model/dashboard/dashboard_view_model.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:flutter/material.dart'; import 'package:flutter/material.dart';
class MainActions { class MainActions {
@ -60,7 +60,7 @@ class MainActions {
Navigator.pushNamed( Navigator.pushNamed(
context, context,
Routes.lightningInvoice, Routes.lightningInvoice,
arguments: [LightningReceivePageOption.lightningInvoice], arguments: [lightning!.getOptionInvoice()],
); );
return; return;
} }

View file

@ -65,4 +65,35 @@ class CWLightning extends Lightning {
@override @override
List<LightningReceivePageOption> getLightningReceivePageOptions() => List<LightningReceivePageOption> getLightningReceivePageOptions() =>
LightningReceivePageOption.all; LightningReceivePageOption.all;
@override
ReceivePageOption getOptionInvoice() => LightningReceivePageOption.lightningInvoice;
@override
ReceivePageOption getOptionOnchain() => LightningReceivePageOption.lightningOnchain;
String satsToLightningString(int sats) {
const bitcoinAmountLength = 8;
const bitcoinAmountDivider = 100000000;
const lightningAmountDivider = 1;
final bitcoinAmountFormat = NumberFormat()
..maximumFractionDigits = bitcoinAmountLength
..minimumFractionDigits = 1;
String formattedAmount = bitcoinAmountFormat.format(sats);
return formattedAmount.substring(0, formattedAmount.length - 2);
}
String bitcoinAmountToLightningString({required int amount}) {
final bitcoinAmountFormat = NumberFormat()
..maximumFractionDigits = bitcoinAmountLength
..minimumFractionDigits = 1;
String formattedAmount = bitcoinAmountFormat
.format(cryptoAmountToDouble(amount: amount, divider: 1));
return formattedAmount.substring(0, formattedAmount.length - 2);
}
int bitcoinAmountToLightningAmount({required int amount}) {
return amount * 100000000;
}
} }

View file

@ -1,4 +1,5 @@
import 'package:cake_wallet/bitcoin/bitcoin.dart'; import 'package:cake_wallet/bitcoin/bitcoin.dart';
import 'package:cake_wallet/lightning/lightning.dart';
import 'package:cake_wallet/src/screens/receive/widgets/lightning_input_form.dart'; import 'package:cake_wallet/src/screens/receive/widgets/lightning_input_form.dart';
import 'package:cake_wallet/src/screens/receive/widgets/qr_image.dart'; import 'package:cake_wallet/src/screens/receive/widgets/qr_image.dart';
import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart'; import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart';
@ -16,9 +17,8 @@ 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/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_invoice_page_view_model.dart';
import 'package:cake_wallet/view_model/lightning_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_core/receive_page_option.dart';
import 'package:cw_lightning/lightning_receive_page_option.dart'; import 'package:cw_core/lightning_receive_page_option.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_mobx/flutter_mobx.dart'; import 'package:flutter_mobx/flutter_mobx.dart';
@ -175,14 +175,15 @@ class LightningInvoicePage extends BasePage {
int balance = (snapshot.data as List<int>)[2]; int balance = (snapshot.data as List<int>)[2];
if (balance == 0) { if (balance == 0) {
int min = (snapshot.data as List<int>)[0]; int min = (snapshot.data as List<int>)[0];
finalText = finalText = S
S.of(context).lightning_invoice_min(satsToLightningString(min)); .of(context)
.lightning_invoice_min(lightning!.satsToLightningString(min));
} else { } else {
int min = (snapshot.data as List<int>)[0]; int min = (snapshot.data as List<int>)[0];
int max = (snapshot.data as List<int>)[1]; int max = (snapshot.data as List<int>)[1];
finalText = S.of(context).lightning_invoice_min_max( finalText = S.of(context).lightning_invoice_min_max(
satsToLightningString(min), lightning!.satsToLightningString(min),
satsToLightningString(max), lightning!.satsToLightningString(max),
); );
} }
@ -232,18 +233,12 @@ class LightningInvoicePage extends BasePage {
} }
reaction((_) => receiveOptionViewModel.selectedReceiveOption, (ReceivePageOption option) async { reaction((_) => receiveOptionViewModel.selectedReceiveOption, (ReceivePageOption option) async {
switch (option) { if (option == lightning!.getOptionOnchain()) {
case LightningReceivePageOption.lightningInvoice: Navigator.popAndPushNamed(
break; context,
case LightningReceivePageOption.lightningOnchain: Routes.lightningReceiveOnchain,
Navigator.popAndPushNamed( arguments: [LightningReceivePageOption.lightningOnchain],
context, );
Routes.lightningReceiveOnchain,
arguments: [LightningReceivePageOption.lightningOnchain],
);
break;
default:
break;
} }
}); });

View file

@ -1,4 +1,5 @@
import 'package:cake_wallet/entities/qr_view_data.dart'; import 'package:cake_wallet/entities/qr_view_data.dart';
import 'package:cake_wallet/lightning/lightning.dart';
import 'package:cake_wallet/routes.dart'; import 'package:cake_wallet/routes.dart';
import 'package:cake_wallet/src/screens/dashboard/widgets/present_receive_option_picker.dart'; import 'package:cake_wallet/src/screens/dashboard/widgets/present_receive_option_picker.dart';
import 'package:cake_wallet/src/screens/receive/widgets/qr_image.dart'; import 'package:cake_wallet/src/screens/receive/widgets/qr_image.dart';
@ -9,9 +10,7 @@ import 'package:cake_wallet/utils/brightness_util.dart';
import 'package:cake_wallet/utils/show_bar.dart'; 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/dashboard/receive_option_view_model.dart';
import 'package:cake_wallet/view_model/lightning_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_core/receive_page_option.dart';
import 'package:cw_lightning/lightning_receive_page_option.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:cake_wallet/generated/i18n.dart'; import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/src/screens/base_page.dart'; import 'package:cake_wallet/src/screens/base_page.dart';
@ -214,9 +213,9 @@ class LightningReceiveOnchainPage extends BasePage {
return Expanded( return Expanded(
child: Text( child: Text(
S.of(context).lightning_receive_limits( S.of(context).lightning_receive_limits(
satsToLightningString(min), lightning!.satsToLightningString(min),
satsToLightningString(max), lightning!.satsToLightningString(max),
satsToLightningString(fee), lightning!.satsToLightningString(fee),
), ),
maxLines: 10, maxLines: 10,
style: TextStyle( style: TextStyle(
@ -240,18 +239,12 @@ class LightningReceiveOnchainPage extends BasePage {
} }
reaction((_) => receiveOptionViewModel.selectedReceiveOption, (ReceivePageOption option) async { reaction((_) => receiveOptionViewModel.selectedReceiveOption, (ReceivePageOption option) async {
switch (option) { if (option == lightning!.getOptionInvoice()) {
case LightningReceivePageOption.lightningInvoice: Navigator.popAndPushNamed(
Navigator.popAndPushNamed( context,
context, Routes.lightningInvoice,
Routes.lightningInvoice, arguments: [lightning!.getOptionInvoice()],
arguments: [LightningReceivePageOption.lightningInvoice], );
);
break;
case LightningReceivePageOption.lightningOnchain:
break;
default:
break;
} }
}); });

View file

@ -1,13 +1,14 @@
import 'package:cake_wallet/generated/i18n.dart'; import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/lightning/lightning.dart';
import 'package:cake_wallet/src/screens/receive/widgets/anonpay_currency_input_field.dart'; import 'package:cake_wallet/src/screens/receive/widgets/anonpay_currency_input_field.dart';
import 'package:cake_wallet/src/widgets/base_text_form_field.dart'; 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';
import 'package:cake_wallet/lightning/lightning.dart';
class LightningInvoiceForm extends StatelessWidget { class LightningInvoiceForm extends StatelessWidget {
LightningInvoiceForm({ LightningInvoiceForm({
@ -45,7 +46,10 @@ class LightningInvoiceForm extends StatelessWidget {
controller: amountController, controller: amountController,
focusNode: depositAmountFocus, focusNode: depositAmountFocus,
maxAmount: '', maxAmount: '',
minAmount: (lightningInvoicePageViewModel.minimum != null) ? satsToLightningString(lightningInvoicePageViewModel.minimum!.round()) : '...', minAmount: (lightningInvoicePageViewModel.minimum != null)
? lightning!
.satsToLightningString(lightningInvoicePageViewModel.minimum!.round())
: '...',
selectedCurrency: CryptoCurrency.btcln, selectedCurrency: CryptoCurrency.btcln,
); );
}), }),

View file

@ -1,5 +1,6 @@
import 'package:breez_sdk/breez_sdk.dart'; import 'package:breez_sdk/breez_sdk.dart';
import 'package:breez_sdk/bridge_generated.dart'; import 'package:breez_sdk/bridge_generated.dart';
import 'package:cake_wallet/lightning/lightning.dart';
import 'package:cake_wallet/src/widgets/alert_with_one_action.dart'; import 'package:cake_wallet/src/widgets/alert_with_one_action.dart';
import 'package:cake_wallet/src/widgets/base_text_form_field.dart'; import 'package:cake_wallet/src/widgets/base_text_form_field.dart';
import 'package:cake_wallet/src/widgets/keyboard_done_button.dart'; import 'package:cake_wallet/src/widgets/keyboard_done_button.dart';
@ -8,7 +9,6 @@ import 'package:cake_wallet/themes/extensions/keyboard_theme.dart';
import 'package:cake_wallet/themes/theme_base.dart'; import 'package:cake_wallet/themes/theme_base.dart';
import 'package:cake_wallet/utils/responsive_layout_util.dart'; import 'package:cake_wallet/utils/responsive_layout_util.dart';
import 'package:cake_wallet/utils/show_pop_up.dart'; import 'package:cake_wallet/utils/show_pop_up.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';
@ -164,7 +164,7 @@ class LightningSendConfirmPage extends BasePage {
.textFieldBorderTopPanelColor, .textFieldBorderTopPanelColor,
suffixIcon: SizedBox(width: 36), suffixIcon: SizedBox(width: 36),
initialValue: initialValue:
"sats: ${bitcoinAmountToLightningString(amount: (invoice.amountMsat ?? 0) ~/ 1000)}", "sats: ${lightning!.bitcoinAmountToLightningString(amount: (invoice.amountMsat ?? 0) ~/ 1000)}",
placeholderTextStyle: TextStyle( placeholderTextStyle: TextStyle(
fontSize: 16, fontSize: 16,
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,

View file

@ -2,7 +2,6 @@ import 'package:cake_wallet/core/execution_state.dart';
import 'package:cake_wallet/entities/fiat_currency.dart'; import 'package:cake_wallet/entities/fiat_currency.dart';
import 'package:cake_wallet/store/settings_store.dart'; import 'package:cake_wallet/store/settings_store.dart';
import 'package:cake_wallet/view_model/lightning_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/crypto_currency.dart'; import 'package:cw_core/crypto_currency.dart';
import 'package:cw_core/currency.dart'; import 'package:cw_core/currency.dart';
import 'package:cw_core/receive_page_option.dart'; import 'package:cw_core/receive_page_option.dart';

View file

@ -727,6 +727,8 @@ import 'package:cw_core/transaction_priority.dart';
import 'package:cw_core/output_info.dart'; import 'package:cw_core/output_info.dart';
import 'package:cw_core/unspent_coins_info.dart'; import 'package:cw_core/unspent_coins_info.dart';
import 'package:cw_core/wallet_service.dart'; import 'package:cw_core/wallet_service.dart';
import 'package:cw_core/receive_page_option.dart';
import 'package:cw_core/crypto_amount_format.dart';
import 'package:cake_wallet/view_model/send/output.dart'; import 'package:cake_wallet/view_model/send/output.dart';
import 'package:cw_core/wallet_type.dart'; import 'package:cw_core/wallet_type.dart';
import 'package:hive/hive.dart'; import 'package:hive/hive.dart';
@ -742,7 +744,6 @@ import 'package:cw_bitcoin/bitcoin_amount_format.dart';
import 'package:cw_bitcoin/bitcoin_address_record.dart'; import 'package:cw_bitcoin/bitcoin_address_record.dart';
import 'package:cw_bitcoin/bitcoin_transaction_credentials.dart'; import 'package:cw_bitcoin/bitcoin_transaction_credentials.dart';
import 'package:cw_lightning/lightning_wallet_service.dart'; import 'package:cw_lightning/lightning_wallet_service.dart';
import 'package:cw_lightning/lightning_receive_page_option.dart';
"""; """;
const lightningCwPart = "part 'cw_lightning.dart';"; const lightningCwPart = "part 'cw_lightning.dart';";
const lightningContent = """ const lightningContent = """
@ -767,6 +768,11 @@ abstract class Lightning {
WalletService createLightningWalletService( WalletService createLightningWalletService(
Box<WalletInfo> walletInfoSource, Box<UnspentCoinsInfo> unspentCoinSource); Box<WalletInfo> walletInfoSource, Box<UnspentCoinsInfo> unspentCoinSource);
List<LightningReceivePageOption> getLightningReceivePageOptions(); List<LightningReceivePageOption> getLightningReceivePageOptions();
String satsToLightningString(int sats);
LightningReceivePageOption getOptionInvoice();
LightningReceivePageOption getOptionOnchain();
String bitcoinAmountToLightningString({required int amount});
int bitcoinAmountToLightningAmount({required int amount});
} }
"""; """;