Skip to content

Commit

Permalink
Refine data display
Browse files Browse the repository at this point in the history
  • Loading branch information
cronokirby committed Oct 23, 2024
1 parent 77808f8 commit 71df672
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 42 deletions.
41 changes: 3 additions & 38 deletions app/routes/_index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,33 +46,24 @@ class Supply {
constructor(
public total: ValueView,
public staked_percentage: number,
public price: number,
public market_cap: number,
) {}

static async fetch(db: Database, registry: Registry): Promise<Supply> {
const { total, staked, price, market_cap } = await db
const { total, staked } = await db
.selectFrom("insights_supply")
.select(["total", "staked", "price", "market_cap"])
.select(["total", "staked"])
.orderBy("height desc")
.limit(1)
.executeTakeFirstOrThrow();
const umMetadata = registry.getAllAssets().find((x) => x.symbol === "UM")!;
return new Supply(
knownValueView(umMetadata, new Amount(splitLoHi(total))),
Number(staked) / Number(total),
price,
market_cap,
);
}

static fromJson(data: Jsonified<Supply>): Supply {
return new Supply(
ValueView.fromJson(data.total),
data.staked_percentage,
data.price,
data.market_cap,
);
return new Supply(ValueView.fromJson(data.total), data.staked_percentage);
}
}

Expand Down Expand Up @@ -253,16 +244,6 @@ const ShowSupply = ({ supply }: { supply: Supply }) => {
<Table.Th>{"staked"}</Table.Th>
<Table.Td>{(100 * supply.staked_percentage).toFixed(2)}%</Table.Td>
</Table.Tr>
<Table.Tr>
<Table.Th>{"price"}</Table.Th>
<Table.Td>${supply.price.toLocaleString("en-us")}</Table.Td>
</Table.Tr>
<Table.Tr>
<Table.Th>{"market_cap"}</Table.Th>
<Table.Td>
${(supply.market_cap / 1_000_000).toLocaleString("en-us")}
</Table.Td>
</Table.Tr>
</Table.Tbody>
</Table>
</Card>
Expand Down Expand Up @@ -430,22 +411,6 @@ export const meta: MetaFunction = () => {
export default function Index() {
const raw = useLoaderData<Jsonified<Data>>();
const data = Data.fromJson(raw);
console.log(
JSON.stringify(
data.shieldedPool
.filter(
(x) =>
x.now.current.valueView.case === "knownAssetId" &&
x.now.current.valueView.value.metadata!.symbol === "USDC",
)
.map((x) => [
x.now.current.valueView.value?.amount,
x.h24.current.valueView.value?.amount,
x.d7.current.valueView.value?.amount,
x.d30.current.valueView.value?.amount,
]),
),
);
return (
<PenumbraUIProvider>
<Display>
Expand Down
4 changes: 0 additions & 4 deletions backend/database/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ export interface SupplyTable {
total: bigint;
/** Of this amount, how much is currently staked. */
staked: bigint;
/** The current price of the native token, in dollars. */
price: number;
/** price * total. */
market_cap: number;
}

export interface BlockDetails {
Expand Down

0 comments on commit 71df672

Please sign in to comment.