Skip to content

Commit

Permalink
populate leaderboard (#54)
Browse files Browse the repository at this point in the history
* populate leaderboard

* summary stats

* prettier
  • Loading branch information
brenzi authored Aug 26, 2024
1 parent 4ba8428 commit 405a837
Showing 1 changed file with 78 additions and 72 deletions.
150 changes: 78 additions & 72 deletions pages/teerdays.vue
Original file line number Diff line number Diff line change
Expand Up @@ -408,18 +408,34 @@
<dl
class="mt-10 grid grid-cols-1 gap-0.5 overflow-hidden rounded-2xl text-center sm:grid-cols-2 lg:grid-cols-3"
>
<div
v-for="stat in stats"
:key="stat.id"
class="flex flex-col bg-white/5 p-8"
>
<div class="flex flex-col bg-white/5 p-8">
<dt class="text-sm font-semibold leading-6 text-gray-300">
TEERday holder
</dt>
<dd
class="order-first text-3xl font-semibold tracking-tight text-white"
>
{{ summaryHolders }}
</dd>
</div>
<div class="flex flex-col bg-white/5 p-8">
<dt class="text-sm font-semibold leading-6 text-gray-300">
{{ stat.name }}
Total TEER bonded
</dt>
<dd
class="order-first text-3xl font-semibold tracking-tight text-white"
>
{{ stat.value }}
{{ summaryTeerBonded.toFixed(2) }}
</dd>
</div>
<div class="flex flex-col bg-white/5 p-8">
<dt class="text-sm font-semibold leading-6 text-gray-300">
Total TEERdays active
</dt>
<dd
class="order-first text-3xl font-semibold tracking-tight text-white"
>
{{ summaryTeerDays.toFixed(2) }}
</dd>
</div>
</dl>
Expand Down Expand Up @@ -620,26 +636,26 @@
</tr>
</thead>
<tbody class="divide-y divide-gray-800">
<tr v-for="leaderboard in leaderboard">
<tr v-for="(entry, index) in allBonds">
<td
class="whitespace-nowrap py-4 pl-4 pr-3 text-sm font-medium text-white sm:pl-0"
>
{{ leaderboard.rank }}
{{ index + 1 }}
</td>
<td
class="whitespace-nowrap px-3 py-4 text-sm text-gray-300"
>
{{ leaderboard.teerdays }}
{{ entry[2].toFixed(2) }}
</td>
<td
class="whitespace-nowrap px-3 py-4 text-sm text-gray-300"
>
{{ leaderboard.wallet }}
{{ entry[0] }}
</td>
<td
class="whitespace-nowrap px-3 py-4 text-sm text-gray-300"
>
{{ leaderboard.teerbonded }}
{{ entry[1].toFixed(2) }}
</td>
</tr>
</tbody>
Expand Down Expand Up @@ -708,6 +724,7 @@ import {
web3FromAddress,
} from "@polkadot/extension-dapp";
import { ApiPromise, WsProvider } from "@polkadot/api";
import { cryptoWaitReady } from "@polkadot/util-crypto";
import { onMounted, ref, watch } from "vue";
import { useAccount } from "@/store/teerAccount.ts";
import { useInterval } from "@vueuse/core";
Expand All @@ -718,6 +735,10 @@ const accounts = ref([]);
const selectedAccount = ref(null);
const currentBond = ref(null);
const pendingUnlock = ref(null);
const allBonds = ref([]);
const summaryHolders = ref(0);
const summaryTeerBonded = ref(0);
const summaryTeerDays = ref(0);

watch(selectedAccount, (newAccount) => {
if (newAccount) {
Expand All @@ -742,6 +763,51 @@ const connect = () => {

let api: ApiPromise | null = null;

onMounted(async () => {
console.log("trying to init api");
const wsProvider = new WsProvider("wss://paseo.api.integritee.network");
api = await ApiPromise.create({ provider: wsProvider });
console.log("api initialized");
allBonds.value = [];
cryptoWaitReady().then(() => {
api.query.teerDays.teerDayBonds.entries().then((entries) => {
entries.forEach(([key, maybeBond]) => {
console.log(key.args + " " + maybeBond);
let account = key.args[0];
let lastUpdated = new Date(0);
let bond = maybeBond.unwrap();
lastUpdated.setUTCMilliseconds(bond.lastUpdated.toNumber());
let mybond = new Bond(
bond.value / Math.pow(10, 12),
lastUpdated,
bond.accumulatedTokentime / Math.pow(10, 12) / 86400 / 1000,
);
mybond.updateTeerDays();
console.log(mybond);
allBonds.value.push([
account,
mybond.teerBonded,
mybond.accumulatedTeerDays,
42,
]);
});
// sort descending by value
allBonds.value = allBonds.value.sort((a, b) => b[2] - a[2]);
console.log(allBonds.value);
summaryTeerBonded.value = allBonds.value.reduce(
(acc, val) => acc + val[1],
0,
);
summaryTeerDays.value = allBonds.value.reduce(
(acc, val) => acc + val[2],
0,
);
summaryHolders.value = allBonds.value.length;
console.log(summaryHolders.value);
});
});
});

const isFetchingTeerBalance = ref(true);

watch(accountStore, async () => {
Expand All @@ -750,9 +816,6 @@ watch(accountStore, async () => {
console.log("skipping api init. no address");
return;
}
console.log("trying to init api");
const wsProvider = new WsProvider("wss://paseo.api.integritee.network");
api = await ApiPromise.create({ provider: wsProvider });
await api.query.system.account(
accountStore.address,
({
Expand Down Expand Up @@ -974,64 +1037,7 @@ class PendingUnlock {
}
}

const stats = [
{ id: 1, name: "TEERday holder", value: "400" },
{ id: 2, name: "Total TEER bonded​", value: "1000" },
{ id: 4, name: "Total TEERdays ​active​", value: "100 000" },
];

import { ref } from "vue";
const leaderboard = [
{
rank: "1",
teerdays: "12345",
wallet: "x0sdkgfskdfhskjdflshdfkjsdkf",
teerbonded: "12345",
},
{
rank: "2",
teerdays: "12345",
wallet: "x0sdkgfskdfhskjdflshdfkjsdkf",
teerbonded: "12345",
},
{
rank: "3",
teerdays: "12345",
wallet: "x0sdkgfskdfhskjdflshdfkjsdkf",
teerbonded: "12345",
},
{
rank: "4",
teerdays: "12345",
wallet: "x0sdkgfskdfhskjdflshdfkjsdkf",
teerbonded: "12345",
},
{
rank: "5",
teerdays: "12345",
wallet: "x0sdkgfskdfhskjdflshdfkjsdkf",
teerbonded: "12345",
},
{
rank: "6",
teerdays: "12345",
wallet: "x0sdkgfskdfhskjdflshdfkjsdkf",
teerbonded: "12345",
},
{
rank: "7",
teerdays: "12345",
wallet: "x0sdkgfskdfhskjdflshdfkjsdkf",
teerbonded: "12345",
},
{
rank: "8",
teerdays: "12345",
wallet: "x0sdkgfskdfhskjdflshdfkjsdkf",
teerbonded: "12345",
},
// More people...
];

import { XMarkIcon } from "@heroicons/vue/20/solid";
import { Menu, MenuButton, MenuItem, MenuItems } from "@headlessui/vue";
Expand Down

0 comments on commit 405a837

Please sign in to comment.