Skip to content
This repository was archived by the owner on Apr 28, 2023. It is now read-only.

Commit

Permalink
fix: block explorer link in non final dialog (#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael1011 authored Apr 19, 2019
1 parent 8773ada commit e3ec1e9
Showing 1 changed file with 30 additions and 23 deletions.
53 changes: 30 additions & 23 deletions src/views/refund/refundActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const refundResponse = (success, response) => ({
},
});

const refundTransaction = (
const createRefundTransaction = (
refundFile,
response,
destinationAddress,
Expand All @@ -73,19 +73,22 @@ const refundTransaction = (
const lockupTransaction = Transaction.fromHex(response.data.transactionHex);

// TODO: make sure the provided lockup transaction hash was correct and show more specific error if not
return constructRefundTransaction(
[
{
redeemScript,
txHash: lockupTransaction.getHash(),
keys: ECPair.fromPrivateKey(getHexBuffer(refundFile.privateKey)),
...detectSwap(redeemScript, lockupTransaction),
},
],
address.toOutputScript(destinationAddress, getNetwork(currency)),
refundFile.timeoutBlockHeight,
feeEstimation[currency]
);
return {
refundTransaction: constructRefundTransaction(
[
{
redeemScript,
txHash: lockupTransaction.getHash(),
keys: ECPair.fromPrivateKey(getHexBuffer(refundFile.privateKey)),
...detectSwap(redeemScript, lockupTransaction),
},
],
address.toOutputScript(destinationAddress, getNetwork(currency)),
refundFile.timeoutBlockHeight,
feeEstimation[currency]
),
lockupTransactionId: lockupTransaction.getId(),
};
};

export const startRefund = (
Expand All @@ -107,22 +110,23 @@ export const startRefund = (
.then(response => {
dispatch(
getFeeEstimation(feeEstimation => {
const transaction = refundTransaction(
const {
refundTransaction,
lockupTransactionId,
} = createRefundTransaction(
refundFile,
response,
destinationAddress,
currency,
feeEstimation
);

const transactionId = transaction.getId();

dispatch(setRefundTransactionHash(transactionId));
dispatch(setRefundTransactionHash(refundTransaction.getId()));
dispatch(
broadcastRefund(
currency,
transaction.toHex(),
transactionId,
refundTransaction.toHex(),
lockupTransactionId,
() => {
dispatch(refundResponse(true, response.data));

Expand All @@ -142,14 +146,14 @@ export const startRefund = (
};
};

const broadcastRefund = (currency, transaction, transactionId, cb) => {
const broadcastRefund = (currency, transactionHex, lockupTransactionId, cb) => {
const url = `${boltzApi}/broadcasttransaction`;
return dispatch => {
dispatch(refundRequest());
axios
.post(url, {
currency,
transactionHex: transaction,
transactionHex,
})
.then(() => cb())
.catch(response => {
Expand All @@ -165,7 +169,10 @@ const broadcastRefund = (currency, transaction, transactionId, cb) => {

const openExplorer = window.confirm(message);
if (openExplorer) {
window.open(`${getExplorer(currency)}/${transactionId}`, '_blank');
window.open(
`${getExplorer(currency)}/${lockupTransactionId}`,
'_blank'
);
}
} else {
window.alert(message);
Expand Down

0 comments on commit e3ec1e9

Please sign in to comment.