mirror of
https://github.com/status-im/MyCrypto.git
synced 2025-01-25 02:20:24 +00:00
[FEATURE] Add Schedule Gas Limit field
This commit is contained in:
parent
7267f3555f
commit
62f528fc99
@ -17,7 +17,8 @@ import {
|
||||
SetScheduleTimestampFieldAction,
|
||||
SetScheduleTypeAction,
|
||||
SetSchedulingToggleAction,
|
||||
SetScheduleGasPriceFieldAction
|
||||
SetScheduleGasPriceFieldAction,
|
||||
SetScheduleGasLimitFieldAction
|
||||
} from '../actionTypes';
|
||||
import { TypeKeys } from 'actions/transaction/constants';
|
||||
|
||||
@ -139,6 +140,12 @@ const setScheduleGasPriceField = (payload: SetScheduleGasPriceFieldAction['paylo
|
||||
payload
|
||||
});
|
||||
|
||||
type TSetScheduleGasLimitField = typeof setScheduleGasLimitField;
|
||||
const setScheduleGasLimitField = (payload: SetScheduleGasLimitFieldAction['payload']) => ({
|
||||
type: TypeKeys.SCHEDULE_GAS_LIMIT_FIELD_SET,
|
||||
payload
|
||||
});
|
||||
|
||||
type TReset = typeof reset;
|
||||
const reset = (payload: ResetAction['payload'] = { include: {}, exclude: {} }): ResetAction => ({
|
||||
type: TypeKeys.RESET,
|
||||
@ -164,6 +171,7 @@ export {
|
||||
TSetScheduleType,
|
||||
TSetSchedulingToggle,
|
||||
TSetScheduleGasPriceField,
|
||||
TSetScheduleGasLimitField,
|
||||
TReset,
|
||||
inputGasLimit,
|
||||
inputGasPrice,
|
||||
@ -183,5 +191,6 @@ export {
|
||||
setScheduleType,
|
||||
setSchedulingToggle,
|
||||
setScheduleGasPriceField,
|
||||
setScheduleGasLimitField,
|
||||
reset
|
||||
};
|
||||
|
@ -139,6 +139,14 @@ interface SetScheduleGasPriceFieldAction {
|
||||
};
|
||||
}
|
||||
|
||||
interface SetScheduleGasLimitFieldAction {
|
||||
type: TypeKeys.SCHEDULE_GAS_LIMIT_FIELD_SET;
|
||||
payload: {
|
||||
raw: string;
|
||||
value: Wei | null;
|
||||
};
|
||||
}
|
||||
|
||||
type InputFieldAction = InputNonceAction | InputGasLimitAction | InputDataAction;
|
||||
|
||||
type FieldAction =
|
||||
@ -154,7 +162,8 @@ type FieldAction =
|
||||
| SetScheduleTimestampFieldAction
|
||||
| SetScheduleTypeAction
|
||||
| SetSchedulingToggleAction
|
||||
| SetScheduleGasPriceFieldAction;
|
||||
| SetScheduleGasPriceFieldAction
|
||||
| SetScheduleGasLimitFieldAction;
|
||||
|
||||
export {
|
||||
InputGasLimitAction,
|
||||
@ -178,5 +187,6 @@ export {
|
||||
SetScheduleTimestampFieldAction,
|
||||
SetScheduleTypeAction,
|
||||
SetSchedulingToggleAction,
|
||||
SetScheduleGasPriceFieldAction
|
||||
SetScheduleGasPriceFieldAction,
|
||||
SetScheduleGasLimitFieldAction
|
||||
};
|
||||
|
@ -50,6 +50,7 @@ export enum TypeKeys {
|
||||
WINDOW_SIZE_FIELD_SET = 'WINDOW_SIZE_FIELD_SET',
|
||||
WINDOW_START_FIELD_SET = 'WINDOW_START_FIELD_SET',
|
||||
SCHEDULE_GAS_PRICE_FIELD_SET = 'SCHEDULE_GAS_PRICE_SET',
|
||||
SCHEDULE_GAS_LIMIT_FIELD_SET = 'SCHEDULE_GAS_LIMIT_SET',
|
||||
SCHEDULE_TIMESTAMP_FIELD_SET = 'SCHEDULE_TIMESTAMP_FIELD_SET',
|
||||
SCHEDULE_TIMEZONE_SET = 'SCHEDULE_TIMEZONE_SET',
|
||||
SCHEDULE_TYPE_SET = 'SCHEDULE_TYPE_SET',
|
||||
|
@ -59,21 +59,23 @@ class AdvancedGas extends React.Component<Props, State> {
|
||||
};
|
||||
|
||||
public render() {
|
||||
const { autoGasLimitEnabled, gasPrice, validGasPrice } = this.props;
|
||||
const { autoGasLimitEnabled, gasPrice, scheduling, validGasPrice } = this.props;
|
||||
const { gasPriceField, gasLimitField, nonceField, dataField } = this.state.options;
|
||||
|
||||
return (
|
||||
<div className="AdvancedGas row form-group">
|
||||
<div className="AdvancedGas-calculate-limit">
|
||||
<label className="checkbox">
|
||||
<input
|
||||
type="checkbox"
|
||||
defaultChecked={autoGasLimitEnabled}
|
||||
onChange={this.handleToggleAutoGasLimit}
|
||||
/>
|
||||
<span>Automatically Calculate Gas Limit</span>
|
||||
</label>
|
||||
</div>
|
||||
{!scheduling && (
|
||||
<div className="AdvancedGas-calculate-limit">
|
||||
<label className="checkbox">
|
||||
<input
|
||||
type="checkbox"
|
||||
defaultChecked={autoGasLimitEnabled}
|
||||
onChange={this.handleToggleAutoGasLimit}
|
||||
/>
|
||||
<span>Automatically Calculate Gas Limit</span>
|
||||
</label>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="AdvancedGas-flex-wrapper flex-wrapper">
|
||||
{gasPriceField && (
|
||||
@ -97,7 +99,10 @@ class AdvancedGas extends React.Component<Props, State> {
|
||||
|
||||
{gasLimitField && (
|
||||
<div className="AdvancedGas-gas-limit">
|
||||
<GasLimitField customLabel={translateRaw('OFFLINE_STEP2_LABEL_4')} />
|
||||
<GasLimitField
|
||||
customLabel={translateRaw('OFFLINE_STEP2_LABEL_4')}
|
||||
disabled={scheduling}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
{nonceField && (
|
||||
@ -107,11 +112,12 @@ class AdvancedGas extends React.Component<Props, State> {
|
||||
)}
|
||||
</div>
|
||||
|
||||
{dataField && (
|
||||
<div className="AdvancedGas-data">
|
||||
<DataField />
|
||||
</div>
|
||||
)}
|
||||
{dataField &&
|
||||
!scheduling && (
|
||||
<div className="AdvancedGas-data">
|
||||
<DataField />
|
||||
</div>
|
||||
)}
|
||||
|
||||
{this.renderFee()}
|
||||
</div>
|
||||
@ -132,7 +138,7 @@ class AdvancedGas extends React.Component<Props, State> {
|
||||
<SchedulingFeeSummary
|
||||
gasPrice={gasPrice}
|
||||
scheduleGasPrice={scheduleGasPrice}
|
||||
render={({ gasPriceWei, gasLimit, fee, usd }) => (
|
||||
render={({ gasPriceWei, scheduleGasLimit, fee, usd }) => (
|
||||
<div>
|
||||
<span>
|
||||
<UnitDisplay
|
||||
@ -145,8 +151,8 @@ class AdvancedGas extends React.Component<Props, State> {
|
||||
+ {timeBounty && timeBounty.value && timeBounty.value.toString()} + {gasPriceWei}{' '}
|
||||
* {EAC_SCHEDULING_CONFIG.SCHEDULING_GAS_LIMIT.toString()} +{' '}
|
||||
{scheduleGasPrice && scheduleGasPrice.value && scheduleGasPrice.value.toString()}{' '}
|
||||
* ({EAC_SCHEDULING_CONFIG.FUTURE_EXECUTION_COST.toString()} + {gasLimit}) = {fee}{' '}
|
||||
{usd && <span>~= ${usd} USD</span>}
|
||||
* ({EAC_SCHEDULING_CONFIG.FUTURE_EXECUTION_COST.toString()} + {scheduleGasLimit})
|
||||
= {fee} {usd && <span>~= ${usd} USD</span>}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
|
@ -4,7 +4,7 @@ import { connect } from 'react-redux';
|
||||
import { AppState } from 'reducers';
|
||||
import { getNetworkConfig, getOffline } from 'selectors/config';
|
||||
import { getIsEstimating } from 'selectors/gas';
|
||||
import { getGasLimit, getTimeBounty } from 'selectors/transaction';
|
||||
import { getTimeBounty, getScheduleGasLimit } from 'selectors/transaction';
|
||||
import { UnitDisplay, Spinner } from 'components/ui';
|
||||
import { NetworkConfig } from 'types/network';
|
||||
import './FeeSummary.scss';
|
||||
@ -14,13 +14,13 @@ import { gasPriceToBase } from 'libs/units';
|
||||
interface RenderData {
|
||||
gasPriceWei: string;
|
||||
gasPriceGwei: string;
|
||||
gasLimit: string;
|
||||
scheduleGasLimit: string;
|
||||
fee: React.ReactElement<string>;
|
||||
usd: React.ReactElement<string> | null;
|
||||
}
|
||||
|
||||
interface ReduxStateProps {
|
||||
gasLimit: AppState['transaction']['fields']['gasLimit'];
|
||||
scheduleGasLimit: AppState['transaction']['fields']['scheduleGasLimit'];
|
||||
rates: AppState['rates']['rates'];
|
||||
network: NetworkConfig;
|
||||
isOffline: AppState['config']['meta']['offline'];
|
||||
@ -41,7 +41,7 @@ class SchedulingFeeSummary extends React.Component<Props> {
|
||||
public render() {
|
||||
const {
|
||||
gasPrice,
|
||||
gasLimit,
|
||||
scheduleGasLimit,
|
||||
rates,
|
||||
network,
|
||||
isOffline,
|
||||
@ -60,10 +60,10 @@ class SchedulingFeeSummary extends React.Component<Props> {
|
||||
|
||||
const feeBig =
|
||||
gasPrice.value &&
|
||||
gasLimit.value &&
|
||||
scheduleGasLimit.value &&
|
||||
timeBounty.value &&
|
||||
calcEACTotalCost(
|
||||
gasLimit.value,
|
||||
scheduleGasLimit.value,
|
||||
gasPrice.value,
|
||||
scheduleGasPrice.value || gasPriceToBase(EAC_SCHEDULING_CONFIG.SCHEDULE_GAS_PRICE_FALLBACK),
|
||||
timeBounty.value
|
||||
@ -99,7 +99,7 @@ class SchedulingFeeSummary extends React.Component<Props> {
|
||||
gasPriceGwei: gasPrice.raw,
|
||||
fee,
|
||||
usd,
|
||||
gasLimit: gasLimit.raw
|
||||
scheduleGasLimit: scheduleGasLimit.raw
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
@ -108,7 +108,7 @@ class SchedulingFeeSummary extends React.Component<Props> {
|
||||
|
||||
function mapStateToProps(state: AppState): ReduxStateProps {
|
||||
return {
|
||||
gasLimit: getGasLimit(state),
|
||||
scheduleGasLimit: getScheduleGasLimit(state),
|
||||
rates: state.rates.rates,
|
||||
network: getNetworkConfig(state),
|
||||
isOffline: getOffline(state),
|
||||
|
@ -0,0 +1,60 @@
|
||||
import { connect } from 'react-redux';
|
||||
import React from 'react';
|
||||
import { AppState } from 'reducers';
|
||||
import { setScheduleGasLimitField, TSetScheduleGasLimitField } from 'actions/transaction';
|
||||
import { translateRaw } from 'translations';
|
||||
import { Input } from 'components/ui';
|
||||
import { getScheduleGasLimit, isValidScheduleGasLimit } from 'selectors/transaction';
|
||||
import { Wei } from 'libs/units';
|
||||
import { EAC_SCHEDULING_CONFIG } from 'libs/scheduling';
|
||||
|
||||
interface OwnProps {
|
||||
scheduleGasLimit: any;
|
||||
validScheduleGasLimit: boolean;
|
||||
}
|
||||
|
||||
interface DispatchProps {
|
||||
setScheduleGasLimitField: TSetScheduleGasLimitField;
|
||||
}
|
||||
|
||||
type Props = OwnProps & DispatchProps;
|
||||
|
||||
class ScheduleGasLimitFieldClass extends React.Component<Props> {
|
||||
public render() {
|
||||
const { scheduleGasLimit, validScheduleGasLimit } = this.props;
|
||||
|
||||
return (
|
||||
<div className="input-group-wrapper">
|
||||
<label className="input-group">
|
||||
<div className="input-group-header">{translateRaw('TRANS_GAS')}</div>
|
||||
<Input
|
||||
className={!!scheduleGasLimit.raw && !validScheduleGasLimit ? 'invalid' : ''}
|
||||
type="number"
|
||||
placeholder={EAC_SCHEDULING_CONFIG.SCHEDULE_GAS_LIMIT_FALLBACK.toString()}
|
||||
value={scheduleGasLimit.raw}
|
||||
onChange={this.handleGasLimitChange}
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
private handleGasLimitChange = (ev: React.FormEvent<HTMLInputElement>) => {
|
||||
const { value } = ev.currentTarget;
|
||||
|
||||
this.props.setScheduleGasLimitField({
|
||||
raw: value,
|
||||
value: Wei(value)
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export const ScheduleGasLimitField = connect(
|
||||
(state: AppState) => ({
|
||||
scheduleGasLimit: getScheduleGasLimit(state),
|
||||
validScheduleGasLimit: isValidScheduleGasLimit(state)
|
||||
}),
|
||||
{
|
||||
setScheduleGasLimitField
|
||||
}
|
||||
)(ScheduleGasLimitFieldClass);
|
@ -0,0 +1,75 @@
|
||||
import { connect } from 'react-redux';
|
||||
import React from 'react';
|
||||
import { AppState } from 'reducers';
|
||||
import { getCurrentScheduleType, ICurrentScheduleType } from 'selectors/transaction';
|
||||
import {
|
||||
WindowSizeField,
|
||||
TimeBountyField,
|
||||
WindowStartField,
|
||||
ScheduleGasPriceField,
|
||||
ScheduleGasLimitField
|
||||
} from '.';
|
||||
import { ScheduleTimezoneDropDown, ScheduleTimestampField, ScheduleType } from 'components';
|
||||
import './ScheduleFields.scss';
|
||||
|
||||
interface Props {
|
||||
schedulingType: ICurrentScheduleType;
|
||||
}
|
||||
|
||||
class ScheduleFieldsClass extends React.Component<Props> {
|
||||
public render() {
|
||||
const { schedulingType } = this.props;
|
||||
|
||||
return (
|
||||
<div className="scheduled-tx-settings">
|
||||
<div className="scheduled-tx-settings_title">Scheduled Transaction Settings</div>
|
||||
<br />
|
||||
|
||||
<div className="row form-group">
|
||||
<div className="col-xs-12 col-sm-6 col-md-3 col-md-push-9">
|
||||
<ScheduleType />
|
||||
</div>
|
||||
|
||||
{schedulingType.value === 'time' && (
|
||||
<>
|
||||
<div className="col-xs-12 col-md-3 col-md-pull-3">
|
||||
<ScheduleTimestampField />
|
||||
</div>
|
||||
<div className="col-xs-12 col-md-3 col-md-pull-3">
|
||||
<ScheduleTimezoneDropDown />
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
{schedulingType.value === 'block' && (
|
||||
<>
|
||||
<div className="col-xs-12 col-md-6 col-md-pull-3">
|
||||
<WindowStartField />
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
<div className="col-xs-12 col-md-3 col-md-pull-3">
|
||||
<WindowSizeField />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="row form-group">
|
||||
<div className="col-xs-4">
|
||||
<ScheduleGasPriceField />
|
||||
</div>
|
||||
<div className="col-xs-4">
|
||||
<ScheduleGasLimitField />
|
||||
</div>
|
||||
<div className="col-xs-4">
|
||||
<TimeBountyField />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export const ScheduleFields = connect((state: AppState) => ({
|
||||
schedulingType: getCurrentScheduleType(state)
|
||||
}))(ScheduleFieldsClass);
|
@ -3,3 +3,5 @@ export * from './Fields/TimeBounty/TimeBountyField';
|
||||
export * from './Fields/WindowSize/WindowSizeField';
|
||||
export * from './Fields/SchedulingToggle/SchedulingToggle';
|
||||
export * from './Fields/ScheduleGasPriceField';
|
||||
export * from './Fields/ScheduleGasLimitField';
|
||||
export * from './ScheduleFields';
|
||||
|
@ -0,0 +1,27 @@
|
||||
import { setGasLimitField } from 'actions/transaction/actionCreators/fields';
|
||||
import { call, put, takeLatest } from 'redux-saga/effects';
|
||||
import { SagaIterator } from 'redux-saga';
|
||||
import { TypeKeys } from 'actions/transaction/constants';
|
||||
import { SetGasLimitFieldAction, SetSchedulingToggleAction } from 'actions/transaction';
|
||||
import { EAC_SCHEDULING_CONFIG } from 'libs/scheduling';
|
||||
import BN from 'bn.js';
|
||||
|
||||
export function* setGasLimitForScheduling({
|
||||
payload: { value: useScheduling }
|
||||
}: SetSchedulingToggleAction): SagaIterator {
|
||||
const gasLimit = useScheduling ? EAC_SCHEDULING_CONFIG.SCHEDULING_GAS_LIMIT : new BN('21000');
|
||||
|
||||
yield call(setGasLimit, {
|
||||
raw: gasLimit.toString(),
|
||||
value: gasLimit
|
||||
});
|
||||
}
|
||||
|
||||
export function* setGasLimit(payload: SetGasLimitFieldAction['payload']) {
|
||||
yield put(setGasLimitField(payload));
|
||||
}
|
||||
|
||||
export const currentSchedulingToggle = takeLatest(
|
||||
[TypeKeys.SCHEDULING_TOGGLE_SET],
|
||||
setGasLimitForScheduling
|
||||
);
|
@ -2,10 +2,12 @@ import { currentWindowSize } from './currentWindowSize';
|
||||
import { currentWindowStart } from './currentWindowStart';
|
||||
import { currentScheduleTimestamp } from './currentScheduleTimestamp';
|
||||
import { currentTimeBounty } from './currentTimeBounty';
|
||||
import { currentSchedulingToggle } from './currentSchedulingToggle';
|
||||
|
||||
export const schedulingCurrentSagas = [
|
||||
currentWindowSize,
|
||||
currentWindowStart,
|
||||
currentScheduleTimestamp,
|
||||
currentTimeBounty
|
||||
currentTimeBounty,
|
||||
currentSchedulingToggle
|
||||
];
|
||||
|
@ -8,14 +8,8 @@ import {
|
||||
CurrentCustomMessage,
|
||||
GenerateTransaction,
|
||||
SendButton,
|
||||
WindowStartField,
|
||||
ScheduleTimestampField,
|
||||
ScheduleTimezoneDropDown,
|
||||
TimeBountyField,
|
||||
ScheduleType,
|
||||
WindowSizeField,
|
||||
SchedulingToggle,
|
||||
ScheduleGasPriceField
|
||||
ScheduleFields
|
||||
} from 'components';
|
||||
import { OnlyUnlocked, WhenQueryExists } from 'components/renderCbs';
|
||||
import translate from 'translations';
|
||||
@ -25,13 +19,7 @@ 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 {
|
||||
getCurrentScheduleType,
|
||||
ICurrentScheduleType,
|
||||
getCurrentSchedulingToggle,
|
||||
ICurrentSchedulingToggle
|
||||
} from 'selectors/transaction';
|
||||
import './Fields.scss';
|
||||
import { getCurrentSchedulingToggle, ICurrentSchedulingToggle } from 'selectors/transaction';
|
||||
|
||||
const QueryWarning: React.SFC<{}> = () => (
|
||||
<WhenQueryExists
|
||||
@ -47,13 +35,12 @@ interface StateProps {
|
||||
schedulingAvailable: boolean;
|
||||
shouldDisplay: boolean;
|
||||
offline: boolean;
|
||||
schedulingType: ICurrentScheduleType;
|
||||
useScheduling: ICurrentSchedulingToggle['value'];
|
||||
}
|
||||
|
||||
class FieldsClass extends Component<StateProps> {
|
||||
public render() {
|
||||
const { shouldDisplay, schedulingAvailable, useScheduling, schedulingType } = this.props;
|
||||
const { shouldDisplay, schedulingAvailable, useScheduling } = this.props;
|
||||
|
||||
return (
|
||||
<OnlyUnlocked
|
||||
@ -74,52 +61,7 @@ class FieldsClass extends Component<StateProps> {
|
||||
)}
|
||||
</div>
|
||||
|
||||
{useScheduling && (
|
||||
<div className="scheduled-tx-settings">
|
||||
<div className="scheduled-tx-settings_title">
|
||||
Scheduled Transaction Settings
|
||||
</div>
|
||||
<br />
|
||||
|
||||
<div className="row form-group">
|
||||
<div className="col-xs-12 col-sm-6 col-md-3 col-md-push-9">
|
||||
<ScheduleType />
|
||||
</div>
|
||||
|
||||
{schedulingType.value === 'time' && (
|
||||
<>
|
||||
<div className="col-xs-12 col-md-3 col-md-pull-3">
|
||||
<ScheduleTimestampField />
|
||||
</div>
|
||||
<div className="col-xs-12 col-md-3 col-md-pull-3">
|
||||
<ScheduleTimezoneDropDown />
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
{schedulingType.value === 'block' && (
|
||||
<>
|
||||
<div className="col-xs-12 col-md-6 col-md-pull-3">
|
||||
<WindowStartField />
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
<div className="col-xs-12 col-md-3 col-md-pull-3">
|
||||
<WindowSizeField />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="row form-group">
|
||||
<div className="col-xs-6">
|
||||
<ScheduleGasPriceField />
|
||||
</div>
|
||||
<div className="col-xs-6">
|
||||
<TimeBountyField />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{useScheduling && <ScheduleFields />}
|
||||
|
||||
<div className="row form-group">
|
||||
<div className="col-xs-12">
|
||||
@ -162,6 +104,5 @@ export const Fields = connect((state: AppState) => ({
|
||||
schedulingAvailable: getNetworkConfig(state).name === 'Kovan',
|
||||
shouldDisplay: !isAnyOfflineWithWeb3(state),
|
||||
offline: getOffline(state),
|
||||
schedulingType: getCurrentScheduleType(state),
|
||||
useScheduling: getCurrentSchedulingToggle(state).value
|
||||
}))(FieldsClass);
|
||||
|
@ -6,6 +6,7 @@ const TIME_BOUNTY_MIN = new BN('1');
|
||||
|
||||
export const EAC_SCHEDULING_CONFIG = {
|
||||
DAPP_ADDRESS: 'https://app.chronologic.network',
|
||||
SCHEDULE_GAS_LIMIT_FALLBACK: new BN('21000'),
|
||||
SCHEDULE_GAS_PRICE_FALLBACK: 20, // Gwei
|
||||
FEE: new BN('2242000000000000'), // $2
|
||||
FEE_MULTIPLIER: new BN('2'),
|
||||
@ -61,7 +62,7 @@ export const calcEACTotalCost = (
|
||||
export const getScheduleData = (
|
||||
toAddress: string,
|
||||
callData = '',
|
||||
callGas: number,
|
||||
callGas: BN | null,
|
||||
callValue: BN | null,
|
||||
windowSize: number | null,
|
||||
windowStart: any,
|
||||
@ -71,12 +72,14 @@ export const getScheduleData = (
|
||||
) => {
|
||||
if (
|
||||
!callValue ||
|
||||
!callGas ||
|
||||
!callGasPrice ||
|
||||
!windowStart ||
|
||||
!windowSize ||
|
||||
!timeBounty ||
|
||||
timeBounty.lt(new BN(0)) ||
|
||||
callGasPrice.lt(new BN(0))
|
||||
callGasPrice.lt(new BN(0)) ||
|
||||
windowSize < 0
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
@ -33,6 +33,10 @@ const INITIAL_STATE: State = {
|
||||
raw: EAC_SCHEDULING_CONFIG.DEFAULT_SCHEDULING_METHOD,
|
||||
value: EAC_SCHEDULING_CONFIG.DEFAULT_SCHEDULING_METHOD
|
||||
},
|
||||
scheduleGasLimit: {
|
||||
raw: EAC_SCHEDULING_CONFIG.SCHEDULE_GAS_LIMIT_FALLBACK.toString(),
|
||||
value: EAC_SCHEDULING_CONFIG.SCHEDULE_GAS_LIMIT_FALLBACK
|
||||
},
|
||||
scheduleGasPrice: {
|
||||
raw: EAC_SCHEDULING_CONFIG.SCHEDULE_GAS_PRICE_FALLBACK.toString(),
|
||||
value: gasPriceToBase(EAC_SCHEDULING_CONFIG.SCHEDULE_GAS_PRICE_FALLBACK)
|
||||
@ -98,6 +102,8 @@ export const fields = (
|
||||
return updateField('scheduleType')(state, action);
|
||||
case TK.SCHEDULING_TOGGLE_SET:
|
||||
return updateField('schedulingToggle')(state, action);
|
||||
case TK.SCHEDULE_GAS_LIMIT_FIELD_SET:
|
||||
return updateField('scheduleGasLimit')(state, action);
|
||||
case TK.SCHEDULE_GAS_PRICE_FIELD_SET:
|
||||
return updateField('scheduleGasPrice')(state, action);
|
||||
case TK.TOKEN_TO_ETHER_SWAP:
|
||||
|
@ -8,7 +8,8 @@ import {
|
||||
SetScheduleTimestampFieldAction,
|
||||
SetScheduleTypeAction,
|
||||
SetSchedulingToggleAction,
|
||||
SetScheduleGasPriceFieldAction
|
||||
SetScheduleGasPriceFieldAction,
|
||||
SetScheduleGasLimitFieldAction
|
||||
} from 'actions/transaction';
|
||||
import { Wei } from 'libs/units';
|
||||
|
||||
@ -25,5 +26,6 @@ export interface State {
|
||||
windowStart: SetWindowStartFieldAction['payload'];
|
||||
scheduleTimestamp: SetScheduleTimestampFieldAction['payload'];
|
||||
scheduleType: SetScheduleTypeAction['payload'];
|
||||
scheduleGasLimit: SetScheduleGasLimitFieldAction['payload'];
|
||||
scheduleGasPrice: SetScheduleGasPriceFieldAction['payload'];
|
||||
}
|
||||
|
@ -3,7 +3,12 @@ import { getUnit, getTokenTo, getTokenValue } from './meta';
|
||||
import { AppState } from 'reducers';
|
||||
import { TokenValue, Wei, Address } from 'libs/units';
|
||||
import { gasPriceValidator, gasLimitValidator } from 'libs/validators';
|
||||
import { getDataExists, getGasPrice, getGasLimit } from 'selectors/transaction';
|
||||
import {
|
||||
getDataExists,
|
||||
getGasPrice,
|
||||
getGasLimit,
|
||||
getScheduleGasLimit
|
||||
} from 'selectors/transaction';
|
||||
import { isNetworkUnit } from 'selectors/config';
|
||||
import { getAddressMessage, AddressMessage } from 'config';
|
||||
|
||||
@ -47,6 +52,9 @@ const isValidGasLimit = (state: AppState): boolean => gasLimitValidator(getGasLi
|
||||
const isValidScheduleGasPrice = (state: AppState): boolean =>
|
||||
gasPriceValidator(getScheduleGasPrice(state).raw);
|
||||
|
||||
const isValidScheduleGasLimit = (state: AppState): boolean =>
|
||||
gasLimitValidator(getScheduleGasLimit(state).raw);
|
||||
|
||||
function getCurrentToAddressMessage(state: AppState): AddressMessage | undefined {
|
||||
const to = getCurrentTo(state);
|
||||
return getAddressMessage(to.raw);
|
||||
@ -61,6 +69,7 @@ export {
|
||||
isValidCurrentTo,
|
||||
isValidGasPrice,
|
||||
isValidGasLimit,
|
||||
isValidScheduleGasLimit,
|
||||
isValidScheduleGasPrice,
|
||||
getCurrentToAddressMessage
|
||||
};
|
||||
|
@ -16,6 +16,7 @@ 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 getDataExists = (state: AppState) => {
|
||||
@ -49,5 +50,6 @@ export {
|
||||
getScheduleTimestamp,
|
||||
getScheduleType,
|
||||
getSchedulingToggle,
|
||||
getScheduleGasLimit,
|
||||
getScheduleGasPrice
|
||||
};
|
||||
|
@ -27,7 +27,9 @@ import {
|
||||
getValidGasCost,
|
||||
isEtherTransaction,
|
||||
getScheduleGasPrice,
|
||||
isValidScheduleGasPrice
|
||||
isValidScheduleGasPrice,
|
||||
isValidScheduleGasLimit,
|
||||
getScheduleGasLimit
|
||||
} from 'selectors/transaction';
|
||||
import { Wei, Address, gasPriceToBase } from 'libs/units';
|
||||
import { getTransactionFields } from 'libs/transaction/utils/ether';
|
||||
@ -80,7 +82,6 @@ const getSchedulingTransaction = (state: AppState): IGetTransaction => {
|
||||
const scheduleType = getScheduleType(state);
|
||||
const windowStart = getWindowStart(state);
|
||||
const windowSize = getWindowSize(state);
|
||||
const gasLimit = getGasLimit(state);
|
||||
const nonce = getNonce(state);
|
||||
const gasPrice = getGasPrice(state);
|
||||
const timeBounty = getTimeBounty(state);
|
||||
@ -89,17 +90,20 @@ const getSchedulingTransaction = (state: AppState): IGetTransaction => {
|
||||
const scheduleTimestampValid = isScheduleTimestampValid(transactionFields);
|
||||
const scheduleGasPrice = getScheduleGasPrice(state);
|
||||
const scheduleGasPriceValid = isValidScheduleGasPrice(state);
|
||||
const scheduleGasLimit = getScheduleGasLimit(state);
|
||||
const scheduleGasLimitValid = isValidScheduleGasLimit(state);
|
||||
|
||||
const isFullTransaction =
|
||||
isFullTx(state, transactionFields, currentTo, currentValue, dataExists, validGasCost, unit) &&
|
||||
(windowStartValid || scheduleTimestampValid) &&
|
||||
windowSizeValid &&
|
||||
scheduleGasPriceValid;
|
||||
scheduleGasPriceValid &&
|
||||
scheduleGasLimitValid;
|
||||
|
||||
const transactionData = getScheduleData(
|
||||
currentTo.raw,
|
||||
callData.raw,
|
||||
parseInt(gasLimit.raw, 10),
|
||||
scheduleGasLimit.value,
|
||||
currentValue.value,
|
||||
windowSize.value,
|
||||
windowStart.value,
|
||||
@ -109,7 +113,7 @@ const getSchedulingTransaction = (state: AppState): IGetTransaction => {
|
||||
);
|
||||
|
||||
const endowment = calcEACEndowment(
|
||||
gasLimit.value || new BN(21000),
|
||||
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
|
||||
|
@ -28,7 +28,8 @@ describe('fields reducer', () => {
|
||||
scheduleGasPrice: {
|
||||
raw: EAC_SCHEDULING_CONFIG.SCHEDULE_GAS_PRICE_FALLBACK.toString(),
|
||||
value: gasPriceToBase(EAC_SCHEDULING_CONFIG.SCHEDULE_GAS_PRICE_FALLBACK)
|
||||
}
|
||||
},
|
||||
scheduleGasLimit: { raw: '21000', value: new BN(21000) }
|
||||
};
|
||||
const testPayload = { raw: 'test', value: null };
|
||||
|
||||
|
@ -67,6 +67,10 @@ describe('fields selector', () => {
|
||||
scheduleGasPrice: {
|
||||
raw: '1500',
|
||||
value: Wei('1500')
|
||||
},
|
||||
scheduleGasLimit: {
|
||||
raw: '21000',
|
||||
value: Wei('21000')
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -71,6 +71,10 @@ describe('helpers selector', () => {
|
||||
scheduleGasPrice: {
|
||||
raw: '1500',
|
||||
value: Wei('1500')
|
||||
},
|
||||
scheduleGasLimit: {
|
||||
raw: '21000',
|
||||
value: Wei('21000')
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -89,7 +93,8 @@ describe('helpers selector', () => {
|
||||
windowStart: null,
|
||||
scheduleTimestamp: null,
|
||||
scheduleType: 'time',
|
||||
scheduleGasPrice: Wei('1500')
|
||||
scheduleGasPrice: Wei('1500'),
|
||||
scheduleGasLimit: Wei('21000')
|
||||
};
|
||||
expect(reduceToValues(state.transaction.fields)).toEqual(values);
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user