Skip to content

Commit

Permalink
Reorganise code layout
Browse files Browse the repository at this point in the history
  • Loading branch information
mrfelton committed Feb 19, 2024
1 parent 1ad73bd commit 5ce0eaa
Show file tree
Hide file tree
Showing 20 changed files with 571 additions and 944 deletions.
120 changes: 0 additions & 120 deletions src/DataProviderManager.ts

This file was deleted.

48 changes: 48 additions & 0 deletions src/components/Content.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { raw } from "hono/html";
import { Layout } from "./Layout";
import { BlockchainData } from "../lib/DataProviderManager";

export const Content = (props: {
siteData: SiteData;
data: BlockchainData;
}) => (
<Layout {...props.siteData}>
<div class="logo">
<svg
width="20"
height="20"
viewBox="0 0 155 120"
fill="none"
xmlns="http://www.w3.org/2000/svg"
focusable="false"
>
<path
fillRule="evenodd"
clipRule="evenodd"
d="M7.06565 43.2477C1.90963 41.2685 -0.665684 35.4843 1.31353 30.3283C3.29274 25.1722 9.07699 22.5969 14.233 24.5761L51.4526 38.8634C51.4937 38.8798 51.535 38.896 51.5765 38.9119L70.2481 46.0792C75.4041 48.0584 81.1883 45.4831 83.1675 40.3271C85.1468 35.1711 82.5714 29.3868 77.4154 27.4076L77.4132 27.4068C77.4139 27.4064 77.4145 27.406 77.4151 27.4056L58.7436 20.2383C53.5876 18.2591 51.0123 12.4749 52.9915 7.31885C54.9707 2.16283 60.755 -0.412485 65.911 1.56673L120.828 22.6473C120.959 22.6977 121.089 22.7506 121.217 22.8059C121.453 22.8928 121.69 22.9815 121.926 23.0721C147.706 32.9681 160.583 61.8894 150.686 87.6695C140.79 113.45 111.869 126.326 86.089 116.43C85.5927 116.24 85.1011 116.042 84.6144 115.838C84.3783 115.766 84.1431 115.686 83.9091 115.596L30.0742 94.9308C24.9182 92.9516 22.3428 87.1673 24.3221 82.0113C26.3013 76.8553 32.0855 74.2799 37.2415 76.2592L55.9106 83.4256C55.9103 83.4242 55.9099 83.4229 55.9095 83.4215L55.9133 83.423C61.0694 85.4022 66.8536 82.8269 68.8328 77.6709C70.812 72.5148 68.2367 66.7306 63.0807 64.7514L54.6786 61.5261C54.6787 61.5257 54.6788 61.5252 54.6789 61.5247L7.06565 43.2477Z"
fill="currentColor"
></path>
</svg>
</div>

<div class="header">
<h1>{props.siteData.title}</h1>
<p>{props.siteData.subtitle}</p>
</div>

<div class="content">
<pre>
<span class="blue">curl</span> -L -X GET{" "}
<span class="green">'{props.siteData.baseUrl}/v1/fee-estimates'</span>
</pre>

<pre>{raw(JSON.stringify(props.data, null, 2))}</pre>
</div>

<div class="footer">
<a href="https://github.com/LN-Zap/bitcoin-blended-fee-estimator">
https://github.com/LN-Zap/bitcoin-blended-fee-estimator
</a>
</div>
</Layout>
);
21 changes: 21 additions & 0 deletions src/components/Layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export const Layout = (props: SiteData) => {
return (
<html lang="en">
<head>
<title>{props.title}</title>
<meta name="description" content={props.subtitle} />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta charset="UTF-8" />
<meta name="color-scheme" content="light dark" />
<link rel="stylesheet" href="/static/style.css" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" />
<link
href="https://fonts.googleapis.com/css2?family=Arimo&family=Montserrat&family=Roboto:wght@100&display=swap"
rel="stylesheet"
/>
</head>
<body>{props.children}</body>
</html>
);
};
2 changes: 2 additions & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./Content";
export * from "./Layout";
70 changes: 40 additions & 30 deletions src/custom.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
// MempoolFeeEstimates represents the fee estimates for different transaction speeds.
interface Provider {
getBlockHeight(): Promise<number>;
getBlockHash(): Promise<string>;
getFeeEstimates(): Promise<FeeByBlockTarget>;
getAllData(): Promise<ProviderData>;
}

type DataPoint = {
provider: Provider;
blockHeight: number;
blockHash: string;
feeEstimates: FeeByBlockTarget;
};

// CacheConfig represents the configuration for the cache.
type CacheConfig = {
stdTTL: number;
checkperiod: number;
};

// MempoolFeeEstimates represents the data returned by the Mempool API.
type MempoolFeeEstimates = {
[key: string]: number; // dynamic keys with number as value (sat/vb)
fastestFee: number; // fee for the fastest transaction speed (sat/vb)
Expand All @@ -8,6 +28,7 @@ type MempoolFeeEstimates = {
minimumFee: number; // minimum relay fee (sat/vb)
};

// MempoolFeeEstimates represents the data returned by the Esplora API.
type EsploraFeeEstimates = {
[key: string]: number;
};
Expand All @@ -17,28 +38,12 @@ type FeeByBlockTarget = {
[target: string]: number; // fees by confirmation target
};

// Estimates represents the current block hash and fee by block target.
type Estimates = {
current_block_hash: string | null; // current block hash
current_block_height: number | null; // current block height
fee_by_block_target: FeeByBlockTarget; // fee by block target (in sat/kb)
};

// BlockTargetMapping represents the mapping of block targets.
type BlockTargetMapping = {
[key: number]: string; // dynamic numeric keys with string as value
};

// SiteData represents the data of a site.
interface SiteData {
title: string; // title of the site
subtitle: string; // subtitle of the site
children?: any; // children of the site (optional)
}

// ExpectedResponseType represents the expected response type for an http request.
type ExpectedResponseType = "json" | "text"; // can be either 'json' or 'text'

// EstimateMode represents the mode for fee estimation.
type EstimateMode = "ECONOMICAL" | "CONSERVATIVE"; // estimate mode can be either 'ECONOMICAL' or 'CONSERVATIVE'

// BatchRequest represents a bitcoind batch request response.
interface EstimateSmartFeeBatchResponse {
result?: EstimateSmartFeeResponse;
Expand All @@ -60,18 +65,23 @@ interface BestBlockHashResponse {
result: string;
}

// EstimateMode represents the mode for fee estimation.
type EstimateMode = "ECONOMICAL" | "CONSERVATIVE"; // estimate mode can be either 'ECONOMICAL' or 'CONSERVATIVE'

interface Provider {
getBlockHeight(): Promise<number>;
getBlockHash(): Promise<string>;
getFeeEstimates(): Promise<FeeByBlockTarget>;
getAllData(): Promise<ProviderData>;
}

type ProviderData = {
blockHeight: number;
blockHash: string;
feeEstimates: FeeByBlockTarget;
};

// Estimates represents the current block hash and fee by block target.
type Estimates = {
current_block_hash: string | null; // current block hash
current_block_height: number | null; // current block height
fee_by_block_target: FeeByBlockTarget; // fee by block target (in sat/kb)
};

// SiteData represents the data of a site.
interface SiteData {
baseUrl: string; // base url of the site
title: string; // title of the site
subtitle: string; // subtitle of the site
children?: any; // children of the site (optional)
}
Loading

0 comments on commit 5ce0eaa

Please sign in to comment.