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

View file

@ -36,7 +36,7 @@ class LightningBalance extends ElectrumBalance {
@override
String get formattedUnAvailableBalance {
final frozenFormatted = bitcoinAmountToString(amount: frozen);
final frozenFormatted = bitcoinAmountToLightningString(amount: frozen);
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/lightning/lightning.dart';
import 'package:cake_wallet/routes.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/view_model/dashboard/dashboard_view_model.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:cw_lightning/lightning_receive_page_option.dart';
import 'package:flutter/material.dart';
class MainActions {
@ -60,7 +60,7 @@ class MainActions {
Navigator.pushNamed(
context,
Routes.lightningInvoice,
arguments: [LightningReceivePageOption.lightningInvoice],
arguments: [lightning!.getOptionInvoice()],
);
return;
}

View file

@ -65,4 +65,35 @@ class CWLightning extends Lightning {
@override
List<LightningReceivePageOption> getLightningReceivePageOptions() =>
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/lightning/lightning.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/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/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:cw_core/lightning_receive_page_option.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
@ -175,14 +175,15 @@ class LightningInvoicePage extends BasePage {
int balance = (snapshot.data as List<int>)[2];
if (balance == 0) {
int min = (snapshot.data as List<int>)[0];
finalText =
S.of(context).lightning_invoice_min(satsToLightningString(min));
finalText = S
.of(context)
.lightning_invoice_min(lightning!.satsToLightningString(min));
} else {
int min = (snapshot.data as List<int>)[0];
int max = (snapshot.data as List<int>)[1];
finalText = S.of(context).lightning_invoice_min_max(
satsToLightningString(min),
satsToLightningString(max),
lightning!.satsToLightningString(min),
lightning!.satsToLightningString(max),
);
}
@ -232,18 +233,12 @@ class LightningInvoicePage extends BasePage {
}
reaction((_) => receiveOptionViewModel.selectedReceiveOption, (ReceivePageOption option) async {
switch (option) {
case LightningReceivePageOption.lightningInvoice:
break;
case LightningReceivePageOption.lightningOnchain:
Navigator.popAndPushNamed(
context,
Routes.lightningReceiveOnchain,
arguments: [LightningReceivePageOption.lightningOnchain],
);
break;
default:
break;
if (option == lightning!.getOptionOnchain()) {
Navigator.popAndPushNamed(
context,
Routes.lightningReceiveOnchain,
arguments: [LightningReceivePageOption.lightningOnchain],
);
}
});

View file

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

View file

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

View file

@ -1,5 +1,6 @@
import 'package:breez_sdk/breez_sdk.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/base_text_form_field.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/utils/responsive_layout_util.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:flutter/material.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
@ -164,7 +164,7 @@ class LightningSendConfirmPage extends BasePage {
.textFieldBorderTopPanelColor,
suffixIcon: SizedBox(width: 36),
initialValue:
"sats: ${bitcoinAmountToLightningString(amount: (invoice.amountMsat ?? 0) ~/ 1000)}",
"sats: ${lightning!.bitcoinAmountToLightningString(amount: (invoice.amountMsat ?? 0) ~/ 1000)}",
placeholderTextStyle: TextStyle(
fontSize: 16,
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/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';

View file

@ -727,6 +727,8 @@ import 'package:cw_core/transaction_priority.dart';
import 'package:cw_core/output_info.dart';
import 'package:cw_core/unspent_coins_info.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:cw_core/wallet_type.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_transaction_credentials.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 lightningContent = """
@ -767,6 +768,11 @@ abstract class Lightning {
WalletService createLightningWalletService(
Box<WalletInfo> walletInfoSource, Box<UnspentCoinsInfo> unspentCoinSource);
List<LightningReceivePageOption> getLightningReceivePageOptions();
String satsToLightningString(int sats);
LightningReceivePageOption getOptionInvoice();
LightningReceivePageOption getOptionOnchain();
String bitcoinAmountToLightningString({required int amount});
int bitcoinAmountToLightningAmount({required int amount});
}
""";