1
1
import { BaseWallet } from '@cardano-sdk/wallet' ;
2
2
import { Cardano , Serialization , UtxoProvider } from '@cardano-sdk/core' ;
3
- import { HexBlob , isNotNil } from '@cardano-sdk/util' ;
4
- import { Observable , filter , firstValueFrom , interval , map , switchMap , take } from 'rxjs' ;
3
+ import { HexBlob } from '@cardano-sdk/util' ;
4
+ import { Observable , filter , firstValueFrom , interval , switchMap } from 'rxjs' ;
5
5
import { createLogger } from '@cardano-sdk/util-dev' ;
6
- import { getEnv , getWallet , utxoProviderFactory , walletReady , walletVariables } from '../../../src' ;
6
+ import { getEnv , getWallet , submitAndConfirm , utxoProviderFactory , walletReady , walletVariables } from '../../../src' ;
7
7
8
8
const env = getEnv ( walletVariables ) ;
9
9
const logger = createLogger ( ) ;
@@ -85,7 +85,7 @@ const fundScript = async (wallet: BaseWallet, receivingAddress: Cardano.PaymentA
85
85
const txBuilder = wallet . createTxBuilder ( ) ;
86
86
const txOutput = await txBuilder . buildOutput ( ) . address ( receivingAddress ) . coin ( tAdaToSend ) . datum ( datum ) . build ( ) ;
87
87
const signedTx = ( await txBuilder . addOutput ( txOutput ) . build ( ) . sign ( ) ) . tx ;
88
- await wallet . submitTx ( signedTx ) ;
88
+ const [ , txFoundInHistory ] = await submitAndConfirm ( wallet , signedTx , 1 ) ;
89
89
90
90
logger . info (
91
91
`Submitted transaction id: ${ signedTx . id } , inputs: ${ JSON . stringify (
@@ -95,14 +95,6 @@ const fundScript = async (wallet: BaseWallet, receivingAddress: Cardano.PaymentA
95
95
) } .`
96
96
) ;
97
97
98
- const txFoundInHistory = await firstValueFrom (
99
- wallet . transactions . history$ . pipe (
100
- map ( ( txs ) => txs . find ( ( tx ) => tx . id === signedTx . id ) ) ,
101
- filter ( isNotNil ) ,
102
- take ( 1 )
103
- )
104
- ) ;
105
-
106
98
logger . info ( `Found transaction id in chain history: ${ txFoundInHistory . id } ` ) ;
107
99
108
100
// Assert
@@ -135,7 +127,7 @@ const createScriptRefInput = async (wallet: BaseWallet, script: Cardano.Script):
135
127
. build ( ) ;
136
128
137
129
const signedTx = ( await txBuilder . addOutput ( txOutput ) . build ( ) . sign ( ) ) . tx ;
138
- await wallet . submitTx ( signedTx ) ;
130
+ const [ , txFoundInHistory ] = await submitAndConfirm ( wallet , signedTx , 1 ) ;
139
131
140
132
logger . info (
141
133
`Submitted transaction id: ${ signedTx . id } , inputs: ${ JSON . stringify (
@@ -145,14 +137,6 @@ const createScriptRefInput = async (wallet: BaseWallet, script: Cardano.Script):
145
137
) } .`
146
138
) ;
147
139
148
- const txFoundInHistory = await firstValueFrom (
149
- wallet . transactions . history$ . pipe (
150
- map ( ( txs ) => txs . find ( ( tx ) => tx . id === signedTx . id ) ) ,
151
- filter ( isNotNil ) ,
152
- take ( 1 )
153
- )
154
- ) ;
155
-
156
140
logger . info ( `Found transaction id in chain history: ${ txFoundInHistory . id } ` ) ;
157
141
158
142
// Assert
@@ -243,7 +227,7 @@ describe.skip('PersonalWallet/plutus', () => {
243
227
. sign ( )
244
228
) . tx ;
245
229
246
- await wallet . submitTx ( signedTx ) ;
230
+ const [ , txFoundInHistory ] = await submitAndConfirm ( wallet , signedTx , 1 ) ;
247
231
248
232
logger . info (
249
233
`Submitted transaction id: ${ signedTx . id } , inputs: ${ JSON . stringify (
@@ -253,14 +237,6 @@ describe.skip('PersonalWallet/plutus', () => {
253
237
) } .`
254
238
) ;
255
239
256
- const txFoundInHistory = await firstValueFrom (
257
- wallet . transactions . history$ . pipe (
258
- map ( ( txs ) => txs . find ( ( tx ) => tx . id === signedTx . id ) ) ,
259
- filter ( isNotNil ) ,
260
- take ( 1 )
261
- )
262
- ) ;
263
-
264
240
logger . info ( `Found transaction id in chain history: ${ txFoundInHistory . id } ` ) ;
265
241
266
242
// Assert
@@ -327,7 +303,7 @@ describe.skip('PersonalWallet/plutus', () => {
327
303
. sign ( )
328
304
) . tx ;
329
305
330
- await wallet . submitTx ( signedTx ) ;
306
+ const [ , txFoundInHistory ] = await submitAndConfirm ( wallet , signedTx , 1 ) ;
331
307
332
308
logger . info (
333
309
`Submitted transaction id: ${ signedTx . id } , inputs: ${ JSON . stringify (
@@ -337,14 +313,6 @@ describe.skip('PersonalWallet/plutus', () => {
337
313
) } .`
338
314
) ;
339
315
340
- const txFoundInHistory = await firstValueFrom (
341
- wallet . transactions . history$ . pipe (
342
- map ( ( txs ) => txs . find ( ( tx ) => tx . id === signedTx . id ) ) ,
343
- filter ( isNotNil ) ,
344
- take ( 1 )
345
- )
346
- ) ;
347
-
348
316
logger . info ( `Found transaction id in chain history: ${ txFoundInHistory . id } ` ) ;
349
317
350
318
// Assert
0 commit comments