mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-09 12:29:31 +00:00
save
This commit is contained in:
parent
ce2a51835d
commit
d309e528f6
5 changed files with 180 additions and 131 deletions
37
lib/di.dart
37
lib/di.dart
|
@ -608,7 +608,6 @@ Future<void> setup({
|
|||
authService: getIt.get<AuthService>(),
|
||||
initialPaymentRequest: initialPaymentRequest,
|
||||
));
|
||||
|
||||
getIt.registerFactory(
|
||||
() => SendTemplatePage(sendTemplateViewModel: getIt.get<SendTemplateViewModel>()));
|
||||
|
||||
|
@ -1200,11 +1199,6 @@ Future<void> setup({
|
|||
getIt.registerFactory(() => NFTViewModel(appStore, getIt.get<BottomSheetService>()));
|
||||
getIt.registerFactory<TorPage>(() => TorPage(getIt.get<AppStore>()));
|
||||
|
||||
getIt.registerFactory<LightningReceiveOnchainPage>(() => LightningReceiveOnchainPage(
|
||||
addressListViewModel: getIt.get<WalletAddressListViewModel>(),
|
||||
receiveOptionViewModel: ReceiveOptionViewModel(getIt.get<AppStore>().wallet!, ReceivePageOption.lightningOnchain),
|
||||
));
|
||||
|
||||
getIt.registerFactoryParam<LightningInvoicePageViewModel, List<dynamic>, void>((args, _) {
|
||||
final address = args.first as String;
|
||||
final pageOption = args.last as ReceivePageOption;
|
||||
|
@ -1213,29 +1207,38 @@ Future<void> setup({
|
|||
getIt.get<SettingsStore>(),
|
||||
getIt.get<AppStore>().wallet!,
|
||||
getIt.get<SharedPreferences>(),
|
||||
LightningViewModel(),
|
||||
pageOption,
|
||||
);
|
||||
});
|
||||
|
||||
// getIt.registerFactory<LightningInvoicePage>(() => LightningInvoicePage(
|
||||
// lightningInvoicePageViewModel: getIt.get<LightningInvoicePageViewModel>(),
|
||||
// lightningViewModel: LightningViewModel(),
|
||||
// receiveOptionViewModel: ReceiveOptionViewModel(getIt.get<AppStore>().wallet!, ReceivePageOption.lightningInvoice),
|
||||
// getIt.registerFactory<LightningReceiveOnchainPage>(() => LightningReceiveOnchainPage(
|
||||
// addressListViewModel: getIt.get<WalletAddressListViewModel>(),
|
||||
// receiveOptionViewModel: ReceiveOptionViewModel(getIt.get<AppStore>().wallet!, ReceivePageOption.lightningOnchain),
|
||||
// ));
|
||||
|
||||
|
||||
|
||||
getIt.registerFactoryParam<LightningReceiveOnchainPage, List<dynamic>, void>(
|
||||
(List<dynamic> args, _) {
|
||||
final pageOption = args.last as ReceivePageOption;
|
||||
return LightningReceiveOnchainPage(
|
||||
addressListViewModel: getIt.get<WalletAddressListViewModel>(),
|
||||
// lightningViewModel: LightningViewModel(),
|
||||
receiveOptionViewModel: getIt.get<ReceiveOptionViewModel>(param1: pageOption));
|
||||
});
|
||||
|
||||
getIt.registerFactoryParam<LightningInvoicePage, List<dynamic>, void>((List<dynamic> args, _) {
|
||||
final pageOption = args.last as ReceivePageOption;
|
||||
return LightningInvoicePage(
|
||||
lightningInvoicePageViewModel: getIt.get<LightningInvoicePageViewModel>(param1: args),
|
||||
lightningViewModel: LightningViewModel(),
|
||||
receiveOptionViewModel: getIt.get<ReceiveOptionViewModel>(param1: pageOption));
|
||||
lightningInvoicePageViewModel: getIt.get<LightningInvoicePageViewModel>(param1: args),
|
||||
lightningViewModel: LightningViewModel(),
|
||||
receiveOptionViewModel: getIt.get<ReceiveOptionViewModel>(param1: pageOption));
|
||||
});
|
||||
|
||||
|
||||
// getIt.registerFactory<LightningSendPage>(() => LightningSendPage(authService: , sendViewModel: , initialPaymentRequest: ,));
|
||||
getIt.registerFactory<LightningSendPage>(() => LightningSendPage(
|
||||
sendViewModel: getIt.get<SendViewModel>(),
|
||||
authService: getIt.get<AuthService>(),
|
||||
initialPaymentRequest: null,
|
||||
));
|
||||
|
||||
_isSetupFinished = true;
|
||||
}
|
||||
|
|
|
@ -641,8 +641,9 @@ Route<dynamic> createRoute(RouteSettings settings) {
|
|||
fullscreenDialog: true, builder: (_) => getIt.get<LightningSendPage>());
|
||||
|
||||
case Routes.lightningReceiveOnchain:
|
||||
final args = settings.arguments as List;
|
||||
return CupertinoPageRoute<void>(
|
||||
fullscreenDialog: true, builder: (_) => getIt.get<LightningReceiveOnchainPage>());
|
||||
fullscreenDialog: true, builder: (_) => getIt.get<LightningReceiveOnchainPage>(param1: args));
|
||||
|
||||
case Routes.lightningInvoice:
|
||||
final args = settings.arguments as List;
|
||||
|
|
|
@ -35,8 +35,6 @@ class LightningInvoicePage extends BasePage {
|
|||
required this.receiveOptionViewModel,
|
||||
}) : _amountFocusNode = FocusNode() {}
|
||||
|
||||
final _nameController = TextEditingController();
|
||||
final _emailController = TextEditingController();
|
||||
final _descriptionController = TextEditingController();
|
||||
final _amountController = TextEditingController();
|
||||
final FocusNode _amountFocusNode;
|
||||
|
@ -138,48 +136,36 @@ class LightningInvoicePage extends BasePage {
|
|||
bottomSection: Observer(builder: (_) {
|
||||
return Column(
|
||||
children: <Widget>[
|
||||
Padding(
|
||||
padding: EdgeInsets.only(bottom: 15),
|
||||
child: Center(
|
||||
child: Text(
|
||||
S.of(context).anonpay_description("an invoice", "pay"),
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
color: Theme.of(context)
|
||||
.extension<ExchangePageTheme>()!
|
||||
.receiveAmountColor,
|
||||
fontWeight: FontWeight.w500,
|
||||
fontSize: 12),
|
||||
),
|
||||
),
|
||||
),
|
||||
// LoadingPrimaryButton(
|
||||
// text: isInvoice
|
||||
// ? S.of(context).create_invoice
|
||||
// : S.of(context).create_donation_link,
|
||||
// onPressed: () {
|
||||
// FocusScope.of(context).unfocus();
|
||||
// anonInvoicePageViewModel.setRequestParams(
|
||||
// inputAmount: _amountController.text,
|
||||
// inputName: _nameController.text,
|
||||
// inputEmail: _emailController.text,
|
||||
// inputDescription: _descriptionController.text,
|
||||
// );
|
||||
// if (anonInvoicePageViewModel.receipientEmail.isNotEmpty &&
|
||||
// _formKey.currentState != null &&
|
||||
// !_formKey.currentState!.validate()) {
|
||||
// return;
|
||||
// }
|
||||
// if (isInvoice) {
|
||||
// anonInvoicePageViewModel.createInvoice();
|
||||
// } else {
|
||||
// anonInvoicePageViewModel.generateDonationLink();
|
||||
// }
|
||||
// },
|
||||
// color: Theme.of(context).primaryColor,
|
||||
// textColor: Colors.white,
|
||||
// isLoading: anonInvoicePageViewModel.state is IsExecutingState,
|
||||
// Padding(
|
||||
// padding: EdgeInsets.only(bottom: 15),
|
||||
// child: Center(
|
||||
// child: Text(
|
||||
// S.of(context).anonpay_description("an invoice", "pay"),
|
||||
// textAlign: TextAlign.center,
|
||||
// style: TextStyle(
|
||||
// color: Theme.of(context)
|
||||
// .extension<ExchangePageTheme>()!
|
||||
// .receiveAmountColor,
|
||||
// fontWeight: FontWeight.w500,
|
||||
// fontSize: 12),
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
LoadingPrimaryButton(
|
||||
text: S.of(context).create_invoice,
|
||||
onPressed: () {
|
||||
FocusScope.of(context).unfocus();
|
||||
lightningViewModel.createInvoice(amount: _amountController.text, description: _descriptionController.text);
|
||||
lightningInvoicePageViewModel.setRequestParams(
|
||||
inputAmount: _amountController.text,
|
||||
inputDescription: _descriptionController.text,
|
||||
);
|
||||
lightningInvoicePageViewModel.createInvoice();
|
||||
},
|
||||
color: Theme.of(context).primaryColor,
|
||||
textColor: Colors.white,
|
||||
isLoading: lightningInvoicePageViewModel.state is IsExecutingState,
|
||||
),
|
||||
],
|
||||
);
|
||||
}),
|
||||
|
@ -194,33 +180,56 @@ class LightningInvoicePage extends BasePage {
|
|||
return;
|
||||
}
|
||||
|
||||
reaction((_) => receiveOptionViewModel.selectedReceiveOption, (ReceivePageOption option) {
|
||||
reaction((_) => receiveOptionViewModel.selectedReceiveOption, (ReceivePageOption option) async {
|
||||
switch (option) {
|
||||
case ReceivePageOption.lightningInvoice:
|
||||
break;
|
||||
case ReceivePageOption.lightningOnchain:
|
||||
Navigator.popAndPushNamed(context, Routes.lightningReceiveOnchain);
|
||||
final address = await lightningViewModel.receiveOnchain();
|
||||
Navigator.popAndPushNamed(
|
||||
context,
|
||||
Routes.lightningReceiveOnchain,
|
||||
arguments: [address, ReceivePageOption.lightningInvoice],
|
||||
);
|
||||
break;
|
||||
default:
|
||||
}
|
||||
});
|
||||
|
||||
// reaction((_) => anonInvoicePageViewModel.state, (ExecutionState state) {
|
||||
// if (state is ExecutedSuccessfullyState) {
|
||||
// Navigator.pushNamed(context, Routes.anonPayReceivePage, arguments: state.payload);
|
||||
// }
|
||||
// if (state is FailureState) {
|
||||
// showPopUp<void>(
|
||||
// context: context,
|
||||
// builder: (BuildContext context) {
|
||||
// return AlertWithOneAction(
|
||||
// alertTitle: S.of(context).error,
|
||||
// alertContent: state.error.toString(),
|
||||
// buttonText: S.of(context).ok,
|
||||
// buttonAction: () => Navigator.of(context).pop());
|
||||
// });
|
||||
// }
|
||||
// });
|
||||
reaction((_) => lightningInvoicePageViewModel.state, (ExecutionState state) {
|
||||
if (state is ExecutedSuccessfullyState) {
|
||||
// Navigator.pushNamed(context, Routes.anonPayReceivePage, arguments: state.payload);
|
||||
lightningViewModel.createInvoice(
|
||||
amount: state.payload["amount"] as String,
|
||||
description: state.payload["description"] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
if (state is ExecutedSuccessfullyState) {
|
||||
showPopUp<void>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertWithOneAction(
|
||||
// alertTitle: S.of(context).invoice_created,
|
||||
alertTitle: "Invoice created TODO",
|
||||
alertContent: state.payload as String,
|
||||
buttonText: S.of(context).ok,
|
||||
buttonAction: () => Navigator.of(context).pop());
|
||||
});
|
||||
}
|
||||
|
||||
if (state is FailureState) {
|
||||
showPopUp<void>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertWithOneAction(
|
||||
alertTitle: S.of(context).error,
|
||||
alertContent: state.error.toString(),
|
||||
buttonText: S.of(context).ok,
|
||||
buttonAction: () => Navigator.of(context).pop());
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
effectsInstalled = true;
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import 'package:cake_wallet/entities/fiat_currency.dart';
|
|||
import 'package:cake_wallet/entities/preferences_key.dart';
|
||||
import 'package:cake_wallet/entities/receive_page_option.dart';
|
||||
import 'package:cake_wallet/store/settings_store.dart';
|
||||
import 'package:cake_wallet/view_model/lightning_view_model.dart';
|
||||
import 'package:cw_core/crypto_currency.dart';
|
||||
import 'package:cw_core/currency.dart';
|
||||
import 'package:cw_core/wallet_base.dart';
|
||||
|
@ -16,23 +17,23 @@ import 'package:shared_preferences/shared_preferences.dart';
|
|||
|
||||
part 'lightning_invoice_page_view_model.g.dart';
|
||||
|
||||
class LightningInvoicePageViewModel = LightningInvoicePageViewModelBase with _$LightningInvoicePageViewModel;
|
||||
class LightningInvoicePageViewModel = LightningInvoicePageViewModelBase
|
||||
with _$LightningInvoicePageViewModel;
|
||||
|
||||
abstract class LightningInvoicePageViewModelBase with Store {
|
||||
LightningInvoicePageViewModelBase(
|
||||
this.address,
|
||||
this.settingsStore,
|
||||
this._wallet,
|
||||
// this._anonpayInvoiceInfoSource,
|
||||
this.sharedPreferences,
|
||||
this.lightningViewModel,
|
||||
this.pageOption,
|
||||
) : description = '',
|
||||
amount = '',
|
||||
state = InitialExecutionState(),
|
||||
selectedCurrency = walletTypeToCryptoCurrency(_wallet.type),
|
||||
cryptoCurrency = walletTypeToCryptoCurrency(_wallet.type) {
|
||||
// _getPreviousDonationLink();
|
||||
// _fetchLimits();
|
||||
_fetchLimits();
|
||||
}
|
||||
|
||||
List<Currency> get currencies => [walletTypeToCryptoCurrency(_wallet.type), ...FiatCurrency.all];
|
||||
|
@ -42,6 +43,7 @@ abstract class LightningInvoicePageViewModelBase with Store {
|
|||
// final Box<AnonpayInvoiceInfo> _anonpayInvoiceInfoSource;
|
||||
final SharedPreferences sharedPreferences;
|
||||
final ReceivePageOption pageOption;
|
||||
final LightningViewModel lightningViewModel;
|
||||
|
||||
@observable
|
||||
Currency selectedCurrency;
|
||||
|
@ -97,18 +99,14 @@ abstract class LightningInvoicePageViewModelBase with Store {
|
|||
return;
|
||||
}
|
||||
}
|
||||
// final result = await anonPayApi.createInvoice(AnonPayRequest(
|
||||
// cryptoCurrency: cryptoCurrency,
|
||||
// address: address,
|
||||
// amount: amount.isEmpty ? null : amount,
|
||||
// description: description,
|
||||
// fiatEquivalent:
|
||||
// selectedCurrency is FiatCurrency ? (selectedCurrency as FiatCurrency).raw : null,
|
||||
// ));
|
||||
|
||||
// _anonpayInvoiceInfoSource.add(result);
|
||||
|
||||
// state = ExecutedSuccessfullyState(payload: result);
|
||||
try {
|
||||
String bolt11 =
|
||||
await lightningViewModel.createInvoice(amount: amount, description: description);
|
||||
state = ExecutedSuccessfullyState(payload: bolt11);
|
||||
} catch (e) {
|
||||
state = FailureState(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@action
|
||||
|
@ -121,6 +119,7 @@ abstract class LightningInvoicePageViewModelBase with Store {
|
|||
}
|
||||
|
||||
Future<void> _fetchLimits() async {
|
||||
List<String> limits = await lightningViewModel.invoiceLimits();
|
||||
// final limit = await anonPayApi.fetchLimits(
|
||||
// cryptoCurrency: cryptoCurrency,
|
||||
// fiatCurrency: selectedCurrency is FiatCurrency ? selectedCurrency as FiatCurrency : null,
|
||||
|
@ -132,7 +131,7 @@ abstract class LightningInvoicePageViewModelBase with Store {
|
|||
@action
|
||||
void reset() {
|
||||
selectedCurrency = walletTypeToCryptoCurrency(_wallet.type);
|
||||
cryptoCurrency = walletTypeToCryptoCurrency(_wallet.type);
|
||||
cryptoCurrency = walletTypeToCryptoCurrency(_wallet.type);
|
||||
description = '';
|
||||
amount = '';
|
||||
_fetchLimits();
|
||||
|
|
|
@ -22,52 +22,89 @@ abstract class LightningViewModelBase with Store {
|
|||
// ExecutionState state;
|
||||
|
||||
@action
|
||||
Future<void> receiveOnChain() async {
|
||||
print("pressed");
|
||||
// ReceivePaymentRequest req = const ReceivePaymentRequest(
|
||||
// amountMsat: 3000000,
|
||||
// description: "Invoice for 3000 sats",
|
||||
// );
|
||||
// ReceivePaymentResponse receivePaymentResponse =
|
||||
// await BreezSDK().receivePayment(req: req);
|
||||
Future<void> stuff() async {
|
||||
print("pressed");
|
||||
// ReceivePaymentRequest req = const ReceivePaymentRequest(
|
||||
// amountMsat: 3000000,
|
||||
// description: "Invoice for 3000 sats",
|
||||
// );
|
||||
// ReceivePaymentResponse receivePaymentResponse =
|
||||
// await BreezSDK().receivePayment(req: req);
|
||||
|
||||
// print(receivePaymentResponse.lnInvoice);
|
||||
// print(receivePaymentResponse.lnInvoice);
|
||||
|
||||
final sdk = await BreezSDK();
|
||||
final sdk = await BreezSDK();
|
||||
|
||||
sdk.nodeStateStream.listen((event) {
|
||||
// print("Node state: $event");
|
||||
if (event == null) return;
|
||||
int balanceSat = event.maxPayableMsat ~/ 1000;
|
||||
print("sats: $balanceSat");
|
||||
});
|
||||
sdk.nodeStateStream.listen((event) {
|
||||
// print("Node state: $event");
|
||||
if (event == null) return;
|
||||
int balanceSat = event.maxPayableMsat ~/ 1000;
|
||||
print("sats: $balanceSat");
|
||||
});
|
||||
|
||||
// ServiceHealthCheckResponse healthCheck = await sdk.serviceHealthCheck();
|
||||
// print("Current service status is: ${healthCheck.status}");
|
||||
// ServiceHealthCheckResponse healthCheck = await sdk.serviceHealthCheck();
|
||||
// print("Current service status is: ${healthCheck.status}");
|
||||
|
||||
// ReceivePaymentRequest req = ReceivePaymentRequest(
|
||||
// amountMsat: 123 * 1000,
|
||||
// description: "Invoice for 123 sats",
|
||||
// );
|
||||
// final s = await sdk.receivePayment(req: req);
|
||||
// print(s.lnInvoice.bolt11);
|
||||
// ReceivePaymentRequest req = ReceivePaymentRequest(
|
||||
// amountMsat: 123 * 1000,
|
||||
// description: "Invoice for 123 sats",
|
||||
// );
|
||||
// final s = await sdk.receivePayment(req: req);
|
||||
// print(s.lnInvoice.bolt11);
|
||||
|
||||
// ReceiveOnchainRequest req = const ReceiveOnchainRequest();
|
||||
// SwapInfo swapInfo = await sdk.receiveOnchain(req: req);
|
||||
// // Send your funds to the below bitcoin address
|
||||
// String address = swapInfo.bitcoinAddress;
|
||||
// print(address);
|
||||
// print("Minimum amount allowed to deposit in sats: ${swapInfo.minAllowedDeposit}");
|
||||
// print("Maximum amount allowed to deposit in sats: ${swapInfo.maxAllowedDeposit}");
|
||||
// ReceiveOnchainRequest req = const ReceiveOnchainRequest();
|
||||
// SwapInfo swapInfo = await sdk.receiveOnchain(req: req);
|
||||
// // Send your funds to the below bitcoin address
|
||||
// String address = swapInfo.bitcoinAddress;
|
||||
// print(address);
|
||||
// print("Minimum amount allowed to deposit in sats: ${swapInfo.minAllowedDeposit}");
|
||||
// print("Maximum amount allowed to deposit in sats: ${swapInfo.maxAllowedDeposit}");
|
||||
|
||||
ListPaymentsRequest lReq = ListPaymentsRequest();
|
||||
ListPaymentsRequest lReq = ListPaymentsRequest();
|
||||
|
||||
var list = await sdk.listPayments(req: lReq);
|
||||
print(list[0].amountMsat);
|
||||
var list = await sdk.listPayments(req: lReq);
|
||||
print(list[0].amountMsat);
|
||||
|
||||
var data = await sdk.fetchNodeData();
|
||||
print(data);
|
||||
var data = await sdk.fetchNodeData();
|
||||
print(data);
|
||||
}
|
||||
|
||||
Future<List<String>> receiveOnchain() async {
|
||||
final sdk = await BreezSDK();
|
||||
|
||||
ReceiveOnchainRequest req = const ReceiveOnchainRequest();
|
||||
SwapInfo swapInfo = await sdk.receiveOnchain(req: req);
|
||||
print(swapInfo.bitcoinAddress);
|
||||
print("Minimum amount allowed to deposit in sats: ${swapInfo.minAllowedDeposit}");
|
||||
print("Maximum amount allowed to deposit in sats: ${swapInfo.maxAllowedDeposit}");
|
||||
return [
|
||||
swapInfo.bitcoinAddress,
|
||||
swapInfo.minAllowedDeposit.toString(),
|
||||
swapInfo.maxAllowedDeposit.toString()
|
||||
];
|
||||
}
|
||||
|
||||
Future<String> createInvoice({required String amount, String? description}) async {
|
||||
final sdk = await BreezSDK();
|
||||
final req = ReceivePaymentRequest(
|
||||
amountMsat: int.parse(amount) * 1000,
|
||||
description: description ?? '',
|
||||
);
|
||||
final res = await sdk.receivePayment(req: req);
|
||||
print(res.lnInvoice.bolt11);
|
||||
return res.lnInvoice.bolt11;
|
||||
}
|
||||
|
||||
Future<List<String>> invoiceLimits() async {
|
||||
final sdk = await BreezSDK();
|
||||
final req = ReceivePaymentRequest(
|
||||
amountMsat: 1000,
|
||||
description: 'limits',
|
||||
);
|
||||
// final res = await sdk.receivePayment(req: req);
|
||||
// print(res.lnInvoice.);
|
||||
// return res.lnInvoice.bolt11;
|
||||
// TODO: figure out how to get the limits
|
||||
return ['1000', '20000'];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue