zepio/app/containers/send.js

72 lines
1.5 KiB
JavaScript
Raw Normal View History

2018-12-20 10:56:45 -08:00
// @flow
import { connect } from 'react-redux';
2018-12-21 07:44:11 -08:00
import eres from 'eres';
2018-12-20 10:56:45 -08:00
2018-12-21 07:44:11 -08:00
import rpc from '../../services/api';
2018-12-20 10:56:45 -08:00
import { SendView } from '../views/send';
2018-12-21 07:44:11 -08:00
import {
sendTransaction,
sendTransactionSuccess,
sendTransactionError,
} from '../redux/modules/send';
2019-01-07 10:59:27 -08:00
import filterObjectNullKeys from '../utils/filterObjectNullKeys';
2018-12-20 10:56:45 -08:00
import type { AppState } from '../types/app-state';
2018-12-21 07:44:11 -08:00
import type { Dispatch } from '../types/redux';
export type SendTransactionInput = {
from: string,
to: string,
2019-01-07 10:59:27 -08:00
amount: string,
2018-12-21 07:44:11 -08:00
fee: number,
memo: string,
};
2018-12-20 10:56:45 -08:00
2018-12-21 07:44:11 -08:00
const mapStateToProps = ({ walletSummary, sendStatus }: AppState) => ({
2018-12-20 10:56:45 -08:00
balance: walletSummary.total,
zecPrice: walletSummary.zecPrice,
addresses: walletSummary.addresses,
2018-12-21 07:44:11 -08:00
error: sendStatus.error,
isSending: sendStatus.isSending,
});
const mapDispatchToProps = (dispatch: Dispatch) => ({
sendTransaction: async ({
from,
to,
amount,
fee,
memo,
}: SendTransactionInput) => {
dispatch(sendTransaction());
const [sendErr] = await eres(
2019-01-07 10:59:27 -08:00
rpc.z_sendmany(
from,
// $FlowFixMe
[
filterObjectNullKeys({
address: to,
amount: Number.parseFloat(amount),
memo,
}),
],
1,
Number.parseFloat(String(fee)),
),
2018-12-21 07:44:11 -08:00
);
// eslint-disable-next-line
if (sendErr) return dispatch(sendTransactionError({ error: sendErr.message }));
dispatch(sendTransactionSuccess());
},
2018-12-20 10:56:45 -08:00
});
2018-12-21 07:44:11 -08:00
export const SendContainer = connect(
mapStateToProps,
mapDispatchToProps,
)(SendView);