mirror of
https://github.com/status-im/MyCrypto.git
synced 2025-01-09 18:45:38 +00:00
6ec04f6731
* Fixed borked tag. * Fix saga tests. * fix tscheck error
34 lines
1.3 KiB
TypeScript
34 lines
1.3 KiB
TypeScript
import { isEtherTransaction } from 'selectors/transaction';
|
|
import { SetCurrentToAction } from 'actions/transaction/actionTypes/current';
|
|
import { setToField } from 'actions/transaction/actionCreators/fields';
|
|
import { setTokenTo } from 'actions/transaction/actionCreators/meta';
|
|
import { Address } from 'libs/units';
|
|
import { select, call, put, takeLatest } from 'redux-saga/effects';
|
|
import { SagaIterator } from 'redux-saga';
|
|
import { isValidENSAddress, isValidETHAddress } from 'libs/validators';
|
|
import { TypeKeys } from 'actions/transaction/constants';
|
|
|
|
export function* setCurrentTo({ payload: raw }: SetCurrentToAction): SagaIterator {
|
|
const validAddress: boolean = yield call(isValidETHAddress, raw);
|
|
const validEns: boolean = yield call(isValidENSAddress, raw);
|
|
const etherTransaction: boolean = yield select(isEtherTransaction);
|
|
|
|
let value: Buffer | null = null;
|
|
let error: string | null = null;
|
|
if (validAddress) {
|
|
value = Address(raw);
|
|
} else if (validEns) {
|
|
// TODO: Resolve ENS on networks that support it, error on ones that don't
|
|
error = 'ENS is not supported yet';
|
|
}
|
|
|
|
const payload = { raw, value, error };
|
|
if (etherTransaction) {
|
|
yield put(setToField(payload));
|
|
} else {
|
|
yield put(setTokenTo(payload));
|
|
}
|
|
}
|
|
|
|
export const currentTo = takeLatest([TypeKeys.CURRENT_TO_SET], setCurrentTo);
|