feat: fetch refund txid

This commit is contained in:
Shubham Kumar
2025-05-19 19:06:07 -04:00
committed by Evan Kaloudis
parent 08788e5ff4
commit 27e4357d9b
4 changed files with 30 additions and 35 deletions
@@ -213,8 +213,8 @@ class LncModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMod
Log.d("createRefundTransaction called", "");
try {
Lndmobile.createRefundTransaction(endpoint, swapId, claimLeaf, refundLeaf, transactionHex, privateKey, servicePubKey, feeRate, timeoutBlockHeight, destinationAddress, lockupAddress, isTestnet)
promise.resolve(null)
var txid = Lndmobile.createRefundTransaction(endpoint, swapId, claimLeaf, refundLeaf, transactionHex, privateKey, servicePubKey, feeRate, timeoutBlockHeight, destinationAddress, lockupAddress, isTestnet)
promise.resolve(txid)
} catch (e: Exception) {
val exceptionAsString = e.toString()
promise.reject(exceptionAsString)
+2 -2
View File
@@ -306,12 +306,12 @@ RCT_EXPORT_METHOD(createRefundTransaction:(NSString *)endpoint
rejecter:(RCTPromiseRejectBlock)reject)
{
NSError *error;
LndmobileCreateRefundTransaction(endpoint, swapId, claimLeaf, refundLeaf, transactionHex, privateKey, servicePubKey, feeRate, timeoutBlockHeight, destinationAddress, lockupAddress, isTestnet, &error);
NSString *txid = LndmobileCreateRefundTransaction(endpoint, swapId, claimLeaf, refundLeaf, transactionHex, privateKey, servicePubKey, feeRate, timeoutBlockHeight, destinationAddress, lockupAddress, isTestnet, &error);
if (error) {
NSLog(@"createRefundTransaction error %@", error);
reject(@"createRefundTransaction_error", error.localizedDescription, error);
} else {
resolve(@"Success");
resolve(txid);
}
}
+2 -2
View File
@@ -144,7 +144,7 @@ export const createRefundTransaction = async ({
isTestnet?: boolean;
}): Promise<string> => {
try {
const error: string = await LncModule.createRefundTransaction(
const txid: string = await LncModule.createRefundTransaction(
endpoint,
swapId,
claimLeaf,
@@ -158,7 +158,7 @@ export const createRefundTransaction = async ({
lockupAddress,
isTestnet
);
return error;
return txid;
} catch (e) {
throw e;
}
+24 -29
View File
@@ -65,9 +65,9 @@ export default class RefundSwap extends React.Component<
fee: any,
endpoint: string,
destinationAddress: string
): Promise<boolean> => {
): Promise<void> => {
try {
await createRefundTransaction({
const txid = await createRefundTransaction({
endpoint: endpoint.replace('/v2', ''),
swapId: swapData.id,
claimLeaf: swapData.swapTree.claimLeaf.output,
@@ -83,15 +83,14 @@ export default class RefundSwap extends React.Component<
});
this.setState({
loading: false,
refundStatus: 'Refund transaction created successfully'
refundStatus: `Refund transaction created successfully. TXID: ${txid}`
});
console.log('Refund transaction created successfully');
return true;
console.log('Refund transaction created successfully. TXID:', txid);
} catch (error: any) {
this.setState({ loading: false, error: error.message });
console.error('Error creating refund transaction:', error);
return false;
throw error;
}
};
@@ -174,38 +173,34 @@ export default class RefundSwap extends React.Component<
error: '',
refundStatus: ''
});
let submitted = false;
try {
if (submitted) {
this.setState({
refundStatus:
'Refund Transaction already created and submitted successfully'
});
console.log(
'Refund Transaction already created and submitted successfully. Skipping.'
// Fetch the lockup transaction
const lockupTransaction =
await SwapStore?.getLockupTransaction(
swapData.id
);
} else {
const lockupTransaction =
await SwapStore?.getLockupTransaction(
swapData.id
);
submitted = await this.createRefundTransaction(
swapData,
lockupTransaction,
fee,
HOST,
destinationAddress
);
}
// Create and submit the refund transaction
await this.createRefundTransaction(
swapData,
lockupTransaction,
fee,
HOST,
destinationAddress
);
console.log(
'Refund transaction created successfully.'
);
} catch (error) {
console.error('Error in refund process:', error);
} finally {
this.setState({ loading: false });
}
console.log('Refund submission status:', submitted);
}}
secondary
disabled={!destinationAddress}
disabled={!destinationAddress || this.state.loading}
/>
</Screen>
);