mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-04-07 15:07:28 +00:00
code cleanup and fixes
This commit is contained in:
parent
51f57b4684
commit
aa9f32e8c0
3 changed files with 20 additions and 61 deletions
cw_lightning/lib
lib/view_model
|
@ -1,7 +1,5 @@
|
|||
import 'package:bitcoin_flutter/bitcoin_flutter.dart' as bitcoin;
|
||||
import 'package:bitcoin_flutter/src/payments/index.dart' show PaymentData;
|
||||
import 'package:cw_bitcoin/address_from_output.dart';
|
||||
import 'package:cw_bitcoin/bitcoin_address_record.dart';
|
||||
import 'package:cw_bitcoin/bitcoin_amount_format.dart';
|
||||
import 'package:cw_core/transaction_direction.dart';
|
||||
import 'package:cw_core/transaction_info.dart';
|
||||
|
|
|
@ -192,8 +192,13 @@ abstract class LightningWalletBase
|
|||
);
|
||||
});
|
||||
|
||||
// final payments = await sdk.listPayments(req: ListPaymentsRequest());
|
||||
// print("payments: $payments");
|
||||
sdk.paymentsStream.listen((payments) {
|
||||
_isTransactionUpdating = true;
|
||||
print("payment event: $payments");
|
||||
var txs = convertToTxInfo(payments);
|
||||
transactionHistory.addMany(txs);
|
||||
_isTransactionUpdating = false;
|
||||
});
|
||||
|
||||
print("initialized breez: ${(await sdk.isInitialized())}");
|
||||
}
|
||||
|
@ -261,15 +266,10 @@ abstract class LightningWalletBase
|
|||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Map<String, LightningTransactionInfo>> fetchTransactions() async {
|
||||
final sdk = await BreezSDK();
|
||||
|
||||
final payments = await sdk.listPayments(req: ListPaymentsRequest());
|
||||
final Map<String, LightningTransactionInfo> result = {};
|
||||
Map<String, LightningTransactionInfo> convertToTxInfo(List<Payment> payments) {
|
||||
final Map<String, LightningTransactionInfo>
|
||||
|
||||
for (var tx in payments) {
|
||||
print(tx.details.data);
|
||||
var details = tx.details.data as LnPaymentDetails;
|
||||
bool isSend = false;
|
||||
if (details.lnAddress?.isNotEmpty ?? false) {
|
||||
|
@ -278,7 +278,7 @@ abstract class LightningWalletBase
|
|||
if (details.lnurlMetadata?.isNotEmpty ?? false) {
|
||||
isSend = true;
|
||||
}
|
||||
result[tx.id] = LightningTransactionInfo(
|
||||
transactions[tx.id] = LightningTransactionInfo(
|
||||
WalletType.lightning,
|
||||
isPending: false,
|
||||
id: tx.id,
|
||||
|
@ -290,8 +290,17 @@ abstract class LightningWalletBase
|
|||
confirmations: 1,
|
||||
);
|
||||
}
|
||||
return transactions;
|
||||
}
|
||||
|
||||
return result;
|
||||
@override
|
||||
Future<Map<String, LightningTransactionInfo>> fetchTransactions() async {
|
||||
final sdk = await BreezSDK();
|
||||
|
||||
final payments = await sdk.listPayments(req: ListPaymentsRequest());
|
||||
final transactions = convertToTxInfo(payments);
|
||||
|
||||
return transactions;
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -13,54 +13,6 @@ abstract class LightningViewModelBase with Store {
|
|||
// @observable
|
||||
// ExecutionState state;
|
||||
|
||||
@action
|
||||
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);
|
||||
|
||||
final sdk = await BreezSDK();
|
||||
|
||||
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}");
|
||||
|
||||
// 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}");
|
||||
|
||||
ListPaymentsRequest lReq = ListPaymentsRequest();
|
||||
|
||||
var list = await sdk.listPayments(req: lReq);
|
||||
print(list[0].amountMsat);
|
||||
|
||||
var data = await sdk.fetchNodeData();
|
||||
print(data);
|
||||
}
|
||||
|
||||
Future<List<String>> receiveOnchain() async {
|
||||
final sdk = await BreezSDK();
|
||||
|
||||
|
|
Loading…
Reference in a new issue