Skip to content

Commit

Permalink
feat: add update witness function
Browse files Browse the repository at this point in the history
  • Loading branch information
sschiessl-bcp committed Nov 1, 2023
1 parent 7bd49e1 commit 6790b93
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 8 deletions.
27 changes: 27 additions & 0 deletions app/actions/AccountActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,33 @@ class AccountActions {
});
};
}

updateWitness({url, account, witness_id, signingKey}) {
console.log("asdsa");
const account_id = account.get("id");
var tr = WalletApi.new_transaction();
var payload = {
fee: {
amount: 0,
asset_id: "1.3.0"
},
witness: witness_id,
witness_account: account_id
};
payload.new_signing_key = signingKey;
payload.new_url = url;
tr.add_type_operation("witness_update", payload);
return dispatch => {
return WalletDb.process_transaction(tr, null, true)
.then(() => {
dispatch(true);
})
.catch(error => {
console.log("----- Update witness error ----->", error);
dispatch(false);
});
};
}
}

export default alt.createActions(AccountActions);
1 change: 1 addition & 0 deletions app/assets/locales/locale-en.json
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@
"info": "Info",
"join_committee": "Join committee",
"join_witnesses": "Join Witnesses",
"update_witness": "Update Witness",
"line": "Line",
"max_pay": "Maximum total pay",
"missing": "Needed",
Expand Down
20 changes: 19 additions & 1 deletion app/components/Account/Voting/Witnesses.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ export default class Witnesses extends Component {
render() {
const showWitnessModal = () => {
this.setState({
showCreateWitnessModalUpdate: false,
showCreateWitnessModal: !this.state.showCreateWitnessModal
});
};
const showUpdateWitnessModal = () => {
this.setState({
showCreateWitnessModalUpdate: true,
showCreateWitnessModal: !this.state.showCreateWitnessModal
});
};
Expand All @@ -27,7 +34,10 @@ export default class Witnesses extends Component {
const addWitnessHandler = this.props.addWitnessHandler;
const removeWitnessHandler = this.props.removeWitnessHandler;

const {showCreateWitnessModal} = this.state;
const {
showCreateWitnessModal,
showCreateWitnessModalUpdate
} = this.state;
const {
all_witnesses,
proxy_witnesses,
Expand All @@ -38,6 +48,7 @@ export default class Witnesses extends Component {
filterSearch,
account
} = this.props;

return (
<div>
<div className={cnames("content-block")}>
Expand All @@ -46,6 +57,12 @@ export default class Witnesses extends Component {
<Button onClick={showWitnessModal}>
<Translate content="account.votes.join_witnesses" />
</Button>
<Button
style={{marginLeft: "8px"}}
onClick={showUpdateWitnessModal}
>
<Translate content="account.votes.update_witness" />
</Button>
</div>

<div className="selector inline-block">
Expand Down Expand Up @@ -75,6 +92,7 @@ export default class Witnesses extends Component {
<JoinWitnessesModal
visible={showCreateWitnessModal}
account={account}
updateOrCreate={showCreateWitnessModalUpdate}
hideModal={showWitnessModal}
/>
</div>
Expand Down
49 changes: 42 additions & 7 deletions app/components/Modal/JoinWitnessesModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {Modal, Button, Input, Select, Form} from "bitshares-ui-style-guide";
import Icon from "../Icon/Icon";
import {PublicKey} from "bitsharesjs";
import utils from "common/utils";
import {ChainStore} from "bitsharesjs";

class JoinWitnessesModal extends React.Component {
constructor(props) {
Expand All @@ -17,6 +18,7 @@ class JoinWitnessesModal extends React.Component {
getInitialState(props) {
return {
witnessAccount: props.account,
witnessObject: null,
signingKey: "",
url: ""
};
Expand All @@ -27,19 +29,52 @@ class JoinWitnessesModal extends React.Component {
this.state.url !== ns.visible ||
this.props.visible !== np.visible ||
this.state.signingKey !== ns.signingKey ||
this.state.witnessAccount !== ns.witnessAccount
this.state.witnessAccount !== ns.witnessAccount ||
this.props.updateOrCreate !== np.updateOrCreate
);
}

componentDidUpdate(prevProps) {
let oldId = prevProps.account.get("id");
let newId = this.props.account.get("id");
if (newId !== oldId || this.state.witnessObject == null) {
ChainStore.fetchWitnessByAccount(this.props.account.get("id")).then(
response => {
if (response == null) {
this.props.hideModal();
this.setState({
witnessObject: {}
});
} else {
this.setState({
witnessObject: response,
url: response.get("url"),
signingKey: response.get("signing_key"),
witness_id: response.get("id")
});
}
}
);
}
}

onAddWitness() {
const {witnessAccount, signingKey, url} = this.state;

if (witnessAccount && signingKey) {
AccountActions.createWitness({
account: witnessAccount,
url,
signingKey
});
if (this.props.updateOrCreate) {
AccountActions.updateWitness({
account: witnessAccount,
url: this.state.url,
signingKey: this.state.signingKey,
witness_id: this.state.witnessObject.get("id")
});
} else {
AccountActions.createWitness({
account: witnessAccount,
url,
signingKey
});
}
}
this.props.hideModal();
}
Expand Down

0 comments on commit 6790b93

Please sign in to comment.