Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
roma219 committed Apr 4, 2018
1 parent f76e5ce commit 6aaa4f3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
17 changes: 11 additions & 6 deletions src/actions/transactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,20 @@ export const removePendingDistribution = (store) => {
commit(types.REMOVE_PENDING_DISTRIBUTION);
};


export const handleOrdersError = (store) => {
const { commit } = store;
commit(types.PROCESS_PENDING_ORDERS_ERROR);
createOrdersFromDistribution(store);
};


export const processPendingOrders = async (store) => {
const { getters, commit, rootGetters } = store;
commit(types.PROCESS_PENDING_ORDERS_REQUEST);
const keys = rootGetters['account/getKeys'];
if (!keys) {
commit(types.PROCESS_PENDING_ORDERS_ERROR);
createOrdersFromDistribution(store);
handleOrdersError(store);
return {
success: false,
error: 'Account is locked'
Expand All @@ -101,8 +108,7 @@ export const processPendingOrders = async (store) => {
orders: pendingOrders.sellOrders,
keys });
if (!sellResult.success) {
commit(types.PROCESS_PENDING_ORDERS_ERROR);
createOrdersFromDistribution(store);
handleOrdersError(store);
return {
success: false,
error: sellResult.error
Expand All @@ -117,8 +123,7 @@ export const processPendingOrders = async (store) => {
});
console.log(buyResult);
if (!buyResult.success) {
commit(types.PROCESS_PENDING_ORDERS_ERROR);
createOrdersFromDistribution(store);
handleOrdersError(store);
return {
success: false,
error: buyResult.error
Expand Down
11 changes: 8 additions & 3 deletions src/modules/transactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import * as actions from '../actions/transactions';

const initialState = {
pendingDistributionUpdate: null,
pendingOrders: {},
pendingOrders: {
sellOrders: [],
buyOrders: []
},
pendingTransfer: false,
pending: false,
error: null,
Expand All @@ -24,7 +27,8 @@ const initialState = {

const getters = {
getPendingOrders: state => state.pendingOrders,
hasPendingOrders: state => state.pendingOrders.sellOrders || state.pendingOrders.buyOrders,
hasPendingOrders: state => state.pendingOrders.sellOrders.length
|| state.pendingOrders.buyOrders.length,
getPendingDistribution: state => state.pendingDistributionUpdate,
hasPendingTransfer: state => state.pendingTransfer !== false,
areTransactionsProcessing: state => state.transactionsProcessing,
Expand Down Expand Up @@ -61,7 +65,8 @@ const mutations = {
},
[types.REMOVE_PENDING_DISTRIBUTION](state) {
state.pendingDistributionUpdate = null;
state.pendingOrders = {};
state.pendingOrders.sellOrders = [];
state.pendingOrders.buyOrders = [];
state.sellOrdersProcessed = false;
},
[types.PROCESS_PENDING_ORDERS_REQUEST](state) {
Expand Down

0 comments on commit 6aaa4f3

Please sign in to comment.