Skip to content

Commit

Permalink
Merge pull request #975 from chronologic/develop
Browse files Browse the repository at this point in the history
Update master to v1.4.1
  • Loading branch information
josipbagaric authored Feb 1, 2019
2 parents 23df73c + 6b72d63 commit 7de64d6
Show file tree
Hide file tree
Showing 7 changed files with 790 additions and 923 deletions.
12 changes: 11 additions & 1 deletion __tests__/TransactionDetails.unit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import TransactionDetails from '../app/components/TransactionScanner/Transaction
import { TransactionStore } from '../app/stores/TransactionStore';
import TokenHelper from '../app/services/token-helper';
import LoadingStateStore from '../app/stores/LoadingStateStore';
import TransactionHelper from '../app/services/transaction-helper';

describe('TransactionDetails', () => {
it('correctly renders', async () => {
Expand Down Expand Up @@ -54,7 +55,16 @@ describe('TransactionDetails', () => {
}
};

const transactionStore = new TransactionStore(eacService, web3Service);
const transactionHelper = new TransactionHelper();

const transactionStore = new TransactionStore(
eacService,
web3Service,
{},
{},
{},
transactionHelper
);
const tokenHelper = new TokenHelper(web3Service);

const loadingStateStore = new LoadingStateStore(web3Service, {}, transactionStore);
Expand Down
7 changes: 5 additions & 2 deletions app/components/TransactionScanner/BlockOrTimeDisplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,13 @@ class BlockOrTimeDisplay extends Component {
}

render() {
const { duration } = this.props;
const { duration, includeUnitText, isTimestamp } = this.props;
const { block, time } = this.state;

if (block) {
return `${block} ${duration ? 'blocks ' : ''}(${time})`;
return `${includeUnitText && !isTimestamp ? 'block ' : ''}${block} ${
duration ? 'blocks ' : ''
}(${time})`;
}

return time;
Expand All @@ -110,6 +112,7 @@ class BlockOrTimeDisplay extends Component {

BlockOrTimeDisplay.propTypes = {
duration: PropTypes.bool,
includeUnitText: PropTypes.any,
isTimestamp: PropTypes.any,
model: PropTypes.any,
eacService: PropTypes.any,
Expand Down
60 changes: 32 additions & 28 deletions app/components/TransactionScanner/TransactionDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,18 +275,6 @@ class TransactionDetails extends Component {
this.setState({ isFrozen: isFrozen || transaction.isCancelled });
}

getTransactionPropertyTimeDisplay(transaction, property) {
let display = '';

if (transaction[property] && transaction[property].toString) {
const parsedUnixTime = moment.unix(transaction[property].toString());

display = parsedUnixTime.format('YYYY/MM/DD HH:mm:ss');
}

return display;
}

handleProxyDataClick() {
this.setState({
proxyDataCheckBox: !this.state.proxyDataCheckBox
Expand Down Expand Up @@ -342,6 +330,8 @@ class TransactionDetails extends Component {
async setupDetails() {
const { transaction, transactionStore, transactionMissingData } = this.props;

await transactionStore.init();

const status = await transactionStore.getTxStatus(transaction, moment().unix());

const statePropertiesToSet = {
Expand Down Expand Up @@ -562,9 +552,32 @@ class TransactionDetails extends Component {
return <ValueDisplay priceInWei={this.props.transaction.callValue} />;
}

isCancelButtonEnabled() {
const { transaction, transactionMissingData, transactionStore } = this.props;
const { isFrozen, status } = this.state;
const isOwner = this.isOwner(transaction);
const isTimestamp = transactionStore.isTxUnitTimestamp(transaction);

let isBeforeClaimWindowStart = false;

if (isTimestamp) {
isBeforeClaimWindowStart = moment.unix(transaction.claimWindowStart) > moment();
} else {
isBeforeClaimWindowStart = transaction.claimWindowStart > transactionStore.lastBlock;
}

return (
!transactionMissingData &&
isOwner &&
!isFrozen &&
((status === TRANSACTION_STATUS.SCHEDULED && isBeforeClaimWindowStart) ||
status === TRANSACTION_STATUS.MISSED)
);
}

render() {
const { transaction, transactionMissingData } = this.props;
const { callData, executedAt, isFrozen, status, tokenTransferApproved } = this.state;
const { transaction, transactionMissingData, transactionStore } = this.props;
const { callData, executedAt, status, tokenTransferApproved } = this.state;
const {
bounty,
callGas,
Expand All @@ -578,7 +591,7 @@ class TransactionDetails extends Component {
} = transaction;

const isOwner = this.isOwner(transaction);
const isTimestamp = transaction.temporalUnit === 2;
const isTimestamp = transactionStore.isTxUnitTimestamp(transaction);

const tokenTransferApprovalStatus = tokenTransferApproved ? 'Approved' : 'Not Approved';

Expand Down Expand Up @@ -714,23 +727,14 @@ class TransactionDetails extends Component {
<div className="col-12">{this.getInfoMessage()}</div>
</div>
<CancelSection
cancelButtonEnabled={
!transactionMissingData &&
isOwner &&
!isFrozen &&
((status === TRANSACTION_STATUS.SCHEDULED &&
moment() < moment.unix(transaction.claimWindowStart)) ||
status === TRANSACTION_STATUS.MISSED)
}
cancelButtonEnabled={this.isCancelButtonEnabled()}
cancelBtnRef={el => (this.cancelBtn = el)}
cancelTransaction={this.cancelTransaction}
claimWindowStart={this.getTransactionPropertyTimeDisplay(transaction, 'claimWindowStart')}
executionWindowEnd={this.getTransactionPropertyTimeDisplay(
transaction,
'executionWindowEnd'
)}
claimWindowStart={transaction.claimWindowStart}
executionWindowEnd={transaction.executionWindowEnd}
isOwner={isOwner}
owner={owner}
isTimestamp={isTimestamp}
/>
<ProxySection
afterExecutionWindow={this.state.afterExecutionWindow}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React from 'react';
import PropTypes from 'prop-types';
import { BlockOrTimeDisplay } from '../BlockOrTimeDisplay';

const CancelSection = props => {
const { cancelButtonEnabled, cancelBtnRef, cancelTransaction, claimWindowStart, executionWindowEnd, isOwner, owner } = props;
const { cancelButtonEnabled, cancelBtnRef, cancelTransaction, claimWindowStart, executionWindowEnd, isOwner, isTimestamp, owner } = props;

return (
<div className="row mt-4">
Expand All @@ -21,12 +22,16 @@ const CancelSection = props => {
<br />
<ol className="list-normalized">
<li>
Before <b>{claimWindowStart}</b>{' '}
Before <b>
<BlockOrTimeDisplay model={claimWindowStart} isTimestamp={isTimestamp} includeUnitText={true} />
</b>{' '}
(Claim Window Start)
</li>
<li>
When wasn&#39;t executed by any TimeNode after{' '}
<b>{executionWindowEnd}</b>{' '}
<b>
<BlockOrTimeDisplay model={executionWindowEnd} isTimestamp={isTimestamp} includeUnitText={true} />
</b>{' '}
(Execution Window End)
</li>
<li>When it hasn&#39;t been already cancelled</li>
Expand Down
4 changes: 3 additions & 1 deletion app/services/transaction-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ export default class TransactionHelper {
if (this.isTxUnitTimestamp(transaction)) {
afterExecutionWindow = transaction.executionWindowEnd.lessThan(currentTimestamp);
} else {
afterExecutionWindow = transaction.executionWindowEnd.lessThan(currentBlock);
if (currentBlock) {
afterExecutionWindow = transaction.executionWindowEnd.lessThan(currentBlock);
}
}

return Boolean(afterExecutionWindow && !transaction.wasCalled);
Expand Down
Loading

0 comments on commit 7de64d6

Please sign in to comment.