- { title &&
{title} }
+ { label &&
{label} }
{
- maxAmount && (
+ useMaxLabel && (
- {maxAmountTitle}
+ {useMaxLabel}
)
}
@@ -67,7 +78,7 @@ const AmountField = ({
onChange={handleAmountChange}
name={name}
value={amount.value}
- placeholder={inputPlaceHolder}
+ placeholder={placeholder}
className={`${styles.input} ${amount.error ? 'error' : ''}`}
isLoading={amount.isLoading}
status={amount.error ? 'error' : 'ok'}
@@ -82,15 +93,11 @@ const AmountField = ({
/>
)}
- {showEntireBalanceWarning && (
-
-
-
{t('You are about to send your entire balance')}
-
-
+ {(showEntireBalanceWarning && useMaxWarning !== false) && (
+
)}
);
diff --git a/src/components/shared/transactionPriority/index.js b/src/components/shared/transactionPriority/index.js
index 3236da1df3..b030881e52 100644
--- a/src/components/shared/transactionPriority/index.js
+++ b/src/components/shared/transactionPriority/index.js
@@ -1,7 +1,15 @@
import { withTranslation } from 'react-i18next';
import TransactionPriority from './transactionPriority';
-import useTransactionFeeCalculation from './useTransactionFeeCalculation';
+import useTransactionFeeCalculation, {
+ normalizeVotesForTx,
+ getNumberOfSignatures,
+} from './useTransactionFeeCalculation';
import useTransactionPriority from './useTransactionPriority';
-export { useTransactionPriority, useTransactionFeeCalculation };
+export {
+ useTransactionPriority,
+ useTransactionFeeCalculation,
+ normalizeVotesForTx,
+ getNumberOfSignatures,
+};
export default withTranslation()(TransactionPriority);
diff --git a/src/components/shared/transactionPriority/reducer.js b/src/components/shared/transactionPriority/reducer.js
index 94c602fcad..0df0438f42 100644
--- a/src/components/shared/transactionPriority/reducer.js
+++ b/src/components/shared/transactionPriority/reducer.js
@@ -1,12 +1,12 @@
/* eslint-disable import/prefer-default-export */
-import { tokenMap, minAccountBalance } from '@constants';
+import { tokenMap, MIN_ACCOUNT_BALANCE } from '@constants';
import { toRawLsk } from '@utils/lsk';
const calculateAvailableBalance = (balance, token) => {
if (token !== tokenMap.LSK.key) {
return balance;
}
- return Math.max(balance - minAccountBalance, 0);
+ return Math.max(balance - MIN_ACCOUNT_BALANCE, 0);
};
const initialFee = {
diff --git a/src/components/shared/transactionPriority/useTransactionFeeCalculation.js b/src/components/shared/transactionPriority/useTransactionFeeCalculation.js
index c76dab0a4e..b373735edf 100644
--- a/src/components/shared/transactionPriority/useTransactionFeeCalculation.js
+++ b/src/components/shared/transactionPriority/useTransactionFeeCalculation.js
@@ -4,13 +4,48 @@ import { getTransactionFee } from '@api/transaction';
import { DEFAULT_NUMBER_OF_SIGNATURES } from '@constants';
import { actionTypes, reducer, getInitialState } from './reducer';
-const getNumberOfSignatures = (account) => {
+/**
+ * Converts the votes object stored in Redux store
+ * which looks like { delegateAddress: { confirmed, unconfirmed } }
+ * into an array of objects that Lisk Element expects, looking like
+ * [{ delegatesAddress, amount }]
+ *
+ * @param {Object} votes - votes object retrieved from the Redux store
+ * @returns {Array} Array of votes as Lisk Element expects
+ */
+export const normalizeVotesForTx = votes =>
+ Object.keys(votes)
+ .filter(address => votes[address].confirmed !== votes[address].unconfirmed)
+ .map(delegateAddress => ({
+ delegateAddress,
+ amount: (votes[delegateAddress].unconfirmed - votes[delegateAddress].confirmed).toString(),
+ }));
+
+/**
+ * Returns the number of signatures required to sign
+ * a transaction. Returns 1 for ordinary accounts.
+ *
+ * @param {object} account - the active account info
+ * @returns {number} Number of signatures
+ */
+export const getNumberOfSignatures = (account) => {
if (account?.summary?.isMultisignature) {
return account.keys.numberOfSignatures;
}
return DEFAULT_NUMBER_OF_SIGNATURES;
};
+/**
+ * Custom hook to define tx fee
+ *
+ * @param {object} data
+ * @param {string} data.token - Option of LSK and BTC
+ * @param {object} data.account - Active account info
+ * @param {object} data.selectedPriority - Selected priority info
+ * @param {object} data.transaction - Raw transaction payload
+ * @param {array} data.priorityOptions - Array of priority configs for High, Mid, Low
+ * @returns {object}
+ */
const useTransactionFeeCalculation = ({
token, account, selectedPriority, transaction, priorityOptions,
}) => {
diff --git a/src/constants/transactions.js b/src/constants/transactions.js
index 3aba717cc7..72401fa7cb 100644
--- a/src/constants/transactions.js
+++ b/src/constants/transactions.js
@@ -1,16 +1,19 @@
const maxMessageLength = 64;
-const minAccountBalance = 5000000;
-const minFeePerByte = 1000;
+const MIN_ACCOUNT_BALANCE = 5000000;
+const MIN_FEE_PER_BYTE = 1000;
const DUMMY_RECIPIENT_ADDRESS = 'lskdxc4ta5j43jp9ro3f8zqbxta9fn6jwzjucw7yt';
const DEFAULT_NUMBER_OF_SIGNATURES = 1;
const DEFAULT_SIGNATURE_BYTE_SIZE = 64;
+const VOTE_AMOUNT_STEP = 1e9;
+
export {
maxMessageLength,
- minAccountBalance,
- minFeePerByte,
+ MIN_ACCOUNT_BALANCE,
+ MIN_FEE_PER_BYTE,
DEFAULT_NUMBER_OF_SIGNATURES,
DUMMY_RECIPIENT_ADDRESS,
DEFAULT_SIGNATURE_BYTE_SIZE,
+ VOTE_AMOUNT_STEP,
};
diff --git a/src/utils/api/transaction/lsk.js b/src/utils/api/transaction/lsk.js
index 217871a7cd..77cac4cd27 100644
--- a/src/utils/api/transaction/lsk.js
+++ b/src/utils/api/transaction/lsk.js
@@ -3,7 +3,7 @@ import { transactions } from '@liskhq/lisk-client';
import {
tokenMap,
- minFeePerByte,
+ MIN_FEE_PER_BYTE,
DEFAULT_NUMBER_OF_SIGNATURES,
MODULE_ASSETS_MAP,
MODULE_ASSETS_NAME_ID_MAP,
@@ -268,7 +268,7 @@ export const getTransactionFee = async ({
// tie breaker is only meant for medium and high processing speeds
const tieBreaker = selectedPriority.selectedIndex === 0
- ? 0 : (minFeePerByte * feePerByte * Math.random());
+ ? 0 : (MIN_FEE_PER_BYTE * feePerByte * Math.random());
const size = transactions.getBytes(schema, transactionObject).length;
diff --git a/src/utils/validators.js b/src/utils/validators.js
index dc2fffd5a0..e18a109273 100644
--- a/src/utils/validators.js
+++ b/src/utils/validators.js
@@ -2,7 +2,7 @@ import * as bitcoin from 'bitcoinjs-lib';
import { cryptography } from '@liskhq/lisk-client';
import numeral from 'numeral';
-import { tokenMap, minAccountBalance, regex as reg } from '@constants';
+import { tokenMap, MIN_ACCOUNT_BALANCE, regex as reg } from '@constants';
import { toRawLsk } from './lsk';
import i18n from '../i18n';
@@ -106,14 +106,14 @@ export const validateAmountFormat = ({
message: i18n.t('Provided amount will result in a wallet with less than the minimum balance.'),
fn: () => {
const rawValue = toRawLsk(numeral(value).value());
- return funds - rawValue < minAccountBalance;
+ return funds - rawValue < MIN_ACCOUNT_BALANCE;
},
},
VOTES_MAX: {
message: i18n.t('The vote amount is too high. You should keep at least 0.05 LSK available in your account.'),
fn: () => {
const rawValue = toRawLsk(numeral(value).value());
- return funds - rawValue < minAccountBalance;
+ return funds - rawValue < MIN_ACCOUNT_BALANCE;
},
},
};