diff --git a/client/src/app.js b/client/src/app.js
index a03c8468..bb06be3a 100644
--- a/client/src/app.js
+++ b/client/src/app.js
@@ -41,8 +41,8 @@ import {
import l10n, { defaultLang } from './l10n'
import * as views from './views'
-const highValueAssetCategory = assetId => `dashboard-high-value-asset-${assetId}`
- , highValueAssetPriceCategory = assetId => `dashboard-high-value-asset-price-${assetId}`
+const highValueAssetCategory = assetId => `high-value-asset-${assetId}`
+ , highValueAssetPriceCategory = assetId => `high-value-asset-price-${assetId}`
, apiBase = (process.env.API_URL || '/api').replace(/\/+$/, '')
, bitcoinMarketChartUrl = process.env.BITCOIN_MARKET_CHART_URL || 'https://api.coingecko.com/api/v3/coins/bitcoin/market_chart?vs_currency=usd&days=1&interval=hourly'
, blockTemplatePollIntervalMs = pollIntervalsMs.fast
@@ -75,6 +75,9 @@ const highValueAssetCategory = assetId => `dashboard-high-value-asset-${assetId}
], [])
const reservedPaths = [ 'mempool', 'assets', 'search' ]
+ , recentAssetsCount = 10
+ , assetListQueryKeys = [ 'start_index', 'sort_field', 'sort_dir', 'limit' ]
+ , isAssetListQuery = query => assetListQueryKeys.some(key => query[key] != null)
, NEW_TABLE_ENTRY_MS = 2000
, initialAutocompleteState = {
query: '',
@@ -306,7 +309,10 @@ export default function main(
, last_txids: parseHashes(loc.query.txids)
, est_chain_seen_count: +loc.query.c || 0
}))
- , goAssetList$ = !process.env.IS_ELEMENTS ? O.empty() : route('/assets').map(loc => ({
+ , assetsRoute$ = !process.env.IS_ELEMENTS ? O.empty() : route('/assets')
+ , goAssets$ = assetsRoute$.filter(loc => !isAssetListQuery(loc.query))
+ , goLegacyAssetList$ = assetsRoute$.filter(loc => isAssetListQuery(loc.query))
+ , goAssetList$ = !process.env.IS_ELEMENTS ? O.empty() : route('/assets/all').map(loc => ({
start_index: +loc.query.start_index || 0
, sort_field: loc.query.sort_field != null ? loc.query.sort_field : 'name'
, sort_dir: loc.query.sort_dir != null ? loc.query.sort_dir : 'asc'
@@ -585,8 +591,7 @@ export default function main(
tipId: null
})
- // dashboard
- , dashboardHighValueAssets$ = !showHighValueAssets
+ , highValueAssets$ = !showHighValueAssets
? O.of({})
: O.merge(...highValueAssetDefinitions.reduce((replies, asset) => [
...replies,
@@ -612,7 +617,7 @@ export default function main(
, dashboardState$ = O.combineLatest(
blocks$,
mempoolRecent$,
- dashboardHighValueAssets$,
+ highValueAssets$,
(blks, txs, highValueAssets) => ({
dashblocks: blks.slice(0, 5),
dashTxs: txs.slice(0, 11),
@@ -670,6 +675,7 @@ export default function main(
// Assets List State
, assetList$ = !process.env.IS_ELEMENTS ? O.empty() :
reply('assetlist', true).map(r => ({ assets: r.body, total: r.headers['x-total-results'] || 493 }))
+ , recentAssets$ = !process.env.IS_ELEMENTS ? O.empty() : reply('recent-assets')
// The minimally required data to start rendering the UI
// In elements, we block rendering until the assetMap is loaded. Otherwise, we can start immediately.
@@ -688,6 +694,7 @@ export default function main(
, goPush$.mapTo('pushtx')
, goScan$.mapTo('scan')
, goMempool$.mapTo('mempool')
+ , goAssets$.mapTo('assets')
, goAssetList$.mapTo('assetList')
, error$.mapTo('error'))
.combineLatest(isReady$, loading$, (view, isReady, loading) =>
@@ -724,6 +731,21 @@ export default function main(
pollingScheduler
).filter(pollIndex => pollIndex == 0 || hasFocus())
+ , highValueAssetFetch$ = !showHighValueAssets ? O.empty() : O.merge(
+ O.merge(goHome$, pollViewing(pollIntervalsMs.slow, 'dashBoard', view$)).mapTo(true)
+ , O.merge(
+ view$.map(view => view == 'assets').distinctUntilChanged().filter(Boolean)
+ , pollViewing(pollIntervalsMs.standard, 'assets', view$)
+ ).mapTo(false)
+ )
+ .scan(({ sentAt }, ignoreFreshness) => {
+ const now = pollingScheduler ? pollingScheduler.now() : Date.now()
+ return ignoreFreshness || now - sentAt >= pollIntervalsMs.slow
+ ? { sentAt: now, send: true }
+ : { sentAt, send: false }
+ }, { sentAt: -Infinity, send: false })
+ .filter(({ send }) => send)
+
, dashboardEpochStartHeight$ = dashboardLatestBlock$
.map(block => block.height - (block.height % difficultyPeriod))
.distinctUntilChanged()
@@ -740,6 +762,7 @@ export default function main(
, tx$.filter(notNully).withLatestFrom(t$, (tx, t) => t`Transaction: ${tx.txid}`)
, addr$.filter(notNully).withLatestFrom(goAddr$, t$, (_, goAddr, t) => t`Address: ${goAddr.display_addr}`)
, asset$.filter(notNully).withLatestFrom(t$, (asset, t) => t`Asset: ${asset.asset_id}`)
+ , goAssets$.withLatestFrom(t$, (_, t) => t`Registered assets`)
, goAssetList$.withLatestFrom(t$, (_, t) => t`Registered assets`)
, goPush$.withLatestFrom(t$, (_, t) => t`Broadcast transaction`)
, goMempool$.withLatestFrom(t$, (_, t) => t`Mempool`)
@@ -755,7 +778,7 @@ export default function main(
, mempool$, mempoolRecent$, feeEst$, bitcoinMarketChart$, bitcoinPrice$
, tx$, txBlock$, previousBlock$, txAnalysis$, openTx$
, goAddr$, addr$, addrTxs$, addrQR$
- , assetMap$, assetList$, goAssetList$, goAsset$, asset$, assetTxs$, unblinded$
+ , assetMap$, assetList$, goAssetList$, recentAssets$, highValueAssets$, goAsset$, asset$, assetTxs$, unblinded$
, autocomplete$: autocomplete$.distinctUntilChanged(sameAutocompleteView)
, isReady$, loading$, page$, view$, title$
})
@@ -907,10 +930,7 @@ export default function main(
, { category: 'fee-est', method: 'GET', path: '/fee-estimates' }
, { category: 'mempool', method: 'GET', path: '/mempool' }])
- // fetch asset stats and USD prices only while viewing the Liquid dashboard
- , !showHighValueAssets ? O.empty() :
- O.merge(goHome$, pollViewing(pollIntervalsMs.slow, 'dashBoard', view$))
- .flatMap(_ => highValueAssetRequests)
+ , highValueAssetFetch$.flatMap(_ => highValueAssetRequests)
//
// elements/liquid only
//
@@ -923,6 +943,9 @@ export default function main(
, goAssetList$.map(d => ({ category: 'assetlist', method: 'GET', path: '/assets/registry'
, query: { sort_field: d.sort_field, sort_dir: d.sort_dir, limit: d.limit, start_index: d.start_index } }))
+ , goAssets$.mapTo({ category: 'recent-assets', method: 'GET', path: '/assets/registry'
+ , query: { sort: 'created_at_desc', limit: recentAssetsCount } })
+
// fetch asset and its txs
, !process.env.IS_ELEMENTS ? O.empty() :
goAsset$.flatMap(d => [{ category: 'asset', method: 'GET', path: `/asset/${d.asset_id}` }
@@ -947,6 +970,7 @@ export default function main(
searchResult$.filter(Boolean).map(result => ({ type: 'replace', ...result }))
, selectAutocomplete$.map(result => ({ type: 'push', pathname: result.pathname }))
, byHeight$.map(hash => ({ type: 'replace', pathname: `/block/${hash}` }))
+ , goLegacyAssetList$.map(loc => ({ type: 'replace', pathname: '/assets/all', search: (loc.search || '').replace(/^\?/, '') }))
, pushedtx$.map(txid => ({ type: 'push', pathname: `/tx/${txid}` }))
, selectBlockGridTx$.map(txid => ({ type: 'push', pathname: `/tx/${txid}` }))
, updateQuery$.map(([ pathname, hash, qs ]) => ({ type: 'replace', pathname, hash, search: qs, state: { noRouting: true } }))
diff --git a/client/src/components/high-value-assets.js b/client/src/components/high-value-assets.js
index 1b98e6b7..4ad77358 100644
--- a/client/src/components/high-value-assets.js
+++ b/client/src/components/high-value-assets.js
@@ -6,7 +6,7 @@ import {
formatDollarAmount,
} from "../lib/high-value-assets";
-export const highValueAssets = (t, assetData = {}) => {
+export const highValueAssets = (t, assetData = {}, { showViewMore = true } = {}) => {
const rows = assets
.map((asset, index) => {
const data = assetData[asset.asset_id] || {};
@@ -61,12 +61,14 @@ export const highValueAssets = (t, assetData = {}) => {
);
})}
-
- {t`See More`}
-
-

-
-
+ {showViewMore ? (
+
+ {t`See More`}
+
+

+
+
+ ) : ""}
);
};
diff --git a/client/src/views/asset-list.js b/client/src/views/asset-list.js
index b72b5e6a..1d0f2e59 100644
--- a/client/src/views/asset-list.js
+++ b/client/src/views/asset-list.js
@@ -13,14 +13,18 @@ const staticRoot = process.env.STATIC_ROOT || "";
export default ({ assetList, goAssetList, loading, t, ...S }) => {
const { assets, total } = assetList || {};
const { start_index, sort_dir, sort_field, limit } = goAssetList;
- const pageLink = `assets?sort_field=${encodeURIComponent(sort_field)}&sort_dir=${encodeURIComponent(sort_dir)}`;
+ const pageLink = `assets/all?sort_field=${encodeURIComponent(sort_field)}&sort_dir=${encodeURIComponent(sort_dir)}`;
const reverseSortDir = encodeURIComponent(
sort_dir === "asc" ? "desc" : "asc",
);
return layout(
-
-
+
+
+
+
+ {t`Back to Assets Page`}
+
{!assets ? (
{loader()}
) : !assets.length ? (
@@ -44,35 +48,7 @@ export default ({ assetList, goAssetList, loading, t, ...S }) => {
{paginationControls(total, start_index, limit, pageLink)}
@@ -85,6 +61,36 @@ export default ({ assetList, goAssetList, loading, t, ...S }) => {
);
};
+export const assetRow = (asset, t) => (
+
+
+
+
+
+
+ {asset.name}
+
+
+
+
+ {asset.ticker || None}
+
+
+
+
+ {getSupply(asset, t)}
+
+
+
+
+ {(asset.entity && asset.entity.domain) || None}
+
+
+
+
+
+);
+
const sortHeader = (label, field, className, { sort_field, sort_dir, reverseSortDir }) => {
if (!field) {
return
{label}
;
@@ -96,7 +102,7 @@ const sortHeader = (label, field, className, { sort_field, sort_dir, reverseSort
;
- return
{label} {sortIcon};
+ return
{label} {sortIcon};
};
const paginationControls = (total, startIndex, limit, pageLink) => {
diff --git a/client/src/views/assets.js b/client/src/views/assets.js
new file mode 100644
index 00000000..7d81bb0c
--- /dev/null
+++ b/client/src/views/assets.js
@@ -0,0 +1,51 @@
+import layout from "./layout";
+import loader from "../components/loading";
+import { CurrencyDollarIcon } from "../components/icons";
+import { highValueAssets } from "../components/high-value-assets";
+import { showHighValueAssets, staticRoot } from "../const";
+import { assetRow } from "./asset-list";
+
+export default ({ recentAssets, highValueAssets: highValueAssetData, t, ...S }) =>
+ layout(
+
+
+ {showHighValueAssets
+ ? highValueAssets(t, highValueAssetData, { showViewMore: false })
+ : ""}
+ {!recentAssets ? (
+
{loader()}
+ ) : !recentAssets.length ? (
+
+
{t`No registered assets`}
+
+ ) : (
+
+
+
+
+
+
{t`Recently Registered Assets`}
+
+
+
+
NAME
+
TICKER
+
TOTAL SUPPLY
+
ISSUER DOMAIN
+
+
+
+ {recentAssets.map(asset => assetRow(asset, t))}
+
+
+ {t`See All Assets`}
+
+

+
+
+
+ )}
+
+
,
+ { activeTab: "assets", t, ...S },
+ );
diff --git a/client/src/views/index.js b/client/src/views/index.js
index 4c674185..742ff246 100644
--- a/client/src/views/index.js
+++ b/client/src/views/index.js
@@ -16,6 +16,7 @@ if (process.env.IS_ELEMENTS) {
exports.asset = require('./asset').default
if (process.env.ASSET_MAP_URL) {
+ exports.assets = require('./assets').default
exports.assetList = require('./asset-list').default
}
}
diff --git a/test/app.test.js b/test/app.test.js
index 98264f99..625e8c6f 100644
--- a/test/app.test.js
+++ b/test/app.test.js
@@ -201,7 +201,7 @@ const makeTx = (txid, status = { confirmed: false }) => ({
const highValueAssetRequestCount = (requests, frame) => requests.filter(
(request) =>
request.frame === frame &&
- request.category.startsWith("dashboard-high-value-asset-"),
+ request.category.startsWith("high-value-asset-"),
).length;
test("requests and consumes block templates on an Elements dashboard", () => {
@@ -404,7 +404,7 @@ test("uses the configured dashboard request cadences without immediate duplicate
);
const highValueAssetRequests = requests.filter((request) =>
- request.category.startsWith("dashboard-high-value-asset-"));
+ request.category.startsWith("high-value-asset-"));
assert.deepEqual(
[...new Set(highValueAssetRequests.map((request) => request.frame))],
slowFrames,
@@ -1184,3 +1184,123 @@ test("refocusing after a failed lookup retries it", () => {
assert.equal(states[states.length - 1].loading, true);
subscription.unsubscribe();
});
+
+const highValueAssetBatchFrames = (requests) => [...new Set(requests
+ .filter((request) => request.category.startsWith("high-value-asset-"))
+ .map((request) => request.frame))];
+
+const runPages = (pages, maxFrames) => {
+ const scheduler = new TestScheduler(() => {});
+ const page$ = new Subject();
+ const requests = [];
+
+ scheduler.maxFrames = maxFrames;
+ main(makeSources({
+ route: makeRouteDriver(() => page$)(empty$),
+ }), pollingOptions(scheduler)).HTTP
+ .subscribe((request) => requests.push({ ...request, frame: scheduler.frame }));
+ for (const [frame, pathname] of pages) {
+ scheduler.schedule(() => page$.next({ pathname, search: "", hash: "" }), frame);
+ }
+ scheduler.flush();
+ return requests;
+};
+
+const hour = 60 * 60 * 1000;
+const minute = 60 * 1000;
+
+test("requests the most recently registered assets on the assets page", () => {
+ const requests = runPages([[0, "/assets"]], 0);
+
+ assert.deepEqual(
+ requests.filter((request) => request.category === "recent-assets")
+ .map(({ url, query }) => ({ url, query })),
+ [{ url: "/api/assets/registry", query: { sort: "created_at_desc", limit: 10 } }],
+ );
+ assert.equal(requests.filter((request) => request.category === "assetlist").length, 0);
+});
+
+test("requests the full registry list on the all-assets page", () => {
+ const requests = runPages([[0, "/assets/all"]], hour - 1);
+
+ assert.deepEqual(
+ requests.filter((request) => request.category === "assetlist")
+ .map(({ query }) => query),
+ [{ sort_field: "name", sort_dir: "asc", limit: 50, start_index: 0 }],
+ );
+ assert.equal(requests.filter((request) => request.category === "recent-assets").length, 0);
+ assert.deepEqual(highValueAssetBatchFrames(requests), []);
+});
+
+test("refreshes high-value assets once per slow interval on a focused assets page", () => {
+ const requests = runPages([[0, "/assets"]], hour - 1);
+ const frames = highValueAssetBatchFrames(requests);
+
+ assert.deepEqual(frames, [0, 1, 2, 3, 4, 5].map((n) => n * pollIntervalsMs.slow));
+ for (const frame of frames) {
+ assert.equal(
+ highValueAssetRequestCount(requests, frame),
+ highValueAssetDefinitions.length * 2,
+ );
+ }
+});
+
+test("reuses fresh high-value assets while browsing between asset pages", () => {
+ const pages = [];
+ for (let n = 0; n < 60; n++) {
+ pages.push([n * minute, n % 2 ? "/assets/all" : "/assets"]);
+ }
+ const frames = highValueAssetBatchFrames(runPages(pages, hour - 1));
+
+ assert.deepEqual(frames, [0, 10, 20, 30, 40, 50].map((n) => n * minute));
+});
+
+test("reuses dashboard high-value assets on the assets page until they expire", () => {
+ const frames = highValueAssetBatchFrames(runPages([
+ [0, "/"],
+ [2 * minute, "/assets"],
+ ], 15 * minute));
+
+ assert.deepEqual(frames, [0, pollIntervalsMs.slow]);
+});
+
+test("redirects old assets list links to the all-assets page with their parameters", () => {
+ const page$ = new Subject();
+ const requests = [];
+ const navigations = [];
+ const sinks = main(makeSources({
+ route: makeRouteDriver(() => page$)(empty$),
+ }));
+
+ sinks.HTTP.subscribe((request) => requests.push(request));
+ sinks.route.subscribe((navigation) => navigations.push(navigation));
+ page$.next({ pathname: "/assets", search: "?sort_field=ticker&start_index=50", hash: "" });
+
+ assert.deepEqual(navigations, [{
+ type: "replace",
+ pathname: "/assets/all",
+ search: "sort_field=ticker&start_index=50",
+ }]);
+ assert.equal(requests.filter((request) =>
+ request.category === "recent-assets" ||
+ request.category.startsWith("high-value-asset-")).length, 0);
+
+ page$.next({ pathname: "/assets/all", search: "?sort_field=ticker&start_index=50", hash: "" });
+ assert.deepEqual(
+ requests.filter((request) => request.category === "assetlist").map(({ query }) => query),
+ [{ sort_field: "ticker", sort_dir: "asc", limit: 50, start_index: 50 }],
+ );
+});
+
+test("keeps the assets overview for links without list parameters", () => {
+ const page$ = new Subject();
+ const navigations = [];
+ const sinks = main(makeSources({
+ route: makeRouteDriver(() => page$)(empty$),
+ }));
+
+ sinks.route.subscribe((navigation) => navigations.push(navigation));
+ page$.next({ pathname: "/assets", search: "?lang=en", hash: "" });
+
+ assert.deepEqual(navigations, []);
+});
diff --git a/test/assets-page.test.js b/test/assets-page.test.js
new file mode 100644
index 00000000..f93623ed
--- /dev/null
+++ b/test/assets-page.test.js
@@ -0,0 +1,42 @@
+const test = require('node:test')
+const assert = require('node:assert/strict')
+const render = require('snabbdom-to-html')
+
+process.env.IS_ELEMENTS = '1'
+process.env.SHOW_HIGH_VALUE_ASSETS = '1'
+
+const t = require('../client/src/l10n').default.en
+const { default: assets } = require('../client/src/views/assets')
+const { default: assetList } = require('../client/src/views/asset-list')
+
+const asset = {
+ asset_id: 'a'.repeat(64),
+ name: 'Example',
+ ticker: 'EXM',
+ precision: 0,
+ chain_stats: { issued_amount: 10, burned_amount: 0, has_blinded_issuances: false },
+ mempool_stats: { issued_amount: 0, burned_amount: 0, has_blinded_issuances: false },
+}
+const page = { pathname: '/assets', query: {} }
+
+test('renders high-value assets above the recently registered assets', () => {
+ const html = render(assets({ t, page, recentAssets: [ asset ], highValueAssets: {} }))
+
+ assert.ok(html.indexOf('High-Value Assets') < html.indexOf('Recently Registered Assets'))
+ assert.match(html, /href="asset\/a{64}"/)
+ assert.match(html, /href="assets\/all"[^>]*>
See All Assets<\/span>/)
+ assert.doesNotMatch(html, /See More/)
+})
+
+test('renders the all-assets table with a link back to the assets page', () => {
+ const html = render(assetList({
+ t,
+ page: { ...page, pathname: '/assets/all' },
+ assetList: { assets: [ asset ], total: 1 },
+ goAssetList: { start_index: 0, sort_field: 'name', sort_dir: 'asc', limit: 50 },
+ }))
+
+ assert.ok(html.indexOf('Back to Assets Page') < html.indexOf('All Assets'))
+ assert.match(html, /