Skip to content

Commit

Permalink
Merge pull request #80 from tokenman-dev/fix/order-auction
Browse files Browse the repository at this point in the history
Fix: split nodelogic and applogic order creation call
  • Loading branch information
josadcha committed May 29, 2020
2 parents c4dfb39 + c8094b4 commit 8715031
Show file tree
Hide file tree
Showing 17 changed files with 115 additions and 30 deletions.
2 changes: 1 addition & 1 deletion mocks/api/v2/peatio/account/balances/GET.mock
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Access-Control-Allow-Credentials: true
},
{
"currency":"usdt",
"balance":"1.0",
"balance":"1000.0",
"locked":"0.0"
}
]
1 change: 1 addition & 0 deletions public/config/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ window.env = {
zendeskUrl: 'https://wiprex.zendesk.com',
finexUrl: '',
moonPayUrl: 'https://buy-staging.moonpay.io',
nodelogicUrl: '',
},
minutesUntilAutoLogout: '5',
withCredentials: false,
Expand Down
2 changes: 1 addition & 1 deletion src/custom/containers/AccountHistory/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class AccountComponent extends React.Component<Props, State> {
public renderContent = list => {
const { markets, primaryCurrency, wallet, currencies, tickers } = this.props;
const estimateMarket = markets.find(market => market.id === primaryCurMarketId);
const estimatePrecision = primaryCurrency.toLowerCase() === estimateMarket.base_unit ? estimateMarket.amount_precision : estimateMarket.price_precision;
const estimatePrecision = estimateMarket ? primaryCurrency.toLowerCase() === estimateMarket.base_unit ? estimateMarket.amount_precision : estimateMarket.price_precision : 0;
const estimateCurrency = estimateUnitValue(primaryCurrency, wallet.currency.toLowerCase(), 1, currencies, markets, tickers);

return (
Expand Down
2 changes: 1 addition & 1 deletion src/custom/containers/AuctionHistory/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ class HistoryComponent extends React.Component<Props, State> {
private retrieveData = () => {
const { copyrightHistory, marketsData, primaryCurrency } = this.props;
const estimateMarket = marketsData.find(market => market.id === primaryCurMarketId);
const estimatePrecision = primaryCurrency.toLowerCase() === estimateMarket.base_unit ? estimateMarket.amount_precision : estimateMarket.price_precision;
const estimatePrecision = estimateMarket ? primaryCurrency.toLowerCase() === estimateMarket.base_unit ? estimateMarket.amount_precision : estimateMarket.price_precision : 0;

return [...copyrightHistory]
.map(item => this.renderTableRow(item, +estimatePrecision));
Expand Down
2 changes: 1 addition & 1 deletion src/custom/containers/ClosedOrders/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class ClosedOrdersComponent extends React.Component<Props> {
private renderTable = () => {
const {closedOrders, markets, primaryCurrency, currentMarket, currencies, tickers} = this.props;
const estimateMarket = markets.find(market => market.id === primaryCurMarketId);
const estimatePrecision = primaryCurrency.toLowerCase() === estimateMarket.base_unit ? estimateMarket.amount_precision : estimateMarket.price_precision;
const estimatePrecision = estimateMarket ? primaryCurrency.toLowerCase() === estimateMarket.base_unit ? estimateMarket.amount_precision : estimateMarket.price_precision : 0;
const estimateCurrency = estimateUnitValue(primaryCurrency, currentMarket.quote_unit, 1, currencies, markets, tickers);

return (
Expand Down
2 changes: 1 addition & 1 deletion src/custom/containers/HeaderToolbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class HeaderToolbarContainer extends React.Component<Props> {

const estimateCurrency = estimateUnitValue(primaryCurrency, formattedMarket.quote_unit, 1, currencies, markets, tickers);
const estimateMarket = markets.find(market => market.id === primaryCurMarketId);
const estimatePrecision = primaryCurrency.toLowerCase() === estimateMarket.base_unit ? estimateMarket.amount_precision : estimateMarket.price_precision;
const estimatePrecision = estimateMarket ? primaryCurrency.toLowerCase() === estimateMarket.base_unit ? estimateMarket.amount_precision : estimateMarket.price_precision : 0;

return (
<div className={marketChangeClass}>
Expand Down
2 changes: 1 addition & 1 deletion src/custom/containers/HistoryElement/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ class HistoryComponent extends React.Component<Props, State> {
private retrieveData = () => {
const { list, marketsData, primaryCurrency } = this.props;
const estimateMarket = marketsData.find(i => i.id === primaryCurMarketId);
const estimatePrecision = primaryCurrency.toLowerCase() === estimateMarket.base_unit ? estimateMarket.amount_precision : estimateMarket.price_precision;
const estimatePrecision = estimateMarket ? primaryCurrency.toLowerCase() === estimateMarket.base_unit ? estimateMarket.amount_precision : estimateMarket.price_precision : 0;

return [...list]
.map(item => this.renderTableRow(item, +estimatePrecision));
Expand Down
2 changes: 1 addition & 1 deletion src/custom/containers/Order/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class OrderInsert extends React.PureComponent<Props, StoreProps> {
const defaultCurrentTicker = { last: '0' };

const estimateMarket = markets.find(i => i.id === primaryCurMarketId);
const estimatePrecision = primaryCurrency.toLowerCase() === estimateMarket.base_unit ? estimateMarket.amount_precision : estimateMarket.price_precision;
const estimatePrecision = estimateMarket ? primaryCurrency.toLowerCase() === estimateMarket.base_unit ? estimateMarket.amount_precision : estimateMarket.price_precision : 0;

return (
<div className={!isMobile ? 'pg-order' : 'pg-order-mobile'} ref={this.orderRef}>
Expand Down
2 changes: 1 addition & 1 deletion src/custom/containers/OrderConfirmModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class OrderConfirmComponent extends React.PureComponent<Props> {
const formattedMarket = currentMarket && addTickerToMarket(currentMarket, tickers);
const priceEstimated = estimateUnitValue(primaryCurrency, formattedMarket.quote_unit, +price, currencies, markets, tickers);
const estimateMarket = markets.find(i => i.id === primaryCurMarketId);
const estimatePrecision = primaryCurrency.toLowerCase() === estimateMarket.base_unit ? estimateMarket.amount_precision : estimateMarket.price_precision;
const estimatePrecision = estimateMarket ? primaryCurrency.toLowerCase() === estimateMarket.base_unit ? estimateMarket.amount_precision : estimateMarket.price_precision : 0;

return (
<div>
Expand Down
31 changes: 26 additions & 5 deletions src/plugins/auction/modules/user/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import {
AUCTION_ROYALTY_FETCH,
AUCTION_ROYALTY_DATA,
AUCTION_ROYALTY_ERROR,
ORDER_NODELOGIC_FETCH,
ORDER_NODELOGIC_ERROR,
} from './constants';
import { OrderAuctionData , DataAuctionInterface, DetailsAuctionInterface, AuctionRoyalty, MyBid } from './types';

Expand Down Expand Up @@ -126,10 +128,7 @@ export interface OrderAuctionExecution {

export interface OrderAuctionExecuteFetch {
type: typeof AUCTION_ORDER_EXECUTE_FETCH;
payload: {
order: OrderAuctionExecution,
generalInfo ? : NodelogicAuctionOrderExcution,
};
payload: OrderAuctionExecution;
}

export interface OrderAuctionExecuteData {
Expand All @@ -142,6 +141,16 @@ export interface OrderAuctionExecuteError {
payload: CommonError;
}

export interface OrderNodelogicFetch {
type: typeof ORDER_NODELOGIC_FETCH;
payload: NodelogicAuctionOrderExcution;
}

export interface OrderNodelogicError {
type: typeof ORDER_NODELOGIC_ERROR;
payload: CommonError;
}

export interface OrdersAuctionFetch {
type: typeof AUCTION_ORDERS_FETCH;
payload ? : {
Expand Down Expand Up @@ -236,7 +245,9 @@ export type AuctionOrderAction =
HistoryAuctionFetch |
HistoryAuctionError |
OrdersAuctionPop |
OrdersAuctionPush;
OrdersAuctionPush |
OrderNodelogicFetch |
OrderNodelogicError;

export const auctionUpdate = (payload: UpdateAuction['payload']): UpdateAuction => ({
type: AUCTION_UPDATE,
Expand Down Expand Up @@ -326,6 +337,16 @@ export const auctionOrderExecuteError = (payload: OrderAuctionExecuteError['payl
payload,
});

export const orderNodelogicFetch = (payload: OrderNodelogicFetch['payload']): OrderNodelogicFetch => ({
type: ORDER_NODELOGIC_FETCH,
payload,
});

export const orderNodelogicError = (payload: OrderNodelogicError['payload']): OrderNodelogicError => ({
type: ORDER_NODELOGIC_ERROR,
payload,
});

export const auctionOrderCancel = (payload: OrderAuctionCancelFetch['payload']): OrderAuctionCancelFetch => ({
type: AUCTION_ORDER_CANCEL_FETCH,
payload,
Expand Down
3 changes: 3 additions & 0 deletions src/plugins/auction/modules/user/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ export const AUCTION_UPDATE_CURRENT_AUCTION = 'AUCTION/UPDATE_CURRENT_AUCTION';
export const AUCTION_ROYALTY_FETCH = 'AUCTION/ROYALTY_FETCH';
export const AUCTION_ROYALTY_DATA = 'AUCTION/ROYALTY_DATA';
export const AUCTION_ROYALTY_ERROR = 'AUCTION/ROYALTY_ERROR';

export const ORDER_NODELOGIC_FETCH = 'AUCTION/ORDER_NODELOGIC_FETCH';
export const ORDER_NODELOGIC_ERROR = 'AUCTION/ORDER_NODELOGIC_ERROR';
41 changes: 41 additions & 0 deletions src/plugins/auction/modules/user/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import {
AUCTION_ROYALTY_FETCH,
AUCTION_ROYALTY_DATA,
AUCTION_ROYALTY_ERROR,
ORDER_NODELOGIC_FETCH,
ORDER_NODELOGIC_ERROR,
} from './constants';
import { DataAuctionInterface, DetailsAuctionInterface, OrderAuctionData, AuctionRoyalty, DetailsAuctionInterfaceRanger, MyBid } from './types';
import { reverseGenericBids } from './helpers';
Expand All @@ -38,6 +40,7 @@ export interface PublicAuctionState {
list: DataAuctionInterface[];
success: boolean;
error?: CommonError;
nodeLogicError?: CommonError;
}

export interface OrderAuctionState extends CommonState {
Expand Down Expand Up @@ -66,6 +69,12 @@ export interface OrderAuctionState extends CommonState {
success: boolean;
error?: CommonError;
};
orderNodeLogic: {
loading: boolean;
success: boolean;
data?: OrderAuctionData;
error?: CommonError;
};
}

export const initialPublicAuctionState: PublicAuctionState = {
Expand Down Expand Up @@ -95,6 +104,10 @@ export const initialOrderAuctionState: OrderAuctionState = {
total: 0,
page: 0,
},
orderNodeLogic: {
success: false,
loading: false,
},
};


Expand Down Expand Up @@ -275,6 +288,27 @@ const auctionOrderExecuteReducer = (state: OrderAuctionState['execute'], action:
}
};

const orderNodeLogicReducer = (state: OrderAuctionState['orderNodeLogic'], action: AuctionOrderAction) => {
switch (action.type) {
case ORDER_NODELOGIC_FETCH:
return {
...state,
success: false,
loading: true,
nodeLogicError: undefined,
};
case ORDER_NODELOGIC_ERROR:
return {
...state,
success: false,
loading: false,
nodeLogicError: action.payload,
};
default:
return state;
}
};

const auctionOrdersFetchReducer = (state: OrderAuctionState['fetch'], action: AuctionOrderAction) => {
switch (action.type) {
case AUCTION_ORDERS_FETCH:
Expand Down Expand Up @@ -379,6 +413,13 @@ export const auctionOrderReducer = (state = initialOrderAuctionState, action: Au
...state,
execute: auctionOrderExecuteReducer(auctionOrderExecuteState, action),
};
case ORDER_NODELOGIC_FETCH:
case ORDER_NODELOGIC_ERROR:
const ordernodeLogicState = { ...state.orderNodeLogic };
return {
...state,
orderNodeLogic: orderNodeLogicReducer(ordernodeLogicState, action),
};
case AUCTION_HISTORY_FETCH:
case AUCTION_HISTORY_DATA:
case AUCTION_HISTORY_ERROR:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ describe('Auction Order Execute', () => {
};

const expectedActionsSuccess = [
auctionOrderExecuteFetch({order: fakePayload}),
auctionOrderExecuteFetch(fakePayload),
auctionOrderExecuteData(fakeOrder),
updateCurrentAuction(fakeOrder),
alertPush({ message: ['success.order.created'], type: 'success'}),
];

const expectedActionsError = [
auctionOrderExecuteFetch({order: fakePayload}),
auctionOrderExecuteFetch(fakePayload),
auctionOrderExecuteError({ code: 500, message: ['Server error'] }),
];

Expand All @@ -90,7 +90,7 @@ describe('Auction Order Execute', () => {
}
});
});
store.dispatch(auctionOrderExecuteFetch({order: fakePayload}));
store.dispatch(auctionOrderExecuteFetch(fakePayload));
return promise;
});

Expand All @@ -105,7 +105,7 @@ describe('Auction Order Execute', () => {
}
});
});
store.dispatch(auctionOrderExecuteFetch({order: fakePayload}));
store.dispatch(auctionOrderExecuteFetch(fakePayload));
return promise;
});
});
Expand Down
13 changes: 1 addition & 12 deletions src/plugins/auction/modules/user/sagas/auctionOrderCreateSaga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,9 @@ const auctionOrderOptions = (csrfToken?: string): RequestOptions => {
};
};

const nodelogicAuctionOrderOptions = (csrfToken?: string): RequestOptions => {
return {
apiVersion: 'nodelogic',
headers: { 'X-CSRF-Token': csrfToken },
};
};

export function* auctionOrderCreateSaga(action: OrderAuctionExecuteFetch) {
try {
if (action.payload.generalInfo !== undefined) {
yield call(API.post(nodelogicAuctionOrderOptions(getCsrfToken())), '/orders', action.payload.generalInfo);
}
const order = yield call(API.post(auctionOrderOptions(getCsrfToken())), '/private/auctions/orders', action.payload.order);

const order = yield call(API.post(auctionOrderOptions(getCsrfToken())), '/private/auctions/orders', action.payload);
yield put(auctionOrderExecuteData(order));
yield put(updateCurrentAuction(order));
yield put(alertPush({ message: ['success.order.created'], type: 'success'}));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// tslint:disable-next-line
import { call, put } from 'redux-saga/effects';
import { API, RequestOptions } from '../../../../../api';
import {
orderNodelogicError,
OrderNodelogicFetch,
} from '../actions';
import { getCsrfToken } from '../../../../../helpers';

const nodelogicAuctionOrderOptions = (csrfToken?: string): RequestOptions => {
return {
apiVersion: 'nodelogic',
headers: { 'X-CSRF-Token': csrfToken },
};
};

export function* createFixedOrderNodelogic(action: OrderNodelogicFetch) {
try {
yield call(API.post(nodelogicAuctionOrderOptions(getCsrfToken())), '/orders', action.payload);
} catch (error) {
yield put(orderNodelogicError(error));
}
}
3 changes: 3 additions & 0 deletions src/plugins/auction/modules/user/sagas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
AUCTION_ORDER_EXECUTE_FETCH,
AUCTION_ORDERS_FETCH,
AUCTION_ROYALTY_FETCH,
ORDER_NODELOGIC_FETCH,
} from '../constants';
import { auctionHistorySaga } from './auctionHistorySaga';
import { auctionOrderCancelSaga } from './auctionOrderCancelSaga';
Expand All @@ -16,6 +17,7 @@ import { auctionOrdersSaga } from './auctionOrdersSaga';
import { auctionItemSaga } from './auctionItemSaga';
import { auctionSaga } from '../../user/sagas/auctionSaga';
import { auctionRoyaltySaga } from './auctionRoyaltySaga';
import { createFixedOrderNodelogic } from './createFixedOrderNodelogic';

export function* rootUserAuctionSaga() {
yield takeEvery(AUCTION_FETCH, auctionSaga);
Expand All @@ -25,4 +27,5 @@ export function* rootUserAuctionSaga() {
yield takeEvery(AUCTION_ORDER_EXECUTE_FETCH, auctionOrderCreateSaga);
yield takeLatest(AUCTION_HISTORY_FETCH, auctionHistorySaga);
yield takeEvery(AUCTION_ROYALTY_FETCH ,auctionRoyaltySaga);
yield takeEvery(ORDER_NODELOGIC_FETCH, createFixedOrderNodelogic);
}
6 changes: 5 additions & 1 deletion src/plugins/auction/screens/AuctionDetailsScreen/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import {
selectAuctionOrderExecuteError,
selectAuctionOrderExecuteSuccess,
auctionOrderCancel,
orderNodelogicFetch,
} from '../../modules';
import { estimateUnitValue } from '../../../../helpers/estimateValue';
import { selectCurrentPrimaryCurrency } from '../../../../custom/modules';
Expand Down Expand Up @@ -97,6 +98,7 @@ interface DispatchProps {
auctionOrdersPush: typeof auctionOrdersPush;
auctionOrderCancel: typeof auctionOrderCancel;
memberLevelsFetch: typeof memberLevelsFetch;
orderNodelogicFetch: typeof orderNodelogicFetch;
}

interface State {
Expand Down Expand Up @@ -653,7 +655,8 @@ class AuctionDetailsContainer extends React.Component<Props, State> {
percentage: +currentAuction.tokens_ordered * 100 / +currentAuction.supply,
};

this.props.orderExecute({ order, generalInfo: payload });
this.props.orderExecute(order);
this.props.orderNodelogicFetch(payload);
this.setState({
amount: 0,
});
Expand Down Expand Up @@ -751,6 +754,7 @@ const mapDispatchToProps: MapDispatchToProps<DispatchProps, {}> = dispatch => ({
auctionOrdersPush: payload => dispatch(auctionOrdersPush(payload)),
auctionOrderCancel: payload => dispatch(auctionOrderCancel(payload)),
memberLevelsFetch: () => dispatch(memberLevelsFetch()),
orderNodelogicFetch: payload => dispatch(orderNodelogicFetch(payload)),
});

// tslint:disable-next-line:no-any
Expand Down

0 comments on commit 8715031

Please sign in to comment.