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

Commit

Permalink
feat: show block explorer link for non final transactions (#166)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael1011 authored Apr 18, 2019
1 parent 5dd03fb commit bbc3181
Showing 1 changed file with 39 additions and 13 deletions.
52 changes: 39 additions & 13 deletions src/views/refund/refundActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import { ECPair, address, Transaction } from 'bitcoinjs-lib';
import { constructRefundTransaction, detectSwap } from 'boltz-core';
import { boltzApi } from '../../constants';
import * as actionTypes from '../../constants/actions';
import { getHexBuffer, getNetwork, getFeeEstimation } from '../../utils';
import {
getHexBuffer,
getNetwork,
getFeeEstimation,
getExplorer,
} from '../../utils';

const verifyRefundFile = (fileJSON, keys) => {
const verify = keys.every(key => fileJSON.hasOwnProperty(key));
Expand Down Expand Up @@ -110,13 +115,20 @@ export const startRefund = (
feeEstimation
);

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

cb();
})
dispatch(setRefundTransactionHash(transactionId));
dispatch(
broadcastRefund(
currency,
transaction.toHex(),
transactionId,
() => {
dispatch(refundResponse(true, response.data));

cb();
}
)
);
})
);
Expand All @@ -130,20 +142,34 @@ export const startRefund = (
};
};

const broadcastRefund = (currency, refundTransaction, cb) => {
const broadcastRefund = (currency, transaction, transactionId, cb) => {
const url = `${boltzApi}/broadcasttransaction`;
return dispatch => {
dispatch(refundRequest());
axios
.post(url, {
currency,
transactionHex: refundTransaction,
transactionHex: transaction,
})
.then(() => cb())
.catch(error => {
const message = error.response.data.error;

window.alert(`Failed to broadcast refund transaction: ${message}`);
.catch(response => {
const error = response.response.data.error;
let message = `Failed to broadcast refund transaction: ${error}`;

if (
error ===
'please wait until your lockup transaction has 10 confirmations before you try to refund'
) {
message +=
'. Click OK to open the lockup transaction in a block explorer';

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

0 comments on commit bbc3181

Please sign in to comment.