Merge pull request #270 from status-im/fix/infinite-loop

Fix infinite loop in the Sell page and add txHash to addOffer
This commit is contained in:
Jonathan Rainville 2019-05-24 15:02:02 -04:00 committed by GitHub
commit 9f1ee69cec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 11 deletions

View File

@ -120,10 +120,10 @@ module.exports = async (licensePrice, arbitrationLicensePrice, feeAmount, deps)
await rate.send({from: buyerAddress, gas: gas + 1000}); await rate.send({from: buyerAddress, gas: gas + 1000});
})); }));
console.log('Creating arbitrations'); console.log('Creating arbitrations');
await Promise.all(addresses.slice(escrowStartIndex, 5).map(async (creatorAddress, idx) => { await Promise.all(addresses.slice(escrowStartIndex, 5).map(async (creatorAddress, idx) => {
const ethOfferId = offerReceipts[idx - offerStartIndex + escrowStartIndex].events.OfferAdded.returnValues.offerId; const ethOfferId = offerReceipts[idx - offerStartIndex + escrowStartIndex].events.OfferAdded.returnValues.offerId;
let gas, receipt; let gas, receipt;
@ -141,8 +141,8 @@ module.exports = async (licensePrice, arbitrationLicensePrice, feeAmount, deps)
const pay = deps.contracts.Escrow.methods.pay(escrowId); const pay = deps.contracts.Escrow.methods.pay(escrowId);
gas = await pay.estimateGas({from: buyerAddress}); gas = await pay.estimateGas({from: buyerAddress});
receipt = await pay.send({from: buyerAddress, gas: gas + 1000}); receipt = await pay.send({from: buyerAddress, gas: gas + 1000});
const openCase = deps.contracts.Escrow.methods.openCase(escrowId); const openCase = deps.contracts.Escrow.methods.openCase(escrowId, 'My Motive is...');
gas = await openCase.estimateGas({from: buyerAddress}); gas = await openCase.estimateGas({from: buyerAddress});
receipt = await openCase.send({from: buyerAddress, gas: gas + 1000}); receipt = await openCase.send({from: buyerAddress, gas: gas + 1000});
})); }));

View File

@ -1,6 +1,6 @@
import { import {
LOAD_OFFERS_SUCCEEDED, LOAD_USER_SUCCEEDED, LOAD_OFFERS_SUCCEEDED, LOAD_USER_SUCCEEDED,
ADD_OFFER, ADD_OFFER_SUCCEEDED, ADD_OFFER_FAILED, RESET_ADD_OFFER_STATUS, ADD_OFFER, ADD_OFFER_SUCCEEDED, ADD_OFFER_FAILED, RESET_ADD_OFFER_STATUS, ADD_OFFER_PRE_SUCCESS,
UPDATE_USER, UPDATE_USER_SUCCEEDED, UPDATE_USER_FAILED, RESET_UPDATE_USER_STATUS, UPDATE_USER, UPDATE_USER_SUCCEEDED, UPDATE_USER_FAILED, RESET_UPDATE_USER_STATUS,
LOAD_USER_LOCATION_SUCCEEDED, SET_CURRENT_USER, LOAD_USER_TRADE_NUMBER_SUCCEEDED LOAD_USER_LOCATION_SUCCEEDED, SET_CURRENT_USER, LOAD_USER_TRADE_NUMBER_SUCCEEDED
} from './constants'; } from './constants';
@ -11,6 +11,7 @@ import {toChecksumAddress} from '../../utils/address';
const DEFAULT_STATE = { const DEFAULT_STATE = {
addOfferStatus: States.none, addOfferStatus: States.none,
addOfferTx: '',
updateUserStatus: States.none, updateUserStatus: States.none,
users: {}, users: {},
offers: {} offers: {}
@ -30,11 +31,20 @@ function reducer(state = DEFAULT_STATE, action) {
switch (action.type) { switch (action.type) {
case RESET_ADD_OFFER_STATUS: case RESET_ADD_OFFER_STATUS:
return { return {
...state, addOfferStatus: States.none ...state,
addOfferStatus: States.none,
addOfferTx: ''
}; };
case ADD_OFFER: case ADD_OFFER:
return { return {
...state, addOfferStatus: States.pending ...state,
addOfferStatus: States.pending,
addOfferTx: ''
};
case ADD_OFFER_PRE_SUCCESS:
return {
...state,
addOfferTx: action.txHash
}; };
case ADD_OFFER_SUCCEEDED: { case ADD_OFFER_SUCCEEDED: {
return { return {

View File

@ -62,3 +62,5 @@ export const getUsersWithOffers = (state) => {
}; };
export const getAllUsers = state => state.metadata.users; export const getAllUsers = state => state.metadata.users;
export const getAddOfferTx = state => state.metadata.addOfferTx;

View File

@ -8,6 +8,7 @@ import {
SET_ARBITRATOR SET_ARBITRATOR
} from './constants'; } from './constants';
import {RESET_STATE, PURGE_STATE} from "../network/constants"; import {RESET_STATE, PURGE_STATE} from "../network/constants";
import {ADD_OFFER_SUCCEEDED} from '../metadata/constants';
const DEFAULT_STATE = { const DEFAULT_STATE = {
asset: '', asset: '',
@ -60,6 +61,7 @@ function reducer(state = DEFAULT_STATE, action) {
username: action.username, username: action.username,
statusContactCode: action.statusContactCode statusContactCode: action.statusContactCode
}; };
case ADD_OFFER_SUCCEEDED:
case PURGE_STATE: case PURGE_STATE:
case RESET_STATE: { case RESET_STATE: {
return DEFAULT_STATE; return DEFAULT_STATE;

View File

@ -38,7 +38,7 @@ class Margin extends Component {
}; };
componentDidMount() { componentDidMount() {
if (!this.props.seller.currency) { if (!this.props.seller.currency && this.props.addOfferStatus !== States.success) {
this.props.wizard.previous(); this.props.wizard.previous();
} else { } else {
this.setState({ready: true}); this.setState({ready: true});
@ -79,7 +79,7 @@ class Margin extends Component {
switch(this.props.addOfferStatus){ switch(this.props.addOfferStatus){
case States.pending: case States.pending:
return <Loading mining/>; return <Loading mining txHash={this.props.txHash}/>;
case States.failed: case States.failed:
return <ErrorInformation transaction retry={this.postOffer} cancel={this.props.resetAddOfferStatus}/>; return <ErrorInformation transaction retry={this.postOffer} cancel={this.props.resetAddOfferStatus}/>;
case States.none: case States.none:
@ -112,7 +112,8 @@ Margin.propTypes = {
wizard: PropTypes.object, wizard: PropTypes.object,
footer: PropTypes.object, footer: PropTypes.object,
getFee: PropTypes.func, getFee: PropTypes.func,
fee: PropTypes.string fee: PropTypes.string,
txHash: PropTypes.string
}; };
const mapStateToProps = state => ({ const mapStateToProps = state => ({
@ -120,7 +121,8 @@ const mapStateToProps = state => ({
addOfferStatus: metadata.selectors.getAddOfferStatus(state), addOfferStatus: metadata.selectors.getAddOfferStatus(state),
token: network.selectors.getTokenByAddress(state, newSeller.selectors.getNewSeller(state).asset), token: network.selectors.getTokenByAddress(state, newSeller.selectors.getNewSeller(state).asset),
prices: prices.selectors.getPrices(state), prices: prices.selectors.getPrices(state),
fee: escrow.selectors.getFee(state) fee: escrow.selectors.getFee(state),
txHash: metadata.selectors.getAddOfferTx(state)
}); });
export default connect( export default connect(