[FEATURE] Move scheduling code into one directory

This commit is contained in:
Daniel Kmak 2018-04-02 10:43:15 +02:00 committed by Bagaric
parent 353eeb5384
commit 42af363088
37 changed files with 234 additions and 198 deletions

View File

@ -4,10 +4,5 @@ export * from './network';
export * from './sign';
export * from './broadcast';
export * from './current';
export * from './timeBounty';
export * from './windowSize';
export * from './windowStart';
export * from './scheduleTimestamp';
export * from './scheduleType';
export * from './schedulingToggle';
export * from './sendEverything';
export * from '../../../containers/Tabs/ScheduleTransaction/actions/transaction/actionCreators';

View File

@ -112,12 +112,11 @@ class AdvancedGas extends React.Component<Props, State> {
)}
</div>
{dataField &&
!scheduling && (
<div className="AdvancedGas-data">
<DataField />
</div>
)}
{dataField && (
<div className="AdvancedGas-data">
<DataField />
</div>
)}
{this.renderFee()}
</div>

View File

@ -0,0 +1,6 @@
export * from './timeBounty';
export * from './windowSize';
export * from './windowStart';
export * from './scheduleTimestamp';
export * from './scheduleType';
export * from './schedulingToggle';

View File

@ -2,7 +2,7 @@ import {
SetCurrentScheduleTimestampAction,
SetScheduleTimezoneAction
} from '../actionTypes/scheduleTimestamp';
import { TypeKeys } from '../';
import { TypeKeys } from 'actions/transaction';
export type TSetCurrentScheduleTimestamp = typeof setCurrentScheduleTimestamp;
export const setCurrentScheduleTimestamp = (

View File

@ -1,5 +1,5 @@
import { SetCurrentScheduleTypeAction } from '../actionTypes/scheduleType';
import { TypeKeys } from '../';
import { TypeKeys } from 'actions/transaction';
export type TSetCurrentScheduleType = typeof setCurrentScheduleType;
export const setCurrentScheduleType = (

View File

@ -1,5 +1,5 @@
import { SetCurrentSchedulingToggleAction } from '../actionTypes/schedulingToggle';
import { TypeKeys } from '../';
import { TypeKeys } from 'actions/transaction';
type TSetCurrentSchedulingToggle = typeof setCurrentSchedulingToggle;
const setCurrentSchedulingToggle = (

View File

@ -1,5 +1,5 @@
import { SetCurrentTimeBountyAction } from '../actionTypes/timeBounty';
import { TypeKeys } from '../';
import { TypeKeys } from 'actions/transaction';
type TSetCurrentTimeBounty = typeof setCurrentTimeBounty;
const setCurrentTimeBounty = (

View File

@ -1,5 +1,5 @@
import { SetCurrentWindowSizeAction } from '../actionTypes/windowSize';
import { TypeKeys } from '../';
import { TypeKeys } from 'actions/transaction';
type TSetCurrentWindowSize = typeof setCurrentWindowSize;
const setCurrentWindowSize = (

View File

@ -1,5 +1,5 @@
import { SetCurrentWindowStartAction } from '../actionTypes/windowStart';
import { TypeKeys } from '../';
import { TypeKeys } from 'actions/transaction';
type TSetCurrentWindowStart = typeof setCurrentWindowStart;
const setCurrentWindowStart = (

View File

@ -1,4 +1,4 @@
import { TypeKeys } from '../constants';
import { TypeKeys } from 'actions/transaction';
/* user input */

View File

@ -1,4 +1,4 @@
import { TypeKeys } from '../constants';
import { TypeKeys } from 'actions/transaction';
/* user input */

View File

@ -1,4 +1,4 @@
import { TypeKeys } from '../constants';
import { TypeKeys } from 'actions/transaction';
/* user input */

View File

@ -1,4 +1,4 @@
import { TypeKeys } from '../constants';
import { TypeKeys } from 'actions/transaction';
/* user input */

View File

@ -1,4 +1,4 @@
import { TypeKeys } from '../constants';
import { TypeKeys } from 'actions/transaction';
/* user input */

View File

@ -1,4 +1,4 @@
import { TypeKeys } from '../constants';
import { TypeKeys } from 'actions/transaction';
/* user input */

View File

@ -1,7 +1,6 @@
import { connect } from 'react-redux';
import { AppState } from 'reducers';
import {
getSchedulingTransaction,
isNetworkRequestPending,
isValidGasPrice,
isValidGasLimit,
@ -10,6 +9,7 @@ import {
} from 'selectors/transaction';
import { getWalletType } from 'selectors/wallet';
import { GenerateTransactionFactoryClass } from 'components/GenerateTransactionFactory';
import { getSchedulingTransaction } from '../selectors/transaction';
export const ScheduleTransactionFactory = connect((state: AppState) => ({
...getSchedulingTransaction(state),

View File

@ -7,10 +7,10 @@ import {
isValidGasPrice,
isValidGasLimit,
getSignedTx,
getWeb3Tx,
getSchedulingTransaction
getWeb3Tx
} from 'selectors/transaction';
import { SendButtonFactoryClass } from 'components/SendButtonFactory';
import { getSchedulingTransaction } from '../selectors/transaction';
const mapStateToProps = (state: AppState) => {
return {

View File

@ -6,3 +6,5 @@ export * from './Fields/ScheduleGasPriceField';
export * from './Fields/ScheduleGasLimitField';
export * from './Fields/ScheduleDepositField';
export * from './ScheduleFields';
export * from './GenerateScheduleTransactionButton';
export * from './SendScheduleTransactionButton';

View File

@ -3,7 +3,7 @@ import { call, put, takeLatest } from 'redux-saga/effects';
import { SagaIterator } from 'redux-saga';
import { TypeKeys } from 'actions/transaction/constants';
import { SetScheduleTimestampFieldAction } from 'actions/transaction';
import { SetCurrentScheduleTimestampAction } from 'actions/transaction/actionTypes/scheduleTimestamp';
import { SetCurrentScheduleTimestampAction } from '../../../actions/transaction/actionTypes/scheduleTimestamp';
export function* setCurrentScheduleTimestamp({
payload: raw

View File

@ -3,12 +3,12 @@ import { call, put, takeLatest, select } from 'redux-saga/effects';
import { SagaIterator } from 'redux-saga';
import { TypeKeys } from 'actions/transaction/constants';
import { SetTimeBountyFieldAction } from 'actions/transaction';
import { SetCurrentTimeBountyAction } from 'actions/transaction/actionTypes/timeBounty';
import { getDecimal, getUnit } from 'selectors/transaction';
import { validDecimal, validNumber } from 'libs/validators';
import { toTokenBase } from 'libs/units';
import { validateInput } from 'sagas/transaction/validationHelpers';
import BN from 'bn.js';
import { SetCurrentTimeBountyAction } from '../../../actions/transaction/actionTypes/timeBounty';
export function* setCurrentTimeBounty({ payload: raw }: SetCurrentTimeBountyAction): SagaIterator {
const decimal: number = yield select(getDecimal);

View File

@ -3,7 +3,7 @@ import { call, put, takeLatest } from 'redux-saga/effects';
import { SagaIterator } from 'redux-saga';
import { TypeKeys } from 'actions/transaction/constants';
import { SetWindowSizeFieldAction } from 'actions/transaction';
import { SetCurrentWindowSizeAction } from 'actions/transaction/actionTypes/windowSize';
import { SetCurrentWindowSizeAction } from '../../../actions/transaction/actionTypes/windowSize';
export function* setCurrentWindowSize({ payload: raw }: SetCurrentWindowSizeAction): SagaIterator {
let value: number | null = null;

View File

@ -3,7 +3,7 @@ import { call, put, takeLatest } from 'redux-saga/effects';
import { SagaIterator } from 'redux-saga';
import { TypeKeys } from 'actions/transaction/constants';
import { SetWindowStartFieldAction } from 'actions/transaction';
import { SetCurrentWindowStartAction } from 'actions/transaction/actionTypes/windowStart';
import { SetCurrentWindowStartAction } from '../../../actions/transaction/actionTypes/windowStart';
export function* setCurrentWindowStart({
payload: raw

View File

@ -0,0 +1,35 @@
import { AppState } from 'reducers';
import { getFields } from 'selectors/transaction';
const getTimeBounty = (state: AppState) => getFields(state).timeBounty;
const getWindowSize = (state: AppState) => getFields(state).windowSize;
const getWindowStart = (state: AppState) => getFields(state).windowStart;
const getScheduleTimestamp = (state: AppState) => getFields(state).scheduleTimestamp;
const getScheduleType = (state: AppState) => getFields(state).scheduleType;
const getSchedulingToggle = (state: AppState) => getFields(state).schedulingToggle;
const getScheduleGasLimit = (state: AppState) => getFields(state).scheduleGasLimit;
const getScheduleGasPrice = (state: AppState) => getFields(state).scheduleGasPrice;
const getScheduleDeposit = (state: AppState) => getFields(state).scheduleDeposit;
const schedulingFields = [
'windowStart',
'windowSize',
'scheduleTimestamp',
'schedulingToggle',
'scheduleDeposit',
'scheduleGasLimit',
'scheduleGasPrice'
];
export {
getTimeBounty,
getWindowSize,
getWindowStart,
getScheduleTimestamp,
getScheduleType,
getSchedulingToggle,
getScheduleGasLimit,
getScheduleGasPrice,
getScheduleDeposit,
schedulingFields
};

View File

@ -0,0 +1,23 @@
import { AppState } from 'reducers';
export const isWindowSizeValid = (transactionFields: AppState['transaction']['fields']) => {
const { windowSize } = transactionFields;
return Boolean(windowSize && windowSize.value);
};
export const isWindowStartValid = (
transactionFields: AppState['transaction']['fields'],
latestBlock: string
) => {
const { windowStart } = transactionFields;
return Boolean(windowStart && windowStart.value && windowStart.value > parseInt(latestBlock, 10));
};
export const isScheduleTimestampValid = (transactionFields: AppState['transaction']['fields']) => {
const { scheduleTimestamp } = transactionFields;
const now = new Date();
return Boolean(scheduleTimestamp && scheduleTimestamp.value && scheduleTimestamp.value > now);
};

View File

@ -0,0 +1,7 @@
export * from './transaction';
export * from './windowSize';
export * from './windowStart';
export * from './timeBounty';
export * from './scheduleTimestamp';
export * from './scheduleType';
export * from './schedulingToggle';

View File

@ -0,0 +1,118 @@
import { AppState } from 'reducers';
import {
IGetTransaction,
getCurrentTo,
getCurrentValue,
getFields,
getUnit,
getDataExists,
getData,
getValidGasCost,
getScheduleType,
getWindowStart,
getNonce,
getGasPrice,
getTimeBounty,
getWindowSize,
getScheduleGasPrice,
isValidScheduleGasPrice,
getScheduleGasLimit,
isValidScheduleGasLimit,
isValidScheduleDeposit,
getScheduleDeposit
} from 'selectors/transaction';
import { Address, gasPriceToBase } from 'libs/units';
import {
EAC_SCHEDULING_CONFIG,
getScheduleData,
calcEACEndowment,
EAC_ADDRESSES
} from 'libs/scheduling';
import BN from 'bn.js';
import { makeTransaction } from 'libs/transaction';
import {
isFullTx,
isWindowSizeValid,
isWindowStartValid,
isScheduleTimestampValid
} from 'selectors/transaction/helpers';
import EthTx from 'ethereumjs-tx';
import { getLatestBlock } from 'selectors/config';
const getSchedulingTransaction = (state: AppState): IGetTransaction => {
const currentTo = getCurrentTo(state);
const currentValue = getCurrentValue(state);
const transactionFields = getFields(state);
const unit = getUnit(state);
const dataExists = getDataExists(state);
const callData = getData(state);
const validGasCost = getValidGasCost(state);
const scheduleType = getScheduleType(state);
const windowStart = getWindowStart(state);
const windowSize = getWindowSize(state);
const nonce = getNonce(state);
const gasPrice = getGasPrice(state);
const timeBounty = getTimeBounty(state);
const windowSizeValid = isWindowSizeValid(transactionFields);
const windowStartValid = isWindowStartValid(transactionFields, getLatestBlock(state));
const scheduleTimestampValid = isScheduleTimestampValid(transactionFields);
const scheduleGasPrice = getScheduleGasPrice(state);
const scheduleGasPriceValid = isValidScheduleGasPrice(state);
const scheduleGasLimit = getScheduleGasLimit(state);
const scheduleGasLimitValid = isValidScheduleGasLimit(state);
const depositValid = isValidScheduleDeposit(state);
const deposit = getScheduleDeposit(state);
const isFullTransaction =
isFullTx(state, transactionFields, currentTo, currentValue, dataExists, validGasCost, unit) &&
(windowStartValid || scheduleTimestampValid) &&
windowSizeValid &&
scheduleGasPriceValid &&
scheduleGasLimitValid &&
depositValid;
const transactionData = getScheduleData(
currentTo.raw,
callData.raw,
scheduleGasLimit.value,
currentValue.value,
windowSize.value,
windowStart.value,
scheduleGasPrice.value,
timeBounty.value,
deposit.value
);
const endowment = calcEACEndowment(
scheduleGasLimit.value || EAC_SCHEDULING_CONFIG.SCHEDULE_GAS_LIMIT_FALLBACK,
currentValue.value || new BN(0),
scheduleGasPrice.value || gasPriceToBase(EAC_SCHEDULING_CONFIG.SCHEDULE_GAS_PRICE_FALLBACK),
timeBounty.value
);
const transactionOptions = {
to: Address(
scheduleType.value === 'time'
? EAC_ADDRESSES.KOVAN.timestampScheduler
: EAC_ADDRESSES.KOVAN.blockScheduler
),
data: transactionData,
gasLimit: EAC_SCHEDULING_CONFIG.SCHEDULING_GAS_LIMIT,
gasPrice: gasPrice.value,
nonce: new BN(0),
value: endowment
};
if (nonce) {
transactionOptions.nonce = new BN(nonce.raw);
}
const transaction: EthTx = makeTransaction(transactionOptions);
return {
transaction,
isFullTransaction
};
};
export { getSchedulingTransaction };

View File

@ -1,6 +1,6 @@
import { AppState } from 'reducers';
import { getLatestBlock } from 'selectors/config';
import { getWindowStart } from './fields';
import { getLatestBlock } from '../config';
interface ICurrentWindowStart {
raw: string;

View File

@ -9,7 +9,9 @@ import {
GenerateTransaction,
SendButton,
SchedulingToggle,
ScheduleFields
ScheduleFields,
GenerateScheduleTransactionButton,
SendScheduleTransactionButton
} from 'components';
import { OnlyUnlocked, WhenQueryExists } from 'components/renderCbs';
import translate from 'translations';
@ -17,8 +19,6 @@ import translate from 'translations';
import { AppState } from 'reducers';
import { NonStandardTransaction } from './components';
import { getOffline, getNetworkConfig } from 'selectors/config';
import { SendScheduleTransactionButton } from 'containers/Tabs/ScheduleTransaction/components/SendScheduleTransactionButton';
import { GenerateScheduleTransactionButton } from 'containers/Tabs/ScheduleTransaction/components/GenerateScheduleTransactionButton';
import { getCurrentSchedulingToggle, ICurrentSchedulingToggle } from 'selectors/transaction';
const QueryWarning: React.SFC<{}> = () => (

View File

@ -10,15 +10,6 @@ const getGasLimit = (state: AppState) => getFields(state).gasLimit;
const getGasPrice = (state: AppState) => getFields(state).gasPrice;
const getValue = (state: AppState) => getFields(state).value;
const getNonce = (state: AppState) => getFields(state).nonce;
const getTimeBounty = (state: AppState) => getFields(state).timeBounty;
const getWindowSize = (state: AppState) => getFields(state).windowSize;
const getWindowStart = (state: AppState) => getFields(state).windowStart;
const getScheduleTimestamp = (state: AppState) => getFields(state).scheduleTimestamp;
const getScheduleType = (state: AppState) => getFields(state).scheduleType;
const getSchedulingToggle = (state: AppState) => getFields(state).schedulingToggle;
const getScheduleGasLimit = (state: AppState) => getFields(state).scheduleGasLimit;
const getScheduleGasPrice = (state: AppState) => getFields(state).scheduleGasPrice;
const getScheduleDeposit = (state: AppState) => getFields(state).scheduleDeposit;
const getDataExists = (state: AppState) => {
const { value } = getData(state);
@ -44,14 +35,7 @@ export {
getNonce,
getGasPrice,
getDataExists,
getValidGasCost,
getTimeBounty,
getWindowSize,
getWindowStart,
getScheduleTimestamp,
getScheduleType,
getSchedulingToggle,
getScheduleGasLimit,
getScheduleGasPrice,
getScheduleDeposit
getValidGasCost
};
export * from '../../containers/Tabs/ScheduleTransaction/selectors/fields';

View File

@ -1,5 +1,5 @@
import { AppState } from 'reducers';
import { ICurrentTo, ICurrentValue } from 'selectors/transaction';
import { ICurrentTo, ICurrentValue, schedulingFields } from 'selectors/transaction';
import { isNetworkUnit } from 'selectors/config';
type TransactionFields = AppState['transaction']['fields'];
@ -29,13 +29,9 @@ export const isFullTx = (
const { data, value, to, ...rest } = transactionFields;
const partialParamsToCheck = { ...rest };
delete partialParamsToCheck.windowStart;
delete partialParamsToCheck.windowSize;
delete partialParamsToCheck.scheduleTimestamp;
delete partialParamsToCheck.schedulingToggle;
delete partialParamsToCheck.scheduleDeposit;
delete partialParamsToCheck.scheduleGasLimit;
delete partialParamsToCheck.scheduleGasPrice;
for (const param of schedulingFields) {
delete (partialParamsToCheck as any)[param];
}
const validPartialParams = Object.values(partialParamsToCheck).reduce<boolean>(
(isValid, v: AppState['transaction']['fields'] & ICurrentTo & ICurrentValue) =>
@ -66,24 +62,4 @@ export const isFullTx = (
}
};
export const isWindowSizeValid = (transactionFields: AppState['transaction']['fields']) => {
const { windowSize } = transactionFields;
return Boolean(windowSize && windowSize.value);
};
export const isWindowStartValid = (
transactionFields: AppState['transaction']['fields'],
latestBlock: string
) => {
const { windowStart } = transactionFields;
return Boolean(windowStart && windowStart.value && windowStart.value > parseInt(latestBlock, 10));
};
export const isScheduleTimestampValid = (transactionFields: AppState['transaction']['fields']) => {
const { scheduleTimestamp } = transactionFields;
const now = new Date();
return Boolean(scheduleTimestamp && scheduleTimestamp.value && scheduleTimestamp.value > now);
};
export * from '../../containers/Tabs/ScheduleTransaction/selectors/helpers';

View File

@ -4,10 +4,5 @@ export * from './fields';
export * from './meta';
export * from './sign';
export * from './current';
export * from './windowSize';
export * from './windowStart';
export * from './timeBounty';
export * from './scheduleTimestamp';
export * from './scheduleType';
export * from './schedulingToggle';
export * from './network';
export * from '../../containers/Tabs/ScheduleTransaction/selectors';

View File

@ -1,48 +1,21 @@
import { AppState } from 'reducers';
import { getCurrentTo, getCurrentValue } from './current';
import {
getFields,
getData,
getWindowStart,
getNonce,
getTimeBounty,
getScheduleType,
getWindowSize
} from './fields';
import { getFields } from './fields';
import { makeTransaction, IHexStrTransaction } from 'libs/transaction';
import EthTx from 'ethereumjs-tx';
import { getUnit } from 'selectors/transaction/meta';
import {
reduceToValues,
isFullTx,
isWindowStartValid,
isScheduleTimestampValid,
isWindowSizeValid
} from 'selectors/transaction/helpers';
import { reduceToValues, isFullTx } from 'selectors/transaction/helpers';
import {
getGasPrice,
getGasLimit,
getDataExists,
getSerializedTransaction,
getValidGasCost,
isEtherTransaction,
getScheduleGasPrice,
isValidScheduleGasPrice,
isValidScheduleGasLimit,
getScheduleGasLimit,
isValidScheduleDeposit,
getScheduleDeposit
isEtherTransaction
} from 'selectors/transaction';
import { Wei, Address, gasPriceToBase } from 'libs/units';
import { Wei } from 'libs/units';
import { getTransactionFields } from 'libs/transaction/utils/ether';
import { getNetworkConfig, getLatestBlock } from 'selectors/config';
import BN from 'bn.js';
import {
EAC_SCHEDULING_CONFIG,
calcEACEndowment,
EAC_ADDRESSES,
getScheduleData
} from 'libs/scheduling';
import { getNetworkConfig } from 'selectors/config';
const getTransactionState = (state: AppState) => state.transaction;
@ -73,82 +46,6 @@ const getTransaction = (state: AppState): IGetTransaction => {
return { transaction, isFullTransaction };
};
const getSchedulingTransaction = (state: AppState): IGetTransaction => {
const currentTo = getCurrentTo(state);
const currentValue = getCurrentValue(state);
const transactionFields = getFields(state);
const unit = getUnit(state);
const dataExists = getDataExists(state);
const callData = getData(state);
const validGasCost = getValidGasCost(state);
const scheduleType = getScheduleType(state);
const windowStart = getWindowStart(state);
const windowSize = getWindowSize(state);
const nonce = getNonce(state);
const gasPrice = getGasPrice(state);
const timeBounty = getTimeBounty(state);
const windowSizeValid = isWindowSizeValid(transactionFields);
const windowStartValid = isWindowStartValid(transactionFields, getLatestBlock(state));
const scheduleTimestampValid = isScheduleTimestampValid(transactionFields);
const scheduleGasPrice = getScheduleGasPrice(state);
const scheduleGasPriceValid = isValidScheduleGasPrice(state);
const scheduleGasLimit = getScheduleGasLimit(state);
const scheduleGasLimitValid = isValidScheduleGasLimit(state);
const depositValid = isValidScheduleDeposit(state);
const deposit = getScheduleDeposit(state);
const isFullTransaction =
isFullTx(state, transactionFields, currentTo, currentValue, dataExists, validGasCost, unit) &&
(windowStartValid || scheduleTimestampValid) &&
windowSizeValid &&
scheduleGasPriceValid &&
scheduleGasLimitValid &&
depositValid;
const transactionData = getScheduleData(
currentTo.raw,
callData.raw,
scheduleGasLimit.value,
currentValue.value,
windowSize.value,
windowStart.value,
scheduleGasPrice.value,
timeBounty.value,
deposit.value
);
const endowment = calcEACEndowment(
scheduleGasLimit.value || EAC_SCHEDULING_CONFIG.SCHEDULE_GAS_LIMIT_FALLBACK,
currentValue.value || new BN(0),
scheduleGasPrice.value || gasPriceToBase(EAC_SCHEDULING_CONFIG.SCHEDULE_GAS_PRICE_FALLBACK),
timeBounty.value
);
const transactionOptions = {
to: Address(
scheduleType.value === 'time'
? EAC_ADDRESSES.KOVAN.timestampScheduler
: EAC_ADDRESSES.KOVAN.blockScheduler
),
data: transactionData,
gasLimit: EAC_SCHEDULING_CONFIG.SCHEDULING_GAS_LIMIT,
gasPrice: gasPrice.value,
nonce: new BN(0),
value: endowment
};
if (nonce) {
transactionOptions.nonce = new BN(nonce.raw);
}
const transaction: EthTx = makeTransaction(transactionOptions);
return {
transaction,
isFullTransaction
};
};
const nonStandardTransaction = (state: AppState): boolean => {
const etherTransaction = isEtherTransaction(state);
const { isFullTransaction } = getTransaction(state);
@ -192,7 +89,6 @@ const serializedAndTransactionFieldsMatch = (state: AppState, isLocallySigned: b
};
export {
getSchedulingTransaction,
getTransaction,
getTransactionState,
getGasCost,