@@ -3,11 +3,7 @@ import { getUsername } from '@/wallets/lib/protocols/spark'
3
3
4
4
export const name = 'SPARK'
5
5
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 ) {
11
7
await init ( )
12
8
13
9
const config = defaultConfig ( 'mainnet' )
@@ -22,22 +18,34 @@ export async function testSendPayment ({ mnemonic }, { signal }) {
22
18
storageDir : 'breez-sdk-spark'
23
19
} )
24
20
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 )
29
22
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 ( )
34
24
35
- const available = await sdk . checkLightningAddressAvailable ( { username } )
36
- if ( available ) {
37
- await sdk . registerLightningAddress ( { username, description : 'Running Spark SDK' } )
38
- }
25
+ return result
26
+ }
39
27
40
- sdk . disconnect ( )
28
+ export async function sendPayment ( bolt11 , { mnemonic } , { signal } ) {
29
+ // TODO(spark): implement
30
+ }
41
31
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
+ )
43
51
}
0 commit comments