MyCrypto/common/reducers/schedule/schedule.ts

78 lines
2.9 KiB
TypeScript
Raw Normal View History

Ethereum Alarm Clock Integration (#1343) * [FEATURE] Initial EAC integration. * Title and explanation * [FEATURE] Move the Schedule Payment to the main tab. * [FEATURE] TimeBounty slider. * [FEATURE] Move to main menu. * [FEATURE] Redirection to the DApp for details. * [FEATURE] Timestamp scheduling * Scheduling: Basic date and time widget * Linting fixes * Moved the datetime field to new tab * Fixed push errors * Added missing specs * Undid unintentional UI change * Fixed some failing tests * Ignore datetime parameter when checking if a transaction is full * Added a date selector widget and renamed ScheduleTimestamp to ScheduleDate * Marked componentDidMount * Initialized Pikaday * Revert "Initialized Pikaday" This reverts commit 4e5bf5b2b882f236f5977400abf9b7092cbd1592. * Revert "Marked componentDidMount" This reverts commit 85d52192ac58f4b6ca9219e702f7390cd27e582f. * Revert "Added a date selector widget and renamed ScheduleTimestamp to ScheduleDate" This reverts commit aaad0ac9b565a78d1bfc631754160919fd38a59b. * Converted the date picker into a datetime picker * Added decent styling to the datetimepicker * Added validation to the datetime picker * Fixed prepush errors for scheduling timestamp * Adjusted validation logic scheduling timestamp * [FEATURE] Move scheduling to main tab. * [FEATURE] Timezone selector * [FEATURE] Scheduling: Timezone selector * Removed zombie files * [FEATURE] Reimplement Time Bounty. * [FEATURE] Time/block selector * [FEATURE] Add Window Size field. * [FEATURE] Time/block switch functionality * Implemented time/block switcher fuctionality * [FEATURE] Add Schedule Gas Price field. * [FEATURE] Scheduling toggle * [FEATURE] Add basic styling and network check. * [FEATURE] Add Schedule Gas Limit field * [FEATURE] "Scheduled" button styling * Reordered, renamed and centered scheduling elements * Added the toggle button styling * Class -> ClassName * [FEATURE] Add Deposit field * [FEATURE] Move scheduling code into one directory * [FIX] Scheduling responsiveness * [FIX] Datetime picker not working on md screens * [FEATURE] Timestamp Scheduling basic functionality * [FIX] Fix data serialization. * [FEATURE] Timezone inclusion * [FEATURE] Add ChronoLogic logo. * [FEATURE] Add link to image. * [FIX] Update CSS of logo. * [FEATURE] Default Window Size * [FEATURE] Modified Help component to enable acting as a tooltip * [FEATURE] Call contract to validate scheduling params * [FIX] Change moment import to fix tests * [FEATURE] Gas estimation for scheduling * [FEATURE] Additional validation * [FEATURE] UI changes and descriptions * [FEATURE] Add tooltip to window and fix fee display. * [FIX] Fix ethereumjs-abi dependency. * [FEATURE] Hide scheduling when sending tokens. * [FIX] Improved styling datetime picker * [FEATURE] Add Redux state for scheduling * [FEATURE] Create Toggle component, Share code between components * [FEATURE] Use Tooltip component for help. * [FEATURE] Better datetime picker * [FEATURE] Remove fee * Trigger mycryptobuild * [FIX] Timestamp scheduling - Validation match * [FIX] EAC integration touchups * [FIX] Code review fixes * [FIX] Window Size type * [FIX] Type fixes. * [FIX] Make tooltips only show on icons + resposiveness fixes * [FIX] Break tooltips into more lines * [FIX] Remove unnecessary code. * [FIX] Remove unnecessary code. * [FIX] Remove unnecessary types declaration. * [FIX] Fee class names
2018-04-14 22:21:33 +00:00
import { ScheduleFieldAction, TypeKeys as TK } from 'actions/schedule';
import { Reducer } from 'redux';
import { State } from './typings';
import { gasPriceToBase, fromWei } from 'libs/units';
import { EAC_SCHEDULING_CONFIG } from 'libs/scheduling';
import moment from 'moment-timezone';
import { minFromNow } from 'selectors/schedule/helpers';
const INITIAL_STATE: State = {
schedulingToggle: { value: false },
windowSize: { raw: '', value: null },
windowStart: { raw: '', value: null },
scheduleTimestamp: {
raw: moment(minFromNow(60)).format(EAC_SCHEDULING_CONFIG.SCHEDULE_TIMESTAMP_FORMAT),
value: minFromNow(60)
},
scheduleTimezone: { raw: moment.tz.guess(), value: moment.tz.guess() },
timeBounty: {
raw: fromWei(EAC_SCHEDULING_CONFIG.TIME_BOUNTY_DEFAULT, 'ether'),
value: EAC_SCHEDULING_CONFIG.TIME_BOUNTY_DEFAULT
},
scheduleType: {
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)
},
scheduleDeposit: { raw: '', value: null },
scheduleParamsValidity: { value: true }
};
const updateScheduleField = (key: keyof State): Reducer<State> => (
state: State,
action: ScheduleFieldAction
) => ({
...state,
[key]: { ...state[key], ...action.payload }
});
export const schedule = (state: State = INITIAL_STATE, action: ScheduleFieldAction) => {
switch (action.type) {
case TK.TIME_BOUNTY_FIELD_SET:
return updateScheduleField('timeBounty')(state, action);
case TK.WINDOW_SIZE_FIELD_SET:
return updateScheduleField('windowSize')(state, action);
case TK.WINDOW_START_FIELD_SET:
return updateScheduleField('windowStart')(state, action);
case TK.SCHEDULE_TIMESTAMP_FIELD_SET:
return updateScheduleField('scheduleTimestamp')(state, action);
case TK.SCHEDULE_TIMEZONE_SET:
return updateScheduleField('scheduleTimezone')(state, action);
case TK.SCHEDULE_TYPE_SET:
return updateScheduleField('scheduleType')(state, action);
case TK.SCHEDULING_TOGGLE_SET:
return updateScheduleField('schedulingToggle')(state, action);
case TK.SCHEDULE_GAS_LIMIT_FIELD_SET:
return updateScheduleField('scheduleGasLimit')(state, action);
case TK.SCHEDULE_GAS_PRICE_FIELD_SET:
return updateScheduleField('scheduleGasPrice')(state, action);
case TK.SCHEDULE_DEPOSIT_FIELD_SET:
return updateScheduleField('scheduleDeposit')(state, action);
case TK.SCHEDULE_PARAMS_VALIDITY_SET:
return updateScheduleField('scheduleParamsValidity')(state, action);
default:
return state;
}
};
export { State };
export default schedule;