Skip to content

Commit

Permalink
CP-103 Updated golos-js logic
Browse files Browse the repository at this point in the history
  • Loading branch information
zavz9t committed Nov 5, 2018
1 parent 7412e14 commit 285b713
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 14 deletions.
2 changes: 1 addition & 1 deletion chain-post/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,6 @@ <h5 class="modal-title" id="chainTitle">Load post content from any Chain</h5>
<script src="../js/lib/bootstrap.bundle.min.js" integrity="sha384-pjaaA8dDz/5BgdFUPX6M/9SUZv4d12SUPF0axWc+VRZkx5xU3daN+lYb49+Ax+Tl" crossorigin="anonymous"></script>
<script src="../js/lib/bootstrap-select.min.js" crossorigin="anonymous"></script>

<script src="js/main.min.js?t=1541342803"></script>
<script src="js/main.js?t=1541342807"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion chain-post/js/main.min.js

Large diffs are not rendered by default.

37 changes: 30 additions & 7 deletions js/adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,7 @@ class AbstractAdapter
this.reconnect();
let adapterInstance = this;

adapterInstance.connection.config.set(keyConnBusy, true);
adapterInstance.connection.api.getContent(author, permlink, function(err, result) {
adapterInstance.processGetGetContent(author, permlink, this.getReturnVotesParameter(), function(err, result) {
if (err) {
tool.handlePublishError(adapterInstance.name, err);
adapterInstance.connection.config.set(keyConnBusy, false);
Expand Down Expand Up @@ -257,13 +256,30 @@ class AbstractAdapter
});
}

async processGetGetContent(author, permlink, votes, callback) {
this.connection.config.set(keyConnBusy, true);
if (votes === null) {
this.connection.api.getContent(author, permlink, function (err, result) {
callback(err, result);
});
} else {
this.connection.api.getContent(author, permlink, votes, function (err, result) {
callback(err, result);
});
}
}

getReturnVotesParameter() {
return null
}

vote(url, accounts) {
let params = tool.parsePostUrl(url);

this.reconnect();
let adapterInstance = this;

adapterInstance.connection.api.getContent(params[`author`], params[`permlink`], function(err, result) {
this.processGetGetContent(params[`author`], params[`permlink`], this.getReturnVotesParameter(), function(err, result) {
if (err) {
tool.handlePublishError(adapterInstance.name, err);

Expand Down Expand Up @@ -356,7 +372,7 @@ class AbstractAdapter
this.reconnect();
let adapterInstance = this;

adapterInstance.connection.api.getContent(params[`author`], params[`permlink`], function(err, result) {
this.processGetGetContent(params[`author`], params[`permlink`], this.getReturnVotesParameter(), function(err, result) {
if (err) {
console.error(adapterInstance.name + `\n- - -\n` + err);

Expand Down Expand Up @@ -523,6 +539,10 @@ class Golos extends AbstractAdapter
reconnect() {
this.connection.config.set(`websocket`, `wss://ws.golos.io`);
}

getReturnVotesParameter() {
return -1
}
}

class Vox extends AbstractAdapter
Expand Down Expand Up @@ -776,6 +796,10 @@ class Viz extends AbstractAdapter
this.connection.config.set(`websocket`, `wss://ws.viz.ropox.tools`);
}

getReturnVotesParameter() {
return -1
}

async broadcastSend(wif, author, permlink, operations) {
while (true === this.connection.config.get(keyConnBusy)) {
console.info(this.name + `:broadcastSend: wait execution for 1 sec`);
Expand All @@ -786,8 +810,7 @@ class Viz extends AbstractAdapter
this.reconnect();
let adapterInstance = this;

adapterInstance.connection.config.set(keyConnBusy, true);
adapterInstance.connection.api.getContent(author, permlink, 0, function(err, result) {
this.processGetGetContent(author, permlink, 0, function(err, result) {
if (err) {
tool.handlePublishError(adapterInstance.name, err);
adapterInstance.connection.config.set(keyConnBusy, false);
Expand Down Expand Up @@ -831,7 +854,7 @@ class Viz extends AbstractAdapter
this.reconnect();
let adapterInstance = this;

adapterInstance.connection.api.getContent(params[`author`], params[`permlink`], -1, function(err, result) {
this.processGetGetContent(params[`author`], params[`permlink`], this.getReturnVotesParameter(), function(err, result) {
if (err) {
tool.handlePublishError(adapterInstance.name, err);

Expand Down
2 changes: 1 addition & 1 deletion js/constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ I decided to change this and discovered a new world that surrounds me! Today I s
`
, publishSuccess: `
<div class="alert alert-success alert-dismissible fade show" role="alert">
<img src="../img/chain/%1$s-16.png" alt="%1$s"> <a href="%2$s" target="_blank" rel="noopener noreferrer">%2$s</a> <a href="/voter/?url=%2$s" target="_blank" rel="noopener noreferrer"><img src="../img/logo/upvote-16.png" title="Upvote" /></a>
<img src="../img/chain/%1$s-16.png" alt="%1$s"> <a href="%2$s" target="_blank" rel="noopener noreferrer">%2$s</a> <a href="/voter/?url=%2$s" target="_blank" rel="noopener noreferrer"><img src="../img/tool/upvote-16.png" title="Upvote" /></a>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
Expand Down
2 changes: 1 addition & 1 deletion levels/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@
<script src="../js/lib/jquery.min.js" integrity="sha384-tsQFqpEReu7ZLhBV2VZlAu7zcOV+rXbYlF2cqB8txI/8aZajjp4Bqd+V6D5IgvKT" crossorigin="anonymous"></script>
<script src="../js/lib/bootstrap.bundle.min.js" integrity="sha384-pjaaA8dDz/5BgdFUPX6M/9SUZv4d12SUPF0axWc+VRZkx5xU3daN+lYb49+Ax+Tl" crossorigin="anonymous"></script>

<script src="js/main.min.js?t=1541342801"></script>
<script src="js/main.min.js?t=1541342807"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion levels/js/main.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion voter/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,6 @@
<script src="../js/lib/bootstrap-select.min.js" crossorigin="anonymous"></script>
<script src="../js/lib/sortable.min.js" crossorigin="anonymous"></script>

<script src="js/main.min.js?t=1541342803"></script>
<script src="js/main.min.js?t=1541342807"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion voter/js/main.min.js

Large diffs are not rendered by default.

0 comments on commit 285b713

Please sign in to comment.