Skip to content

Commit

Permalink
CP-102 Levels: Added claim button
Browse files Browse the repository at this point in the history
  • Loading branch information
zavz9t committed Nov 5, 2018
1 parent 285b713 commit 060ed7e
Show file tree
Hide file tree
Showing 11 changed files with 220 additions and 49 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.js?t=1541342807"></script>
<script src="js/main.min.js?t=1541448270"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion chain-post/js/main.min.js

Large diffs are not rendered by default.

139 changes: 124 additions & 15 deletions js/adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,42 +24,42 @@ class AbstractAdapter
return ``;
}

static factory(section) {
if (!(section in items)) {
switch (section) {
static factory(chainName) {
if (!(chainName in items)) {
switch (chainName) {
case constant.adapterSteem:
items[section] = new Steem();
items[chainName] = new Steem();
break;
case constant.adapterGolos:
items[section] = new Golos();
items[chainName] = new Golos();
break;
case constant.adapterVox:
items[section] = new Vox();
items[chainName] = new Vox();
break;
case constant.adapterWls:
items[section] = new Wls();
items[chainName] = new Wls();
break;
case constant.adapterSerey:
items[section] = new Serey();
items[chainName] = new Serey();
break;
case constant.adapterWeku:
items[section] = new Weku();
items[chainName] = new Weku();
break;
case constant.adapterSmoke:
items[section] = new Smoke();
items[chainName] = new Smoke();
break;
case constant.adapterViz:
items[section] = new Viz();
items[chainName] = new Viz();
break;
default:
throw sprintf(
`factory: Section "%s" is not implemented yet!`,
section
`factory: Chain "%s" is not implemented yet!`,
chainName
);
}
}

return items[section];
return items[chainName];
}

static buildJsonMetadata(tags, options)
Expand Down Expand Up @@ -103,7 +103,7 @@ class AbstractAdapter

async isWifValid(username, wif, successCallback, failCallback) {
while (true === this.connection.config.get(keyConnBusy)) {
console.log(this.name + `:isWifValid: wait execution for 1 sec`);
console.info(this.name + `:isWifValid: wait execution for 1 sec`);

await sleep(1000);
}
Expand Down Expand Up @@ -424,6 +424,55 @@ class AbstractAdapter

return operations;
}

async claimRewardBalance(wif, username, successCallback, failCallback) {
let adapterInstance = this;

this.reconnect();
this.processAccountsInfo([username], function (accounts, gp) {
if (accounts.length !== 1) {
if (failCallback) {
failCallback(sprintf(`User "%s" not found in "%s" chain.`, username, adapterInstance.name));
}
console.error(message);

return;
}

adapterInstance.claimRewardBalanceProcess(wif, accounts[0], gp, successCallback, failCallback);
});
}

async claimRewardBalanceProcess(wif, account, gp, successCallback, failCallback) {
let adapterInstance = this;

this.connection.broadcast.claimRewardBalance(
wif
, account.name
, account.reward_steem_balance
, account.reward_sbd_balance
, account.reward_vesting_balance
, function(error, result) {
if (error) {
failCallback(sprintf(`Failed to claim rewards of "%s" account.`, account.name));
console.error(error);

return;
}

adapterInstance.connection.api.getAccounts([account.name], function(error, result) {
if (error) {
failCallback(sprintf(`Failed to load new account "%s" data.`, account.name));
console.error(error);

return;
}

successCallback(result[0], gp);
});
}
);
}
}

class Steem extends AbstractAdapter
Expand Down Expand Up @@ -624,6 +673,36 @@ class Wls extends AbstractAdapter
reconnect() {
this.connection.api.setOptions({ url: `https://rpc.wls.services` })
}

async claimRewardBalanceProcess(wif, account, gp, successCallback, failCallback) {
let adapterInstance = this;

this.connection.broadcast.claimRewardBalance(
wif
, account.name
, account.reward_steem_balance
, account.reward_vesting_balance
, function(error, result) {
if (error) {
failCallback(sprintf(`Failed to claim rewards of "%s" account.`, account.name));
console.error(error);

return;
}

adapterInstance.connection.api.getAccounts([account.name], function(error, result) {
if (error) {
failCallback(sprintf(`Failed to load new account "%s" data.`, account.name));
console.error(error);

return;
}

successCallback(result[0], gp);
});
}
);
}
}

class Serey extends AbstractAdapter
Expand Down Expand Up @@ -732,6 +811,36 @@ class Smoke extends AbstractAdapter

return operations;
}

async claimRewardBalanceProcess(wif, account, gp, successCallback, failCallback) {
let adapterInstance = this;

this.connection.broadcast.claimRewardBalance(
wif
, account.name
, account.reward_steem_balance
, account.reward_vesting_balance
, function(error, result) {
if (error) {
failCallback(sprintf(`Failed to claim rewards of "%s" account.`, account.name));
console.error(error);

return;
}

adapterInstance.connection.api.getAccounts([account.name], function(error, result) {
if (error) {
failCallback(sprintf(`Failed to load new account "%s" data.`, account.name));
console.error(error);

return;
}

successCallback(result[0], gp);
});
}
);
}
}

class Viz extends AbstractAdapter
Expand Down
10 changes: 6 additions & 4 deletions js/constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,8 @@ I decided to change this and discovered a new world that surrounds me! Today I s
, levelsSectionItem: `
<hr />
<div id="%1$s" class="section-container">
<h2 class="section-title text-center"><img src="../img/chain/%1$s-32.png" alt="%2$s" /> %2$s</h2>
<div id="%1$s" class="chain-container">
<h2 class="chain-title text-center"><img src="../img/chain/%1$s-32.png" alt="%2$s" /> %2$s</h2>
</div>
Expand All @@ -471,7 +471,7 @@ I decided to change this and discovered a new world that surrounds me! Today I s
, levelsAccountItem: `
<hr />
<div class="account-wrapper row align-items-center justify-content-center">
<div class="col-4"><h5>@%1$s</h5></div>
<div class="col-4"><h5 class="username">@%1$s</h5></div>
<div class="col-8">
<div class="progress-title">Voting Power</div>
<div class="progress">
Expand All @@ -483,7 +483,9 @@ I decided to change this and discovered a new world that surrounds me! Today I s
<div class="progress-bar progress-bar-striped bg-success" role="progressbar" style="width: %3$s%%" aria-valuenow="%3$s" aria-valuemin="0" aria-valuemax="100">%3$s%%</div>
</div>
<div class="pending-rewards">Pending rewards: %4$s</div>
<div class="power">Power: <span class="power-value">%4$s</span></div>
<div class="pending-rewards">Pending rewards: <span class="rewards-value">%5$s</span> <button class="btn btn-outline-info btn-sm claim-rewards"><i class="fa fa-refresh fa-spin loader"></i> Claim</button></div>
</div>
</div>
`
Expand Down
4 changes: 2 additions & 2 deletions js/static/smoke-js.min.js

Large diffs are not rendered by default.

14 changes: 9 additions & 5 deletions js/tool.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,17 +183,21 @@ function startPublishing(buttonElement) {
jQuery(buttonElement).addClass(constant.htmlNames.loadingClassName);
}

function finishPublishing() {
function finishPublishing(buttonElement) {
if (!buttonElement) {
buttonElement = jQuery(constant.htmlNavigation.submitFormButton);
}

if (false === areAdaptersPublishing()) {
jQuery(constant.htmlNavigation.submitFormButton).prop(constant.htmlNames.disabledPropName, false);
jQuery(constant.htmlNavigation.submitFormButton).removeClass(constant.htmlNames.loadingClassName);
buttonElement.prop(constant.htmlNames.disabledPropName, false);
buttonElement.removeClass(constant.htmlNames.loadingClassName);
}
}

function handleSuccessfulPost(section, result) {
decreasePublishAdapters();

console.log(section, result);
console.info(section, result);

let funcName = parseFunctionName(arguments.callee.toString())
, urlFormat = `%s/%s/@%s/%s`
Expand Down Expand Up @@ -252,7 +256,7 @@ function handleSuccessfulPost(section, result) {
}

function handleSuccessfulVote(section, accounts) {
console.log(section, accounts);
console.info(section, accounts);

jQuery(constant.htmlNavigation.resultBlock).append(
sprintf(
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=1541342807"></script>
<script src="js/main.min.js?t=1541448270"></script>
</body>
</html>
Loading

0 comments on commit 060ed7e

Please sign in to comment.