Skip to content

Commit

Permalink
Add a categories rating, error messages and move a bots rating to ste…
Browse files Browse the repository at this point in the history
…em-js
  • Loading branch information
sihaelov committed Feb 13, 2018
1 parent b8dbe06 commit 256e3d5
Show file tree
Hide file tree
Showing 8 changed files with 223 additions and 88 deletions.
8 changes: 8 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,16 @@
</template>

<script>
import { Menu, MenuItem } from 'element-ui';
export default {
name: 'app',
components: {
'el-menu': Menu,
'el-menu-item': MenuItem,
},
data() {
return {
};
Expand Down
121 changes: 50 additions & 71 deletions src/components/Bots.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,20 @@

<script>
import { Card, Table, TableColumn } from 'element-ui';
import steem from 'steem';
import formatNumberMixin from '@/utils/FormatNumber';
steem.api.setOptions({ url: 'https://api.steemit.com' });
export default {
name: 'Bots',
components: {
'el-card': Card,
'el-table': Table,
'el-table-column': TableColumn,
},
mixins: [formatNumberMixin],
data() {
return {
isLoading: false,
Expand All @@ -39,82 +47,53 @@ export default {
loadData() {
this.isLoading = true;
const botList = `(
'aksdwi',
'boomerang',
'appreciator',
'buildawhale',
'upmyvote',
'sneaky-ninja',
'upme',
'jerrybanfield',
'booster',
'ipromote',
'postpromoter',
'allaz',
'pushup',
'minnowhelper'
)
`;
const sqlBots = `
SELECT
name,
vesting_shares,
delegated_vesting_shares,
received_vesting_shares
FROM Accounts
WHERE name IN ${botList}
`;
const botList = [
'aksdwi',
'boomerang',
'appreciator',
'buildawhale',
'upmyvote',
'sneaky-ninja',
'upme',
'jerrybanfield',
'booster',
'ipromote',
'postpromoter',
'allaz',
'pushup',
'minnowhelper',
];
// SQL:
// json_metadata, voting_power, reputation
// vesting_shares, delegated_vesting_shares , received_vesting_shares
const ajaxData = {
query: sqlBots,
};
fetch('https://sql.steemhelpers.com/api', {
method: 'post',
headers: {
'Content-type': 'application/json; charset=utf-8',
},
body: JSON.stringify(ajaxData),
mode: 'cors',
dataType: 'json',
})
.then((response) => {
if (response.status >= 400 && response.status < 600) {
throw new Error(response.statusText);
}
return response.json();
})
.then((data) => {
this.tableData = data.rows;
steem.api.setOptions({ url: 'https://api.steemit.com' });
steem.api.getDynamicGlobalProperties((err, result) => {
const totalVestingFundSteem = parseFloat(result.total_vesting_fund_steem.split(' ')[0]);
const totalVestingShares = parseFloat(result.total_vesting_shares.split(' ')[0]);
this.calculateSteemPower(totalVestingFundSteem, totalVestingShares);
console.log(err, result);
});
})
.catch((error) => {
// JS:
// reward_vesting_balance: "2.047894 VESTS"
// reward_vesting_steem:"0.001 STEEM"
steem.api.getAccounts(botList, (getAccountsError, botAccountList) => {
// console.log(getAccountsError, botAccountList);
if (getAccountsError) {
this.isLoading = false;
console.log('Request failed', error);
this.$notify({ title: 'Error' });
return;
}
this.tableData = botAccountList;
steem.api.getDynamicGlobalProperties((globalPropsError, result) => {
if (globalPropsError) {
this.isLoading = false;
this.$notify({ title: 'Error' });
return;
}
const totalVestingFundSteem = parseFloat(result.total_vesting_fund_steem.split(' ')[0]);
const totalVestingShares = parseFloat(result.total_vesting_shares.split(' ')[0]);
this.calculateSteemPower(totalVestingFundSteem, totalVestingShares);
});
});
}, // loadData
formatter(valueInt) {
let valueStr = valueInt.toString();
if (valueStr.length > 6) {
valueStr = `${Number((valueInt / 1000000).toFixed(2))}M`;
} else if (valueStr.length > 3) {
valueStr = `${(valueInt / 1000).toFixed()}k`;
}
return valueStr;
},
calculateSteemPower(totalVestingFundSteem, totalVestingShares) {
let newTableData = [];
Expand All @@ -129,7 +108,7 @@ export default {
let totalSteemPowerRaw = steemPower + (receivedSteemPower - delegatedSteemPower);
totalSteemPowerRaw = parseInt(totalSteemPowerRaw);
const totalSteemPower = this.formatter(totalSteemPowerRaw);
const totalSteemPower = this.formatNumber(totalSteemPowerRaw);
const newRow = Object.assign({}, row, {
steem_power: steemPower,
Expand Down
137 changes: 137 additions & 0 deletions src/components/Categories.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
<template>
<div class="categories">

<el-card style="max-width: 500px; margin: 50px auto;">

<el-table :data="topCategories" v-loading="isLoading">
<el-table-column prop="category" label="Category">
<template slot-scope="scope">
<a :href="`https://steemit.com/trending/${scope.row.category}`" target="_blank">
{{scope.row.category}}
</a>
</template>
</el-table-column>

<el-table-column prop="pending_payout_value" label="Pending payout" width="120">
<template slot-scope="scope">
${{formatPendingPayout(scope.row.pending_payout_value)}}
</template>
</el-table-column>

<el-table-column prop="children" label="Comments" width="90">
<template slot-scope="scope">
{{formatNumber(scope.row.children)}}
</template>
</el-table-column>

<el-table-column prop="net_votes" label="Votes" width="65">
<template slot-scope="scope">
{{formatNumber(scope.row.net_votes)}}
</template>
</el-table-column>

</el-table>

</el-card>

</div>
</template>

<script>
import { Card, Table, TableColumn } from 'element-ui';
import formatNumberMixin from '@/utils/FormatNumber';
export default {
name: 'Homepage',
components: {
'el-card': Card,
'el-table': Table,
'el-table-column': TableColumn,
},
mixins: [formatNumberMixin],
data() {
return {
isLoading: false,
activeSorter: 'pending_payout_value',
topCategories: [],
};
},
methods: {
changeSorter(menuSorter) {
this.activeSorter = menuSorter;
this.authors = [];
this.lastProfileValue = 999999;
this.loadData();
},
isActiveSorter(menuSorter) {
return this.activeSorter === menuSorter;
},
loadTopCategories() {
this.isLoading = true;
const sqlTopCategoriesBase = `
SELECT TOP 100
category,
SUM(Comments.pending_payout_value) as pending_payout_value,
SUM(Comments.children) as children,
SUM(Comments.net_votes) as net_votes,
COUNT(*) as posts
FROM Comments
WHERE depth=0 AND created BETWEEN GETDATE()-7 AND GETDATE()
GROUP BY category
ORDER BY SUM(Comments.{sorter}) DESC
`;
const sqlTopCategories = sqlTopCategoriesBase.replace(/{sorter}/g, this.activeSorter);
const ajaxData = {
query: sqlTopCategories,
};
fetch('https://sql.steemhelpers.com/api', {
method: 'post',
headers: {
'Content-type': 'application/json; charset=utf-8',
},
body: JSON.stringify(ajaxData),
mode: 'cors',
dataType: 'json',
})
.then((response) => {
this.isLoading = false;
if (response.status >= 400 && response.status < 600) {
throw new Error(response.statusText);
}
return response.json();
})
.then((data) => {
this.topCategories = data.rows;
})
.catch((error) => {
console.log('Request failed', error);
// Materialize.toast('Error!', 4000);
});
}, // loadTopCategories
formatPendingPayout(pendingPayoutRaw) {
const pendingPayout = Math.round(Number.parseFloat(pendingPayoutRaw));
return this.formatNumber(pendingPayout);
},
},
mounted() {
this.loadTopCategories();
},
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style>
</style>
11 changes: 8 additions & 3 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,21 @@
import Vue from 'vue';
import infiniteScroll from 'vue-infinite-scroll';

import ElementUI from 'element-ui';
// import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import locale from 'element-ui/lib/locale/lang/en';
import lang from 'element-ui/lib/locale/lang/en';
import locale from 'element-ui/lib/locale';
import { Loading } from 'element-ui';

import App from './App';
import router from './router';

Vue.config.productionTip = false;
Vue.use(infiniteScroll);
Vue.use(ElementUI, { locale });

// Vue.use(ElementUI, { lang });
locale.use(lang);
Vue.use(Loading.directive);

/* eslint-disable no-new */
new Vue({
Expand Down
6 changes: 6 additions & 0 deletions src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Vue from 'vue';
import Router from 'vue-router';
import Homepage from '@/components/Homepage';
import Bots from '@/components/Bots';
import Categories from '@/components/Categories';

Vue.use(Router);

Expand All @@ -17,5 +18,10 @@ export default new Router({
name: 'bots',
component: Bots,
},
{
path: '/categories',
name: 'categories',
component: Categories,
},
],
});
14 changes: 14 additions & 0 deletions src/utils/FormatNumber.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

export default {
methods: {
formatNumber(valueInt) {
let valueStr = valueInt.toString();
if (valueStr.length > 6) {
valueStr = `${Number((valueInt / 1000000).toFixed(2))}M`;
} else if (valueStr.length > 3) {
valueStr = `${(valueInt / 1000).toFixed()}k`;
}
return valueStr;
},
},
};
3 changes: 0 additions & 3 deletions test/e2e/specs/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ module.exports = {
browser
.url(devServer)
.waitForElementVisible('#app', 5000)
.assert.elementPresent('.hello')
.assert.containsText('h1', 'Welcome to Your Vue.js App')
.assert.elementCount('img', 1)
.end();
},
};
11 changes: 0 additions & 11 deletions test/unit/specs/HelloWorld.spec.js

This file was deleted.

0 comments on commit 256e3d5

Please sign in to comment.