Skip to content

Commit

Permalink
hotfix: allowing voting when using proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
dafuga authored and aaroncox committed Jul 19, 2019
1 parent 9b421ea commit 2cbd1e3
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 35 deletions.
4 changes: 3 additions & 1 deletion app/renderer/assets/locales/en-US/producers.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"producer_json_unavailable_header": "Information Unavailable",
"producer_none_loaded": "No producers data loaded...",
"producer_none_match": "No producers match the search query.",
"producers_no_voting": "Block producers are not voted in on this Blockchain, therefore this section is read-only",
"producer_production_disabled": "Inactive",
"producer_production_enabled": "Producing",
"producer_production_never": "Never",
Expand All @@ -41,6 +40,8 @@
"producer_voter_remove_all_votes_header": "Remove all votes?",
"producer_voter_remove_all_votes_subheader": "Saving after removing all existing votes will uncast any vote you have previously cast for any producer.",
"producer_voter_save_changes": "Submit votes for selected producers",
"producer_voter_start_voting_after_proxying": "Submit your votes and stop proxying",
"producer_voter_start_voting_after_proxying_warning": "Please note that once the following vote is cast, you will no longer be proxying your votes.",
"producer_voter_total_staked": "Total Staked",
"producer_voter_unregistered_block_producers": "Unregistered Producers",
"producer_voter_votes_used": "total votes cast",
Expand Down Expand Up @@ -104,6 +105,7 @@
"producers_info_nodes_seeds": "Seed Nodes",
"producers_info_social": "Social Media Links",
"producers_info_website": "Official Website",
"producers_no_voting": "Block producers are not voted in on this Blockchain, therefore this section is read-only",
"producers_none_match": "Nothing matches this query..",
"producers_panel_refresh_proxy": "Refresh Proxy Vote",
"producers_proxies": "Proxies",
Expand Down
58 changes: 30 additions & 28 deletions app/shared/components/Producers.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Producers extends Component<Props> {
constructor(props) {
super(props);
this.state = {
editingProducers: false,
lastError: false,
lastTransaction: {},
previewing: false,
Expand Down Expand Up @@ -48,15 +49,15 @@ class Producers extends Component<Props> {
|| (nextProps.producers.proxy && nextProps.producers.proxy !== this.state.selected_account)
) {
const { accounts } = nextProps;
const { selected: currentlySelected, editingProducers } = this.state;
// If an account is loaded, attempt to load it's votes
if (settings.account && accounts[settings.account]) {
const account = accounts[settings.account];
if (account.voter_info) {
const selected_account = account.voter_info.proxy || account.account_name;
let selected = account.voter_info.producers
if (selected_account !== settings.account && accounts[selected_account]) {
selected = accounts[selected_account].voter_info.producers;
}
const selected = editingProducers ?
currentlySelected :
accounts[selected_account] && accounts[selected_account].voter_info.producers;
// If the voter_info entry exists, load those votes into state
this.setState({
selected,
Expand All @@ -74,31 +75,32 @@ class Producers extends Component<Props> {
this.setState({
addProxy: proxyAccout
});
}
};

removeProxy = () => {
this.setState({
removeProxy: true
});
}
};

onClose = () => {
this.setState({
addProxy: false,
removeProxy: false
});
}
};

addProducer = (producer) => {
const producers = [...this.state.selected];
if (producers.indexOf(producer) === -1) {
producers.push(producer);
producers.sort();
this.setState({
selected: producers
selected: producers,
editingProducers: true,
});
}
}
};

removeProducer = (producer) => {
const producers = [...this.state.selected];
Expand All @@ -107,9 +109,10 @@ class Producers extends Component<Props> {
producers.splice(index, 1);
}
this.setState({
selected: producers
selected: producers,
editingProducers: true,
});
}
};

previewProducerVotes = (previewing) => this.setState({
previewing,
Expand All @@ -135,9 +138,9 @@ class Producers extends Component<Props> {
this.setState({
lastError: false, // Reset the last error
lastTransaction: {}, // Reset the last transaction
submitting: true
submitting: true,
});
}
};

render() {
const {
Expand All @@ -163,6 +166,7 @@ class Producers extends Component<Props> {
} = this.props;
const {
addProxy,
editingProducers,
lastError,
lastTransaction,
previewing,
Expand Down Expand Up @@ -220,13 +224,13 @@ class Producers extends Component<Props> {
tables={tables}
/>

<Divider hidden />

{(!isProxying) ? (
<Divider hidden={!isProxying} />
{(!isProxying || editingProducers) && (
<ProducersVotingPreview
account={account}
actions={actions}
blockExplorers={allBlockExplorers[connection.chainKey]}
isProxying={isProxying}
lastError={lastError}
lastTransaction={lastTransaction}
open={previewing}
Expand All @@ -239,7 +243,7 @@ class Producers extends Component<Props> {
system={system}
unregisteredProducers={unregisteredProducers}
/>
) : ''}
)}

<ProducersSelector
account={accounts[settings.account]}
Expand Down Expand Up @@ -304,17 +308,15 @@ class Producers extends Component<Props> {
if (connection.supportedContracts && connection.supportedContracts.includes('regproxyinfo')) {
tabPanes.push({
menuItem: t('producers_proxies'),
render: () => {
return (
<Tab.Pane>
<Proxies
{...this.props}
addProxy={this.addProxy.bind(this)}
removeProxy={this.removeProxy.bind(this)}
/>
</Tab.Pane>
);
}
render: () => (
<Tab.Pane>
<Proxies
{...this.props}
addProxy={this.addProxy.bind(this)}
removeProxy={this.removeProxy.bind(this)}
/>
</Tab.Pane>
)
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class ProducersVotingPreview extends Component<Props> {
account,
actions,
blockExplorers,
isProxying,
lastError,
onConfirm,
selected,
Expand All @@ -28,13 +29,14 @@ class ProducersVotingPreview extends Component<Props> {
blockExplorers={blockExplorers}
button={{
color: 'green',
content: t('producer_voter_save_changes'),
content: (isProxying ? t('producer_voter_start_voting_after_proxying') : t('producer_voter_save_changes')),
fluid: true,
icon: ''
}}
content={(
<ProducersVotingPreviewSelection
account={account}
isProxying={isProxying}
lastError={lastError}
onConfirm={onConfirm}
selected={selected}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class ProducersVotingPreviewSelection extends Component<Props> {
render() {
const {
account,
isProxying,
lastError,
onClose,
onConfirm,
Expand All @@ -30,6 +31,13 @@ class ProducersVotingPreviewSelection extends Component<Props> {
return (
<Segment loading={submitting}>
<Header icon="alarm" content={t('producer_voter_preview_confirm_changes_title')} />
{isProxying && (
<Message
content={t('producer_voter_start_voting_after_proxying_warning')}
icon="warning sign"
warning
/>
)}
<Modal.Content>
<Segment basic padded>
<ProducersTable
Expand Down
1 change: 0 additions & 1 deletion app/shared/components/Producers/BlockProducers/Selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class ProducersSelector extends Component<Props> {
);
listItems.push(unregisteredProducers.map((producer) => (
<ProducersSelectorItem
isProxying={isProxying}
key={`${isProxying}-${producer}-unregistered`}
producer={producer}
removeProducer={this.props.removeProducer}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Button, List } from 'semantic-ui-react';
export default class ProducersSelectorItem extends Component<Props> {
render() {
const {
isProxying,
producer,
removeProducer
} = this.props;
Expand All @@ -14,7 +13,6 @@ export default class ProducersSelectorItem extends Component<Props> {
<List.Content>
<Button
color="red"
disabled={isProxying}
icon="circle minus"
onClick={() => removeProducer(producer)}
size="tiny"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class ProducersTableRow extends Component<Props> {
trigger={(
<Button
color={isSelected ? 'blue' : 'grey'}
disabled={!isValidUser || isProxying}
disabled={!isValidUser}
icon={isSelected ? 'checkmark box' : 'minus square outline'}
onClick={
(isSelected)
Expand Down
2 changes: 1 addition & 1 deletion app/shared/components/Producers/Proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class ProducersProxy extends Component<Props> {
? (
<div>
<Button
color="green"
color="teal"
content={t('producers_panel_refresh_proxy')}
fluid
icon="sync"
Expand Down

0 comments on commit 2cbd1e3

Please sign in to comment.