mirror of
https://github.com/status-im/MyCrypto.git
synced 2025-01-20 16:09:28 +00:00
985ea0fb89
* [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
109 lines
3.8 KiB
TypeScript
109 lines
3.8 KiB
TypeScript
import { select, call, put, takeEvery } from 'redux-saga/effects';
|
|
import { SagaIterator } from 'redux-saga';
|
|
import { SetUnitMetaAction, TypeKeys } from 'actions/transaction';
|
|
import {
|
|
getTokenTo,
|
|
getTokenValue,
|
|
getTo,
|
|
getPreviousUnit,
|
|
getValue,
|
|
getDecimalFromUnit
|
|
} from 'selectors/transaction';
|
|
import { isNetworkUnit } from 'selectors/config';
|
|
import { getToken, MergedToken } from 'selectors/wallet';
|
|
import { TokenValue, Address } from 'libs/units';
|
|
import {
|
|
swapTokenToEther,
|
|
swapEtherToToken,
|
|
swapTokenToToken
|
|
} from 'actions/transaction/actionCreators/swap';
|
|
import { encodeTransfer } from 'libs/transaction';
|
|
import { AppState } from 'reducers';
|
|
import { bufferToHex } from 'ethereumjs-util';
|
|
import { validateInput, rebaseUserInput, IInput } from 'sagas/transaction/validationHelpers';
|
|
import { setSchedulingToggle } from 'actions/schedule';
|
|
|
|
export function* handleSetUnitMeta({ payload: currentUnit }: SetUnitMetaAction): SagaIterator {
|
|
const previousUnit: string = yield select(getPreviousUnit);
|
|
const prevUnit = yield select(isNetworkUnit, previousUnit);
|
|
const currUnit = yield select(isNetworkUnit, currentUnit);
|
|
const etherToEther = currUnit && prevUnit;
|
|
const etherToToken = !currUnit && prevUnit;
|
|
const tokenToEther = currUnit && !prevUnit;
|
|
const tokenToToken = !currUnit && !prevUnit;
|
|
const decimal: number = yield select(getDecimalFromUnit, currentUnit);
|
|
|
|
if (etherToEther || previousUnit === '') {
|
|
return;
|
|
}
|
|
|
|
if (tokenToEther) {
|
|
const tokenTo: AppState['transaction']['meta']['tokenTo'] = yield select(getTokenTo);
|
|
const tokenValue: AppState['transaction']['meta']['tokenValue'] = yield select(getTokenValue);
|
|
|
|
//set the 'to' field from what the token 'to' field was
|
|
// if switching to ether, clear token data and value
|
|
const { value, raw }: IInput = yield call(rebaseUserInput, tokenValue);
|
|
|
|
const isValid = yield call(validateInput, value, currentUnit);
|
|
return yield put(
|
|
swapTokenToEther({ to: tokenTo, value: { raw, value: isValid ? value : null }, decimal })
|
|
);
|
|
}
|
|
|
|
if (etherToToken || tokenToToken) {
|
|
const currentToken: MergedToken | undefined = yield select(getToken, currentUnit);
|
|
if (!currentToken) {
|
|
throw Error('Could not find token during unit swap');
|
|
}
|
|
const input:
|
|
| AppState['transaction']['fields']['value']
|
|
| AppState['transaction']['meta']['tokenValue'] = etherToToken
|
|
? yield select(getValue)
|
|
: yield select(getTokenValue);
|
|
const { raw, value }: IInput = yield call(rebaseUserInput, input);
|
|
|
|
const isValid = yield call(validateInput, value, currentUnit);
|
|
const to: AppState['transaction']['fields']['to'] = yield select(getTo);
|
|
|
|
const valueToEncode = isValid && value ? value : TokenValue('0');
|
|
let addressToEncode;
|
|
if (etherToToken) {
|
|
addressToEncode = to.value || Address('0x0');
|
|
} else {
|
|
const tokenTo: AppState['transaction']['meta']['tokenTo'] = yield select(getTokenTo);
|
|
addressToEncode = tokenTo.value || Address('0x0');
|
|
}
|
|
|
|
const data = encodeTransfer(addressToEncode, valueToEncode);
|
|
|
|
const basePayload = {
|
|
data: { raw: bufferToHex(data), value: data },
|
|
to: { raw: '', value: Address(currentToken.address) },
|
|
tokenValue: { raw, value: isValid ? value : null },
|
|
decimal
|
|
};
|
|
// need to set meta fields for tokenTo and tokenValue
|
|
if (etherToToken) {
|
|
yield put(
|
|
setSchedulingToggle({
|
|
value: false
|
|
})
|
|
);
|
|
|
|
return yield put(
|
|
swapEtherToToken({
|
|
...basePayload,
|
|
tokenTo: to
|
|
})
|
|
);
|
|
}
|
|
// need to rebase the token if the decimal has changed and re-validate
|
|
if (tokenToToken) {
|
|
return yield put(swapTokenToToken(basePayload));
|
|
}
|
|
}
|
|
}
|
|
|
|
export const handleSetUnit = [takeEvery(TypeKeys.UNIT_META_SET, handleSetUnitMeta)];
|