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

[transactions] allow account transfers for non-mixed accounts #3446

Merged
merged 1 commit into from May 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/components/inputs/AccountsSelect/AccountsSelect.jsx
Expand Up @@ -22,7 +22,8 @@ const AccountsSelect = ({
const { account, accounts, placeholder } = useAccountsSelect({
accountProp,
accountsType,
filterAccounts
filterAccounts,
onChange
});

const selectKeyDown = (e) => {
Expand Down
14 changes: 13 additions & 1 deletion app/components/inputs/AccountsSelect/hooks.js
Expand Up @@ -16,7 +16,8 @@ const messages = defineMessages({
export const useAccountsSelect = ({
accountProp,
accountsType,
filterAccounts
filterAccounts,
onChange
}) => {
const spendingAccounts = useSelector(sel.spendingAccounts);
const visibleAccounts = useSelector(sel.visibleAccounts);
Expand Down Expand Up @@ -56,6 +57,17 @@ export const useAccountsSelect = ({
const [account, setAccount] = useState(accountProp);
const [accounts, setAccounts] = useState(() => getAccountsToShow());

useEffect(() => {
const newAccounts = getAccountsToShow();
if (!isEqual(newAccounts, accounts)) {
if (!newAccounts.find((a) => isEqual(a.value, account.value))) {
setAccount(newAccounts[0]);
onChange(newAccounts[0]);
}
setAccounts(newAccounts);
}
}, [filterAccounts, getAccountsToShow, account, accounts, onChange]);

useEffect(() => {
let newAccount = null;

Expand Down
6 changes: 3 additions & 3 deletions app/components/shared/SendTransaction/Form.jsx
Expand Up @@ -51,15 +51,15 @@ const Form = ({
<div className={styles.detailsValueColumn}>
<Balance
flat
amount={totalSpent}
amount={isValid() ? totalSpent : 0}
classNameUnit={styles.detailsUnit}
/>
<Balance
flat
amount={estimatedFee}
amount={isValid() ? estimatedFee : 0}
classNameUnit={styles.detailsUnit}
/>
<div>{`${estimatedSignedSize} Bytes`}</div>
<div>{`${isValid() ? estimatedSignedSize : 0} Bytes`}</div>
</div>
</div>
)}
Expand Down
27 changes: 22 additions & 5 deletions app/components/shared/SendTransaction/SendTransaction.jsx
Expand Up @@ -126,13 +126,29 @@ const SendTransaction = ({
};

const onShowSendSelf = () => {
const newOutputs = [{ ...outputs[0], data: baseOutput().data }];
const newOutputs = [
{
...outputs[0],
data: {
...baseOutput().data,
amount: outputs[0].data.amount
}
}
];
setIsSendSelf(true);
onSetOutputs(newOutputs);
};

const onShowSendOthers = () => {
const newOutputs = [{ ...outputs[0], data: baseOutput().data }];
const newOutputs = [
{
...outputs[0],
data: {
...baseOutput().data,
amount: outputs[0].data.amount
}
}
];
setIsSendSelf(false);
onSetOutputs(newOutputs);
};
Expand Down Expand Up @@ -205,11 +221,12 @@ const SendTransaction = ({
const getOutputRows = () => {
// if sending to another accounts from same wallet, there is no need to
// filter accounts.
const filterAccounts = filterFromAccounts
? filterFromAccounts
: isSendSelf
const filterAccounts = isSendSelf
? []
: filterFromAccounts
? filterFromAccounts
: notMixedAccounts;

const accountsType = filterAccounts ? "visible" : "spending";
return outputs.map((output, index) => ({
data: (
Expand Down
Expand Up @@ -212,6 +212,9 @@
margin: 0;
}
@media screen and (max-width: 1179px) {
.amountContainer .sendInputWrapper {
width: 185px;
}
.sendOutputContainer {
margin: 20px 0 20px 20px;
width: 360px;
Expand Down