Skip to content

Commit

Permalink
Merge branch 'release/2.2.0' into 4009-responsiveness-issues-220
Browse files Browse the repository at this point in the history
  • Loading branch information
reyraa authored Jan 10, 2022
2 parents 528a745 + 52ace16 commit 85a445a
Show file tree
Hide file tree
Showing 39 changed files with 809 additions and 570 deletions.
3 changes: 1 addition & 2 deletions i18n/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@
"Members": "Members",
"Message": "Message",
"Message (optional)": "Message (optional)",
"Message signature aborted on device": "Message signature aborted on device",
"Min": "Min",
"Minimize": "Minimize",
"Missed slot": "Missed slot",
Expand Down Expand Up @@ -346,7 +345,7 @@
"Please carefully write down these 12 words and store them in a safe place.": "Please carefully write down these 12 words and store them in a safe place.",
"Please check the address": "Please check the address",
"Please check the highlighted word and make sure it’s correct.": "Please check the highlighted word and make sure it’s correct.",
"Please confirm the message on your {{model}}": "Please confirm the message on your {{model}}",
"Please confirm the message on your {{deviceModel}}": "Please confirm the message on your {{deviceModel}}",
"Please confirm the transaction on your {{deviceModel}}": "Please confirm the transaction on your {{deviceModel}}",
"Please enter a valid public key for each member.": "Please enter a valid public key for each member.",
"Please enter vote amounts for the delegates you wish to vote for": "Please enter vote amounts for the delegates you wish to vote for",
Expand Down
8 changes: 4 additions & 4 deletions src/components/screens/dashboard/newsFeed/newsParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ const NewsParser = ({ children }) => {
const REGEX_USER = /\B(@[a-zA-Z0-9_]+)/g; // regex for @users
const REGEX_HASHTAG = /\B(#[A-Za-z0-9-_]+)/g; // regex for #hashtags
const textWithHashtag = reactStringReplace(Html5Entities.decode(children), REGEX_HASHTAG,
(hashtag, i) => (
(hashtag, index, offset) => (
<a
key={hashtag + i}
key={hashtag + index + offset}
href={`https://twitter.com/hashtag/${hashtag.slice(1)}`}
target="_blank"
className="hashtag"
>
{hashtag}
</a>
));
const textWithUsers = reactStringReplace(textWithHashtag, REGEX_USER, (user, i) => (
const textWithUsers = reactStringReplace(textWithHashtag, REGEX_USER, (user, index, offset) => (
<a
key={user + i}
key={user + index + offset}
href={`https://twitter.com/${user.slice(1)}`}
target="_blank"
className="user"
Expand Down
32 changes: 16 additions & 16 deletions src/components/screens/hwWalletLogin/selectAccount/selectAccount.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import LoadingIcon from '../loadingIcon';
import styles from './selectAccount.css';

const Tab = ({
tabName, tabId, accountsList,
name, id, accountsList,
onSaveNameAccounts, onSelectAccount,
}) => (
<div tabName={tabName} tabId={tabId} className={`${styles.deviceContainer} ${`tab-${tabId}`} hw-container`}>
{accountsList.map((account, index) => (
<div name={name} id={id} className={`${styles.deviceContainer} ${`tab-${id}`} hw-container`}>
{accountsList.map((data) => (
<AccountCard
key={`hw-account-tabId-${index}`}
account={account}
index={index}
key={`hw-account-tabId-${data.index}`}
account={data.account}
index={data.index}
onSaveNameAccounts={onSaveNameAccounts}
onSelectAccount={onSelectAccount}
/>
Expand Down Expand Up @@ -140,16 +140,16 @@ class SelectAccount extends React.Component {
nonEmptyAccounts,
emptyAccounts,
reclaimAccounts,
} = hwAccounts.reduce((acc, account) => {
} = hwAccounts.reduce((acc, account, index) => {
if (account.legacy) {
acc.reclaimAccounts = [...acc.reclaimAccounts, account];
acc.reclaimAccounts = [...acc.reclaimAccounts, { index, account }];
return acc;
}
if (account.summary?.balance > 0) {
acc.nonEmptyAccounts = [...acc.nonEmptyAccounts, account];
acc.nonEmptyAccounts = [...acc.nonEmptyAccounts, { index, account }];
return acc;
}
acc.emptyAccounts = [...acc.emptyAccounts, account];
acc.emptyAccounts = [...acc.emptyAccounts, { index, account }];
return acc;
}, { nonEmptyAccounts: [], emptyAccounts: [], reclaimAccounts: [] });

Expand All @@ -170,22 +170,22 @@ class SelectAccount extends React.Component {
? (
<TabsContainer name="main-tabs">
<Tab
tabName={t('Active')}
tabId="active"
name={t('Active')}
id="active"
accountsList={nonEmptyAccounts}
onSaveNameAccounts={this.onSaveNameAccounts}
onSelectAccount={this.onSelectAccount}
/>
<Tab
tabName={t('Empty')}
tabId="empty"
name={t('Empty')}
id="empty"
accountsList={emptyAccounts}
onSaveNameAccounts={this.onSaveNameAccounts}
onSelectAccount={this.onSelectAccount}
/>
<Tab
tabName={t('Pending reclaim ({{numOfAccounts}})', { numOfAccounts: reclaimAccounts.length })}
tabId="reclaim"
name={t('Pending reclaim ({{numOfAccounts}})', { numOfAccounts: reclaimAccounts.length })}
id="reclaim"
accountsList={reclaimAccounts}
onSaveNameAccounts={this.onSaveNameAccounts}
onSelectAccount={this.onSelectAccount}
Expand Down
76 changes: 76 additions & 0 deletions src/components/screens/monitor/delegates/delegates.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,59 @@ describe('Delegates monitor page', () => {
});
};

function initSanctionedProps() {
props.sanctionedDelegates = {
isLoading: false,
data: [
{
address: 'lsktaa9xuys6hztyaryvx6msu279mpkn9sz6w5or2',
consecutiveMissedBlocks: 220,
isBanned: true,
lastForgedHeight: 16695471,
producedBlocks: 1404,
rank: 1563,
registrationHeight: 16331164,
rewards: '140200000000',
status: 'banned',
totalVotesReceived: '2170000000000',
username: 'ziqi',
voteWeight: '0',
},
{
address: 'lsksaca4v9r3uotdzdhje3smwa49rvj2h2sn5yskt',
consecutiveMissedBlocks: 0,
isBanned: false,
lastForgedHeight: 16784595,
producedBlocks: 4929,
rank: 1503,
registrationHeight: 16270293,
rewards: '491800000000',
status: 'punished',
totalVotesReceived: '8771000000000',
username: 'liskjp',
voteWeight: '0',
},
{
address: 'lskr39gqjxhepd9o5txgmups9zjhjaadfjgm5dc87',
consecutiveMissedBlocks: 229,
isBanned: true,
lastForgedHeight: 16739690,
producedBlocks: 2014,
rank: 1436,
registrationHeight: 16270293,
rewards: '201125000000',
status: 'banned',
totalVotesReceived: '2356000000000',
username: 'acheng',
voteWeight: '0',
},
],
loadData: jest.fn(),
clearData: jest.fn(),
urlSearchParams: {},
};
}

const { blocks } = store.getState();

beforeEach(() => {
Expand Down Expand Up @@ -140,4 +193,27 @@ describe('Delegates monitor page', () => {
wrapper = setup(props);
expect(wrapper.find('a.delegate-row')).toHaveLength(blocks.forgers.length);
});

it('properly sorts delegates by their status', () => {
initSanctionedProps();
wrapper = setup(props);
switchTab('sanctioned');

const sortByBtn = wrapper.find('span.sort-by');
const statuses = wrapper.find('a.delegate-row > span:first-child ~ span ~ span > span').map(ele => ele.text());
statuses.forEach((status, index) => {
expect(status).equal(index === 1 ? 'Punished' : 'Banned');
});

sortByBtn.last().simulate('click');

statuses.forEach((status, index) => {
expect(status).equal(index === 2 ? 'Banned' : 'Punished');
});

wrapper.find('span.sort-by').at(1).simulate('click');
statuses.forEach((status, index) => {
expect(status).equal(index === 2 ? 'Punished' : 'Banned');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ export const DelegateDetails = ({
export const RoundState = ({
activeTab, state, isBanned, t, time,
}) => {
// if (activeTab === 'active') console.log('lastBlock', lastBlock);
if (state === undefined) {
return (
<span className={`${getRoundStateClass(activeTab)} ${styles.noEllipsis} ${styles.statusIconsContainer}`}>-</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const TableWrapper = compose(
}
return 0;
},
sanctionedStatus: (a, b, direction) => ((direction === 'asc' ? a.status > b.status : b.status > a.status) ? 1 : -1),
}),
)(({
delegates, handleLoadMore, t, activeTab, blocks,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export default (activeTab, changeSort, t) => ([
classList: getStatusClass(activeTab),
sort: {
fn: changeSort,
key: 'status',
key: activeTab === 'sanctioned' ? 'sanctionedStatus' : 'status',
},
},
]);
3 changes: 2 additions & 1 deletion src/components/screens/multiSignature/form/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ const validators = [
message: t => t('Either change the optional member to mandatory or define more optional members.'),
},
{
pattern: (mandatory, optional) => mandatory.length === 0 && optional.length > 0,
pattern: (mandatory, optional, signatures) =>
mandatory.length === 0 && optional.length === signatures,
message: t => t('All members can not be optional. Consider changing them to mandatory.'),
},
{
Expand Down
8 changes: 5 additions & 3 deletions src/components/screens/multiSignature/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
import React from 'react';
import { withRouter } from 'react-router-dom';

import MultiStep from '../../shared/multiStep';
import { removeSearchParamsFromUrl } from '../../../utils/searchParams';
import Dialog from '../../toolbox/dialog/dialog';
import TransactionSignature from '@shared/transactionSignature';
import MultiStep from '@shared/multiStep';
import { removeSearchParamsFromUrl } from '@utils/searchParams';
import Dialog from '@toolbox/dialog/dialog';

import Form from './form';
import Summary from './summary';
Expand All @@ -25,6 +26,7 @@ const MultiSignature = ({ history }) => {
>
<Form />
<Summary />
<TransactionSignature />
<Status />
</MultiStep>
</Dialog>
Expand Down
2 changes: 0 additions & 2 deletions src/components/screens/multiSignature/summary/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import Summary from './summary';

const mapStateToProps = state => ({
account: getActiveTokenAccount(state),
signedTransaction: state.transactions.signedTransaction,
txSignatureError: state.transactions.txSignatureError,
});

const mapDispatchToProps = {
Expand Down
39 changes: 14 additions & 25 deletions src/components/screens/multiSignature/summary/summary.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { useEffect } from 'react';
import React from 'react';
import { MODULE_ASSETS_NAME_ID_MAP } from '@constants';
import TransactionInfo from '@shared/transactionInfo';
import { isEmpty } from '@utils/helpers';
import Box from '@toolbox/box';
import BoxContent from '@toolbox/box/content';
import BoxFooter from '@toolbox/box/footer';
Expand All @@ -22,39 +21,29 @@ const Summary = ({
prevStep,
nextStep,
multisigGroupRegistered,
signedTransaction,
txSignatureError,
}) => {
// eslint-disable-next-line max-statements
const onConfirm = () => {
multisigGroupRegistered({
fee,
mandatoryKeys,
optionalKeys,
numberOfSignatures,
nextStep({
rawTransaction: {
fee: String(fee),
mandatoryKeys,
optionalKeys,
numberOfSignatures,
},
actionFunction: multisigGroupRegistered,
statusInfo: {
mandatoryKeys,
optionalKeys,
numberOfSignatures,
},
});
};

const goBack = () => {
prevStep({ mandatoryKeys, optionalKeys, numberOfSignatures });
};

useEffect(() => {
// success
if (!isEmpty(signedTransaction)) {
nextStep({
transactionInfo: signedTransaction,
});
}
}, [signedTransaction]);

useEffect(() => {
// error
if (txSignatureError) {
nextStep({ error: txSignatureError });
}
}, [txSignatureError]);

return (
<section className={styles.wrapper}>
<Box className={styles.container}>
Expand Down
17 changes: 14 additions & 3 deletions src/components/screens/multiSignature/summary/summary.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { mount } from 'enzyme';
import * as hwManagerAPI from '@utils/hwManager';
import Summary from './summary';
import accounts from '../../../../../test/constants/accounts';
import flushPromises from '../../../../../test/unit-test-utils/flushPromises';

const mockTransaction = {
fee: 0.02,
Expand Down Expand Up @@ -56,8 +55,20 @@ describe('Multisignature summary component', () => {

it('Should call props.nextStep', async () => {
wrapper.find('button.confirm').simulate('click');
await flushPromises();
expect(props.multisigGroupRegistered).toHaveBeenCalledWith(mockTransaction);
expect(props.nextStep).toHaveBeenCalledWith({
rawTransaction: {
fee: String(props.fee),
mandatoryKeys: props.mandatoryKeys,
optionalKeys: props.optionalKeys,
numberOfSignatures: props.numberOfSignatures,
},
actionFunction: props.multisigGroupRegistered,
statusInfo: {
mandatoryKeys: props.mandatoryKeys,
optionalKeys: props.optionalKeys,
numberOfSignatures: props.numberOfSignatures,
},
});
});

it('Should call props.prevStep', () => {
Expand Down
Loading

0 comments on commit 85a445a

Please sign in to comment.