Skip to content

Commit

Permalink
Using single component for navigation which shows both messages and t…
Browse files Browse the repository at this point in the history
…ransactions requests
  • Loading branch information
VSaric committed Jan 25, 2023
1 parent c87747f commit 1f59ce3
Show file tree
Hide file tree
Showing 13 changed files with 156 additions and 193 deletions.
38 changes: 27 additions & 11 deletions test/e2e/tests/navigate-transactions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,55 +28,69 @@ describe('Navigate transactions', function () {

// navigate transactions
await driver.clickElement('[data-testid="next-page"]');
let navigationElement = await driver.findElement('.navigation');
let navigationElement = await driver.findElement(
'.confirm-page-container-navigation',
);
let navigationText = await navigationElement.getText();
assert.equal(
navigationText.includes('2 of 4'),
true,
'changed transaction right',
);
await driver.clickElement('[data-testid="next-page"]');
navigationElement = await driver.findElement('.navigation');
navigationElement = await driver.findElement(
'.confirm-page-container-navigation',
);
navigationText = await navigationElement.getText();
assert.equal(
navigationText.includes('3 of 4'),
true,
'changed transaction right',
);
await driver.clickElement('[data-testid="next-page"]');
navigationElement = await driver.findElement('.navigation');
navigationElement = await driver.findElement(
'.confirm-page-container-navigation',
);
navigationText = await navigationElement.getText();
assert.equal(
navigationText.includes('4 of 4'),
true,
'changed transaction right',
);
await driver.clickElement('[data-testid="first-page"]');
navigationElement = await driver.findElement('.navigation');
navigationElement = await driver.findElement(
'.confirm-page-container-navigation',
);
navigationText = await navigationElement.getText();
assert.equal(
navigationText.includes('1 of 4'),
true,
'navigate to first transaction',
);
await driver.clickElement('[data-testid="last-page"]');
navigationElement = await driver.findElement('.navigation');
navigationElement = await driver.findElement(
'.confirm-page-container-navigation',
);
navigationText = await navigationElement.getText();
assert.equal(
navigationText.includes('4 of 4'),
true,
'navigate to last transaction',
);
await driver.clickElement('[data-testid="previous-page"]');
navigationElement = await driver.findElement('.navigation');
navigationElement = await driver.findElement(
'.confirm-page-container-navigation',
);
navigationText = await navigationElement.getText();
assert.equal(
navigationText.includes('3 of 4'),
true,
'changed transaction left',
);
await driver.clickElement('[data-testid="previous-page"]');
navigationElement = await driver.findElement('.navigation');
navigationElement = await driver.findElement(
'.confirm-page-container-navigation',
);
navigationText = await navigationElement.getText();
assert.equal(
navigationText.includes('2 of 4'),
Expand Down Expand Up @@ -104,7 +118,9 @@ describe('Navigate transactions', function () {
await driver.press('#password', driver.Key.ENTER);

await driver.clickElement('[data-testid="next-page"]');
let navigationElement = await driver.findElement('.navigation');
let navigationElement = await driver.findElement(
'.confirm-page-container-navigation',
);
let navigationText = await navigationElement.getText();
assert.equal(
navigationText.includes('2 of 4'),
Expand All @@ -121,7 +137,7 @@ describe('Navigate transactions', function () {
await driver.switchToWindow(extension);
navigationElement = await driver.waitForSelector(
{
css: '.navigation',
css: '.confirm-page-container-navigation',
text: '2 of 5',
},
{ timeout: 10000 },
Expand Down Expand Up @@ -154,7 +170,7 @@ describe('Navigate transactions', function () {
await driver.clickElement({ text: 'Reject', tag: 'button' });
const navigationElement = await driver.waitForSelector(
{
css: '.navigation',
css: '.confirm-page-container-navigation',
text: '1 of 3',
},
{ timeout: 10000 },
Expand Down Expand Up @@ -187,7 +203,7 @@ describe('Navigate transactions', function () {
await driver.clickElement({ text: 'Confirm', tag: 'button' });
const navigationElement = await driver.waitForSelector(
{
css: '.navigation',
css: '.confirm-page-container-navigation',
text: '1 of 3',
},
{ timeout: 10000 },
Expand Down
1 change: 0 additions & 1 deletion ui/components/app/app-components.scss
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,3 @@
@import 'network-account-balance-header/index';
@import 'approve-content-card/index';
@import 'transaction-alerts/transaction-alerts';
@import 'navigation/index';
Original file line number Diff line number Diff line change
@@ -1,44 +1,125 @@
import React from 'react';
import React, { useContext } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { useHistory } from 'react-router-dom';
import { useHistory, useParams } from 'react-router-dom';
import {
getCurrentChainId,
getUnapprovedTransactions,
unconfirmedTransactionsHashSelector,
unapprovedDecryptMsgsSelector,
unapprovedEncryptionPublicKeyMsgsSelector,
} from '../../../../selectors';
import { transactionMatchesNetwork } from '../../../../../shared/modules/transaction.utils';
import { CONFIRM_TRANSACTION_ROUTE } from '../../../../helpers/constants/routes';
import { I18nContext } from '../../../../contexts/i18n';
import {
CONFIRM_TRANSACTION_ROUTE,
SIGNATURE_REQUEST_PATH,
} from '../../../../helpers/constants/routes';
import { clearConfirmTransaction } from '../../../../ducks/confirm-transaction/confirm-transaction.duck';
import { hexToDecimal } from '../../../../../shared/modules/conversion.utils';
import Navigation from '../../navigation';

const ConfirmPageContainerNavigation = () => {
const t = useContext(I18nContext);
const dispatch = useDispatch();
const history = useHistory();
const { id } = useParams();

const unapprovedDecryptMsgs = useSelector(unapprovedDecryptMsgsSelector);
const unapprovedEncryptionPublicKeyMsgs = useSelector(
unapprovedEncryptionPublicKeyMsgsSelector,
);
const uncofirmedTransactions = useSelector(
unconfirmedTransactionsHashSelector,
);

const unapprovedTxs = useSelector(getUnapprovedTransactions);
const currentChainId = useSelector(getCurrentChainId);
const network = hexToDecimal(currentChainId);
const enumUnapprovedDecryptMsgsKey = Object.keys(unapprovedDecryptMsgs);
const enumUnapprovedEncryptMsgsKey = Object.keys(
unapprovedEncryptionPublicKeyMsgs,
);
const enumDecryptAndEncryptMsgs = [
...enumUnapprovedDecryptMsgsKey,
...enumUnapprovedEncryptMsgsKey,
];

const enumUnapprovedTxs = Object.keys(uncofirmedTransactions).filter(
(key) => enumDecryptAndEncryptMsgs.includes(key) === false,
);

const currentNetworkUnapprovedTxs = Object.keys(unapprovedTxs)
.filter((key) =>
transactionMatchesNetwork(unapprovedTxs[key], currentChainId, network),
)
.reduce((acc, key) => ({ ...acc, [key]: unapprovedTxs[key] }), {});
const currentPosition = enumUnapprovedTxs.indexOf(id);

const enumUnapprovedTxs = Object.keys(currentNetworkUnapprovedTxs);
const totalTx = enumUnapprovedTxs.length;
const positionOfCurrentTx = currentPosition + 1;
const nextTxId = enumUnapprovedTxs[currentPosition + 1];
const prevTxId = enumUnapprovedTxs[currentPosition - 1];
const showNavigation = enumUnapprovedTxs.length > 1;
const firstTx = enumUnapprovedTxs[0];
const lastTx = enumUnapprovedTxs[enumUnapprovedTxs.length - 1];

const onNextTx = (txId) => {
if (txId) {
dispatch(clearConfirmTransaction());
history.push(`${CONFIRM_TRANSACTION_ROUTE}/${txId}`);
history.push(
uncofirmedTransactions[txId]?.msgParams
? `${CONFIRM_TRANSACTION_ROUTE}/${txId}${SIGNATURE_REQUEST_PATH}`
: `${CONFIRM_TRANSACTION_ROUTE}/${txId}`,
);
}
};

return (
<Navigation
enumUnapprovedTxsOrUnconfirmedMessages={enumUnapprovedTxs}
onNext={onNextTx}
/>
<div
className="confirm-page-container-navigation"
style={{
display: showNavigation ? 'flex' : 'none',
}}
>
<div
className="confirm-page-container-navigation__container"
data-testid="navigation-container"
style={{
visibility: prevTxId ? 'initial' : 'hidden',
}}
>
<button
className="confirm-page-container-navigation__arrow"
data-testid="first-page"
onClick={() => onNextTx(firstTx)}
>
<i className="fa fa-angle-double-left fa-2x" />
</button>
<button
className="confirm-page-container-navigation__arrow"
data-testid="previous-page"
onClick={() => onNextTx(prevTxId)}
>
<i className="fa fa-angle-left fa-2x" />
</button>
</div>
<div className="confirm-page-container-navigation__textcontainer">
<div className="confirm-page-container-navigation__navtext">
{positionOfCurrentTx} {t('ofTextNofM')} {totalTx}
</div>
<div className="confirm-page-container-navigation__longtext">
{t('requestsAwaitingAcknowledgement')}
</div>
</div>
<div
className="confirm-page-container-navigation__container"
style={{
visibility: nextTxId ? 'initial' : 'hidden',
}}
>
<button
className="confirm-page-container-navigation__arrow"
data-testid="next-page"
onClick={() => onNextTx(nextTxId)}
>
<i className="fa fa-angle-right fa-2x" />
</button>
<button
className="confirm-page-container-navigation__arrow"
data-testid="last-page"
onClick={() => onNextTx(lastTx)}
>
<i className="fa fa-angle-double-right fa-2x" />
</button>
</div>
</div>
);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.navigation {
.confirm-page-container-navigation {
display: flex;
justify-content: space-between;
font: inherit;
Expand Down
1 change: 1 addition & 0 deletions ui/components/app/confirm-page-container/index.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@import 'confirm-page-container-content/index';
@import 'confirm-page-container-header/index';
@import 'confirm-detail-row/index';
@import 'confirm-page-container-navigation/index';
///: BEGIN:ONLY_INCLUDE_IN(flask)
@import 'flask/index';
///: END:ONLY_INCLUDE_IN
Expand Down
1 change: 0 additions & 1 deletion ui/components/app/navigation/index.js

This file was deleted.

96 changes: 0 additions & 96 deletions ui/components/app/navigation/navigation.js

This file was deleted.

Loading

0 comments on commit 1f59ce3

Please sign in to comment.