-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(analytics): add circulation page
- Loading branch information
1 parent
c19c726
commit c31aba0
Showing
23 changed files
with
611 additions
and
375 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const format = new Intl.NumberFormat('en-US').format | ||
export const formatPercentage = new Intl.NumberFormat('en-US', { | ||
style: 'percent', | ||
maximumFractionDigits: 2, | ||
}).format |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,12 @@ | ||
<script lang="ts"> | ||
import Computation from '~/lib/Computation.svelte' | ||
import Nav from '~/lib/Nav.svelte' | ||
import PhatContract from '~/lib/PhatContract.svelte' | ||
</script> | ||
|
||
<svelte:head> | ||
<title>Phala Analytics</title> | ||
</svelte:head> | ||
|
||
<header class="mx-auto px-4 md:px-6 mt-4 md:mt-6 max-w-7xl"> | ||
<Nav /> | ||
</header> | ||
|
||
<main class="max-w-5xl mx-auto mt-6 md:mt-14 px-4 md:px-6 mb-6"> | ||
<Computation /> | ||
<div class="mt-4 overflow-hidden" /> | ||
<PhatContract /> | ||
</main> | ||
<Computation /> | ||
<div class="mt-4 overflow-hidden" /> | ||
<PhatContract /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<script lang="ts"> | ||
import {compactFormat} from '@phala/utils' | ||
import Decimal from 'decimal.js' | ||
import {Doughnut} from 'svelte-chartjs' | ||
import {derived} from 'svelte/store' | ||
import {getCirculation} from '~/stores/circulation' | ||
const totalSupply = new Decimal(1e9) | ||
const display = derived(getCirculation(), ({data: circulation}) => { | ||
let circulatingSupply = 'ㅤ' | ||
if (circulation != null) { | ||
circulatingSupply = `${compactFormat( | ||
new Decimal(circulation.totalCirculation), | ||
)} PHA` | ||
} | ||
return [['Circulating Supply', circulatingSupply]] | ||
}) | ||
const chartData = derived(getCirculation(), ({data: circulation}) => { | ||
if (circulation == null) return null | ||
return { | ||
labels: ['Ethereum', 'Phala', 'Khala'], | ||
datasets: [ | ||
{ | ||
label: 'Circulating Supply', | ||
data: [ | ||
parseInt(circulation.ethereumCirculation), | ||
parseInt(circulation.phalaCirculation), | ||
parseInt(circulation.khalaCirculation), | ||
], | ||
backgroundColor: ['#12100B', '#c5ff46', '#03ffff'], | ||
}, | ||
], | ||
} | ||
}) | ||
</script> | ||
|
||
<svelte:head> | ||
<title>Token | Phala Analytics</title> | ||
</svelte:head> | ||
|
||
<h1 class="font-montserrat text-4xl font-bold my-8">Circulation</h1> | ||
<div class="flex flex-wrap gap-4"> | ||
<div class="flex flex-col flex-1 gap-4"> | ||
<section class="card flex-1"> | ||
<span class="data-label">Circulating Supply</span> | ||
<div class="data-value mt-1">{$display[0][1]}</div> | ||
</section> | ||
<section class="card flex-1">s</section> | ||
</div> | ||
<section class="card flex-1"> | ||
{#if $chartData != null} | ||
<Doughnut data={$chartData} options={{borderWidth: 0, cutout: '95%'}} /> | ||
{/if} | ||
</section> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,33 @@ | ||
import {createQuery} from '@tanstack/svelte-query' | ||
import Decimal from 'decimal.js' | ||
|
||
interface CirculationData { | ||
ethereumTotalSupply: string | ||
ethereumMiningRewards: string | ||
ethereumPhalaChainbridge: string | ||
ethereumKhalaChainbridge: string | ||
ethereumSygmaBridge: string | ||
ethereumCirculation: string | ||
phalaTotalIssuance: string | ||
phalaMiningRewards: string | ||
phalaCrowdloan: string | ||
phalaChainbridge: string | ||
phalaSygmaBridge: string | ||
phalaCirculation: string | ||
khalaTotalIssuance: string | ||
khalaMiningRewards: string | ||
khalaCrowdloan: string | ||
khalaChainbridge: string | ||
khalaSygmaBridge: string | ||
khalaCirculation: string | ||
totalCirculation: string | ||
lastUpdate: number | ||
} | ||
|
||
const fetchCirculationData = async () => { | ||
const res = await fetch( | ||
'https://pha-circulation-server.vercel.app/api/circulation', | ||
) | ||
const amount = await res.text() | ||
if (amount != null) { | ||
return new Decimal(amount) | ||
} | ||
const res = await fetch('https://pha-circulation-server.vercel.app/api/all') | ||
const data = (await res.json()) as CirculationData | ||
return data | ||
} | ||
|
||
export const getCirculation = () => | ||
createQuery(['circulation'], fetchCirculationData) | ||
createQuery({queryKey: ['circulation'], queryFn: fetchCirculationData}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { sveltekit } from '@sveltejs/kit/vite'; | ||
import { defineConfig } from 'vite'; | ||
import {sveltekit} from '@sveltejs/kit/vite' | ||
import {defineConfig} from 'vite' | ||
|
||
export default defineConfig({ | ||
plugins: [sveltekit()] | ||
}); | ||
plugins: [sveltekit()], | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.