Merge pull request #32 from andrerfneves/feature/get-new-address-startup
Feature/get new address startup
This commit is contained in:
commit
c35a609319
|
@ -11,14 +11,11 @@ const SelectWrapper = styled.div`
|
|||
flex-direction: row;
|
||||
border-radius: ${props => props.theme.boxBorderRadius};
|
||||
border: none;
|
||||
background-color: ${// $FlowFixMe
|
||||
props => props.theme.colors.inputBackground};
|
||||
color: ${// $FlowFixMe
|
||||
props => props.theme.colors.text};
|
||||
background-color: ${props => props.theme.colors.inputBackground};
|
||||
color: ${props => props.theme.colors.text};
|
||||
width: 100%;
|
||||
outline: none;
|
||||
font-family: ${// $FlowFixMe
|
||||
props => props.theme.fontFamily};
|
||||
font-family: ${props => props.theme.fontFamily};
|
||||
cursor: pointer;
|
||||
position: relative;
|
||||
|
||||
|
@ -72,6 +69,7 @@ const OptionsWrapper = styled.div`
|
|||
position: absolute;
|
||||
width: 100%;
|
||||
${props => `${props.placement}: ${`-${props.optionsAmount * 60}px`}`};
|
||||
overflow-y: auto;
|
||||
`;
|
||||
|
||||
const Option = styled.button`
|
||||
|
|
|
@ -13,6 +13,7 @@ const Wrapper = styled.div`
|
|||
font-family: ${props => props.theme.fontFamily}
|
||||
background-color: ${props => props.theme.colors.sidebarBg};
|
||||
padding-top: 15px;
|
||||
position: relative;
|
||||
`;
|
||||
|
||||
const StyledLink = styled(Link)`
|
||||
|
@ -34,7 +35,6 @@ const StyledLink = styled(Link)`
|
|||
border-right: ${props => (props.isActive
|
||||
? `1px solid ${props.theme.colors.sidebarItemActive}`
|
||||
: 'none')};
|
||||
z-index: 100;
|
||||
cursor: pointer;
|
||||
|
||||
&:hover {
|
||||
|
|
|
@ -74,6 +74,24 @@ const mapDispatchToProps = (dispatch: Dispatch) => ({
|
|||
sortBy('day'),
|
||||
])(transactions);
|
||||
|
||||
if (!zAddresses.length) {
|
||||
const [getNewZAddressErr, newZAddress] = await eres(
|
||||
rpc.z_getnewaddress(),
|
||||
);
|
||||
|
||||
if (!getNewZAddressErr && newZAddress) {
|
||||
zAddresses.push(newZAddress);
|
||||
}
|
||||
}
|
||||
|
||||
if (!transparentAddresses.length) {
|
||||
const [getNewAddressErr, newAddress] = await eres(rpc.getnewaddress(''));
|
||||
|
||||
if (!getNewAddressErr && newAddress) {
|
||||
transparentAddresses.push(newAddress);
|
||||
}
|
||||
}
|
||||
|
||||
dispatch(
|
||||
loadWalletSummarySuccess({
|
||||
transparent: walletSummary.transparent,
|
||||
|
|
|
@ -10,6 +10,7 @@ import {
|
|||
sendTransaction,
|
||||
sendTransactionSuccess,
|
||||
sendTransactionError,
|
||||
resetSendTransaction,
|
||||
} from '../redux/modules/send';
|
||||
|
||||
import filterObjectNullKeys from '../utils/filterObjectNullKeys';
|
||||
|
@ -31,6 +32,7 @@ const mapStateToProps = ({ walletSummary, sendStatus }: AppState) => ({
|
|||
addresses: walletSummary.addresses,
|
||||
error: sendStatus.error,
|
||||
isSending: sendStatus.isSending,
|
||||
operationId: sendStatus.operationId,
|
||||
});
|
||||
|
||||
const mapDispatchToProps = (dispatch: Dispatch) => ({
|
||||
|
@ -43,7 +45,7 @@ const mapDispatchToProps = (dispatch: Dispatch) => ({
|
|||
}: SendTransactionInput) => {
|
||||
dispatch(sendTransaction());
|
||||
|
||||
const [sendErr] = await eres(
|
||||
const [sendErr, operationId] = await eres(
|
||||
rpc.z_sendmany(
|
||||
from,
|
||||
// $FlowFixMe
|
||||
|
@ -60,10 +62,11 @@ const mapDispatchToProps = (dispatch: Dispatch) => ({
|
|||
);
|
||||
|
||||
// eslint-disable-next-line
|
||||
if (sendErr) return dispatch(sendTransactionError({ error: sendErr.message }));
|
||||
if (sendErr || !operationId) return dispatch(sendTransactionError({ error: sendErr.message }));
|
||||
|
||||
dispatch(sendTransactionSuccess());
|
||||
dispatch(sendTransactionSuccess({ operationId }));
|
||||
},
|
||||
resetSendView: () => dispatch(resetSendTransaction()),
|
||||
});
|
||||
|
||||
export const SendContainer = connect(
|
||||
|
|
|
@ -4,15 +4,22 @@ 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';
|
||||
|
||||
export const sendTransaction = () => ({
|
||||
type: SEND_TRANSACTION,
|
||||
payload: {},
|
||||
});
|
||||
|
||||
export const sendTransactionSuccess = () => ({
|
||||
export const sendTransactionSuccess = ({
|
||||
operationId,
|
||||
}: {
|
||||
operationId: string,
|
||||
}) => ({
|
||||
type: SEND_TRANSACTION_SUCCESS,
|
||||
payload: {},
|
||||
payload: {
|
||||
operationId,
|
||||
},
|
||||
});
|
||||
|
||||
export const sendTransactionError = ({ error }: { error: string }) => ({
|
||||
|
@ -22,24 +29,41 @@ export const sendTransactionError = ({ error }: { error: string }) => ({
|
|||
},
|
||||
});
|
||||
|
||||
export const resetSendTransaction = () => ({
|
||||
type: RESET_SEND_TRANSACTION,
|
||||
payload: {},
|
||||
});
|
||||
|
||||
export type State = {
|
||||
isSending: boolean,
|
||||
error: string | null,
|
||||
operationId: string | null,
|
||||
};
|
||||
|
||||
const initialState = {
|
||||
isSending: false,
|
||||
error: null,
|
||||
operationId: null,
|
||||
};
|
||||
|
||||
export default (state: State = initialState, action: Action) => {
|
||||
export default (state: State = initialState, action: Action): State => {
|
||||
switch (action.type) {
|
||||
case SEND_TRANSACTION:
|
||||
return { isSending: true, error: null };
|
||||
return { isSending: true, error: null, operationId: null };
|
||||
case SEND_TRANSACTION_SUCCESS:
|
||||
return { isSending: false, error: null };
|
||||
return {
|
||||
isSending: false,
|
||||
error: null,
|
||||
operationId: action.payload.operationId,
|
||||
};
|
||||
case SEND_TRANSACTION_ERROR:
|
||||
return { isSending: false, error: action.payload.error };
|
||||
return {
|
||||
isSending: false,
|
||||
error: action.payload.error,
|
||||
operationId: null,
|
||||
};
|
||||
case RESET_SEND_TRANSACTION:
|
||||
return initialState;
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ export const ReceiveView = ({ addresses }: Props) => (
|
|||
{(addresses || []).map(address => (
|
||||
<Row alignItems='center' justifyContent='space-between'>
|
||||
<ColumnComponent width='85%'>
|
||||
<Label value='Your z-address: ' />
|
||||
<Label value='Your Address: ' />
|
||||
<InputComponent
|
||||
value={address}
|
||||
onChange={() => {}}
|
||||
|
|
|
@ -17,6 +17,7 @@ import { Button } from '../components/button';
|
|||
import formatNumber from '../utils/formatNumber';
|
||||
|
||||
import type { SendTransactionInput } from '../containers/send';
|
||||
import type { State as SendState } from '../redux/modules/send';
|
||||
|
||||
const FormWrapper = styled.div`
|
||||
margin-top: ${props => props.theme.layoutContentPaddingTop};
|
||||
|
@ -77,14 +78,20 @@ const FormButton = styled(Button)`
|
|||
}
|
||||
`;
|
||||
|
||||
type Props = {
|
||||
const SuccessWrapper = styled(ColumnComponent)`
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 100%;
|
||||
`;
|
||||
|
||||
type Props = SendState & {
|
||||
balance: number,
|
||||
zecPrice: number,
|
||||
addresses: string[],
|
||||
sendTransaction: SendTransactionInput => void,
|
||||
// error: string | null,
|
||||
isSending: boolean,
|
||||
resetSendView: () => void,
|
||||
};
|
||||
|
||||
type State = {
|
||||
showFee: boolean,
|
||||
from: string,
|
||||
|
@ -95,16 +102,18 @@ type State = {
|
|||
memo: string,
|
||||
};
|
||||
|
||||
const initialState = {
|
||||
showFee: false,
|
||||
from: '',
|
||||
amount: '0',
|
||||
to: '',
|
||||
feeType: FEES.LOW,
|
||||
fee: FEES.LOW,
|
||||
memo: '',
|
||||
};
|
||||
|
||||
export class SendView extends PureComponent<Props, State> {
|
||||
state = {
|
||||
showFee: false,
|
||||
from: '',
|
||||
amount: '0',
|
||||
to: '',
|
||||
feeType: FEES.LOW,
|
||||
fee: FEES.LOW,
|
||||
memo: '',
|
||||
};
|
||||
state = initialState;
|
||||
|
||||
handleChange = (field: string) => (value: string) => {
|
||||
this.setState(() => ({
|
||||
|
@ -149,9 +158,20 @@ export class SendView extends PureComponent<Props, State> {
|
|||
});
|
||||
};
|
||||
|
||||
reset = () => {
|
||||
const { resetSendView } = this.props;
|
||||
|
||||
this.setState(initialState, () => resetSendView());
|
||||
};
|
||||
|
||||
render() {
|
||||
const {
|
||||
addresses, balance, zecPrice, isSending,
|
||||
addresses,
|
||||
balance,
|
||||
zecPrice,
|
||||
isSending,
|
||||
error,
|
||||
operationId,
|
||||
} = this.props;
|
||||
const {
|
||||
showFee, from, amount, to, memo, fee, feeType,
|
||||
|
@ -171,9 +191,20 @@ export class SendView extends PureComponent<Props, State> {
|
|||
append: 'USD $',
|
||||
});
|
||||
|
||||
return (
|
||||
return operationId ? (
|
||||
<SuccessWrapper>
|
||||
<TextComponent value={`Processing operation: ${operationId}`} />
|
||||
<TextComponent value={`Amount: ${amount}`} />
|
||||
<TextComponent value={`From: ${from}`} />
|
||||
<TextComponent value={`To: ${to}`} />
|
||||
<button type='button' onClick={this.reset}>
|
||||
Send again!
|
||||
</button>
|
||||
</SuccessWrapper>
|
||||
) : (
|
||||
<RowComponent justifyContent='space-between'>
|
||||
<FormWrapper>
|
||||
{error && <TextComponent value={error} />}
|
||||
<InputLabelComponent value='From' />
|
||||
<SelectComponent
|
||||
onChange={this.handleChange('from')}
|
||||
|
|
|
@ -745,7 +745,7 @@ export type APIMethods = {
|
|||
z_exportviewingkey: (zaddr: string) => Promise<string>,
|
||||
z_exportwallet: (filename: string) => Promise<string>,
|
||||
z_getbalance: (address: string, minconf?: number) => Promise<number>,
|
||||
z_getnewaddress: (type: string) => Promise<string>,
|
||||
z_getnewaddress: (type: ?string) => Promise<string>,
|
||||
z_getoperationresult: (operationid?: string[]) => Promise<Object[]>,
|
||||
z_getoperationstatus: (operationid?: string[]) => Promise<Object[]>,
|
||||
z_gettotalbalance: (
|
||||
|
|
Loading…
Reference in New Issue