mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-03-12 09:32:33 +00:00
send updates
This commit is contained in:
parent
6ca2a5d8ed
commit
7dc999bdb1
10 changed files with 159 additions and 60 deletions
|
@ -103,6 +103,7 @@ class CryptoCurrency extends EnumerableItem<int> with Serializable<int> implemen
|
|||
CryptoCurrency.kaspa,
|
||||
CryptoCurrency.digibyte,
|
||||
CryptoCurrency.usdtSol,
|
||||
CryptoCurrency.btcln,
|
||||
];
|
||||
|
||||
static const havenCurrencies = [
|
||||
|
|
|
@ -1205,8 +1205,10 @@ Future<void> setup({
|
|||
getIt.registerFactory(() => NFTViewModel(appStore, getIt.get<BottomSheetService>()));
|
||||
getIt.registerFactory<TorPage>(() => TorPage(getIt.get<AppStore>()));
|
||||
|
||||
|
||||
getIt.registerFactory<LightningViewModel>(() => LightningViewModel());
|
||||
getIt.registerFactory<LightningViewModel>(() => LightningViewModel(
|
||||
settingsStore: getIt.get<SettingsStore>(),
|
||||
fiatConversionStore: getIt.get<FiatConversionStore>(),
|
||||
));
|
||||
getIt.registerFactoryParam<LightningInvoicePageViewModel, List<dynamic>, void>((args, _) {
|
||||
final pageOption = args.first as ReceivePageOption;
|
||||
return LightningInvoicePageViewModel(
|
||||
|
@ -1244,12 +1246,14 @@ Future<void> setup({
|
|||
() => CryptoCurrency.btcln,
|
||||
),
|
||||
authService: getIt.get<AuthService>(),
|
||||
lightningViewModel: getIt.get<LightningViewModel>(),
|
||||
);
|
||||
});
|
||||
|
||||
getIt.registerFactoryParam<LightningSendConfirmPage, LNInvoice, void>((LNInvoice invoice, _) {
|
||||
return LightningSendConfirmPage(
|
||||
invoice: invoice,
|
||||
lightningViewModel: getIt.get<LightningViewModel>(),
|
||||
);
|
||||
});
|
||||
|
||||
|
|
|
@ -276,6 +276,8 @@ class TrocadorExchangeProvider extends ExchangeProvider {
|
|||
return 'MATIC';
|
||||
case CryptoCurrency.zec:
|
||||
return 'Mainnet';
|
||||
case CryptoCurrency.btcln:
|
||||
return 'Lightning';
|
||||
default:
|
||||
return currency.tag != null ? _normalizeTag(currency.tag!) : 'Mainnet';
|
||||
}
|
||||
|
@ -287,6 +289,8 @@ class TrocadorExchangeProvider extends ExchangeProvider {
|
|||
return 'zec';
|
||||
case CryptoCurrency.usdcEPoly:
|
||||
return 'usdce';
|
||||
case CryptoCurrency.btcln:
|
||||
return 'btc';
|
||||
default:
|
||||
return currency.title.toLowerCase();
|
||||
}
|
||||
|
|
|
@ -146,15 +146,17 @@ class AnonpayCurrencyInputField extends StatelessWidget {
|
|||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Text(
|
||||
S.of(context).min_value(minAmount, selectedCurrency.toString()),
|
||||
style: TextStyle(
|
||||
fontSize: 10,
|
||||
height: 1.2,
|
||||
color: Theme.of(context).extension<ExchangePageTheme>()!.hintTextColor),
|
||||
),
|
||||
if (minAmount.isNotEmpty) ...[
|
||||
Text(
|
||||
S.of(context).min_value(minAmount, selectedCurrency.toString()),
|
||||
style: TextStyle(
|
||||
fontSize: 10,
|
||||
height: 1.2,
|
||||
color: Theme.of(context).extension<ExchangePageTheme>()!.hintTextColor),
|
||||
),
|
||||
],
|
||||
SizedBox(width: 10),
|
||||
if (maxAmount.isNotEmpty) ...[
|
||||
SizedBox(width: 10),
|
||||
Text(S.of(context).max_value(maxAmount, selectedCurrency.toString()),
|
||||
style: TextStyle(
|
||||
fontSize: 10,
|
||||
|
|
|
@ -23,7 +23,8 @@ class QrImage extends StatelessWidget {
|
|||
return qr.QrImageView(
|
||||
data: data,
|
||||
errorCorrectionLevel: errorCorrectionLevel,
|
||||
version: version ?? 9, // Previous value: 7 something happened after flutter upgrade monero wallets addresses are longer than ver. 7 ???
|
||||
// Previous value: 7 something happened after flutter upgrade monero wallets addresses are longer than ver. 7 ???
|
||||
version: 14,// previously 9, but btc lightning addresses are /really/ long
|
||||
size: size,
|
||||
foregroundColor: foregroundColor,
|
||||
backgroundColor: backgroundColor,
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
import 'package:breez_sdk/breez_sdk.dart';
|
||||
import 'package:breez_sdk/bridge_generated.dart';
|
||||
import 'package:breez_sdk/bridge_generated.dart' as BZG;
|
||||
import 'package:cake_wallet/entities/fiat_currency.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/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';
|
||||
|
@ -9,6 +11,7 @@ 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:cake_wallet/view_model/lightning_view_model.dart';
|
||||
import 'package:cw_core/crypto_currency.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_mobx/flutter_mobx.dart';
|
||||
|
@ -19,14 +22,24 @@ import 'package:cake_wallet/src/widgets/scollable_with_bottom_section.dart';
|
|||
import 'package:cake_wallet/generated/i18n.dart';
|
||||
|
||||
class LightningSendConfirmPage extends BasePage {
|
||||
LightningSendConfirmPage({required this.invoice}) : _formKey = GlobalKey<FormState>();
|
||||
LightningSendConfirmPage({required this.invoice, required this.lightningViewModel})
|
||||
: _formKey = GlobalKey<FormState>() {
|
||||
initialSatAmount = ((invoice.amountMsat ?? 0) ~/ 1000);
|
||||
_amountController = TextEditingController();
|
||||
_fiatAmountController = TextEditingController();
|
||||
_amountController.text = initialSatAmount.toString();
|
||||
_fiatAmountController.text = lightningViewModel.formattedFiatAmount(initialSatAmount);
|
||||
}
|
||||
|
||||
final GlobalKey<FormState> _formKey;
|
||||
final controller = PageController(initialPage: 0);
|
||||
LNInvoice invoice;
|
||||
|
||||
final bolt11Controller = TextEditingController();
|
||||
final _bolt11FocusNode = FocusNode();
|
||||
BZG.LNInvoice invoice;
|
||||
late int initialSatAmount;
|
||||
late TextEditingController _amountController;
|
||||
late TextEditingController _fiatAmountController;
|
||||
final FocusNode _depositAmountFocus = FocusNode();
|
||||
final LightningViewModel lightningViewModel;
|
||||
|
||||
bool _effectsInstalled = false;
|
||||
|
||||
|
@ -78,18 +91,8 @@ class LightningSendConfirmPage extends BasePage {
|
|||
@override
|
||||
AppBarStyle get appBarStyle => AppBarStyle.transparent;
|
||||
|
||||
double _sendCardHeight(BuildContext context) {
|
||||
final double initialHeight = 465;
|
||||
|
||||
if (!responsiveLayoutUtil.shouldRenderMobileUI) {
|
||||
return initialHeight - 66;
|
||||
}
|
||||
return initialHeight;
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose(BuildContext context) {
|
||||
// sendViewModel.onClose();
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
|
||||
|
@ -108,7 +111,6 @@ class LightningSendConfirmPage extends BasePage {
|
|||
actions: [
|
||||
KeyboardActionsItem(
|
||||
focusNode: FocusNode(),
|
||||
// focusNode: _amountFocusNode,
|
||||
toolbarButtons: [(_) => KeyboardDoneButton()],
|
||||
),
|
||||
]),
|
||||
|
@ -157,27 +159,49 @@ class LightningSendConfirmPage extends BasePage {
|
|||
validator: null,
|
||||
),
|
||||
SizedBox(height: 24),
|
||||
BaseTextFormField(
|
||||
enabled: false,
|
||||
borderColor: Theme.of(context)
|
||||
.extension<ExchangePageTheme>()!
|
||||
.textFieldBorderTopPanelColor,
|
||||
suffixIcon: SizedBox(width: 36),
|
||||
initialValue:
|
||||
"sats: ${lightning!.bitcoinAmountToLightningString(amount: (invoice.amountMsat ?? 0) ~/ 1000)}",
|
||||
placeholderTextStyle: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Theme.of(context).extension<ExchangePageTheme>()!.hintTextColor,
|
||||
if (invoice.amountMsat == null)
|
||||
Observer(builder: (_) {
|
||||
return AnonpayCurrencyInputField(
|
||||
controller: _amountController,
|
||||
focusNode: _depositAmountFocus,
|
||||
maxAmount: '',
|
||||
minAmount: '',
|
||||
selectedCurrency: CryptoCurrency.btcln,
|
||||
);
|
||||
})
|
||||
else
|
||||
BaseTextFormField(
|
||||
enabled: false,
|
||||
borderColor: Theme.of(context)
|
||||
.extension<ExchangePageTheme>()!
|
||||
.textFieldBorderTopPanelColor,
|
||||
suffixIcon: SizedBox(width: 36),
|
||||
initialValue:
|
||||
"sats: ${lightning!.bitcoinAmountToLightningString(amount: initialSatAmount)}",
|
||||
placeholderTextStyle: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Theme.of(context).extension<ExchangePageTheme>()!.hintTextColor,
|
||||
),
|
||||
textStyle: TextStyle(
|
||||
fontSize: 16, fontWeight: FontWeight.w600, color: Colors.white),
|
||||
validator: null,
|
||||
),
|
||||
textStyle: TextStyle(
|
||||
fontSize: 16, fontWeight: FontWeight.w600, color: Colors.white),
|
||||
validator: null,
|
||||
),
|
||||
SizedBox(height: 24),
|
||||
BaseTextFormField(
|
||||
enabled: false,
|
||||
initialValue: "USD: ${invoice.amountMsat}",
|
||||
controller: _fiatAmountController,
|
||||
prefixIcon: Padding(
|
||||
padding: EdgeInsets.only(top: 9),
|
||||
child: Text(
|
||||
lightningViewModel.fiat.title + ':',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
borderColor: Theme.of(context)
|
||||
.extension<ExchangePageTheme>()!
|
||||
.textFieldBorderTopPanelColor,
|
||||
|
@ -226,21 +250,37 @@ class LightningSendConfirmPage extends BasePage {
|
|||
onPressed: () async {
|
||||
try {
|
||||
final sdk = await BreezSDK();
|
||||
await sdk.sendPayment(req: SendPaymentRequest(bolt11: invoice.bolt11));
|
||||
late BZG.SendPaymentRequest req;
|
||||
|
||||
lightningViewModel.setLoading(true);
|
||||
|
||||
if (invoice.amountMsat == null) {
|
||||
req = BZG.SendPaymentRequest(
|
||||
bolt11: invoice.bolt11,
|
||||
amountMsat: int.parse(_amountController.text) * 1000,
|
||||
);
|
||||
} else {
|
||||
req = BZG.SendPaymentRequest(bolt11: invoice.bolt11);
|
||||
}
|
||||
|
||||
await sdk.sendPayment(req: req);
|
||||
|
||||
lightningViewModel.setLoading(false);
|
||||
|
||||
showPopUp<void>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertWithOneAction(
|
||||
alertTitle: '',
|
||||
alertContent: S
|
||||
.of(context)
|
||||
.send_success(CryptoCurrency.btc.toString()),
|
||||
alertContent:
|
||||
S.of(context).send_success(CryptoCurrency.btc.toString()),
|
||||
buttonText: S.of(context).ok,
|
||||
buttonAction: () {
|
||||
Navigator.of(context).pop();
|
||||
});
|
||||
});
|
||||
} catch (e) {
|
||||
lightningViewModel.setLoading(false);
|
||||
showPopUp<void>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
|
@ -254,7 +294,7 @@ class LightningSendConfirmPage extends BasePage {
|
|||
},
|
||||
color: Theme.of(context).primaryColor,
|
||||
textColor: Colors.white,
|
||||
isLoading: false,
|
||||
isLoading: lightningViewModel.loading,
|
||||
),
|
||||
],
|
||||
);
|
||||
|
@ -275,6 +315,11 @@ class LightningSendConfirmPage extends BasePage {
|
|||
return;
|
||||
}
|
||||
|
||||
_amountController.addListener(() {
|
||||
final amount = _amountController.text;
|
||||
_fiatAmountController.text = lightningViewModel.formattedFiatAmount(int.parse(amount));
|
||||
});
|
||||
|
||||
_effectsInstalled = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ import 'package:breez_sdk/bridge_generated.dart';
|
|||
import 'package:cake_wallet/core/auth_service.dart';
|
||||
import 'package:cake_wallet/src/widgets/address_text_field.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';
|
||||
import 'package:cake_wallet/themes/extensions/exchange_page_theme.dart';
|
||||
import 'package:cake_wallet/themes/extensions/keyboard_theme.dart';
|
||||
|
@ -12,10 +11,10 @@ import 'package:cake_wallet/themes/theme_base.dart';
|
|||
import 'package:cake_wallet/utils/payment_request.dart';
|
||||
import 'package:cake_wallet/utils/responsive_layout_util.dart';
|
||||
import 'package:cake_wallet/utils/show_pop_up.dart';
|
||||
import 'package:cake_wallet/view_model/lightning_view_model.dart';
|
||||
import 'package:cake_wallet/view_model/send/output.dart';
|
||||
import 'package:cw_core/crypto_currency.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_mobx/flutter_mobx.dart';
|
||||
import 'package:keyboard_actions/keyboard_actions.dart';
|
||||
import 'package:cake_wallet/routes.dart';
|
||||
import 'package:cake_wallet/src/screens/base_page.dart';
|
||||
|
@ -28,10 +27,12 @@ class LightningSendPage extends BasePage {
|
|||
LightningSendPage({
|
||||
required this.output,
|
||||
required this.authService,
|
||||
required this.lightningViewModel,
|
||||
}) : _formKey = GlobalKey<FormState>();
|
||||
|
||||
final Output output;
|
||||
final AuthService authService;
|
||||
final LightningViewModel lightningViewModel;
|
||||
final GlobalKey<FormState> _formKey;
|
||||
final controller = PageController(initialPage: 0);
|
||||
|
||||
|
@ -191,10 +192,12 @@ class LightningSendPage extends BasePage {
|
|||
text: S.of(context).send,
|
||||
color: Theme.of(context).primaryColor,
|
||||
textColor: Colors.white,
|
||||
isLoading: false,
|
||||
isLoading: lightningViewModel.loading,
|
||||
onPressed: () async {
|
||||
try {
|
||||
lightningViewModel.setLoading(true);
|
||||
await processInput(context);
|
||||
lightningViewModel.setLoading(false);
|
||||
} catch (e) {
|
||||
showPopUp<void>(
|
||||
context: context,
|
||||
|
|
|
@ -154,6 +154,11 @@ abstract class ExchangeTradeViewModelBase with Store {
|
|||
}
|
||||
|
||||
static bool _checkIfCanSend(TradesStore tradesStore, WalletBase wallet) {
|
||||
|
||||
if (wallet.currency == CryptoCurrency.btcln) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool _isEthToken() =>
|
||||
wallet.currency == CryptoCurrency.eth &&
|
||||
tradesStore.trade!.from.tag == CryptoCurrency.eth.title;
|
||||
|
|
|
@ -500,6 +500,7 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
|
|||
/// return after the first successful trade
|
||||
return;
|
||||
} catch (e) {
|
||||
print(e);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -599,10 +600,13 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
|
|||
receiveCurrency = CryptoCurrency.btc;
|
||||
break;
|
||||
case WalletType.bitcoin:
|
||||
case WalletType.lightning:
|
||||
depositCurrency = CryptoCurrency.btc;
|
||||
receiveCurrency = CryptoCurrency.xmr;
|
||||
break;
|
||||
case WalletType.lightning:
|
||||
depositCurrency = CryptoCurrency.btcln;
|
||||
receiveCurrency = CryptoCurrency.xmr;
|
||||
break;
|
||||
case WalletType.litecoin:
|
||||
depositCurrency = CryptoCurrency.ltc;
|
||||
receiveCurrency = CryptoCurrency.xmr;
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
import 'dart:async';
|
||||
import 'package:breez_sdk/breez_sdk.dart';
|
||||
import 'package:breez_sdk/bridge_generated.dart';
|
||||
import 'package:breez_sdk/bridge_generated.dart' as BZG;
|
||||
import 'package:cake_wallet/entities/calculate_fiat_amount_raw.dart';
|
||||
import 'package:cake_wallet/entities/fiat_currency.dart';
|
||||
import 'package:cake_wallet/lightning/lightning.dart';
|
||||
import 'package:cake_wallet/store/dashboard/fiat_conversion_store.dart';
|
||||
import 'package:cake_wallet/store/settings_store.dart';
|
||||
import 'package:cw_core/crypto_currency.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
|
||||
part 'lightning_view_model.g.dart';
|
||||
|
@ -8,13 +14,37 @@ part 'lightning_view_model.g.dart';
|
|||
class LightningViewModel = LightningViewModelBase with _$LightningViewModel;
|
||||
|
||||
abstract class LightningViewModelBase with Store {
|
||||
LightningViewModelBase() {}
|
||||
LightningViewModelBase({
|
||||
required this.settingsStore,
|
||||
required this.fiatConversionStore,
|
||||
}) {}
|
||||
|
||||
final SettingsStore settingsStore;
|
||||
final FiatConversionStore fiatConversionStore;
|
||||
|
||||
@observable
|
||||
bool loading = false;
|
||||
|
||||
@action
|
||||
void setLoading(bool value) {
|
||||
loading = value;
|
||||
}
|
||||
|
||||
FiatCurrency get fiat => settingsStore.fiatCurrency;
|
||||
|
||||
String formattedFiatAmount(int sats) {
|
||||
String amount = calculateFiatAmountRaw(
|
||||
cryptoAmount: lightning!.formatterLightningAmountToDouble(amount: sats),
|
||||
price: fiatConversionStore.prices[CryptoCurrency.btcln],
|
||||
);
|
||||
return amount;
|
||||
}
|
||||
|
||||
Future<List<String>> receiveOnchain() async {
|
||||
final sdk = await BreezSDK();
|
||||
|
||||
ReceiveOnchainRequest req = const ReceiveOnchainRequest();
|
||||
SwapInfo swapInfo = await sdk.receiveOnchain(req: req);
|
||||
BZG.ReceiveOnchainRequest req = const BZG.ReceiveOnchainRequest();
|
||||
BZG.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;
|
||||
|
@ -29,7 +59,7 @@ abstract class LightningViewModelBase with Store {
|
|||
|
||||
Future<String> createInvoice({required String amountSats, String? description}) async {
|
||||
final sdk = await BreezSDK();
|
||||
final req = ReceivePaymentRequest(
|
||||
final req = BZG.ReceivePaymentRequest(
|
||||
amountMsat: (double.parse(amountSats) * 1000).round(),
|
||||
description: description ?? '',
|
||||
);
|
||||
|
@ -39,8 +69,8 @@ abstract class LightningViewModelBase with Store {
|
|||
|
||||
Future<List<int>> invoiceSoftLimitsSats() async {
|
||||
final sdk = await BreezSDK();
|
||||
ReceivePaymentRequest? req = null;
|
||||
req = ReceivePaymentRequest(
|
||||
BZG.ReceivePaymentRequest? req = null;
|
||||
req = BZG.ReceivePaymentRequest(
|
||||
amountMsat: 10000 * 1000, // 10000 sats
|
||||
description: "limits",
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue