2018-12-21 07:44:11 -08:00
|
|
|
// @flow
|
|
|
|
import type { Action } from '../../types/redux';
|
|
|
|
|
|
|
|
export const SEND_TRANSACTION = 'SEND_TRANSACTION';
|
|
|
|
export const SEND_TRANSACTION_SUCCESS = 'SEND_TRANSACTION_SUCCESS';
|
|
|
|
export const SEND_TRANSACTION_ERROR = 'SEND_TRANSACTION_ERROR';
|
2019-01-10 06:51:32 -08:00
|
|
|
export const RESET_SEND_TRANSACTION = 'RESET_SEND_TRANSACTION';
|
2019-01-21 10:16:16 -08:00
|
|
|
export const VALIDATE_ADDRESS_SUCCESS = 'VALIDATE_ADDRESS_SUCCESS';
|
|
|
|
export const VALIDATE_ADDRESS_ERROR = 'VALIDATE_ADDRESS_SUCCESS';
|
2019-01-24 06:15:09 -08:00
|
|
|
export const LOAD_ZEC_PRICE = 'LOAD_ZEC_PRICE';
|
2018-12-21 07:44:11 -08:00
|
|
|
|
|
|
|
export const sendTransaction = () => ({
|
|
|
|
type: SEND_TRANSACTION,
|
|
|
|
payload: {},
|
|
|
|
});
|
|
|
|
|
2019-01-10 06:51:32 -08:00
|
|
|
export const sendTransactionSuccess = ({
|
|
|
|
operationId,
|
|
|
|
}: {
|
|
|
|
operationId: string,
|
|
|
|
}) => ({
|
2018-12-21 07:44:11 -08:00
|
|
|
type: SEND_TRANSACTION_SUCCESS,
|
2019-01-10 06:51:32 -08:00
|
|
|
payload: {
|
|
|
|
operationId,
|
|
|
|
},
|
2018-12-21 07:44:11 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
export const sendTransactionError = ({ error }: { error: string }) => ({
|
|
|
|
type: SEND_TRANSACTION_ERROR,
|
|
|
|
payload: {
|
|
|
|
error,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2019-01-10 06:51:32 -08:00
|
|
|
export const resetSendTransaction = () => ({
|
|
|
|
type: RESET_SEND_TRANSACTION,
|
|
|
|
payload: {},
|
|
|
|
});
|
|
|
|
|
2019-01-21 10:16:16 -08:00
|
|
|
export const validateAddressSuccess = ({ isValid }: { isValid: boolean }) => ({
|
|
|
|
type: VALIDATE_ADDRESS_SUCCESS,
|
|
|
|
payload: {
|
|
|
|
isValid,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
export const validateAddressError = () => ({
|
|
|
|
type: VALIDATE_ADDRESS_ERROR,
|
|
|
|
payload: {},
|
|
|
|
});
|
|
|
|
|
2019-01-24 06:15:09 -08:00
|
|
|
export const loadZECPrice = ({ value }: { value: number }) => ({
|
|
|
|
type: LOAD_ZEC_PRICE,
|
|
|
|
payload: {
|
|
|
|
value,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2018-12-21 07:44:11 -08:00
|
|
|
export type State = {
|
|
|
|
isSending: boolean,
|
2019-01-21 10:16:16 -08:00
|
|
|
isToAddressValid: boolean,
|
2018-12-21 07:44:11 -08:00
|
|
|
error: string | null,
|
2019-01-10 06:51:32 -08:00
|
|
|
operationId: string | null,
|
2019-01-24 06:15:09 -08:00
|
|
|
zecPrice: number,
|
2018-12-21 07:44:11 -08:00
|
|
|
};
|
|
|
|
|
2019-01-21 10:16:16 -08:00
|
|
|
const initialState: State = {
|
2018-12-21 07:44:11 -08:00
|
|
|
isSending: false,
|
|
|
|
error: null,
|
2019-01-10 06:51:32 -08:00
|
|
|
operationId: null,
|
2019-01-21 10:16:16 -08:00
|
|
|
isToAddressValid: false,
|
2019-01-24 06:15:09 -08:00
|
|
|
zecPrice: 0,
|
2018-12-21 07:44:11 -08:00
|
|
|
};
|
|
|
|
|
2019-01-10 06:51:32 -08:00
|
|
|
export default (state: State = initialState, action: Action): State => {
|
2018-12-21 07:44:11 -08:00
|
|
|
switch (action.type) {
|
|
|
|
case SEND_TRANSACTION:
|
2019-01-21 10:16:16 -08:00
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
isSending: true,
|
|
|
|
error: null,
|
|
|
|
operationId: null,
|
|
|
|
};
|
2018-12-21 07:44:11 -08:00
|
|
|
case SEND_TRANSACTION_SUCCESS:
|
2019-01-10 06:51:32 -08:00
|
|
|
return {
|
2019-01-21 10:16:16 -08:00
|
|
|
...state,
|
2019-01-10 06:51:32 -08:00
|
|
|
isSending: false,
|
|
|
|
error: null,
|
|
|
|
operationId: action.payload.operationId,
|
|
|
|
};
|
2018-12-21 07:44:11 -08:00
|
|
|
case SEND_TRANSACTION_ERROR:
|
2019-01-10 06:51:32 -08:00
|
|
|
return {
|
2019-01-21 10:16:16 -08:00
|
|
|
...state,
|
2019-01-10 06:51:32 -08:00
|
|
|
isSending: false,
|
|
|
|
error: action.payload.error,
|
|
|
|
operationId: null,
|
|
|
|
};
|
2019-01-21 10:16:16 -08:00
|
|
|
case VALIDATE_ADDRESS_SUCCESS:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
isToAddressValid: action.payload.isValid,
|
|
|
|
};
|
|
|
|
case VALIDATE_ADDRESS_ERROR:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
isToAddressValid: false,
|
|
|
|
};
|
2019-01-24 06:15:09 -08:00
|
|
|
case LOAD_ZEC_PRICE:
|
|
|
|
return { ...state, zecPrice: action.payload.value };
|
2019-01-10 06:51:32 -08:00
|
|
|
case RESET_SEND_TRANSACTION:
|
|
|
|
return initialState;
|
2018-12-21 07:44:11 -08:00
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
};
|