Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display a warning message when user sends the entire balance - Closes #3366 #3729

Merged
merged 5 commits into from
Aug 17, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions i18n/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,7 @@
"Write message": "Write message",
"Written by": "Written by",
"YYYY": "YYYY",
"You are about to send your entire balance": "You are about to send your entire balance",
"You are disconnected": "You are disconnected",
"You can also download, print and store safely your passphrase.": "You can also download, print and store safely your passphrase.",
"You can learn more": "You can learn more",
Expand Down
2 changes: 2 additions & 0 deletions src/app/variables.css
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ or "warn/action" ineastd of "red/green"
--color-jade-green-transparent: rgba(43, 214, 123, 0.1);
--color-tooltip-bg: rgb(255, 255, 255, 0.7);
--color-tooltip-arrow: rgb(255, 255, 255, 0.7);
--color-warning-border: #f7e36d;
--color-warning-bg: #fffce8;

/*************************
Box
Expand Down
1 change: 1 addition & 0 deletions src/components/screens/send/form/formBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const FormBase = ({
maxAmountTitle={t('Send entire balance')}
inputPlaceHolder={t('Insert transaction amount')}
name="amount"
t={t}
displayConverter
/>
{ children }
Expand Down
54 changes: 54 additions & 0 deletions src/components/shared/amountField/amountField.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import './../../../app/mixins.css';

.amountFieldHeader {
display: flex;
justify-content: space-between;
Expand All @@ -11,6 +13,7 @@
.amountField {
align-items: center;
display: flex;
flex-direction: column;
position: relative;
width: 100%;

Expand Down Expand Up @@ -42,3 +45,54 @@
display: flex;
margin-bottom: 8px;
}

.entireBalanceWarning {
display: flex;
justify-content: flex-start;
align-items: center;
width: 100%;
position: relative;
box-sizing: border-box;
background-color: var(--color-warning-bg);
border: 1px solid var(--color-warning-border);
border-radius: 5px;
margin-top: 6px;
padding: 10px;

& > img {
width: 20px;
margin-right: 10px;
}

& > span {
@mixin contentSmall normal;

color: var(--color-maastricht-black);
}

& > .closeBtn {
align-items: center;
cursor: pointer;
height: 12px;
right: 22px;
position: absolute;

&::before,
&::after {
background-color: currentColor;
color: var(--color-maastricht-black);
content: '';
height: 13px;
position: absolute;
width: 1px;
}

&::before {
transform: rotate(45deg);
}

&::after {
transform: rotate(-45deg);
}
}
}
26 changes: 23 additions & 3 deletions src/components/shared/amountField/index.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
import React from 'react';
import React, { useState } from 'react';
import {
formatAmountBasedOnLocale,
} from '@utils/formattedNumber';
import { fromRawLsk } from '@utils/lsk';
import { Input } from '@toolbox/inputs';
import { TertiaryButton } from '@toolbox/buttons';
import Icon from '@toolbox/icon';
import Converter from '../converter';
import styles from './amountField.css';

const AmountField = ({
amount, maxAmount, setAmountField, className,
title, maxAmountTitle, inputPlaceHolder, name,
displayConverter,
displayConverter, t,
}) => {
const setEntireBalance = () => {
const [showEntireBalanceWarning, setShowEntireBalanceWarning] = useState(false);
const setEntireBalance = (e) => {
e.preventDefault();
const value = formatAmountBasedOnLocale({
value: fromRawLsk(maxAmount.value),
format: '0.[00000000]',
});
setAmountField({ value }, maxAmount);
setShowEntireBalanceWarning(true);
};

const resetInput = (e) => {
e.preventDefault();
setShowEntireBalanceWarning(false);
setAmountField({ value: '' }, maxAmount);
};

const handleAmountChange = ({ target }) => {
Expand Down Expand Up @@ -69,6 +79,16 @@ const AmountField = ({
/>
)}
</span>
{showEntireBalanceWarning && (
<div className={styles.entireBalanceWarning}>
<Icon name="warningYellow" />
<span>{t('You are about to send your entire balance')}</span>
<div
className={styles.closeBtn}
onClick={resetInput}
/>
</div>
)}
</label>
);
};
Expand Down