From b8bdd1d1b10ab9ec2cf8f223548bd7398245e364 Mon Sep 17 00:00:00 2001 From: Erdem Yerebasmaz Date: Wed, 29 May 2024 15:06:02 +0300 Subject: [PATCH] Use a single instance of BreezSDK on Dart snippets - Add documentation that recommends using single instance of BreezSDK and possible options on how. - Add documentation on how to use initialize() in light of recent SDK stream management changes. --- snippets/dart_snippets/bin/dart_snippets.dart | 4 +- snippets/dart_snippets/lib/buy_btc.dart | 4 +- .../dart_snippets/lib/closed_channel.dart | 6 +- .../dart_snippets/lib/communicating_fees.dart | 10 +- .../dart_snippets/lib/connecting_lsp.dart | 10 +- .../dart_snippets/lib/fiat_currencies.dart | 6 +- .../dart_snippets/lib/getting_started.dart | 25 +++- snippets/dart_snippets/lib/list_payments.dart | 6 +- snippets/dart_snippets/lib/lnurl_auth.dart | 6 +- snippets/dart_snippets/lib/lnurl_pay.dart | 6 +- .../dart_snippets/lib/lnurl_withdraw.dart | 6 +- snippets/dart_snippets/lib/metadata.dart | 6 +- snippets/dart_snippets/lib/pay_onchain.dart | 10 +- .../dart_snippets/lib/receive_onchain.dart | 14 +- .../dart_snippets/lib/receive_payment.dart | 4 +- snippets/dart_snippets/lib/sdk_instance.dart | 3 + snippets/dart_snippets/lib/send_payment.dart | 4 +- .../lib/send_spontaneous_payment.dart | 6 +- .../dart_snippets/lib/service_status.dart | 6 +- .../lib/static_channel_backup.dart | 4 +- snippets/dart_snippets/lib/webhook.dart | 6 +- snippets/dart_snippets/pubspec.lock | 140 +++++++++--------- 22 files changed, 157 insertions(+), 135 deletions(-) create mode 100644 snippets/dart_snippets/lib/sdk_instance.dart diff --git a/snippets/dart_snippets/bin/dart_snippets.dart b/snippets/dart_snippets/bin/dart_snippets.dart index 12976354..65f4dc74 100644 --- a/snippets/dart_snippets/bin/dart_snippets.dart +++ b/snippets/dart_snippets/bin/dart_snippets.dart @@ -1,5 +1,5 @@ -import 'package:breez_sdk/breez_sdk.dart'; +import 'package:dart_snippets/sdk_instance.dart'; void main(List arguments) { - BreezSDK().initialize(); + breezSDK.initialize(); } diff --git a/snippets/dart_snippets/lib/buy_btc.dart b/snippets/dart_snippets/lib/buy_btc.dart index 17e67872..cb566397 100644 --- a/snippets/dart_snippets/lib/buy_btc.dart +++ b/snippets/dart_snippets/lib/buy_btc.dart @@ -1,10 +1,10 @@ -import 'package:breez_sdk/breez_sdk.dart'; import 'package:breez_sdk/bridge_generated.dart'; +import 'package:dart_snippets/sdk_instance.dart'; Future buyBitcoin() async { // ANCHOR: buy-btc BuyBitcoinRequest req = const BuyBitcoinRequest(provider: BuyBitcoinProvider.Moonpay); - BuyBitcoinResponse resp = await BreezSDK().buyBitcoin(req: req); + BuyBitcoinResponse resp = await breezSDK.buyBitcoin(req: req); // ANCHOR_END: buy-btc return resp; } diff --git a/snippets/dart_snippets/lib/closed_channel.dart b/snippets/dart_snippets/lib/closed_channel.dart index 89967b17..1a651390 100644 --- a/snippets/dart_snippets/lib/closed_channel.dart +++ b/snippets/dart_snippets/lib/closed_channel.dart @@ -1,4 +1,4 @@ -import 'package:breez_sdk/breez_sdk.dart'; +import 'package:dart_snippets/sdk_instance.dart'; import 'package:breez_sdk/bridge_generated.dart'; Future prepareRedeemOnchainFunds( @@ -8,7 +8,7 @@ Future prepareRedeemOnchainFunds( toAddress: "bc1..", satPerVbyte: satPerVbyte, ); - final resp = await BreezSDK().prepareRedeemOnchainFunds(req: req); + final resp = await breezSDK.prepareRedeemOnchainFunds(req: req); // ANCHOR_END: prepare-redeem-onchain-funds return resp; } @@ -20,7 +20,7 @@ Future redeemOnchainFunds( toAddress: "bc1..", satPerVbyte: satPerVbyte, ); - final resp = await BreezSDK().redeemOnchainFunds(req: req); + final resp = await breezSDK.redeemOnchainFunds(req: req); // ANCHOR_END: redeem-onchain-funds return resp; } diff --git a/snippets/dart_snippets/lib/communicating_fees.dart b/snippets/dart_snippets/lib/communicating_fees.dart index ebb2dbbc..c87fdccb 100644 --- a/snippets/dart_snippets/lib/communicating_fees.dart +++ b/snippets/dart_snippets/lib/communicating_fees.dart @@ -1,13 +1,13 @@ -import 'package:breez_sdk/breez_sdk.dart'; +import 'package:dart_snippets/sdk_instance.dart'; import 'package:breez_sdk/bridge_generated.dart'; Future getFeeInfoBeforeInvoiceCreated() async { // ANCHOR: get-fee-info-before-receiving-payment - NodeState? nodeInfo = await BreezSDK().nodeInfo(); + NodeState? nodeInfo = await breezSDK.nodeInfo(); if (nodeInfo != null) { int inboundLiquiditySat = nodeInfo.inboundLiquidityMsats ~/ 1000; - OpenChannelFeeResponse openingFeeResponse = await BreezSDK().openChannelFee(req: OpenChannelFeeRequest()); + OpenChannelFeeResponse openingFeeResponse = await breezSDK.openChannelFee(req: OpenChannelFeeRequest()); OpeningFeeParams openingFees = openingFeeResponse.feeParams; double feePercentage = (openingFees.proportional * 100) / 1000000; @@ -31,12 +31,12 @@ Future getFeeInfoAfterInvoiceCreated({required ReceivePaymentResponse rece Future getFeeInfoReceiveOnchain() async { // ANCHOR: get-fee-info-receive-onchain - SwapInfo swapInfo = await BreezSDK().receiveOnchain(req: ReceiveOnchainRequest()); + SwapInfo swapInfo = await breezSDK.receiveOnchain(req: ReceiveOnchainRequest()); int minDepositSat = swapInfo.minAllowedDeposit; int maxDepositSat = swapInfo.maxAllowedDeposit; - NodeState? nodeInfo = await BreezSDK().nodeInfo(); + NodeState? nodeInfo = await breezSDK.nodeInfo(); if (nodeInfo != null) { int inboundLiquiditySat = nodeInfo.inboundLiquidityMsats ~/ 1000; diff --git a/snippets/dart_snippets/lib/connecting_lsp.dart b/snippets/dart_snippets/lib/connecting_lsp.dart index 5a8b61c8..9136da2c 100644 --- a/snippets/dart_snippets/lib/connecting_lsp.dart +++ b/snippets/dart_snippets/lib/connecting_lsp.dart @@ -1,10 +1,10 @@ -import 'package:breez_sdk/breez_sdk.dart'; +import 'package:dart_snippets/sdk_instance.dart'; import 'package:breez_sdk/bridge_generated.dart'; Future getLspInfo() async { // ANCHOR: get-lsp-info - String? lspId = await BreezSDK().lspId(); - LspInformation? lspInfo = await BreezSDK().lspInfo(); + String? lspId = await breezSDK.lspId(); + LspInformation? lspInfo = await breezSDK.lspInfo(); print(lspId); print(lspInfo); // ANCHOR_END: get-lsp-info @@ -12,13 +12,13 @@ Future getLspInfo() async { Future> listLsps() async { // ANCHOR: list-lsps - List availableLsps = await BreezSDK().listLsps(); + List availableLsps = await breezSDK.listLsps(); // ANCHOR_END: list-lsps return availableLsps; } Future connectLsp(String lspId) async { // ANCHOR: connect-lsp - await BreezSDK().connectLSP(lspId); + await breezSDK.connectLSP(lspId); // ANCHOR_END: connect-lsp } \ No newline at end of file diff --git a/snippets/dart_snippets/lib/fiat_currencies.dart b/snippets/dart_snippets/lib/fiat_currencies.dart index 9de0f5c2..75c69fdc 100644 --- a/snippets/dart_snippets/lib/fiat_currencies.dart +++ b/snippets/dart_snippets/lib/fiat_currencies.dart @@ -1,16 +1,16 @@ -import 'package:breez_sdk/breez_sdk.dart'; +import 'package:dart_snippets/sdk_instance.dart'; import 'package:breez_sdk/bridge_generated.dart'; Future> listFiatCurrencies() async { // ANCHOR: list-fiat-currencies - List fiatCurrencyList = await BreezSDK().listFiatCurrencies(); + List fiatCurrencyList = await breezSDK.listFiatCurrencies(); // ANCHOR_END: list-fiat-currencies return fiatCurrencyList; } Future> fetchFiatRates(String lspId) async { // ANCHOR: fetch-fiat-rates - Map fiatRatesMap = await BreezSDK().fetchFiatRates(); + Map fiatRatesMap = await breezSDK.fetchFiatRates(); // print your desired rate print(fiatRatesMap["USD"]?.value); // ANCHOR_END: fetch-fiat-rates diff --git a/snippets/dart_snippets/lib/getting_started.dart b/snippets/dart_snippets/lib/getting_started.dart index 9e56933c..d19a566f 100644 --- a/snippets/dart_snippets/lib/getting_started.dart +++ b/snippets/dart_snippets/lib/getting_started.dart @@ -1,16 +1,27 @@ import 'dart:typed_data'; import 'package:breez_sdk/breez_sdk.dart'; +import 'package:dart_snippets/sdk_instance.dart'; import 'package:breez_sdk/bridge_generated.dart'; Future initializeSDK() async { // ANCHOR: init-sdk - // Initialize SDK logs listener - BreezSDK().initialize(); + // It is recommended to use a single instance of BreezSDK across your Dart/Flutter app. + // + // All of the snippets assume a BreezSDK object is created on entrypoint of the app as such: + // + // BreezSDK breezSDK = BreezSDK(); + // + // and is accessible throughout the app. There are various approaches on how to achieve this; creating a Singleton class using factory constructor, using state management libraries such as 'provider', 'GetX', 'Riverpod' and 'Redux' to name a few. + + // Initializes SDK events & log streams. + // + // Call once on your Dart entrypoint file, e.g.; `lib/main.dart`. + breezSDK.initialize(); // Create the default config - Uint8List seed = await BreezSDK().mnemonicToSeed(""); + Uint8List seed = await breezSDK.mnemonicToSeed(""); String inviteCode = ""; String apiKey = ""; NodeConfig nodeConfig = NodeConfig.greenlight( @@ -19,7 +30,7 @@ Future initializeSDK() async { inviteCode: inviteCode, ), ); - Config config = await BreezSDK().defaultConfig( + Config config = await breezSDK.defaultConfig( envType: EnvironmentType.Production, apiKey: apiKey, nodeConfig: nodeConfig, @@ -30,20 +41,20 @@ Future initializeSDK() async { // Connect to the Breez SDK make it ready for use ConnectRequest connectRequest = ConnectRequest(config: config, seed: seed); - return await BreezSDK().connect(req: connectRequest); + return await breezSDK.connect(req: connectRequest); // ANCHOR_END: init-sdk } Future connectRestoreOnly(Config config, Uint8List seed) async { // ANCHOR: init-sdk-restore-only ConnectRequest connectRequest = ConnectRequest(config: config, seed: seed, restoreOnly: true); - return await BreezSDK().connect(req: connectRequest); + return await breezSDK.connect(req: connectRequest); // ANCHOR_END: init-sdk-restore-only } Future fetchBalance(String lspId) async { // ANCHOR: fetch-balance - NodeState? nodeInfo = await BreezSDK().nodeInfo(); + NodeState? nodeInfo = await breezSDK.nodeInfo(); if (nodeInfo != null) { int lnBalance = nodeInfo.channelsBalanceMsat; int onchainBalance = nodeInfo.onchainBalanceMsat; diff --git a/snippets/dart_snippets/lib/list_payments.dart b/snippets/dart_snippets/lib/list_payments.dart index c34ce2b4..a86116ce 100644 --- a/snippets/dart_snippets/lib/list_payments.dart +++ b/snippets/dart_snippets/lib/list_payments.dart @@ -1,10 +1,10 @@ -import 'package:breez_sdk/breez_sdk.dart'; +import 'package:dart_snippets/sdk_instance.dart'; import 'package:breez_sdk/bridge_generated.dart'; Future> listPayments() async { // ANCHOR: list-payments ListPaymentsRequest req = ListPaymentsRequest(); - List paymentsList = await BreezSDK().listPayments(req: req); + List paymentsList = await breezSDK.listPayments(req: req); print(paymentsList); // ANCHOR_END: list-payments return paymentsList; @@ -29,7 +29,7 @@ Future> listPaymentsFiltered({ offset: offset, limit: limit, ); - List paymentsList = await BreezSDK().listPayments(req: req); + List paymentsList = await breezSDK.listPayments(req: req); print(paymentsList); // ANCHOR_END: list-payments-filtered return paymentsList; diff --git a/snippets/dart_snippets/lib/lnurl_auth.dart b/snippets/dart_snippets/lib/lnurl_auth.dart index 876798ae..cab20d15 100644 --- a/snippets/dart_snippets/lib/lnurl_auth.dart +++ b/snippets/dart_snippets/lib/lnurl_auth.dart @@ -1,4 +1,4 @@ -import 'package:breez_sdk/breez_sdk.dart'; +import 'package:dart_snippets/sdk_instance.dart'; import 'package:breez_sdk/bridge_generated.dart'; Future lnurlAuth() async { @@ -8,9 +8,9 @@ Future lnurlAuth() async { String lnurlAuthUrl = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttvdankjm3lw3skw0tvdankjm3xdvcn6vtp8q6n2dfsx5mrjwtrxdjnqvtzv56rzcnyv3jrxv3sxqmkyenrvv6kve3exv6nqdtyv43nqcmzvdsnvdrzx33rsenxx5unqc3cxgeqgntfgu"; - InputType inputType = await BreezSDK().parseInput(input: lnurlAuthUrl); + InputType inputType = await breezSDK.parseInput(input: lnurlAuthUrl); if (inputType is InputType_LnUrlAuth) { - LnUrlCallbackStatus result = await BreezSDK().lnurlAuth(reqData: inputType.data); + LnUrlCallbackStatus result = await breezSDK.lnurlAuth(reqData: inputType.data); if (result is LnUrlCallbackStatus_Ok) { print("Successfully authenticated"); } else { diff --git a/snippets/dart_snippets/lib/lnurl_pay.dart b/snippets/dart_snippets/lib/lnurl_pay.dart index de04c71e..226c0522 100644 --- a/snippets/dart_snippets/lib/lnurl_pay.dart +++ b/snippets/dart_snippets/lib/lnurl_pay.dart @@ -1,4 +1,4 @@ -import 'package:breez_sdk/breez_sdk.dart'; +import 'package:dart_snippets/sdk_instance.dart'; import 'package:breez_sdk/bridge_generated.dart'; Future lnurlPay() async { @@ -8,7 +8,7 @@ Future lnurlPay() async { /// lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttsv9un7um9wdekjmmw84jxywf5x43rvv35xgmr2enrxanr2cfcvsmnwe3jxcukvde48qukgdec89snwde3vfjxvepjxpjnjvtpxd3kvdnxx5crxwpjvyunsephsz36jf String lnurlPayUrl = "lightning@address.com"; - InputType inputType = await BreezSDK().parseInput(input: lnurlPayUrl); + InputType inputType = await breezSDK.parseInput(input: lnurlPayUrl); if (inputType is InputType_LnUrlPay) { int amountMsat = inputType.data.minSendable; String optionalComment = ""; @@ -19,7 +19,7 @@ Future lnurlPay() async { comment: optionalComment, paymentLabel: optionalPaymentLabel, ); - LnUrlPayResult result = await BreezSDK().lnurlPay(req: req); + LnUrlPayResult result = await breezSDK.lnurlPay(req: req); print(result.data); } // ANCHOR_END: lnurl-pay diff --git a/snippets/dart_snippets/lib/lnurl_withdraw.dart b/snippets/dart_snippets/lib/lnurl_withdraw.dart index 28d85646..cf46b28f 100644 --- a/snippets/dart_snippets/lib/lnurl_withdraw.dart +++ b/snippets/dart_snippets/lib/lnurl_withdraw.dart @@ -1,4 +1,4 @@ -import 'package:breez_sdk/breez_sdk.dart'; +import 'package:dart_snippets/sdk_instance.dart'; import 'package:breez_sdk/bridge_generated.dart'; Future lnurlWithdraw() async { @@ -8,7 +8,7 @@ Future lnurlWithdraw() async { String lnurlWithdrawUrl = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4exctthd96xserjv9mn7um9wdekjmmw843xxwpexdnxzen9vgunsvfexq6rvdecx93rgdmyxcuxverrvcursenpxvukzv3c8qunsdecx33nzwpnvg6ryc3hv93nzvecxgcxgwp3h33lxk"; - InputType inputType = await BreezSDK().parseInput(input: lnurlWithdrawUrl); + InputType inputType = await breezSDK.parseInput(input: lnurlWithdrawUrl); if (inputType is InputType_LnUrlWithdraw) { int amountMsat = inputType.data.minWithdrawable; LnUrlWithdrawRequest req = LnUrlWithdrawRequest( @@ -16,7 +16,7 @@ Future lnurlWithdraw() async { amountMsat: amountMsat, description: "", ); - LnUrlWithdrawResult result = await BreezSDK().lnurlWithdraw(req: req); + LnUrlWithdrawResult result = await breezSDK.lnurlWithdraw(req: req); print(result.data); } // ANCHOR_END: lnurl-withdraw diff --git a/snippets/dart_snippets/lib/metadata.dart b/snippets/dart_snippets/lib/metadata.dart index dd54fe69..6554987b 100644 --- a/snippets/dart_snippets/lib/metadata.dart +++ b/snippets/dart_snippets/lib/metadata.dart @@ -1,9 +1,9 @@ -import 'package:breez_sdk/breez_sdk.dart'; +import 'package:dart_snippets/sdk_instance.dart'; import 'package:breez_sdk/bridge_generated.dart'; Future setPaymentMetadata({required String paymentHash, required String metadata}) async { // ANCHOR: set-payment-metadata - await BreezSDK().setPaymentMetadata(hash: "target-payment-hash", metadata: '{"myCustomValue":true}'); + await breezSDK.setPaymentMetadata(hash: "target-payment-hash", metadata: '{"myCustomValue":true}'); // ANCHOR_END: set-payment-metadata } @@ -16,7 +16,7 @@ Future filterPaymentMetadata() async { ), ]; - await BreezSDK().listPayments( + await breezSDK.listPayments( req: ListPaymentsRequest( metadataFilters: metadataFilters )); diff --git a/snippets/dart_snippets/lib/pay_onchain.dart b/snippets/dart_snippets/lib/pay_onchain.dart index b1c36ded..0a2d0d4a 100644 --- a/snippets/dart_snippets/lib/pay_onchain.dart +++ b/snippets/dart_snippets/lib/pay_onchain.dart @@ -1,9 +1,9 @@ -import 'package:breez_sdk/breez_sdk.dart'; +import 'package:dart_snippets/sdk_instance.dart'; import 'package:breez_sdk/bridge_generated.dart'; Future getCurrentLimits() async { // ANCHOR: get-current-reverse-swap-limits - OnchainPaymentLimitsResponse currentLimits = await BreezSDK().onchainPaymentLimits(); + OnchainPaymentLimitsResponse currentLimits = await breezSDK.onchainPaymentLimits(); print("Minimum amount, in sats: ${currentLimits.minSat}"); print("Maximum amount, in sats: ${currentLimits.maxSat}"); // ANCHOR_END: get-current-reverse-swap-limits @@ -20,7 +20,7 @@ Future preparePayOnchain({ amountType: SwapAmountType.Send, claimTxFeerate: satPerVbyte, ); - PrepareOnchainPaymentResponse prepareRes = await BreezSDK().prepareOnchainPayment(req: req); + PrepareOnchainPaymentResponse prepareRes = await breezSDK.prepareOnchainPayment(req: req); print("Sender amount: ${prepareRes.senderAmountSat} sats"); print("Recipient amount: ${prepareRes.recipientAmountSat} sats"); print("Total fees: ${prepareRes.totalFees} sats"); @@ -37,14 +37,14 @@ Future startReverseSwap({ recipientAddress: onchainRecipientAddress, prepareRes: prepareRes, ); - PayOnchainResponse res = await BreezSDK().payOnchain(req: req); + PayOnchainResponse res = await breezSDK.payOnchain(req: req); // ANCHOR_END: start-reverse-swap return res; } Future> checkReverseSwapStatus() async { // ANCHOR: check-reverse-swaps-status - List inProgOnchainPaymentList = await BreezSDK().inProgressOnchainPayments(); + List inProgOnchainPaymentList = await breezSDK.inProgressOnchainPayments(); for (var inProgOnchainPayment in inProgOnchainPaymentList) { print("Onchain payment ${inProgOnchainPayment.id} in progress, status is ${inProgOnchainPayment.status.name}"); } diff --git a/snippets/dart_snippets/lib/receive_onchain.dart b/snippets/dart_snippets/lib/receive_onchain.dart index 143e2e87..7dad1cd4 100644 --- a/snippets/dart_snippets/lib/receive_onchain.dart +++ b/snippets/dart_snippets/lib/receive_onchain.dart @@ -1,10 +1,10 @@ -import 'package:breez_sdk/breez_sdk.dart'; +import 'package:dart_snippets/sdk_instance.dart'; import 'package:breez_sdk/bridge_generated.dart'; Future generateReceiveOnchainAddress() async { // ANCHOR: generate-receive-onchain-address ReceiveOnchainRequest req = const ReceiveOnchainRequest(); - SwapInfo swapInfo = await BreezSDK().receiveOnchain(req: req); + SwapInfo swapInfo = await breezSDK.receiveOnchain(req: req); // Send your funds to the below bitcoin address String address = swapInfo.bitcoinAddress; @@ -17,7 +17,7 @@ Future generateReceiveOnchainAddress() async { Future getInProgressSwap() async { // ANCHOR: in-progress-swap - SwapInfo? swapInfo = await BreezSDK().inProgressSwap(); + SwapInfo? swapInfo = await breezSDK.inProgressSwap(); print(swapInfo); // ANCHOR_END: in-progress-swap return swapInfo; @@ -25,7 +25,7 @@ Future getInProgressSwap() async { Future> listRefundables() async { // ANCHOR: list-refundables - List refundables = await BreezSDK().listRefundables(); + List refundables = await breezSDK.listRefundables(); for (var refundable in refundables) { print(refundable.bitcoinAddress); } @@ -44,7 +44,7 @@ Future executeRefund({ toAddress: toAddress, satPerVbyte: satPerVbyte, ); - RefundResponse resp = await BreezSDK().refund(req: req); + RefundResponse resp = await breezSDK.refund(req: req); print(resp.refundTxId); // ANCHOR_END: execute-refund return resp; @@ -56,7 +56,7 @@ Future getChannelOpeningFees({ }) async { // ANCHOR: get-channel-opening-fees OpenChannelFeeRequest req = OpenChannelFeeRequest(amountMsat: amountMsat, expiry: expiry); - OpenChannelFeeResponse resp = await BreezSDK().openChannelFee(req: req); + OpenChannelFeeResponse resp = await breezSDK.openChannelFee(req: req); print(resp.feeMsat); // ANCHOR_END: get-channel-opening-fees return resp; @@ -64,6 +64,6 @@ Future getChannelOpeningFees({ Future rescanSwaps() async { // ANCHOR: rescan-swaps - await BreezSDK().rescanSwaps(); + await breezSDK.rescanSwaps(); // ANCHOR_END: rescan-swaps } diff --git a/snippets/dart_snippets/lib/receive_payment.dart b/snippets/dart_snippets/lib/receive_payment.dart index da284605..aab6974c 100644 --- a/snippets/dart_snippets/lib/receive_payment.dart +++ b/snippets/dart_snippets/lib/receive_payment.dart @@ -1,4 +1,4 @@ -import 'package:breez_sdk/breez_sdk.dart'; +import 'package:dart_snippets/sdk_instance.dart'; import 'package:breez_sdk/bridge_generated.dart'; Future receivePayment() async { @@ -7,7 +7,7 @@ Future receivePayment() async { amountMsat: 3000000, description: "Invoice for 3000 sats", ); - ReceivePaymentResponse receivePaymentResponse = await BreezSDK().receivePayment(req: req); + ReceivePaymentResponse receivePaymentResponse = await breezSDK.receivePayment(req: req); print(receivePaymentResponse.lnInvoice); // ANCHOR_END: receive-payment diff --git a/snippets/dart_snippets/lib/sdk_instance.dart b/snippets/dart_snippets/lib/sdk_instance.dart new file mode 100644 index 00000000..e4d02c27 --- /dev/null +++ b/snippets/dart_snippets/lib/sdk_instance.dart @@ -0,0 +1,3 @@ +import 'package:breez_sdk/breez_sdk.dart'; + +BreezSDK breezSDK = BreezSDK(); diff --git a/snippets/dart_snippets/lib/send_payment.dart b/snippets/dart_snippets/lib/send_payment.dart index a16f993a..54f0de32 100644 --- a/snippets/dart_snippets/lib/send_payment.dart +++ b/snippets/dart_snippets/lib/send_payment.dart @@ -1,4 +1,4 @@ -import 'package:breez_sdk/breez_sdk.dart'; +import 'package:dart_snippets/sdk_instance.dart'; import 'package:breez_sdk/bridge_generated.dart'; Future sendPayment({required String bolt11}) async { @@ -8,7 +8,7 @@ Future sendPayment({required String bolt11}) async { int optionalAmountMsat = 3000000; String optionalLabel = "