1- import React from 'react'
21import {
32 getAddressFromBech32 ,
43 getCslUtxos ,
54 getLargestFirstMultiAsset ,
6- getTransactionFromBytes ,
75 getTransactionOutput ,
86 getTransactionWitnessSetFromBytes ,
97 getTxBuilder ,
@@ -23,7 +21,7 @@ const Cip95BuildSignSubmitCard = (props) => {
2321 console . error ( errorMessage )
2422 }
2523
26- const buildSignSubmit = ( ) => {
24+ const buildSignSubmit = async ( ) => {
2725 onWaiting ( true )
2826 try {
2927 // build Tx
@@ -58,33 +56,18 @@ const Cip95BuildSignSubmitCard = (props) => {
5856 const wasmUnsignedTransaction = txBuilder . build_tx ( )
5957 // sign Tx
6058 const unsignedTxHex = bytesToHex ( wasmUnsignedTransaction . to_bytes ( ) )
61-
62- api
63- . signTx ( unsignedTxHex )
64- . then ( ( witnessHex ) => {
65- const wasmUnsignedTransaction = getTransactionFromBytes ( unsignedTxHex )
66- const wasmWitnessSet = getTransactionWitnessSetFromBytes ( witnessHex )
67- const wasmSignedTransaction = getSignedTransaction ( wasmUnsignedTransaction , wasmWitnessSet )
68- const signedTxHex = bytesToHex ( wasmSignedTransaction . to_bytes ( ) )
69-
70- // submit tx
71- api
72- . submitTx ( signedTxHex )
73- . then ( ( txId ) => {
74- onWaiting ( false )
75- console . log ( 'The transaction is sent:' , txId )
76- } )
77- . catch ( ( e ) => {
78- errorHappen ( e )
79- } )
80- } )
81- . catch ( ( e ) => {
82- errorHappen ( e )
83- } )
84-
85- onWaiting ( false )
59+ console . log ( 'Unsigned Tx:' , unsignedTxHex )
60+ const witnessHex = await api ?. signTx ( unsignedTxHex )
61+ const wasmWitnessSet = getTransactionWitnessSetFromBytes ( witnessHex )
62+ const wasmSignedTransaction = getSignedTransaction ( wasmUnsignedTransaction , wasmWitnessSet )
63+ const signedTxHex = bytesToHex ( wasmSignedTransaction . to_bytes ( ) )
64+ console . log ( 'Signed Tx:' , signedTxHex )
65+ const txId = await api ?. submitTx ( signedTxHex )
66+ console . log ( 'The transaction is sent:' , txId )
8667 } catch ( e ) {
8768 errorHappen ( e )
69+ } finally {
70+ onWaiting ( false )
8871 }
8972 }
9073
0 commit comments