mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-06-28 12:29:51 +00:00
updates
This commit is contained in:
parent
572cbfd365
commit
7f21831bbb
8 changed files with 261 additions and 206 deletions
|
@ -56,7 +56,7 @@ dependency_overrides:
|
||||||
bitcoin_base:
|
bitcoin_base:
|
||||||
git:
|
git:
|
||||||
url: https://github.com/cake-tech/bitcoin_base
|
url: https://github.com/cake-tech/bitcoin_base
|
||||||
ref: cake-update-v5
|
ref: cake-update-v6
|
||||||
|
|
||||||
# For information on the generic Dart part of this file, see the
|
# For information on the generic Dart part of this file, see the
|
||||||
# following page: https://dart.dev/tools/pub/pubspec
|
# following page: https://dart.dev/tools/pub/pubspec
|
||||||
|
|
|
@ -43,7 +43,7 @@ dependency_overrides:
|
||||||
bitcoin_base:
|
bitcoin_base:
|
||||||
git:
|
git:
|
||||||
url: https://github.com/cake-tech/bitcoin_base
|
url: https://github.com/cake-tech/bitcoin_base
|
||||||
ref: cake-update-v5
|
ref: cake-update-v6
|
||||||
|
|
||||||
# For information on the generic Dart part of this file, see the
|
# For information on the generic Dart part of this file, see the
|
||||||
# following page: https://dart.dev/tools/pub/pubspec
|
# following page: https://dart.dev/tools/pub/pubspec
|
||||||
|
|
|
@ -223,14 +223,15 @@ abstract class LightningWalletBase extends ElectrumWallet with Store {
|
||||||
await setupLightningNode(mnemonic);
|
await setupLightningNode(mnemonic);
|
||||||
}
|
}
|
||||||
|
|
||||||
totalOnchainBalanceSats() async {
|
Future<void> updateBalance() async {
|
||||||
final balance = await _node?.listBalances();
|
final balance = await _node?.listBalances();
|
||||||
if (balance == null) {
|
if (balance == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_balance[CryptoCurrency.btcln] = LightningBalance(
|
_balance[CryptoCurrency.btcln] = LightningBalance(
|
||||||
confirmed: balance.spendableOnchainBalanceSats.toInt(),
|
confirmed: balance.spendableOnchainBalanceSats.toInt(),
|
||||||
unconfirmed: (balance.totalOnchainBalanceSats - balance.spendableOnchainBalanceSats).toInt(),
|
unconfirmed: 0,
|
||||||
|
// frozen: (balance.totalOnchainBalanceSats - balance.spendableOnchainBalanceSats).toInt(),
|
||||||
frozen: balance.totalOnchainBalanceSats.toInt(),
|
frozen: balance.totalOnchainBalanceSats.toInt(),
|
||||||
);
|
);
|
||||||
print("wallet balance: ${balance.totalOnchainBalanceSats}");
|
print("wallet balance: ${balance.totalOnchainBalanceSats}");
|
||||||
|
@ -260,25 +261,24 @@ abstract class LightningWalletBase extends ElectrumWallet with Store {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
listPaymentsWithFilter(bool printPayments) async {
|
// listPaymentsWithFilter(bool printPayments) async {
|
||||||
// final res =
|
// final res =
|
||||||
// await aliceNode.listPaymentsWithFilter(paymentDirection: ldk.PaymentDirection.outbound);
|
// await _node.listPaymentsWithFilter(paymentDirection: ldk.PaymentDirection.outbound);
|
||||||
// if (res.isNotEmpty) {
|
// if (res.isEmpty) {
|
||||||
// if (printPayments) {
|
// return null;
|
||||||
// if (kDebugMode) {
|
// }
|
||||||
// print("======Payments========");
|
// if (printPayments) {
|
||||||
// for (var e in res) {
|
// if (kDebugMode) {
|
||||||
// print("amountMsat: ${e.amountMsat}");
|
// print("======Payments========");
|
||||||
// print("paymentId: ${e.id.field0}");
|
// for (var e in res) {
|
||||||
// print("status: ${e.status.name}");
|
// print("amountMsat: ${e.amountMsat}");
|
||||||
// }
|
// print("paymentId: ${e.id.field0}");
|
||||||
// }
|
// print("status: ${e.status.name}");
|
||||||
// }
|
// }
|
||||||
// return res.last;
|
// }
|
||||||
// } else {
|
// }
|
||||||
// return null;
|
// return res.last;
|
||||||
// }
|
// }
|
||||||
}
|
|
||||||
|
|
||||||
removeLastPayment() async {
|
removeLastPayment() async {
|
||||||
// final lastPayment = await listPaymentsWithFilter(false);
|
// final lastPayment = await listPaymentsWithFilter(false);
|
||||||
|
@ -292,7 +292,7 @@ abstract class LightningWalletBase extends ElectrumWallet with Store {
|
||||||
|
|
||||||
Future<String> newOnchainAddress() async {
|
Future<String> newOnchainAddress() async {
|
||||||
if (_node == null) {
|
if (_node == null) {
|
||||||
return "";
|
throw Exception("Node is null!");
|
||||||
}
|
}
|
||||||
final payment = await _node!.onChainPayment();
|
final payment = await _node!.onChainPayment();
|
||||||
final address = await payment.newAddress();
|
final address = await payment.newAddress();
|
||||||
|
@ -336,14 +336,27 @@ abstract class LightningWalletBase extends ElectrumWallet with Store {
|
||||||
// ));
|
// ));
|
||||||
}
|
}
|
||||||
|
|
||||||
receiveAndSendPayments() async {
|
Future<String> createInvoice({required BigInt amountMsat, String? description}) async {
|
||||||
// final bobBolt11Handler = await bobNode.bolt11Payment();
|
if (_node == null) {
|
||||||
|
throw Exception("Node is null!");
|
||||||
|
}
|
||||||
|
|
||||||
|
final bolt11Handler = await _node!.bolt11Payment();
|
||||||
// final aliceBolt11Handler = await aliceNode.bolt11Payment();
|
// final aliceBolt11Handler = await aliceNode.bolt11Payment();
|
||||||
// // Bob doesn't have a channel yet, so he can't receive normal payments,
|
// // Bob doesn't have a channel yet, so he can't receive normal payments,
|
||||||
// // but he can receive payments via JIT channels through an LSP configured
|
// // but he can receive payments via JIT channels through an LSP configured
|
||||||
// // in its node.
|
// // in its node.
|
||||||
// invoice = await bobBolt11Handler.receiveViaJitChannel(
|
|
||||||
// amountMsat: BigInt.from(25000 * 1000), description: 'asdf', expirySecs: 9217);
|
// check if we have an open channel:
|
||||||
|
|
||||||
|
final invoice = await bolt11Handler.receiveViaJitChannel(
|
||||||
|
amountMsat: amountMsat,
|
||||||
|
description: description ?? '',
|
||||||
|
expirySecs: 9000,
|
||||||
|
);
|
||||||
|
|
||||||
|
return invoice.signedRawInvoice;
|
||||||
|
|
||||||
// print(invoice!.signedRawInvoice);
|
// print(invoice!.signedRawInvoice);
|
||||||
// setState(() {
|
// setState(() {
|
||||||
// displayText = invoice!.signedRawInvoice;
|
// displayText = invoice!.signedRawInvoice;
|
||||||
|
@ -355,12 +368,12 @@ abstract class LightningWalletBase extends ElectrumWallet with Store {
|
||||||
// });
|
// });
|
||||||
}
|
}
|
||||||
|
|
||||||
stop() async {
|
Future<void> stop() async {
|
||||||
// await bobNode.stop();
|
// await bobNode.stop();
|
||||||
// await aliceNode.stop();
|
// await aliceNode.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future handleEvent(ldk.Node node) async {
|
Future<void> handleEvent(ldk.Node node) async {
|
||||||
final res = await node.nextEvent();
|
final res = await node.nextEvent();
|
||||||
res?.map(paymentSuccessful: (e) {
|
res?.map(paymentSuccessful: (e) {
|
||||||
if (kDebugMode) {
|
if (kDebugMode) {
|
||||||
|
@ -393,6 +406,7 @@ abstract class LightningWalletBase extends ElectrumWallet with Store {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
await node.eventHandled();
|
await node.eventHandled();
|
||||||
|
handleEvent(_node!);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> startNode(ldk.Node node) async {
|
Future<void> startNode(ldk.Node node) async {
|
||||||
|
@ -417,22 +431,44 @@ abstract class LightningWalletBase extends ElectrumWallet with Store {
|
||||||
.setEsploraServer(esploraUrl)
|
.setEsploraServer(esploraUrl)
|
||||||
.setStorageDirPath(workingDir)
|
.setStorageDirPath(workingDir)
|
||||||
.setListeningAddresses([address]);
|
.setListeningAddresses([address]);
|
||||||
|
|
||||||
|
// return ldk.Builder()
|
||||||
|
// .setEntropyBip39Mnemonic(mnemonic: ldk.Mnemonic(seedPhrase: mnemonic))
|
||||||
|
// .setEsploraServer(esploraUrl)
|
||||||
|
// .setStorageDirPath(workingDir)
|
||||||
|
// .setListeningAddresses([address])
|
||||||
|
// .setNetwork(ldk.Network.bitcoin)
|
||||||
|
// .setLiquiditySourceLsps2(address: address, publicKey: publicKey)
|
||||||
|
// .setGossipSourceRgs(DefaultServicesMutinynet.rgsServerUrl)
|
||||||
|
// .setLiquiditySourceLsps2(
|
||||||
|
// address: types.SocketAddress.hostname(
|
||||||
|
// addr: DefaultServicesMutinynet.lsps2SourceAddress,
|
||||||
|
// port: DefaultServicesMutinynet.lsps2SourcePort,
|
||||||
|
// ),
|
||||||
|
// publicKey: types.PublicKey(
|
||||||
|
// hex: DefaultServicesMutinynet.lsps2SourcePublicKey,
|
||||||
|
// ),
|
||||||
|
// token: DefaultServicesMutinynet.lsps2SourceToken,
|
||||||
|
// );
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<String> sendToOnchainAddress({
|
||||||
|
required String address,
|
||||||
|
required BigInt amountSats,
|
||||||
|
}) async {
|
||||||
|
if (_node == null) {
|
||||||
|
throw Exception("Node is null!");
|
||||||
|
}
|
||||||
|
|
||||||
|
final addr = ldk.Address(s: address);
|
||||||
|
final payment = await _node!.onChainPayment();
|
||||||
|
final txid = await payment.sendToAddress(address: addr, amountSats: amountSats);
|
||||||
|
|
||||||
|
print('Sent On-Chain Txid: ${txid.hash}');
|
||||||
|
return txid.hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> setupLightningNode(String mnemonic) async {
|
Future<void> setupLightningNode(String mnemonic) async {
|
||||||
// _sdk = await BreezSDK();
|
|
||||||
// await _logStream?.cancel();
|
|
||||||
// _logStream = _sdk.logStream.listen(_logSdkEntries);
|
|
||||||
|
|
||||||
// try {
|
|
||||||
// if (!(await _sdk.isInitialized())) {
|
|
||||||
// _sdk.initialize();
|
|
||||||
// }
|
|
||||||
// } catch (e) {
|
|
||||||
// print("Error initializing Breez: $e");
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
if (_node != null) {
|
if (_node != null) {
|
||||||
await _node?.stop();
|
await _node?.stop();
|
||||||
}
|
}
|
||||||
|
@ -442,6 +478,11 @@ abstract class LightningWalletBase extends ElectrumWallet with Store {
|
||||||
await startNode(_node!);
|
await startNode(_node!);
|
||||||
print("node started!");
|
print("node started!");
|
||||||
|
|
||||||
|
await handleEvent(_node!);
|
||||||
|
// Timer.periodic(Duration(seconds: 10), (timer) async {
|
||||||
|
// await handleEvent(_node!);
|
||||||
|
// });
|
||||||
|
|
||||||
// // disconnect if already connected
|
// // disconnect if already connected
|
||||||
// try {
|
// try {
|
||||||
// if (await _sdk.isInitialized()) {
|
// if (await _sdk.isInitialized()) {
|
||||||
|
@ -500,6 +541,7 @@ abstract class LightningWalletBase extends ElectrumWallet with Store {
|
||||||
try {
|
try {
|
||||||
syncStatus = AttemptingSyncStatus();
|
syncStatus = AttemptingSyncStatus();
|
||||||
await updateTransactions();
|
await updateTransactions();
|
||||||
|
await updateBalance();
|
||||||
await fetchFees();
|
await fetchFees();
|
||||||
syncStatus = SyncedSyncStatus();
|
syncStatus = SyncedSyncStatus();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -574,37 +616,43 @@ abstract class LightningWalletBase extends ElectrumWallet with Store {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Map<String, LightningTransactionInfo> convertToTxInfo(List<Payment> payments) {
|
Map<String, LightningTransactionInfo> convertToTxInfo(List<ldk.PaymentDetails> payments) {
|
||||||
// Map<String, LightningTransactionInfo> transactions = {};
|
Map<String, LightningTransactionInfo> transactions = {};
|
||||||
|
|
||||||
// for (Payment tx in payments) {
|
for (final tx in payments) {
|
||||||
// bool pending = tx.status == PaymentStatus.Pending;
|
bool pending = tx.status == ldk.PaymentStatus.pending;
|
||||||
// if (tx.status == PaymentStatus.Complete) {
|
|
||||||
// pending = false;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// bool isSend =
|
bool isSend = tx.direction == ldk.PaymentDirection.outbound;
|
||||||
// tx.paymentType == PaymentType.Sent || tx.paymentType == PaymentType.ClosedChannel;
|
|
||||||
// transactions[tx.id] = LightningTransactionInfo(
|
int amount = (tx.amountMsat?.toInt() ?? 0) ~/ 1000;
|
||||||
// isPending: pending,
|
|
||||||
// id: tx.id,
|
// TODO: check if this is a channel closure:
|
||||||
// amount: tx.amountMsat ~/ 1000,
|
bool isChannelClose = false;
|
||||||
// fee: tx.feeMsat ~/ 1000,
|
// if (tx.kind is ldk.PaymentKind.
|
||||||
// date: DateTime.fromMillisecondsSinceEpoch(tx.paymentTime * 1000),
|
|
||||||
// direction: isSend ? TransactionDirection.outgoing : TransactionDirection.incoming,
|
transactions[tx.id.toString()] = LightningTransactionInfo(
|
||||||
// isChannelClose: tx.paymentType == PaymentType.ClosedChannel,
|
isPending: pending,
|
||||||
// );
|
id: tx.id.toString(),
|
||||||
// }
|
amount: amount,
|
||||||
// return transactions;
|
fee: 0, // not available
|
||||||
// }
|
date: DateTime.fromMillisecondsSinceEpoch(tx.latestUpdateTimestamp.toInt() * 1000),
|
||||||
|
direction: isSend ? TransactionDirection.outgoing : TransactionDirection.incoming,
|
||||||
|
isChannelClose: isChannelClose,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return transactions;
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<Map<String, LightningTransactionInfo>> fetchTransactions() async {
|
Future<Map<String, LightningTransactionInfo>> fetchTransactions() async {
|
||||||
// final payments = await _sdk.listPayments(req: ListPaymentsRequest());
|
if (_node == null) {
|
||||||
// final transactions = convertToTxInfo(payments);
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
// return transactions;
|
final payments = await _node!.listPayments();
|
||||||
return {};
|
print(payments);
|
||||||
|
final transactions = convertToTxInfo(payments);
|
||||||
|
return transactions;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -622,9 +670,12 @@ abstract class LightningWalletBase extends ElectrumWallet with Store {
|
||||||
Future<void> init() async {
|
Future<void> init() async {
|
||||||
await super.init();
|
await super.init();
|
||||||
try {
|
try {
|
||||||
await setupLightningNode(mnemonic);
|
print("starting lightning node!");
|
||||||
|
// await setupLightningNode(mnemonic);
|
||||||
|
await setupLightningNode(
|
||||||
|
"puppy interest whip tonight dad never sudden response push zone pig patch");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print("Error initializing Breez: $e");
|
print("Error initializing node: $e");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -640,10 +691,6 @@ abstract class LightningWalletBase extends ElectrumWallet with Store {
|
||||||
'network_type': network == BitcoinNetwork.testnet ? 'testnet' : 'mainnet',
|
'network_type': network == BitcoinNetwork.testnet ? 'testnet' : 'mainnet',
|
||||||
});
|
});
|
||||||
|
|
||||||
Future<void> updateBalance() async {
|
|
||||||
// await _handleNodeState(await _sdk.nodeInfo());
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<String> makePath() async => pathForWallet(name: walletInfo.name, type: walletInfo.type);
|
Future<String> makePath() async => pathForWallet(name: walletInfo.name, type: walletInfo.type);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
|
@ -34,10 +34,6 @@ dependencies:
|
||||||
# url: https://github.com/breez/breez-sdk-flutter.git
|
# url: https://github.com/breez/breez-sdk-flutter.git
|
||||||
# ref: v0.5.2
|
# ref: v0.5.2
|
||||||
cryptography: ^2.0.5
|
cryptography: ^2.0.5
|
||||||
bitcoin_base:
|
|
||||||
git:
|
|
||||||
url: https://github.com/cake-tech/bitcoin_base
|
|
||||||
ref: cake-update-v5
|
|
||||||
fluttertoast: 8.1.4
|
fluttertoast: 8.1.4
|
||||||
ldk_node: ^0.3.0
|
ldk_node: ^0.3.0
|
||||||
|
|
||||||
|
@ -55,9 +51,9 @@ dependency_overrides:
|
||||||
bitcoin_base:
|
bitcoin_base:
|
||||||
git:
|
git:
|
||||||
url: https://github.com/cake-tech/bitcoin_base
|
url: https://github.com/cake-tech/bitcoin_base
|
||||||
ref: cake-update-v5
|
ref: cake-update-v6
|
||||||
meta: 1.11.0
|
meta: 1.11.0
|
||||||
# flutter_rust_bridge: 2.0.0
|
flutter_rust_bridge: 2.0.0
|
||||||
|
|
||||||
# For information on the generic Dart part of this file, see the
|
# For information on the generic Dart part of this file, see the
|
||||||
# following page: https://dart.dev/tools/pub/pubspec
|
# following page: https://dart.dev/tools/pub/pubspec
|
||||||
|
|
|
@ -211,13 +211,12 @@ class LightningSendPage extends BasePage {
|
||||||
),
|
),
|
||||||
SizedBox(height: 24),
|
SizedBox(height: 24),
|
||||||
Observer(builder: (_) {
|
Observer(builder: (_) {
|
||||||
final invoiceSats = 0;
|
final invoiceSats = lightningSendViewModel.invoice?.amountSat ?? null;
|
||||||
// final invoiceSats = lightningSendViewModel.invoice?.amountMsat ?? null;
|
if (invoiceSats != null) {
|
||||||
// if (invoiceSats != null) {
|
_amountController.text = lightning!
|
||||||
// _amountController.text = lightning!
|
.bitcoinAmountToLightningString(amount: invoiceSats.toInt())
|
||||||
// .bitcoinAmountToLightningString(amount: invoiceSats ~/ 1000)
|
.replaceAll(",", "");
|
||||||
// .replaceAll(",", "");
|
}
|
||||||
// }
|
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
if (invoiceSats == null)
|
if (invoiceSats == null)
|
||||||
|
@ -242,7 +241,7 @@ class LightningSendPage extends BasePage {
|
||||||
.textFieldBorderTopPanelColor,
|
.textFieldBorderTopPanelColor,
|
||||||
suffixIcon: SizedBox(width: 36),
|
suffixIcon: SizedBox(width: 36),
|
||||||
initialValue:
|
initialValue:
|
||||||
"sats: ${lightning!.bitcoinAmountToLightningString(amount: invoiceSats ~/ 1000)}",
|
"sats: ${lightning!.bitcoinAmountToLightningString(amount: invoiceSats.toInt())}",
|
||||||
placeholderTextStyle: TextStyle(
|
placeholderTextStyle: TextStyle(
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
fontWeight: FontWeight.w600,
|
fontWeight: FontWeight.w600,
|
||||||
|
@ -288,38 +287,37 @@ class LightningSendPage extends BasePage {
|
||||||
),
|
),
|
||||||
SizedBox(height: 12),
|
SizedBox(height: 12),
|
||||||
Observer(builder: (_) {
|
Observer(builder: (_) {
|
||||||
return SizedBox();
|
if (lightningSendViewModel.invoice?.description?.isEmpty ?? true) {
|
||||||
// if (lightningSendViewModel.invoice?.description?.isEmpty ?? true) {
|
return SizedBox();
|
||||||
// return SizedBox();
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
// return Column(
|
return Column(
|
||||||
// children: [
|
children: [
|
||||||
// BaseTextFormField(
|
BaseTextFormField(
|
||||||
// enabled: false,
|
enabled: false,
|
||||||
// initialValue:
|
initialValue:
|
||||||
// "${S.of(context).description}: ${lightningSendViewModel.invoice?.description}",
|
"${S.of(context).description}: ${lightningSendViewModel.invoice?.description}",
|
||||||
// textInputAction: TextInputAction.next,
|
textInputAction: TextInputAction.next,
|
||||||
// borderColor: Theme.of(context)
|
borderColor: Theme.of(context)
|
||||||
// .extension<ExchangePageTheme>()!
|
.extension<ExchangePageTheme>()!
|
||||||
// .textFieldBorderTopPanelColor,
|
.textFieldBorderTopPanelColor,
|
||||||
// suffixIcon: SizedBox(width: 36),
|
suffixIcon: SizedBox(width: 36),
|
||||||
// placeholderTextStyle: TextStyle(
|
placeholderTextStyle: TextStyle(
|
||||||
// fontSize: 16,
|
fontSize: 16,
|
||||||
// fontWeight: FontWeight.w600,
|
fontWeight: FontWeight.w600,
|
||||||
// color: Theme.of(context)
|
color: Theme.of(context)
|
||||||
// .extension<ExchangePageTheme>()!
|
.extension<ExchangePageTheme>()!
|
||||||
// .hintTextColor,
|
.hintTextColor,
|
||||||
// ),
|
),
|
||||||
// textStyle: TextStyle(
|
textStyle: TextStyle(
|
||||||
// fontSize: 16,
|
fontSize: 16,
|
||||||
// fontWeight: FontWeight.w600,
|
fontWeight: FontWeight.w600,
|
||||||
// color: Colors.white),
|
color: Colors.white),
|
||||||
// validator: null,
|
validator: null,
|
||||||
// ),
|
),
|
||||||
// SizedBox(height: 12),
|
SizedBox(height: 12),
|
||||||
// ],
|
],
|
||||||
// );
|
);
|
||||||
}),
|
}),
|
||||||
if (lightningSendViewModel.btcAddress.isNotEmpty) ...[
|
if (lightningSendViewModel.btcAddress.isNotEmpty) ...[
|
||||||
Observer(
|
Observer(
|
||||||
|
@ -459,19 +457,19 @@ class LightningSendPage extends BasePage {
|
||||||
);
|
);
|
||||||
String feeValue = '';
|
String feeValue = '';
|
||||||
String feeFiatAmount = '';
|
String feeFiatAmount = '';
|
||||||
// if (lightningSendViewModel.invoice != null) {
|
if (lightningSendViewModel.invoice != null) {
|
||||||
// output.address = lightningSendViewModel.invoice!.bolt11;
|
output.address = lightningSendViewModel.invoice!.bolt11;
|
||||||
// output.cryptoAmount =
|
output.cryptoAmount =
|
||||||
// "${lightningSendViewModel.satAmount.toString()} sats";
|
"${lightningSendViewModel.satAmount.toString()} sats";
|
||||||
// } else if (lightningSendViewModel.btcAddress.isNotEmpty) {
|
} else if (lightningSendViewModel.btcAddress.isNotEmpty) {
|
||||||
// output.address = lightningSendViewModel.btcAddress;
|
output.address = lightningSendViewModel.btcAddress;
|
||||||
// feeValue = lightningSendViewModel.estimatedFeeSats.toString();
|
feeValue = lightningSendViewModel.estimatedFeeSats.toString();
|
||||||
// feeFiatAmount = lightningSendViewModel
|
feeFiatAmount = lightningSendViewModel
|
||||||
// .formattedFiatAmount(lightningSendViewModel.estimatedFeeSats);
|
.formattedFiatAmount(lightningSendViewModel.estimatedFeeSats);
|
||||||
// output.cryptoAmount = "${_amountController.text} sats";
|
output.cryptoAmount = "${_amountController.text} sats";
|
||||||
// } else {
|
} else {
|
||||||
// throw Exception("Input cannot be empty");
|
throw Exception("Input cannot be empty");
|
||||||
// }
|
}
|
||||||
output.fiatAmount = lightningSendViewModel
|
output.fiatAmount = lightningSendViewModel
|
||||||
.formattedFiatAmount(int.parse(_amountController.text));
|
.formattedFiatAmount(int.parse(_amountController.text));
|
||||||
bool cancel = await showPopUp<bool>(
|
bool cancel = await showPopUp<bool>(
|
||||||
|
@ -503,15 +501,16 @@ class LightningSendPage extends BasePage {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (lightningSendViewModel.invoice != null) {
|
if (lightningSendViewModel.invoice != null) {
|
||||||
// await lightningSendViewModel.sendInvoice(
|
await lightningSendViewModel.sendInvoice(
|
||||||
// lightningSendViewModel.invoice!,
|
lightningSendViewModel.invoice!,
|
||||||
// int.parse(_amountController.text));
|
int.parse(_amountController.text));
|
||||||
// } else if (lightningSendViewModel.btcAddress.isNotEmpty) {
|
} else if (lightningSendViewModel.btcAddress.isNotEmpty) {
|
||||||
// await lightningSendViewModel.sendBtc(
|
await lightningSendViewModel.sendBtc(
|
||||||
// lightningSendViewModel.btcAddress,
|
lightningSendViewModel.btcAddress,
|
||||||
// int.parse(_amountController.text));
|
BigInt.parse(_amountController.text),
|
||||||
// }
|
);
|
||||||
|
}
|
||||||
|
|
||||||
await showPopUp<void>(
|
await showPopUp<void>(
|
||||||
context: context,
|
context: context,
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
// import 'package:breez_sdk/breez_sdk.dart';
|
|
||||||
// import 'package:breez_sdk/bridge_generated.dart' as BZG;
|
|
||||||
// import 'package:breez_sdk/sdk.dart';
|
|
||||||
import 'package:cake_wallet/bitcoin/bitcoin.dart';
|
import 'package:cake_wallet/bitcoin/bitcoin.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_api_mode.dart';
|
import 'package:cake_wallet/entities/fiat_api_mode.dart';
|
||||||
|
@ -9,6 +6,7 @@ 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/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/view_model/lightning_view_model.dart';
|
||||||
import 'package:cw_core/balance.dart';
|
import 'package:cw_core/balance.dart';
|
||||||
import 'package:cw_core/crypto_currency.dart';
|
import 'package:cw_core/crypto_currency.dart';
|
||||||
import 'package:cw_core/transaction_history.dart';
|
import 'package:cw_core/transaction_history.dart';
|
||||||
|
@ -16,6 +14,7 @@ import 'package:cw_core/transaction_info.dart';
|
||||||
import 'package:cw_core/transaction_priority.dart';
|
import 'package:cw_core/transaction_priority.dart';
|
||||||
import 'package:cw_core/wallet_base.dart';
|
import 'package:cw_core/wallet_base.dart';
|
||||||
import 'package:cw_core/wallet_type.dart';
|
import 'package:cw_core/wallet_type.dart';
|
||||||
|
import 'package:cw_lightning/lightning_wallet.dart';
|
||||||
import 'package:flutter/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
import 'package:mobx/mobx.dart';
|
import 'package:mobx/mobx.dart';
|
||||||
import 'package:collection/collection.dart';
|
import 'package:collection/collection.dart';
|
||||||
|
@ -70,8 +69,8 @@ abstract class LightningSendViewModelBase with Store {
|
||||||
@observable
|
@observable
|
||||||
String btcAddress = "";
|
String btcAddress = "";
|
||||||
|
|
||||||
// @observable
|
@observable
|
||||||
// LNInvoice? invoice;
|
LightningInvoice? invoice;
|
||||||
|
|
||||||
@action
|
@action
|
||||||
void setLoading(bool value) {
|
void setLoading(bool value) {
|
||||||
|
@ -165,73 +164,78 @@ abstract class LightningSendViewModelBase with Store {
|
||||||
return amount;
|
return amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
// @action
|
@action
|
||||||
// Future<void> sendInvoice(BZG.LNInvoice invoice, int satAmount) async {
|
Future<void> sendInvoice(LightningInvoice invoice, BigInt satAmount) async {
|
||||||
// try {
|
try {
|
||||||
// setLoading(true);
|
setLoading(true);
|
||||||
// late BZG.SendPaymentRequest req;
|
// late BZG.SendPaymentRequest req;
|
||||||
|
|
||||||
// if (invoice.amountMsat == null) {
|
// if (invoice.amountMsat == null) {
|
||||||
// req = BZG.SendPaymentRequest(
|
// req = BZG.SendPaymentRequest(
|
||||||
// bolt11: invoice.bolt11,
|
// bolt11: invoice.bolt11,
|
||||||
// amountMsat: satAmount * 1000,
|
// amountMsat: satAmount * 1000,
|
||||||
// );
|
// );
|
||||||
// } else {
|
// } else {
|
||||||
// req = BZG.SendPaymentRequest(bolt11: invoice.bolt11);
|
// req = BZG.SendPaymentRequest(bolt11: invoice.bolt11);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// final response = await _sdk.sendPayment(req: req);
|
// final response = await _sdk.sendPayment(req: req);
|
||||||
// if (response.payment.error != null) {
|
// if (response.payment.error != null) {
|
||||||
// throw Exception(response.payment.error);
|
// throw Exception(response.payment.error);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// if (response.payment.status == BZG.PaymentStatus.Failed) {
|
// if (response.payment.status == BZG.PaymentStatus.Failed) {
|
||||||
// throw Exception("Payment failed");
|
// throw Exception("Payment failed");
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// setLoading(false);
|
throw Exception("Not implemented yet!");
|
||||||
// } catch (e) {
|
|
||||||
// setLoading(false);
|
setLoading(false);
|
||||||
// rethrow;
|
} catch (e) {
|
||||||
// }
|
setLoading(false);
|
||||||
// }
|
rethrow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
Future<void> sendBtc(String address, int satAmount) async {
|
Future<void> sendBtc(String address, BigInt satAmount) async {
|
||||||
// try {
|
try {
|
||||||
// setLoading(true);
|
setLoading(true);
|
||||||
|
|
||||||
// if (satAmount < minSats || (satAmount > maxSats && maxSats != 0)) {
|
// if (satAmount < minSats || (satAmount > maxSats && maxSats != 0)) {
|
||||||
// throw Exception("Amount is outside of liquidity limits!");
|
// throw Exception("Amount is outside of liquidity limits!");
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// BZG.PrepareOnchainPaymentResponse prepareRes = await _sdk.prepareOnchainPayment(
|
// TODO: use proxy layer:
|
||||||
// req: BZG.PrepareOnchainPaymentRequest(
|
(wallet as LightningWallet).sendToOnchainAddress(address: address, amountSats: satAmount);
|
||||||
// amountSat: satAmount,
|
|
||||||
// amountType: BZG.SwapAmountType.Send,
|
|
||||||
// claimTxFeerate: feeRate,
|
|
||||||
// ),
|
|
||||||
// );
|
|
||||||
|
|
||||||
// print("Sender amount: ${prepareRes.senderAmountSat} sats");
|
// BZG.PrepareOnchainPaymentResponse prepareRes = await _sdk.prepareOnchainPayment(
|
||||||
// print("Recipient amount: ${prepareRes.recipientAmountSat} sats");
|
// req: BZG.PrepareOnchainPaymentRequest(
|
||||||
// print("Total fees: ${prepareRes.totalFees} sats");
|
// amountSat: satAmount,
|
||||||
|
// amountType: BZG.SwapAmountType.Send,
|
||||||
|
// claimTxFeerate: feeRate,
|
||||||
|
// ),
|
||||||
|
// );
|
||||||
|
|
||||||
// BZG.PayOnchainRequest req = BZG.PayOnchainRequest(
|
// print("Sender amount: ${prepareRes.senderAmountSat} sats");
|
||||||
// recipientAddress: address,
|
// print("Recipient amount: ${prepareRes.recipientAmountSat} sats");
|
||||||
// prepareRes: prepareRes,
|
// print("Total fees: ${prepareRes.totalFees} sats");
|
||||||
// );
|
|
||||||
// BZG.PayOnchainResponse res = await _sdk.payOnchain(req: req);
|
|
||||||
|
|
||||||
// if (res.reverseSwapInfo.status == BZG.ReverseSwapStatus.Cancelled) {
|
// BZG.PayOnchainRequest req = BZG.PayOnchainRequest(
|
||||||
// throw Exception("Payment cancelled / error");
|
// recipientAddress: address,
|
||||||
// }
|
// prepareRes: prepareRes,
|
||||||
|
// );
|
||||||
|
// BZG.PayOnchainResponse res = await _sdk.payOnchain(req: req);
|
||||||
|
|
||||||
// setLoading(false);
|
// if (res.reverseSwapInfo.status == BZG.ReverseSwapStatus.Cancelled) {
|
||||||
// } catch (e) {
|
// throw Exception("Payment cancelled / error");
|
||||||
// setLoading(false);
|
// }
|
||||||
// rethrow;
|
|
||||||
// }
|
setLoading(false);
|
||||||
|
} catch (e) {
|
||||||
|
setLoading(false);
|
||||||
|
rethrow;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int get feeRate {
|
int get feeRate {
|
||||||
|
|
|
@ -177,3 +177,15 @@ class InvoiceSoftLimitsResult {
|
||||||
required this.balance,
|
required this.balance,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class LightningInvoice {
|
||||||
|
final String bolt11;
|
||||||
|
final BigInt amountSat;
|
||||||
|
final String? description;
|
||||||
|
|
||||||
|
LightningInvoice({
|
||||||
|
required this.bolt11,
|
||||||
|
required this.amountSat,
|
||||||
|
this.description,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
|
@ -97,10 +97,6 @@ dependencies:
|
||||||
polyseed: ^0.0.6
|
polyseed: ^0.0.6
|
||||||
nostr_tools: ^1.0.9
|
nostr_tools: ^1.0.9
|
||||||
solana: ^0.30.1
|
solana: ^0.30.1
|
||||||
bitcoin_base:
|
|
||||||
git:
|
|
||||||
url: https://github.com/cake-tech/bitcoin_base
|
|
||||||
ref: cake-update-v5
|
|
||||||
ledger_flutter: ^1.0.1
|
ledger_flutter: ^1.0.1
|
||||||
hashlib: ^1.19.2
|
hashlib: ^1.19.2
|
||||||
ldk_node: ^0.3.0
|
ldk_node: ^0.3.0
|
||||||
|
@ -141,7 +137,8 @@ dependency_overrides:
|
||||||
bitcoin_base:
|
bitcoin_base:
|
||||||
git:
|
git:
|
||||||
url: https://github.com/cake-tech/bitcoin_base
|
url: https://github.com/cake-tech/bitcoin_base
|
||||||
ref: cake-update-v5
|
ref: cake-update-v6
|
||||||
|
flutter_rust_bridge: 2.0.0
|
||||||
|
|
||||||
flutter_icons:
|
flutter_icons:
|
||||||
image_path: "assets/images/app_logo.png"
|
image_path: "assets/images/app_logo.png"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue