mirror of
https://github.com/trezor/trezor-wallet
synced 2024-12-02 21:28:12 +00:00
fix for "setMax" in Ripple send form
This commit is contained in:
parent
2bf2e0539c
commit
1392b4b5a7
@ -67,8 +67,8 @@ export const validation = (): PayloadAction<State> => (dispatch: Dispatch, getSt
|
|||||||
state.errors = {};
|
state.errors = {};
|
||||||
state.warnings = {};
|
state.warnings = {};
|
||||||
state.infos = {};
|
state.infos = {};
|
||||||
state = dispatch(recalculateTotalAmount(state));
|
|
||||||
state = dispatch(updateCustomFeeLabel(state));
|
state = dispatch(updateCustomFeeLabel(state));
|
||||||
|
state = dispatch(recalculateTotalAmount(state));
|
||||||
state = dispatch(addressValidation(state));
|
state = dispatch(addressValidation(state));
|
||||||
state = dispatch(addressLabel(state));
|
state = dispatch(addressLabel(state));
|
||||||
state = dispatch(amountValidation(state));
|
state = dispatch(amountValidation(state));
|
||||||
@ -79,29 +79,34 @@ export const validation = (): PayloadAction<State> => (dispatch: Dispatch, getSt
|
|||||||
const recalculateTotalAmount = ($state: State): PayloadAction<State> => (dispatch: Dispatch, getState: GetState): State => {
|
const recalculateTotalAmount = ($state: State): PayloadAction<State> => (dispatch: Dispatch, getState: GetState): State => {
|
||||||
const {
|
const {
|
||||||
account,
|
account,
|
||||||
|
network,
|
||||||
pending,
|
pending,
|
||||||
} = getState().selectedAccount;
|
} = getState().selectedAccount;
|
||||||
if (!account) return $state;
|
if (!account || !network) return $state;
|
||||||
|
|
||||||
const state = { ...$state };
|
const state = { ...$state };
|
||||||
|
const fee = toDecimalAmount(state.selectedFeeLevel.fee, network.decimals);
|
||||||
|
|
||||||
if (state.setMax) {
|
if (state.setMax) {
|
||||||
const pendingAmount = getPendingAmount(pending, state.networkSymbol, false);
|
const pendingAmount = getPendingAmount(pending, state.networkSymbol, false);
|
||||||
const availableBalance = new BigNumber(account.balance).minus(pendingAmount);
|
const availableBalance = new BigNumber(account.balance).minus(pendingAmount);
|
||||||
state.amount = calculateMaxAmount(availableBalance, state.selectedFeeLevel.fee);
|
state.amount = calculateMaxAmount(availableBalance, fee);
|
||||||
}
|
}
|
||||||
|
|
||||||
state.total = calculateTotal(state.amount, state.selectedFeeLevel.fee);
|
state.total = calculateTotal(state.amount, fee);
|
||||||
return state;
|
return state;
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateCustomFeeLabel = ($state: State): PayloadAction<State> => (): State => {
|
const updateCustomFeeLabel = ($state: State): PayloadAction<State> => (dispatch: Dispatch, getState: GetState): State => {
|
||||||
|
const { network } = getState().selectedAccount;
|
||||||
|
if (!network) return $state; // flowtype fallback
|
||||||
|
|
||||||
const state = { ...$state };
|
const state = { ...$state };
|
||||||
if ($state.selectedFeeLevel.value === 'Custom') {
|
if ($state.selectedFeeLevel.value === 'Custom') {
|
||||||
state.selectedFeeLevel = {
|
state.selectedFeeLevel = {
|
||||||
...state.selectedFeeLevel,
|
...state.selectedFeeLevel,
|
||||||
fee: state.fee,
|
fee: state.fee,
|
||||||
label: `${toDecimalAmount(state.fee, 6)} ${state.networkSymbol}`,
|
label: `${toDecimalAmount(state.fee, network.decimals)} ${state.networkSymbol}`,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return state;
|
return state;
|
||||||
|
Loading…
Reference in New Issue
Block a user