@@ -3,11 +3,7 @@ import { getUsername } from '@/wallets/lib/protocols/spark'
33
44export const name = 'SPARK'
55
6- export async function sendPayment ( bolt11 , { mnemonic } , { signal } ) {
7- // TODO(spark): implement
8- }
9-
10- export async function testSendPayment ( { mnemonic } , { signal } ) {
6+ async function withSdk ( mnemonic , cb ) {
117 await init ( )
128
139 const config = defaultConfig ( 'mainnet' )
@@ -22,22 +18,34 @@ export async function testSendPayment ({ mnemonic }, { signal }) {
2218 storageDir : 'breez-sdk-spark'
2319 } )
2420
25- const { paymentRequest : sparkAddress } = await sdk . receivePayment ( {
26- // this will always return the same spark address for the same seed
27- paymentMethod : { type : 'sparkAddress' }
28- } )
21+ const result = await cb ( sdk )
2922
30- // check and register lightning address here
31- // if we haven't already so we can test it in the next step
32- // https://sdk-doc-spark.breez.technology/guide/receive_lnurl_pay.html
33- const username = getUsername ( sparkAddress )
23+ sdk . disconnect ( )
3424
35- const available = await sdk . checkLightningAddressAvailable ( { username } )
36- if ( available ) {
37- await sdk . registerLightningAddress ( { username, description : 'Running Spark SDK' } )
38- }
25+ return result
26+ }
3927
40- sdk . disconnect ( )
28+ export async function sendPayment ( bolt11 , { mnemonic } , { signal } ) {
29+ // TODO(spark): implement
30+ }
4131
42- return { username }
32+ export async function testSendPayment ( { mnemonic } , { signal } ) {
33+ return await withSdk (
34+ mnemonic ,
35+ async sdk => {
36+ const { paymentRequest : sparkAddress } = await sdk . receivePayment ( {
37+ // this will always return the same spark address for the same seed
38+ paymentMethod : { type : 'sparkAddress' }
39+ } )
40+
41+ const username = getUsername ( sparkAddress )
42+
43+ const available = await sdk . checkLightningAddressAvailable ( { username } )
44+ if ( available ) {
45+ await sdk . registerLightningAddress ( { username, description : 'Running Spark SDK' } )
46+ }
47+
48+ return { username }
49+ }
50+ )
4351}
0 commit comments