mirror of
https://github.com/status-im/MyCrypto.git
synced 2025-03-02 03:30:31 +00:00
* [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
158 lines
4.9 KiB
TypeScript
158 lines
4.9 KiB
TypeScript
import { SagaIterator, buffers, delay } from 'redux-saga';
|
|
import {
|
|
apply,
|
|
put,
|
|
select,
|
|
take,
|
|
actionChannel,
|
|
call,
|
|
fork,
|
|
race,
|
|
takeEvery
|
|
} from 'redux-saga/effects';
|
|
import BN from 'bn.js';
|
|
import { INode } from 'libs/nodes/INode';
|
|
import { getNodeLib, getOffline, getAutoGasLimitEnabled } from 'selectors/config';
|
|
import { getWalletInst } from 'selectors/wallet';
|
|
import { getTransaction, IGetTransaction, getCurrentToAddressMessage } from 'selectors/transaction';
|
|
import {
|
|
EstimateGasRequestedAction,
|
|
setGasLimitField,
|
|
estimateGasTimedout,
|
|
estimateGasSucceeded,
|
|
TypeKeys,
|
|
estimateGasRequested,
|
|
SetToFieldAction,
|
|
SetDataFieldAction,
|
|
SwapEtherToTokenAction,
|
|
SwapTokenToTokenAction,
|
|
SwapTokenToEtherAction,
|
|
estimateGasFailed
|
|
} from 'actions/transaction';
|
|
import { TypeKeys as ConfigTypeKeys, ToggleAutoGasLimitAction } from 'actions/config';
|
|
import { IWallet } from 'libs/wallet';
|
|
import { makeTransaction, getTransactionFields, IHexStrTransaction } from 'libs/transaction';
|
|
import { AddressMessage } from 'config';
|
|
import { isSchedulingEnabled } from 'selectors/schedule/fields';
|
|
import { setScheduleGasLimitField } from 'actions/schedule';
|
|
|
|
export function* shouldEstimateGas(): SagaIterator {
|
|
while (true) {
|
|
const action:
|
|
| SetToFieldAction
|
|
| SetDataFieldAction
|
|
| SwapEtherToTokenAction
|
|
| SwapTokenToTokenAction
|
|
| SwapTokenToEtherAction
|
|
| ToggleAutoGasLimitAction = yield take([
|
|
TypeKeys.TO_FIELD_SET,
|
|
TypeKeys.DATA_FIELD_SET,
|
|
TypeKeys.ETHER_TO_TOKEN_SWAP,
|
|
TypeKeys.TOKEN_TO_TOKEN_SWAP,
|
|
TypeKeys.TOKEN_TO_ETHER_SWAP,
|
|
ConfigTypeKeys.CONFIG_TOGGLE_AUTO_GAS_LIMIT
|
|
]);
|
|
|
|
const isOffline: boolean = yield select(getOffline);
|
|
const autoGasLimitEnabled: boolean = yield select(getAutoGasLimitEnabled);
|
|
const message: AddressMessage | undefined = yield select(getCurrentToAddressMessage);
|
|
|
|
if (isOffline || !autoGasLimitEnabled || (message && message.gasLimit)) {
|
|
continue;
|
|
}
|
|
|
|
// invalid field is a field that the value is null and the input box isnt empty
|
|
// reason being is an empty field is valid because it'll be null
|
|
const invalidField =
|
|
(action.type === TypeKeys.TO_FIELD_SET || action.type === TypeKeys.DATA_FIELD_SET) &&
|
|
!action.payload.value &&
|
|
action.payload.raw !== '';
|
|
|
|
if (invalidField) {
|
|
continue;
|
|
}
|
|
const { transaction }: IGetTransaction = yield select(getTransaction);
|
|
|
|
const { gasLimit, gasPrice, nonce, chainId, ...rest }: IHexStrTransaction = yield call(
|
|
getTransactionFields,
|
|
transaction
|
|
);
|
|
|
|
yield put(estimateGasRequested(rest));
|
|
}
|
|
}
|
|
|
|
export function* estimateGas(): SagaIterator {
|
|
const requestChan = yield actionChannel(TypeKeys.ESTIMATE_GAS_REQUESTED, buffers.sliding(1));
|
|
|
|
while (true) {
|
|
const autoGasLimitEnabled: boolean = yield select(getAutoGasLimitEnabled);
|
|
const isOffline = yield select(getOffline);
|
|
|
|
if (isOffline || !autoGasLimitEnabled) {
|
|
continue;
|
|
}
|
|
|
|
const { payload }: EstimateGasRequestedAction = yield take(requestChan);
|
|
// debounce 250 ms
|
|
yield call(delay, 250);
|
|
const node: INode = yield select(getNodeLib);
|
|
const walletInst: IWallet = yield select(getWalletInst);
|
|
try {
|
|
const from: string = yield apply(walletInst, walletInst.getAddressString);
|
|
const txObj = { ...payload, from };
|
|
const { gasLimit } = yield race({
|
|
gasLimit: apply(node, node.estimateGas, [txObj]),
|
|
timeout: call(delay, 10000)
|
|
});
|
|
if (gasLimit) {
|
|
const gasSetOptions = {
|
|
raw: gasLimit.toString(),
|
|
value: gasLimit
|
|
};
|
|
|
|
const scheduling: boolean = yield select(isSchedulingEnabled);
|
|
|
|
if (scheduling) {
|
|
yield put(setScheduleGasLimitField(gasSetOptions));
|
|
} else {
|
|
yield put(setGasLimitField(gasSetOptions));
|
|
}
|
|
|
|
yield put(estimateGasSucceeded());
|
|
} else {
|
|
yield put(estimateGasTimedout());
|
|
yield call(localGasEstimation, payload);
|
|
}
|
|
} catch (e) {
|
|
yield put(estimateGasFailed());
|
|
yield call(localGasEstimation, payload);
|
|
}
|
|
}
|
|
}
|
|
|
|
export function* localGasEstimation(payload: EstimateGasRequestedAction['payload']) {
|
|
const tx = yield call(makeTransaction, payload);
|
|
const gasLimit = yield apply(tx, tx.getBaseFee);
|
|
yield put(setGasLimitField({ raw: gasLimit.toString(), value: gasLimit }));
|
|
}
|
|
|
|
export function* setAddressMessageGasLimit() {
|
|
const autoGasLimitEnabled: boolean = yield select(getAutoGasLimitEnabled);
|
|
const message: AddressMessage | undefined = yield select(getCurrentToAddressMessage);
|
|
if (autoGasLimitEnabled && message && message.gasLimit) {
|
|
yield put(
|
|
setGasLimitField({
|
|
raw: message.gasLimit.toString(),
|
|
value: new BN(message.gasLimit)
|
|
})
|
|
);
|
|
}
|
|
}
|
|
|
|
export const gas = [
|
|
fork(shouldEstimateGas),
|
|
fork(estimateGas),
|
|
takeEvery(TypeKeys.TO_FIELD_SET, setAddressMessageGasLimit)
|
|
];
|