aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/send_/send-content/send-amount-row/send-amount-row.utils.js
diff options
context:
space:
mode:
Diffstat (limited to 'ui/app/components/send_/send-content/send-amount-row/send-amount-row.utils.js')
-rw-r--r--ui/app/components/send_/send-content/send-amount-row/send-amount-row.utils.js55
1 files changed, 55 insertions, 0 deletions
diff --git a/ui/app/components/send_/send-content/send-amount-row/send-amount-row.utils.js b/ui/app/components/send_/send-content/send-amount-row/send-amount-row.utils.js
new file mode 100644
index 000000000..5b01b4594
--- /dev/null
+++ b/ui/app/components/send_/send-content/send-amount-row/send-amount-row.utils.js
@@ -0,0 +1,55 @@
+const { isValidAddress } = require('../../../../util')
+
+function getAmountErrorObject ({
+ amount,
+ balance,
+ amountConversionRate,
+ conversionRate,
+ primaryCurrency,
+ selectedToken,
+ gasTotal,
+ tokenBalance,
+}) {
+ let insufficientFunds = false
+ if (gasTotal && conversionRate) {
+ insufficientFunds = !isBalanceSufficient({
+ amount: selectedToken ? '0x0' : amount,
+ gasTotal,
+ balance,
+ primaryCurrency,
+ amountConversionRate,
+ conversionRate,
+ })
+ }
+
+ let inSufficientTokens = false
+ if (selectedToken && tokenBalance !== null) {
+ const { decimals } = selectedToken
+ inSufficientTokens = !isTokenBalanceSufficient({
+ tokenBalance,
+ amount,
+ decimals,
+ })
+ }
+
+ const amountLessThanZero = conversionGreaterThan(
+ { value: 0, fromNumericBase: 'dec' },
+ { value: amount, fromNumericBase: 'hex' },
+ )
+
+ let amountError = null
+
+ if (insufficientFunds) {
+ amountError = this.context.t('insufficientFunds')
+ } else if (insufficientTokens) {
+ amountError = this.context.t('insufficientTokens')
+ } else if (amountLessThanZero) {
+ amountError = this.context.t('negativeETH')
+ }
+
+ return { amount: amountError }
+}
+
+module.exports = {
+ getAmountErrorObject
+}