zepio/app/redux/modules/send.js

112 lines
2.6 KiB
JavaScript
Raw Normal View History

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';
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';
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-29 07:36:13 -08:00
export const sendTransactionSuccess = ({ operationId }: { operationId: string }) => ({
2018-12-21 07:44:11 -08:00
type: SEND_TRANSACTION_SUCCESS,
payload: {
operationId,
},
2018-12-21 07:44:11 -08:00
});
export const sendTransactionError = ({ error }: { error: string }) => ({
type: SEND_TRANSACTION_ERROR,
payload: {
error,
},
});
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: {},
});
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,
operationId: string | null,
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,
operationId: null,
2019-01-21 10:16:16 -08:00
isToAddressValid: false,
zecPrice: 0,
2018-12-21 07:44:11 -08:00
};
2019-01-29 07:36:13 -08:00
// eslint-disable-next-line
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:
return {
2019-01-21 10:16:16 -08:00
...state,
isSending: false,
error: null,
operationId: action.payload.operationId,
};
2018-12-21 07:44:11 -08:00
case SEND_TRANSACTION_ERROR:
return {
2019-01-21 10:16:16 -08:00
...state,
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,
};
case LOAD_ZEC_PRICE:
return { ...state, zecPrice: action.payload.value };
case RESET_SEND_TRANSACTION:
return initialState;
2018-12-21 07:44:11 -08:00
default:
return state;
}
};