Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 35 additions & 11 deletions client/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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: '',
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -585,8 +591,7 @@ export default function main(
tipId: null
})

// dashboard
, dashboardHighValueAssets$ = !showHighValueAssets
, highValueAssets$ = !showHighValueAssets
? O.of({})
: O.merge(...highValueAssetDefinitions.reduce((replies, asset) => [
...replies,
Expand All @@ -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),
Expand Down Expand Up @@ -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.
Expand All @@ -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) =>
Expand Down Expand Up @@ -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()
Expand All @@ -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`)
Expand All @@ -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$
})
Expand Down Expand Up @@ -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
//
Expand All @@ -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}` }
Expand All @@ -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 } }))
Expand Down
16 changes: 9 additions & 7 deletions client/src/components/high-value-assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -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] || {};
Expand Down Expand Up @@ -61,12 +61,14 @@ export const highValueAssets = (t, assetData = {}) => {
);
})}
</div>
<a className="view-more font-link-semibold" href="assets">
<span>{t`See More`}</span>
<div>
<img alt="" src={`${staticRoot}img/icons/arrow-right-blue.svg`} />
</div>
</a>
{showViewMore ? (
<a className="view-more font-link-semibold" href="assets">
<span>{t`See More`}</span>
<div>
<img alt="" src={`${staticRoot}img/icons/arrow-right-blue.svg`} />
</div>
</a>
) : ""}
</div>
);
};
72 changes: 39 additions & 33 deletions client/src/views/asset-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<div key="assets">
<div className="container">
<div key="assetList">
<div className="container asset-list-page">
<a className="asset-list-back-link font-link-semibold" href="assets">
<ChevronLeftIcon />
<span>{t`Back to Assets Page`}</span>
</a>
{!assets ? (
<div className="load-more-container">{loader()}</div>
) : !assets.length ? (
Expand All @@ -44,35 +48,7 @@ export default ({ assetList, goAssetList, loading, t, ...S }) => {
</div>

<div className={`asset-list-body ${loading ? "asset-list-body-loading" : ""}`}>
{assets.map((asset) => (
<a href={`asset/${asset.asset_id}`}>
<div className="assets-table-link-row">
<div className="assets-table-row">
<div className="asset-list-name" data-label={t`Name`}>
<span className="asset-list-field-value">
<CurrencyDollarIcon className="currency-dollar" />
{asset.name}
</span>
</div>
<div className="asset-list-ticker" data-label={t`Ticker`}>
<span className="asset-list-field-value">
{asset.ticker || <em>None</em>}
</span>
</div>
<div className="asset-list-total-supply" data-label={t`Total Supply`}>
<span className="asset-list-field-value">
{getSupply(asset, t)}
</span>
</div>
<div className="asset-list-issuer-domain" data-label={t`Issuer domain`}>
<span className="asset-list-field-value">
{asset.entity.domain}
</span>
</div>
</div>
</div>
</a>
))}
{assets.map(asset => assetRow(asset, t))}
</div>
<div className="asset-list-footer">
{paginationControls(total, start_index, limit, pageLink)}
Expand All @@ -85,6 +61,36 @@ export default ({ assetList, goAssetList, loading, t, ...S }) => {
);
};

export const assetRow = (asset, t) => (
<a href={`asset/${asset.asset_id}`} key={asset.asset_id}>
<div className="assets-table-link-row">
<div className="assets-table-row">
<div className="asset-list-name" data-label={t`Name`}>
<span className="asset-list-field-value">
<CurrencyDollarIcon className="currency-dollar" />
{asset.name}
</span>
</div>
<div className="asset-list-ticker" data-label={t`Ticker`}>
<span className="asset-list-field-value">
{asset.ticker || <em>None</em>}
</span>
</div>
<div className="asset-list-total-supply" data-label={t`Total Supply`}>
<span className="asset-list-field-value">
{getSupply(asset, t)}
</span>
</div>
<div className="asset-list-issuer-domain" data-label={t`Issuer domain`}>
<span className="asset-list-field-value">
{(asset.entity && asset.entity.domain) || <em>None</em>}
</span>
</div>
</div>
</div>
</a>
);

const sortHeader = (label, field, className, { sort_field, sort_dir, reverseSortDir }) => {
if (!field) {
return <p className={className}>{label}</p>;
Expand All @@ -96,7 +102,7 @@ const sortHeader = (label, field, className, { sort_field, sort_dir, reverseSort
<ChevronDownIcon className={sort_field === field && sort_dir === "asc" ? "asset-sort-chevron-muted" : ""} />
</span>;

return <a className={className} href={`assets?sort_field=${field}&sort_dir=${reverseSortDir}`}>{label} {sortIcon}</a>;
return <a className={className} href={`assets/all?sort_field=${field}&sort_dir=${reverseSortDir}`}>{label} {sortIcon}</a>;
};

const paginationControls = (total, startIndex, limit, pageLink) => {
Expand Down
51 changes: 51 additions & 0 deletions client/src/views/assets.js
Original file line number Diff line number Diff line change
@@ -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(
<div key="assets">
<div className="container assets-page">
{showHighValueAssets
? highValueAssets(t, highValueAssetData, { showViewMore: false })
: ""}
{!recentAssets ? (
<div className="load-more-container">{loader()}</div>
) : !recentAssets.length ? (
<div className="asset-container">
<p>{t`No registered assets`}</p>
</div>
) : (
<div className="asset-container recent-assets-table">
<div className="table-header">
<div className="table-header-icon-container">
<CurrencyDollarIcon />
</div>
<h1 className="table-header-title">{t`Recently Registered Assets`}</h1>
</div>

<div className="table-title-row">
<p className="asset-list-name">NAME</p>
<p className="asset-list-ticker">TICKER</p>
<p className="asset-list-total-supply">TOTAL SUPPLY</p>
<p className="asset-list-issuer-domain">ISSUER DOMAIN</p>
</div>

<div className="asset-list-body">
{recentAssets.map(asset => assetRow(asset, t))}
</div>
<a className="view-more font-link-semibold" href="assets/all">
<span>{t`See All Assets`}</span>
<div>
<img alt="" src={`${staticRoot}img/icons/arrow-right-blue.svg`} />
</div>
</a>
</div>
)}
</div>
</div>,
{ activeTab: "assets", t, ...S },
);
1 change: 1 addition & 0 deletions client/src/views/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Loading