|
|
|
@ -6,6 +6,7 @@ import * as BLOCKCHAIN from 'actions/constants/blockchain';
|
|
|
|
|
import { initialState } from 'reducers/SendFormRippleReducer';
|
|
|
|
|
import * as reducerUtils from 'reducers/utils';
|
|
|
|
|
import { fromDecimalAmount } from 'utils/formatUtils';
|
|
|
|
|
import { toFiatCurrency, fromFiatCurrency } from 'utils/fiatConverter';
|
|
|
|
|
|
|
|
|
|
import type {
|
|
|
|
|
Dispatch,
|
|
|
|
@ -109,6 +110,9 @@ export const init = (): AsyncAction => async (
|
|
|
|
|
initialState.selectedFeeLevel
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// initial local currency is set according to wallet settings
|
|
|
|
|
const { localCurrency } = getState().wallet;
|
|
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
|
type: SEND.INIT,
|
|
|
|
|
networkType: 'ripple',
|
|
|
|
@ -116,6 +120,7 @@ export const init = (): AsyncAction => async (
|
|
|
|
|
...initialState,
|
|
|
|
|
networkName: network.shortcut,
|
|
|
|
|
networkSymbol: network.symbol,
|
|
|
|
|
localCurrency,
|
|
|
|
|
feeLevels,
|
|
|
|
|
selectedFeeLevel,
|
|
|
|
|
fee: network.fee.defaultFee,
|
|
|
|
@ -154,6 +159,9 @@ export const onClear = (): AsyncAction => async (
|
|
|
|
|
initialState.selectedFeeLevel
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// initial local currency is set according to wallet settings
|
|
|
|
|
const { localCurrency } = getState().wallet;
|
|
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
|
type: SEND.CLEAR,
|
|
|
|
|
networkType: 'ripple',
|
|
|
|
@ -161,6 +169,7 @@ export const onClear = (): AsyncAction => async (
|
|
|
|
|
...initialState,
|
|
|
|
|
networkName: network.shortcut,
|
|
|
|
|
networkSymbol: network.symbol,
|
|
|
|
|
localCurrency,
|
|
|
|
|
feeLevels,
|
|
|
|
|
selectedFeeLevel,
|
|
|
|
|
fee: network.fee.defaultFee,
|
|
|
|
@ -193,10 +202,10 @@ export const onAddressChange = (address: string): ThunkAction => (
|
|
|
|
|
/*
|
|
|
|
|
* Called from UI on "amount" field change
|
|
|
|
|
*/
|
|
|
|
|
export const onAmountChange = (amount: string): ThunkAction => (
|
|
|
|
|
dispatch: Dispatch,
|
|
|
|
|
getState: GetState
|
|
|
|
|
): void => {
|
|
|
|
|
export const onAmountChange = (
|
|
|
|
|
amount: string,
|
|
|
|
|
shouldUpdateLocalAmount: boolean = true
|
|
|
|
|
): ThunkAction => (dispatch: Dispatch, getState: GetState): void => {
|
|
|
|
|
const state = getState().sendFormRipple;
|
|
|
|
|
dispatch({
|
|
|
|
|
type: SEND.CHANGE,
|
|
|
|
@ -209,6 +218,67 @@ export const onAmountChange = (amount: string): ThunkAction => (
|
|
|
|
|
amount,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (shouldUpdateLocalAmount) {
|
|
|
|
|
const { localCurrency } = getState().sendFormRipple;
|
|
|
|
|
const fiatRates = getState().fiat.find(f => f.network === state.networkName);
|
|
|
|
|
const localAmount = toFiatCurrency(amount, localCurrency, fiatRates);
|
|
|
|
|
dispatch(onLocalAmountChange(localAmount, false));
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Called from UI on "localAmount" field change
|
|
|
|
|
*/
|
|
|
|
|
export const onLocalAmountChange = (
|
|
|
|
|
localAmount: string,
|
|
|
|
|
shouldUpdateAmount: boolean = true
|
|
|
|
|
): ThunkAction => (dispatch: Dispatch, getState: GetState): void => {
|
|
|
|
|
const state = getState().sendFormRipple;
|
|
|
|
|
const { localCurrency } = getState().sendFormRipple;
|
|
|
|
|
const fiatRates = getState().fiat.find(f => f.network === state.networkName);
|
|
|
|
|
const { network } = getState().selectedAccount;
|
|
|
|
|
|
|
|
|
|
// updates localAmount
|
|
|
|
|
dispatch({
|
|
|
|
|
type: SEND.CHANGE,
|
|
|
|
|
networkType: 'ripple',
|
|
|
|
|
state: {
|
|
|
|
|
...state,
|
|
|
|
|
untouched: false,
|
|
|
|
|
touched: { ...state.touched, localAmount: true },
|
|
|
|
|
setMax: false,
|
|
|
|
|
localAmount,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// updates amount
|
|
|
|
|
if (shouldUpdateAmount) {
|
|
|
|
|
if (!network) return;
|
|
|
|
|
// converts amount in local currency to crypto currency that will be sent
|
|
|
|
|
const amount = fromFiatCurrency(localAmount, localCurrency, fiatRates, network.decimals);
|
|
|
|
|
dispatch(onAmountChange(amount, false));
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Called from UI on "localCurrency" selection change
|
|
|
|
|
*/
|
|
|
|
|
export const onLocalCurrencyChange = (localCurrency: {
|
|
|
|
|
value: string,
|
|
|
|
|
label: string,
|
|
|
|
|
}): ThunkAction => (dispatch: Dispatch, getState: GetState): void => {
|
|
|
|
|
const state = getState().sendFormRipple;
|
|
|
|
|
dispatch({
|
|
|
|
|
type: SEND.CHANGE,
|
|
|
|
|
networkType: 'ripple',
|
|
|
|
|
state: {
|
|
|
|
|
...state,
|
|
|
|
|
localCurrency: localCurrency.value,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
// Recalculates amount with new currency rates
|
|
|
|
|
dispatch(onLocalAmountChange(state.localAmount));
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
@ -434,6 +504,8 @@ export default {
|
|
|
|
|
toggleAdvanced,
|
|
|
|
|
onAddressChange,
|
|
|
|
|
onAmountChange,
|
|
|
|
|
onLocalAmountChange,
|
|
|
|
|
onLocalCurrencyChange,
|
|
|
|
|
onSetMax,
|
|
|
|
|
onFeeLevelChange,
|
|
|
|
|
updateFeeLevels,
|
|
|
|
|