mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-03-22 07:08:49 +00:00
fixes
This commit is contained in:
parent
3fd8430e83
commit
c7dd20fa41
13 changed files with 187 additions and 244 deletions
|
@ -35,7 +35,6 @@ import 'package:cw_core/utils/file.dart';
|
||||||
import 'package:cw_core/wallet_base.dart';
|
import 'package:cw_core/wallet_base.dart';
|
||||||
import 'package:cw_core/wallet_info.dart';
|
import 'package:cw_core/wallet_info.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:hex/hex.dart';
|
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive/hive.dart';
|
||||||
import 'package:mobx/mobx.dart';
|
import 'package:mobx/mobx.dart';
|
||||||
import 'package:rxdart/subjects.dart';
|
import 'package:rxdart/subjects.dart';
|
||||||
|
@ -623,16 +622,9 @@ abstract class ElectrumWalletBase
|
||||||
final ins = <bitcoin_base.BtcTransaction>[];
|
final ins = <bitcoin_base.BtcTransaction>[];
|
||||||
|
|
||||||
for (final vin in original.inputs) {
|
for (final vin in original.inputs) {
|
||||||
try {
|
final txHex = await electrumClient.getTransactionHex(hash: vin.txId);
|
||||||
final id = HEX.encode(HEX.decode(vin.txId).reversed.toList());
|
|
||||||
final txHex = await electrumClient.getTransactionHex(hash: id);
|
|
||||||
final tx = bitcoin_base.BtcTransaction.fromRaw(txHex);
|
final tx = bitcoin_base.BtcTransaction.fromRaw(txHex);
|
||||||
ins.add(tx);
|
ins.add(tx);
|
||||||
} catch (_) {
|
|
||||||
ins.add(bitcoin_base.BtcTransaction.fromRaw(
|
|
||||||
await electrumClient.getTransactionHex(hash: vin.txId),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ElectrumTransactionBundle(original,
|
return ElectrumTransactionBundle(original,
|
||||||
|
|
|
@ -14,7 +14,7 @@ import 'package:cake_wallet/core/yat_service.dart';
|
||||||
import 'package:cake_wallet/entities/background_tasks.dart';
|
import 'package:cake_wallet/entities/background_tasks.dart';
|
||||||
import 'package:cake_wallet/entities/exchange_api_mode.dart';
|
import 'package:cake_wallet/entities/exchange_api_mode.dart';
|
||||||
import 'package:cake_wallet/entities/parse_address_from_domain.dart';
|
import 'package:cake_wallet/entities/parse_address_from_domain.dart';
|
||||||
import 'package:cake_wallet/view_model/LightningSendViewModel.dart';
|
import 'package:cake_wallet/view_model/lightning_send_view_model.dart';
|
||||||
import 'package:cw_core/receive_page_option.dart';
|
import 'package:cw_core/receive_page_option.dart';
|
||||||
import 'package:cake_wallet/ethereum/ethereum.dart';
|
import 'package:cake_wallet/ethereum/ethereum.dart';
|
||||||
import 'package:cake_wallet/lightning/lightning.dart';
|
import 'package:cake_wallet/lightning/lightning.dart';
|
||||||
|
|
|
@ -29,18 +29,22 @@ Future<void> startFiatRateUpdate(
|
||||||
|
|
||||||
if (appStore.wallet!.type == WalletType.haven) {
|
if (appStore.wallet!.type == WalletType.haven) {
|
||||||
await updateHavenRate(fiatConversionStore);
|
await updateHavenRate(fiatConversionStore);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterable<CryptoCurrency>? currencies = [];
|
Iterable<CryptoCurrency>? currencies = [];
|
||||||
switch (appStore.wallet!.type) {
|
switch (appStore.wallet!.type) {
|
||||||
case WalletType.ethereum:
|
case WalletType.ethereum:
|
||||||
currencies = ethereum!.getERC20Currencies(appStore.wallet!).where((element) => element.enabled);
|
currencies =
|
||||||
|
ethereum!.getERC20Currencies(appStore.wallet!).where((element) => element.enabled);
|
||||||
break;
|
break;
|
||||||
case WalletType.polygon:
|
case WalletType.polygon:
|
||||||
currencies = polygon!.getERC20Currencies(appStore.wallet!).where((element) => element.enabled);
|
currencies =
|
||||||
|
polygon!.getERC20Currencies(appStore.wallet!).where((element) => element.enabled);
|
||||||
break;
|
break;
|
||||||
case WalletType.solana:
|
case WalletType.solana:
|
||||||
currencies = solana!.getSPLTokenCurrencies(appStore.wallet!).where((element) => element.enabled);
|
currencies =
|
||||||
|
solana!.getSPLTokenCurrencies(appStore.wallet!).where((element) => element.enabled);
|
||||||
break;
|
break;
|
||||||
case WalletType.lightning:
|
case WalletType.lightning:
|
||||||
currencies = [CryptoCurrency.btc];
|
currencies = [CryptoCurrency.btc];
|
||||||
|
|
|
@ -24,22 +24,17 @@ import 'package:cake_wallet/src/widgets/scollable_with_bottom_section.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/themes/extensions/transaction_trade_theme.dart';
|
import 'package:cake_wallet/themes/extensions/transaction_trade_theme.dart';
|
||||||
|
|
||||||
void showInformation(
|
void showInformation(ExchangeTradeViewModel exchangeTradeViewModel, BuildContext context) {
|
||||||
ExchangeTradeViewModel exchangeTradeViewModel, BuildContext context) {
|
|
||||||
final trade = exchangeTradeViewModel.trade;
|
final trade = exchangeTradeViewModel.trade;
|
||||||
final walletName = exchangeTradeViewModel.wallet.name;
|
final walletName = exchangeTradeViewModel.wallet.name;
|
||||||
|
|
||||||
final information = exchangeTradeViewModel.isSendable
|
final information = exchangeTradeViewModel.isSendable
|
||||||
? S.current.exchange_result_confirm(
|
? S.current.exchange_result_confirm(trade.amount, trade.from.toString(), walletName) +
|
||||||
trade.amount, trade.from.toString(), walletName) +
|
|
||||||
exchangeTradeViewModel.extraInfo
|
exchangeTradeViewModel.extraInfo
|
||||||
: S.current.exchange_result_description(
|
: S.current.exchange_result_description(trade.amount, trade.from.toString()) +
|
||||||
trade.amount, trade.from.toString()) +
|
|
||||||
exchangeTradeViewModel.extraInfo;
|
exchangeTradeViewModel.extraInfo;
|
||||||
|
|
||||||
showPopUp<void>(
|
showPopUp<void>(context: context, builder: (_) => InformationPage(information: information));
|
||||||
context: context,
|
|
||||||
builder: (_) => InformationPage(information: information));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class ExchangeTradePage extends BasePage {
|
class ExchangeTradePage extends BasePage {
|
||||||
|
@ -72,8 +67,7 @@ class ExchangeTradePage extends BasePage {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget body(BuildContext context) =>
|
Widget body(BuildContext context) => ExchangeTradeForm(exchangeTradeViewModel);
|
||||||
ExchangeTradeForm(exchangeTradeViewModel);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class ExchangeTradeForm extends StatefulWidget {
|
class ExchangeTradeForm extends StatefulWidget {
|
||||||
|
@ -138,7 +132,9 @@ class ExchangeTradeState extends State<ExchangeTradeForm> {
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 14.0,
|
fontSize: 14.0,
|
||||||
fontWeight: FontWeight.w500,
|
fontWeight: FontWeight.w500,
|
||||||
color: Theme.of(context).extension<TransactionTradeTheme>()!.detailsTitlesColor),
|
color: Theme.of(context)
|
||||||
|
.extension<TransactionTradeTheme>()!
|
||||||
|
.detailsTitlesColor),
|
||||||
),
|
),
|
||||||
if (trade.expiredAt != null)
|
if (trade.expiredAt != null)
|
||||||
TimerWidget(trade.expiredAt!,
|
TimerWidget(trade.expiredAt!,
|
||||||
|
@ -159,10 +155,13 @@ class ExchangeTradeState extends State<ExchangeTradeForm> {
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
border: Border.all(
|
border: Border.all(
|
||||||
width: 3,
|
width: 3,
|
||||||
color: Theme.of(context).extension<ExchangePageTheme>()!.qrCodeColor
|
color: Theme.of(context)
|
||||||
)
|
.extension<ExchangePageTheme>()!
|
||||||
|
.qrCodeColor)),
|
||||||
|
child: QrImage(
|
||||||
|
data: trade.inputAddress ?? fetchingLabel,
|
||||||
|
version: 14,
|
||||||
),
|
),
|
||||||
child: QrImage(data: trade.inputAddress ?? fetchingLabel),
|
|
||||||
)))),
|
)))),
|
||||||
Spacer(flex: 3)
|
Spacer(flex: 3)
|
||||||
]),
|
]),
|
||||||
|
@ -192,10 +191,8 @@ class ExchangeTradeState extends State<ExchangeTradeForm> {
|
||||||
? Builder(
|
? Builder(
|
||||||
builder: (context) => GestureDetector(
|
builder: (context) => GestureDetector(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
Clipboard.setData(
|
Clipboard.setData(ClipboardData(text: value));
|
||||||
ClipboardData(text: value));
|
showBar<void>(context, S.of(context).copied_to_clipboard);
|
||||||
showBar<void>(context,
|
|
||||||
S.of(context).copied_to_clipboard);
|
|
||||||
},
|
},
|
||||||
child: content,
|
child: content,
|
||||||
))
|
))
|
||||||
|
@ -209,17 +206,14 @@ class ExchangeTradeState extends State<ExchangeTradeForm> {
|
||||||
bottomSectionPadding: EdgeInsets.fromLTRB(24, 0, 24, 24),
|
bottomSectionPadding: EdgeInsets.fromLTRB(24, 0, 24, 24),
|
||||||
bottomSection: Observer(builder: (_) {
|
bottomSection: Observer(builder: (_) {
|
||||||
final trade = widget.exchangeTradeViewModel.trade;
|
final trade = widget.exchangeTradeViewModel.trade;
|
||||||
final sendingState =
|
final sendingState = widget.exchangeTradeViewModel.sendViewModel.state;
|
||||||
widget.exchangeTradeViewModel.sendViewModel.state;
|
|
||||||
|
|
||||||
return widget.exchangeTradeViewModel.isSendable &&
|
return widget.exchangeTradeViewModel.isSendable &&
|
||||||
!(sendingState is TransactionCommitted)
|
!(sendingState is TransactionCommitted)
|
||||||
? LoadingPrimaryButton(
|
? LoadingPrimaryButton(
|
||||||
isDisabled: trade.inputAddress == null ||
|
isDisabled: trade.inputAddress == null || trade.inputAddress!.isEmpty,
|
||||||
trade.inputAddress!.isEmpty,
|
|
||||||
isLoading: sendingState is IsExecutingState,
|
isLoading: sendingState is IsExecutingState,
|
||||||
onPressed: () =>
|
onPressed: () => widget.exchangeTradeViewModel.confirmSending(),
|
||||||
widget.exchangeTradeViewModel.confirmSending(),
|
|
||||||
text: S.of(context).confirm,
|
text: S.of(context).confirm,
|
||||||
color: Theme.of(context).primaryColor,
|
color: Theme.of(context).primaryColor,
|
||||||
textColor: Colors.white)
|
textColor: Colors.white)
|
||||||
|
@ -257,26 +251,24 @@ class ExchangeTradeState extends State<ExchangeTradeForm> {
|
||||||
return ConfirmSendingAlert(
|
return ConfirmSendingAlert(
|
||||||
alertTitle: S.of(popupContext).confirm_sending,
|
alertTitle: S.of(popupContext).confirm_sending,
|
||||||
amount: S.of(popupContext).send_amount,
|
amount: S.of(popupContext).send_amount,
|
||||||
amountValue: widget.exchangeTradeViewModel.sendViewModel
|
amountValue: widget
|
||||||
.pendingTransaction!.amountFormatted,
|
.exchangeTradeViewModel.sendViewModel.pendingTransaction!.amountFormatted,
|
||||||
fee: S.of(popupContext).send_fee,
|
fee: S.of(popupContext).send_fee,
|
||||||
feeValue: widget.exchangeTradeViewModel.sendViewModel
|
feeValue: widget
|
||||||
.pendingTransaction!.feeFormatted,
|
.exchangeTradeViewModel.sendViewModel.pendingTransaction!.feeFormatted,
|
||||||
rightButtonText: S.of(popupContext).send,
|
rightButtonText: S.of(popupContext).send,
|
||||||
leftButtonText: S.of(popupContext).cancel,
|
leftButtonText: S.of(popupContext).cancel,
|
||||||
actionRightButton: () async {
|
actionRightButton: () async {
|
||||||
Navigator.of(popupContext).pop();
|
Navigator.of(popupContext).pop();
|
||||||
await widget.exchangeTradeViewModel.sendViewModel
|
await widget.exchangeTradeViewModel.sendViewModel.commitTransaction();
|
||||||
.commitTransaction();
|
|
||||||
transactionStatePopup();
|
transactionStatePopup();
|
||||||
},
|
},
|
||||||
actionLeftButton: () => Navigator.of(popupContext).pop(),
|
actionLeftButton: () => Navigator.of(popupContext).pop(),
|
||||||
feeFiatAmount: widget.exchangeTradeViewModel
|
feeFiatAmount:
|
||||||
.pendingTransactionFeeFiatAmountFormatted,
|
widget.exchangeTradeViewModel.pendingTransactionFeeFiatAmountFormatted,
|
||||||
fiatAmountValue: widget.exchangeTradeViewModel
|
fiatAmountValue:
|
||||||
.pendingTransactionFiatAmountValueFormatted,
|
widget.exchangeTradeViewModel.pendingTransactionFiatAmountValueFormatted,
|
||||||
outputs: widget.exchangeTradeViewModel.sendViewModel
|
outputs: widget.exchangeTradeViewModel.sendViewModel.outputs);
|
||||||
.outputs);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -307,8 +299,7 @@ class ExchangeTradeState extends State<ExchangeTradeForm> {
|
||||||
context: context,
|
context: context,
|
||||||
builder: (BuildContext popupContext) {
|
builder: (BuildContext popupContext) {
|
||||||
return Observer(builder: (_) {
|
return Observer(builder: (_) {
|
||||||
final state = widget
|
final state = widget.exchangeTradeViewModel.sendViewModel.state;
|
||||||
.exchangeTradeViewModel.sendViewModel.state;
|
|
||||||
|
|
||||||
if (state is TransactionCommitted) {
|
if (state is TransactionCommitted) {
|
||||||
return Stack(
|
return Stack(
|
||||||
|
@ -316,20 +307,15 @@ class ExchangeTradeState extends State<ExchangeTradeForm> {
|
||||||
Container(
|
Container(
|
||||||
color: Theme.of(popupContext).colorScheme.background,
|
color: Theme.of(popupContext).colorScheme.background,
|
||||||
child: Center(
|
child: Center(
|
||||||
child: Image.asset(
|
child: Image.asset('assets/images/birthday_cake.png'),
|
||||||
'assets/images/birthday_cake.png'),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Center(
|
Center(
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: EdgeInsets.only(
|
padding: EdgeInsets.only(top: 220, left: 24, right: 24),
|
||||||
top: 220, left: 24, right: 24),
|
|
||||||
child: Text(
|
child: Text(
|
||||||
S.of(popupContext).send_success(widget
|
S.of(popupContext).send_success(
|
||||||
.exchangeTradeViewModel
|
widget.exchangeTradeViewModel.wallet.currency.toString()),
|
||||||
.wallet
|
|
||||||
.currency
|
|
||||||
.toString()),
|
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 22,
|
fontSize: 22,
|
||||||
|
@ -365,19 +351,14 @@ class ExchangeTradeState extends State<ExchangeTradeForm> {
|
||||||
Container(
|
Container(
|
||||||
color: Theme.of(popupContext).colorScheme.background,
|
color: Theme.of(popupContext).colorScheme.background,
|
||||||
child: Center(
|
child: Center(
|
||||||
child: Image.asset(
|
child: Image.asset('assets/images/birthday_cake.png'),
|
||||||
'assets/images/birthday_cake.png'),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
BackdropFilter(
|
BackdropFilter(
|
||||||
filter: ImageFilter.blur(
|
filter: ImageFilter.blur(sigmaX: 3.0, sigmaY: 3.0),
|
||||||
sigmaX: 3.0, sigmaY: 3.0),
|
|
||||||
child: Container(
|
child: Container(
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Theme.of(popupContext)
|
color: Theme.of(popupContext).colorScheme.background.withOpacity(0.25)),
|
||||||
.colorScheme
|
|
||||||
.background
|
|
||||||
.withOpacity(0.25)),
|
|
||||||
child: Center(
|
child: Center(
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: EdgeInsets.only(top: 220),
|
padding: EdgeInsets.only(top: 220),
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import 'package:cake_wallet/lightning/lightning.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_content_override.dart';
|
import 'package:cake_wallet/src/widgets/alert_with_two_actions_content_override.dart';
|
||||||
import 'package:cake_wallet/themes/extensions/dashboard_page_theme.dart';
|
import 'package:cake_wallet/themes/extensions/dashboard_page_theme.dart';
|
||||||
import 'package:cake_wallet/themes/extensions/exchange_page_theme.dart';
|
import 'package:cake_wallet/themes/extensions/exchange_page_theme.dart';
|
||||||
|
@ -242,9 +243,10 @@ class LightningInvoicePage extends BasePage {
|
||||||
showPopUp<void>(
|
showPopUp<void>(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
return AlertWithTwoActionsContentOverride(
|
return AlertWithTwoActions(
|
||||||
alertTitle: S.of(context).invoice_created,
|
alertTitle: S.of(context).invoice_created,
|
||||||
alertContent: Column(
|
alertContent: '',
|
||||||
|
contentWidget: Column(
|
||||||
children: [
|
children: [
|
||||||
Center(
|
Center(
|
||||||
child: AspectRatio(
|
child: AspectRatio(
|
||||||
|
|
|
@ -23,8 +23,7 @@ class QrImage extends StatelessWidget {
|
||||||
return qr.QrImageView(
|
return qr.QrImageView(
|
||||||
data: data,
|
data: data,
|
||||||
errorCorrectionLevel: errorCorrectionLevel,
|
errorCorrectionLevel: errorCorrectionLevel,
|
||||||
// Previous value: 7 something happened after flutter upgrade monero wallets addresses are longer than ver. 7 ???
|
version: 9,// 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,
|
size: size,
|
||||||
foregroundColor: foregroundColor,
|
foregroundColor: foregroundColor,
|
||||||
backgroundColor: backgroundColor,
|
backgroundColor: backgroundColor,
|
||||||
|
|
|
@ -11,7 +11,7 @@ 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:cake_wallet/view_model/LightningSendViewModel.dart';
|
import 'package:cake_wallet/view_model/lightning_send_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_core/crypto_currency.dart';
|
import 'package:cw_core/crypto_currency.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
@ -250,24 +250,10 @@ class LightningSendConfirmPage extends BasePage {
|
||||||
text: S.of(context).send,
|
text: S.of(context).send,
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
try {
|
try {
|
||||||
final sdk = await BreezSDK();
|
await lightningSendViewModel.send(
|
||||||
late BZG.SendPaymentRequest req;
|
invoice,
|
||||||
|
int.parse(_amountController.text)
|
||||||
lightningSendViewModel.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);
|
|
||||||
|
|
||||||
lightningSendViewModel.setLoading(false);
|
|
||||||
|
|
||||||
showPopUp<void>(
|
showPopUp<void>(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
|
@ -281,7 +267,6 @@ class LightningSendConfirmPage extends BasePage {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
lightningSendViewModel.setLoading(false);
|
|
||||||
showPopUp<void>(
|
showPopUp<void>(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
|
|
|
@ -11,8 +11,7 @@ import 'package:cake_wallet/themes/theme_base.dart';
|
||||||
import 'package:cake_wallet/utils/payment_request.dart';
|
import 'package:cake_wallet/utils/payment_request.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:cake_wallet/view_model/LightningSendViewModel.dart';
|
import 'package:cake_wallet/view_model/lightning_send_view_model.dart';
|
||||||
import 'package:cake_wallet/view_model/lightning_view_model.dart';
|
|
||||||
import 'package:cake_wallet/view_model/send/output.dart';
|
import 'package:cake_wallet/view_model/send/output.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';
|
||||||
|
@ -35,7 +34,6 @@ class LightningSendPage extends BasePage {
|
||||||
final AuthService authService;
|
final AuthService authService;
|
||||||
final LightningSendViewModel lightningSendViewModel;
|
final LightningSendViewModel lightningSendViewModel;
|
||||||
final GlobalKey<FormState> _formKey;
|
final GlobalKey<FormState> _formKey;
|
||||||
final controller = PageController(initialPage: 0);
|
|
||||||
|
|
||||||
final bolt11Controller = TextEditingController();
|
final bolt11Controller = TextEditingController();
|
||||||
final bolt11FocusNode = FocusNode();
|
final bolt11FocusNode = FocusNode();
|
||||||
|
@ -206,7 +204,7 @@ class LightningSendPage extends BasePage {
|
||||||
|
|
||||||
Future<void> send(BuildContext context) async {
|
Future<void> send(BuildContext context) async {
|
||||||
try {
|
try {
|
||||||
await processInput(context);
|
await lightningSendViewModel.processInput(context, bolt11Controller.text);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
showPopUp<void>(
|
showPopUp<void>(
|
||||||
context: context,
|
context: context,
|
||||||
|
@ -225,29 +223,6 @@ class LightningSendPage extends BasePage {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> processInput(BuildContext context) async {
|
|
||||||
FocusScope.of(context).unfocus();
|
|
||||||
|
|
||||||
final sdk = await BreezSDK();
|
|
||||||
|
|
||||||
late InputType inputType;
|
|
||||||
|
|
||||||
try {
|
|
||||||
inputType = await sdk.parseInput(input: bolt11Controller.text);
|
|
||||||
} catch (_) {
|
|
||||||
throw Exception("Unknown input type");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (inputType is InputType_Bolt11) {
|
|
||||||
final bolt11 = await sdk.parseInvoice(bolt11Controller.text);
|
|
||||||
Navigator.of(context).pushNamed(Routes.lightningSendConfirm, arguments: bolt11);
|
|
||||||
} else if (inputType is InputType_LnUrlPay) {
|
|
||||||
throw Exception("Unsupported input type");
|
|
||||||
} else {
|
|
||||||
throw Exception("Unknown input type");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void _setEffects(BuildContext context) {
|
void _setEffects(BuildContext context) {
|
||||||
if (_effectsInstalled) {
|
if (_effectsInstalled) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -10,6 +10,7 @@ class AlertWithTwoActions extends BaseAlertDialog {
|
||||||
required this.rightButtonText,
|
required this.rightButtonText,
|
||||||
required this.actionLeftButton,
|
required this.actionLeftButton,
|
||||||
required this.actionRightButton,
|
required this.actionRightButton,
|
||||||
|
this.contentWidget,
|
||||||
this.alertBarrierDismissible = true,
|
this.alertBarrierDismissible = true,
|
||||||
this.isDividerExist = false,
|
this.isDividerExist = false,
|
||||||
// this.leftActionColor,
|
// this.leftActionColor,
|
||||||
|
@ -20,6 +21,7 @@ class AlertWithTwoActions extends BaseAlertDialog {
|
||||||
final String alertContent;
|
final String alertContent;
|
||||||
final String leftButtonText;
|
final String leftButtonText;
|
||||||
final String rightButtonText;
|
final String rightButtonText;
|
||||||
|
final Widget? contentWidget;
|
||||||
final VoidCallback actionLeftButton;
|
final VoidCallback actionLeftButton;
|
||||||
final VoidCallback actionRightButton;
|
final VoidCallback actionRightButton;
|
||||||
final bool alertBarrierDismissible;
|
final bool alertBarrierDismissible;
|
||||||
|
@ -47,4 +49,9 @@ class AlertWithTwoActions extends BaseAlertDialog {
|
||||||
// Color get rightButtonColor => rightActionColor;
|
// Color get rightButtonColor => rightActionColor;
|
||||||
@override
|
@override
|
||||||
bool get isDividerExists => isDividerExist;
|
bool get isDividerExists => isDividerExist;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget content(BuildContext context) {
|
||||||
|
return contentWidget ?? super.content(context);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,48 +0,0 @@
|
||||||
import 'dart:ui';
|
|
||||||
import 'package:cake_wallet/src/widgets/base_alert_dialog.dart';
|
|
||||||
import 'package:flutter/cupertino.dart';
|
|
||||||
|
|
||||||
class AlertWithTwoActionsContentOverride extends BaseAlertDialog {
|
|
||||||
AlertWithTwoActionsContentOverride({
|
|
||||||
required this.alertTitle,
|
|
||||||
required this.alertContent,
|
|
||||||
required this.leftButtonText,
|
|
||||||
required this.rightButtonText,
|
|
||||||
required this.actionLeftButton,
|
|
||||||
required this.actionRightButton,
|
|
||||||
this.alertBarrierDismissible = true,
|
|
||||||
this.isDividerExist = false,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String alertTitle;
|
|
||||||
final Widget alertContent;
|
|
||||||
final String leftButtonText;
|
|
||||||
final String rightButtonText;
|
|
||||||
final VoidCallback actionLeftButton;
|
|
||||||
final VoidCallback actionRightButton;
|
|
||||||
final bool alertBarrierDismissible;
|
|
||||||
// final Color leftActionColor;
|
|
||||||
// final Color rightActionColor;
|
|
||||||
final bool isDividerExist;
|
|
||||||
|
|
||||||
@override
|
|
||||||
String get titleText => alertTitle;
|
|
||||||
@override
|
|
||||||
String get leftActionButtonText => leftButtonText;
|
|
||||||
@override
|
|
||||||
String get rightActionButtonText => rightButtonText;
|
|
||||||
@override
|
|
||||||
VoidCallback get actionLeft => actionLeftButton;
|
|
||||||
@override
|
|
||||||
VoidCallback get actionRight => actionRightButton;
|
|
||||||
@override
|
|
||||||
bool get barrierDismissible => alertBarrierDismissible;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget content(BuildContext context) {
|
|
||||||
return alertContent;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool get isDividerExists => isDividerExist;
|
|
||||||
}
|
|
|
@ -74,6 +74,8 @@ class TransactionListItem extends ActionListItem with Keyable {
|
||||||
price: price);
|
price: price);
|
||||||
break;
|
break;
|
||||||
case WalletType.bitcoin:
|
case WalletType.bitcoin:
|
||||||
|
case WalletType.litecoin:
|
||||||
|
case WalletType.bitcoinCash:
|
||||||
amount = calculateFiatAmountRaw(
|
amount = calculateFiatAmountRaw(
|
||||||
cryptoAmount: bitcoin!.formatterBitcoinAmountToDouble(amount: transaction.amount),
|
cryptoAmount: bitcoin!.formatterBitcoinAmountToDouble(amount: transaction.amount),
|
||||||
price: price);
|
price: price);
|
||||||
|
@ -83,12 +85,6 @@ class TransactionListItem extends ActionListItem with Keyable {
|
||||||
cryptoAmount: lightning!.formatterLightningAmountToDouble(amount: transaction.amount),
|
cryptoAmount: lightning!.formatterLightningAmountToDouble(amount: transaction.amount),
|
||||||
price: price);
|
price: price);
|
||||||
break;
|
break;
|
||||||
case WalletType.litecoin:
|
|
||||||
case WalletType.bitcoinCash:
|
|
||||||
amount = calculateFiatAmountRaw(
|
|
||||||
cryptoAmount: bitcoin!.formatterBitcoinAmountToDouble(amount: transaction.amount),
|
|
||||||
price: price);
|
|
||||||
break;
|
|
||||||
case WalletType.haven:
|
case WalletType.haven:
|
||||||
final asset = haven!.assetOfTransaction(transaction);
|
final asset = haven!.assetOfTransaction(transaction);
|
||||||
final price = balanceViewModel.fiatConvertationStore.prices[asset];
|
final price = balanceViewModel.fiatConvertationStore.prices[asset];
|
||||||
|
|
|
@ -1,12 +1,17 @@
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'package:breez_sdk/breez_sdk.dart';
|
import 'package:breez_sdk/breez_sdk.dart';
|
||||||
import 'package:breez_sdk/bridge_generated.dart' as BZG;
|
import 'package:breez_sdk/bridge_generated.dart' as BZG;
|
||||||
|
import 'package:breez_sdk/bridge_generated.dart';
|
||||||
import 'package:cake_wallet/entities/calculate_fiat_amount_raw.dart';
|
import 'package:cake_wallet/entities/calculate_fiat_amount_raw.dart';
|
||||||
import 'package:cake_wallet/entities/fiat_currency.dart';
|
import 'package:cake_wallet/entities/fiat_currency.dart';
|
||||||
import 'package:cake_wallet/lightning/lightning.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/store/dashboard/fiat_conversion_store.dart';
|
import 'package:cake_wallet/store/dashboard/fiat_conversion_store.dart';
|
||||||
import 'package:cake_wallet/store/settings_store.dart';
|
import 'package:cake_wallet/store/settings_store.dart';
|
||||||
|
import 'package:cake_wallet/utils/show_pop_up.dart';
|
||||||
import 'package:cw_core/crypto_currency.dart';
|
import 'package:cw_core/crypto_currency.dart';
|
||||||
|
import 'package:flutter/widgets.dart';
|
||||||
import 'package:mobx/mobx.dart';
|
import 'package:mobx/mobx.dart';
|
||||||
|
|
||||||
part 'lightning_send_view_model.g.dart';
|
part 'lightning_send_view_model.g.dart';
|
||||||
|
@ -40,4 +45,52 @@ abstract class LightningSendViewModelBase with Store {
|
||||||
return amount;
|
return amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@action
|
||||||
|
Future<void> send(BZG.LNInvoice invoice, int satAmount) async {
|
||||||
|
try {
|
||||||
|
setLoading(true);
|
||||||
|
|
||||||
|
final sdk = await BreezSDK();
|
||||||
|
late BZG.SendPaymentRequest req;
|
||||||
|
|
||||||
|
if (invoice.amountMsat == null) {
|
||||||
|
req = BZG.SendPaymentRequest(
|
||||||
|
bolt11: invoice.bolt11,
|
||||||
|
amountMsat: satAmount * 1000,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
req = BZG.SendPaymentRequest(bolt11: invoice.bolt11);
|
||||||
|
}
|
||||||
|
|
||||||
|
await sdk.sendPayment(req: req);
|
||||||
|
|
||||||
|
setLoading(false);
|
||||||
|
} catch (e) {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@action
|
||||||
|
Future<void> processInput(BuildContext context, String input) async {
|
||||||
|
FocusScope.of(context).unfocus();
|
||||||
|
|
||||||
|
final sdk = await BreezSDK();
|
||||||
|
|
||||||
|
late InputType inputType;
|
||||||
|
|
||||||
|
try {
|
||||||
|
inputType = await sdk.parseInput(input: input);
|
||||||
|
} catch (_) {
|
||||||
|
throw Exception("Unknown input type");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inputType is InputType_Bolt11) {
|
||||||
|
final bolt11 = await sdk.parseInvoice(input);
|
||||||
|
Navigator.of(context).pushNamed(Routes.lightningSendConfirm, arguments: bolt11);
|
||||||
|
} else if (inputType is InputType_LnUrlPay) {
|
||||||
|
throw Exception("Unsupported input type");
|
||||||
|
} else {
|
||||||
|
throw Exception("Unknown input type");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
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/monero/monero.dart';
|
import 'package:cake_wallet/monero/monero.dart';
|
||||||
import 'package:cake_wallet/view_model/unspent_coins/unspent_coins_item.dart';
|
import 'package:cake_wallet/view_model/unspent_coins/unspent_coins_item.dart';
|
||||||
import 'package:cw_core/unspent_coins_info.dart';
|
import 'package:cw_core/unspent_coins_info.dart';
|
||||||
|
@ -63,8 +62,6 @@ abstract class UnspentCoinsListViewModelBase with Store {
|
||||||
return monero!.formatterMoneroAmountToString(amount: fullBalance);
|
return monero!.formatterMoneroAmountToString(amount: fullBalance);
|
||||||
if ([WalletType.bitcoin, WalletType.litecoin, WalletType.bitcoinCash].contains(wallet.type))
|
if ([WalletType.bitcoin, WalletType.litecoin, WalletType.bitcoinCash].contains(wallet.type))
|
||||||
return bitcoin!.formatterBitcoinAmountToString(amount: fullBalance);
|
return bitcoin!.formatterBitcoinAmountToString(amount: fullBalance);
|
||||||
if (wallet.type == WalletType.lightning)
|
|
||||||
return lightning!.formatterLightningAmountToString(amount: fullBalance);
|
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,7 +69,7 @@ abstract class UnspentCoinsListViewModelBase with Store {
|
||||||
if (wallet.type == WalletType.monero) {
|
if (wallet.type == WalletType.monero) {
|
||||||
await monero!.updateUnspents(wallet);
|
await monero!.updateUnspents(wallet);
|
||||||
}
|
}
|
||||||
if ([WalletType.bitcoin, WalletType.litecoin, WalletType.bitcoinCash, WalletType.lightning]
|
if ([WalletType.bitcoin, WalletType.litecoin, WalletType.bitcoinCash]
|
||||||
.contains(wallet.type)) {
|
.contains(wallet.type)) {
|
||||||
await bitcoin!.updateUnspents(wallet);
|
await bitcoin!.updateUnspents(wallet);
|
||||||
}
|
}
|
||||||
|
@ -82,7 +79,7 @@ abstract class UnspentCoinsListViewModelBase with Store {
|
||||||
|
|
||||||
List<Unspent> _getUnspents() {
|
List<Unspent> _getUnspents() {
|
||||||
if (wallet.type == WalletType.monero) return monero!.getUnspents(wallet);
|
if (wallet.type == WalletType.monero) return monero!.getUnspents(wallet);
|
||||||
if ([WalletType.bitcoin, WalletType.litecoin, WalletType.bitcoinCash, WalletType.lightning]
|
if ([WalletType.bitcoin, WalletType.litecoin, WalletType.bitcoinCash]
|
||||||
.contains(wallet.type)) return bitcoin!.getUnspents(wallet);
|
.contains(wallet.type)) return bitcoin!.getUnspents(wallet);
|
||||||
return List.empty();
|
return List.empty();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue