-
Notifications
You must be signed in to change notification settings - Fork 60
Register as delegate - Closes #354 #543
Changes from 6 commits
625399b
6124963
1b0101c
8e4f2b4
fac6282
64b6462
9074cf3
8a2328e
8e2a2d7
7024822
38ce2a9
0d54eaa
55ac449
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,3 +20,6 @@ | |
.menu { | ||
right: -16px !important; | ||
} | ||
.hidden { | ||
display: none; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ import logo from '../../assets/images/LISK-nano.png'; | |
import styles from './header.css'; | ||
import VerifyMessage from '../signVerify/verifyMessage'; | ||
import SignMessage from '../signVerify/signMessage'; | ||
import RegisterDelegate from '../registerDelegate'; | ||
import Send from '../send'; | ||
import PrivateWrapper from '../privateWrapper'; | ||
|
||
|
@@ -20,7 +21,13 @@ const HeaderElement = props => ( | |
theme={styles} | ||
> | ||
<MenuItem caption="Register second passphrase" /> | ||
<MenuItem caption="Register as delegate" /> | ||
<MenuItem caption="Register as delegate" | ||
className={(props.account.isDelegate) ? styles.hidden : ''} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see the PR is in progress, but I just noticed this one thing. IMO more elegant way to conditionally hide an element in react is the ternary operator - There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On a small component with no reprinting effect, there's no difference. I'll change anyways. |
||
onClick={() => props.setActiveDialog({ | ||
title: 'Register as delegate', | ||
childComponent: RegisterDelegate, | ||
})} | ||
/> | ||
<MenuItem caption="Sign message" | ||
className='sign-message' | ||
onClick={() => props.setActiveDialog({ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,9 +18,11 @@ describe('HeaderElement', () => { | |
beforeEach(() => { | ||
const mockInputProps = { | ||
setActiveDialog: () => { }, | ||
account: {}, | ||
}; | ||
propsMock = sinon.mock(mockInputProps); | ||
wrapper = shallow(<HeaderElement setActiveDialog={mockInputProps.setActiveDialog} />); | ||
wrapper = shallow(<HeaderElement account={mockInputProps.account} | ||
setActiveDialog={mockInputProps.setActiveDialog} />); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can be simplified to |
||
}); | ||
|
||
afterEach(() => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,8 +98,10 @@ class LoginFormComponent extends React.Component { | |
getAccount(this.props.peers.data, accountInfo.address).then((result) => { | ||
onAccountUpdated(result); | ||
getDelegate(this.props.peers.data, accountInfo.publicKey).then((data) => { | ||
console.log('success'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove this |
||
onAccountUpdated({ delegate: data.delegate, isDelegate: true }); | ||
}).catch(() => { | ||
console.log('error'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove this |
||
onAccountUpdated({ delegate: {}, isDelegate: false }); | ||
}); | ||
// redirect to main/transactions | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { connect } from 'react-redux'; | ||
import RegisterDelegate from './registerDelegate'; | ||
import { accountUpdated } from '../../actions/account'; | ||
import { successAlertDialogDisplayed, errorAlertDialogDisplayed } from '../../actions/dialog'; | ||
|
||
const mapStateToProps = state => ({ | ||
account: state.account, | ||
peers: state.peers, | ||
}); | ||
|
||
const mapDispatchToProps = dispatch => ({ | ||
onAccountUpdated: data => dispatch(accountUpdated(data)), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I cannot find where is this used. |
||
showSuccessAlert: data => dispatch(successAlertDialogDisplayed(data)), | ||
showErrorAlert: data => dispatch(errorAlertDialogDisplayed(data)), | ||
}); | ||
|
||
const RegisterDelegateConnected = connect( | ||
mapStateToProps, | ||
mapDispatchToProps, | ||
)(RegisterDelegate); | ||
|
||
export default RegisterDelegateConnected; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import React from 'react'; | ||
import grid from 'flexboxgrid/dist/flexboxgrid.css'; | ||
import Input from 'react-toolbox/lib/input'; | ||
import Button from 'react-toolbox/lib/button'; | ||
import InfoParagraph from '../infoParagraph'; | ||
import { registerDelegate } from '../../utils/api/delegate'; | ||
|
||
class RegisterDelegate extends React.Component { | ||
constructor() { | ||
super(); | ||
|
||
this.state = { | ||
title: 'register as delegate', | ||
name: '', | ||
nameError: '', | ||
}; | ||
} | ||
|
||
changeHandler(name, value) { | ||
this.setState({ [name]: value }); | ||
} | ||
|
||
register(username, secondSecret) { | ||
registerDelegate(this.props.peers.data, username, | ||
this.props.account.passphrase, secondSecret) | ||
.then(() => { | ||
this.props.showSuccessAlert({ | ||
text: `Delegate registration was successfully submitted with username: "${this.state.name}". It can take several seconds before it is processed.`, | ||
}); | ||
}) | ||
.catch((error) => { | ||
if (error && error.message === 'Username already exists') { | ||
this.setState({ nameError: error.message }); | ||
} else { | ||
this.props.showErrorAlert({ | ||
text: error && error.message ? `${error.message}.` : 'An error occurred while registering as delegate.', | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
render() { | ||
// notify use about insufficient balance | ||
return ( | ||
<div> | ||
<Input label='Delegate name' required={true} | ||
autoFocus={true} | ||
onChange={this.changeHandler.bind(this, 'name')} | ||
error={this.state.nameError} | ||
value={this.state.name} /> | ||
{ | ||
this.props.account.secondSecret && | ||
<Input label='Second secret' required={true} | ||
value={this.state.secondSecret} /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
} | ||
<hr/> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
<InfoParagraph> | ||
Becoming a delegate requires registration. You may choose your own | ||
delegate name, which can be used to promote your delegate. Only the | ||
top 101 delegates are eligible to forge. All fees are shared equally | ||
between the top 101 delegates. | ||
</InfoParagraph> | ||
<section className={`${grid.row} ${grid['between-xs']}`}> | ||
<Button label='Cancel' className='cancel-button' onClick={this.props.closeDialog} /> | ||
<Button label='Register' | ||
primary={true} raised={true} | ||
disabled={!this.state.name} | ||
onClick={this.register.bind(this, this.state.name, this.state.secondSecret)}/> | ||
</section> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default RegisterDelegate; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.hidden
is not used.