Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asset detail page clean up #253

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

adebayooriyomi
Copy link
Contributor

Clean Up Asset Detail Page
Issue created by Allen
https://gl.blockstream.com/greenaddress/esplora/-/issues/97

Copy link
Collaborator

@shesek shesek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some comments.

Also note that you checked-in two .DS_Store files, maybe add them to gitignore?


return(
<div>
{ assetTxs === null ? <p>{t`No Issuance History`}</p>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A null here would mean that the transactions haven't loaded yet, an empty array would indicate that there are no transactions (which shouldn't really be possible if the asset exists).

Better to show nothing (or more ideally, a loading indicator) rather than the user seeing "No Issuance History" flashing for a moment and disappearing.

// Supply Starts at Zero
let supply = 0
// Sort AssetTxs by block_time and Calculate Supply Change / Total Supply
assetTxs.sort((a,b) => (a.status.block_time > b.status.block_time) ? 1 : ((b.status.block_time > a.status.block_time) ? -1 : 0))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The transactions are already sorted with newest first, if you want oldest first you can just reverse() it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried "assetTxs.reverse()" It wasn't working that's why I used ".sort"

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't working how? It didn't reverse the array?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It didn't reverse the array. I tried console.log(assetTxs) and assetTxs.reverse() got the same array. No changes. :(


// Find all Burn Transactions and Remove them from Supply
tx.vout.map(voutTx => {
if(voutTx.scriptpubkey_type === "op_return"){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly to issuances, this should also filter for outputs of the current asset id only.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes made

// Find all Issuance and add them to Supply
tx.vin.map(vinTx => {
if("issuance" in vinTx){
calTxObj.supplyChange = chain_stats.has_blinded_issuances ? t`Confidential` : formatAssetAmount(("+ " + vinTx.issuance.assetamount), asset.precision, t)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatAssetAmount expects a number, invoking it with the "+ " prefix won't work as expected.

We can have formatAssetAmount() accept an additional optional argument that specificies whether the sign should always be shown explicitly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes made


// Find all Issuance and add them to Supply
tx.vin.map(vinTx => {
if("issuance" in vinTx){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK, while the elements rpc doesn't support it, it is theoretically possible to create a single transaction with multiple issuances, which would confuse this. This should also check for the issued asset id.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes made

@@ -334,6 +338,11 @@ export default function main({ DOM, HTTP, route, storage, scanner: scan$, search
? { category: 'asset-txs', method: 'GET', path: `/asset/${d.asset_id}/txs/chain/${last(d.last_txids)}` }
: { category: 'asset-txs', method: 'GET', path: `/asset/${d.asset_id}/txs` }])

// Fetch Asset Icons
, !process.env.ASSET_MAP_URL ? O.empty() : O.of(
{ category: 'asset-icons', method: 'GET', path: `https://assets.blockstream.info/icons.json` })
Copy link
Collaborator

@shesek shesek Sep 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if loading all the icons all the time is the right way to go at this. The green apps do this to enhance privacy, so the server can't learn which assets the user is interested in. But in a block explorer all privacy bets are off anyway, so we could just make them available as proper images that could be embedded via a URL, say https://assets.blockstream.info/icons/<assetid>.png.

Loading images individually would help reduce bandwidth. The icons.json file currently weights 1MB and is expected to continue growing. And it would also avoid base64 encoding, which requires 1.37x more bytes.

There was some discussion at Blockstream/asset_registry#26 about revamping the icons system, making them available as standalone files could be done as part of that.

(If we're keeping this based on the icons.json file, I would make the URL configurable via an ASSET_ICONS_URL environment variable, change the ternary condition to use that, and add a default value in flavors/liquid-mainnet/config.env.)

@@ -207,6 +207,10 @@ export default function main({ DOM, HTTP, route, storage, scanner: scan$, search
// In elements, we block rendering until the assetMap is loaded. Otherwise, we can start immediately.
, isReady$ = process.env.ASSET_MAP_URL ? assetMap$.mapTo(true).startWith(false) : O.of(true)

// Asset Icons Response
, assetIcons$ = !process.env.ASSET_MAP_URL ? O.of({}) :
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is independent of ASSET_MAP_URL, should use IS_ELEMENTS or the ASSET_ICONS_URL configuration proposed below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes made

})
calculatedAssetTx.push(calTxObj)
})
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could consider deriving calculatedAssetTx as a map() over assetTxs that transforms them into calTxObjs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes made

<div className="assets-table-cell" data-label={t`Name`}>{asset.name}</div>
<div className="assets-table-cell" data-label={t`Name`}>
<div className="assets-table-name">
{assetIcons === null ? "" :
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it okay that the asset-icon-placeholder won't be added to the DOM while the icons are loading?

@@ -45,208 +47,54 @@ export default ({ t, asset, assetTxs, goAsset, openTx, spends, tipHeight, loadin

return layout(
<div>
<div className="jumbotron jumbotron-fluid asset-page">
<div className="container back-nav">
<a href="/assets/" className="back-link"><span>{`<`}</span>{`All Assets`}</a>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Links shouldn't start with a leading /, this will break when esplora is served from a subdirectory and not from the root of the hostname. There's a <base href> tag that makes links relative to the base url.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

`All Assets` should use t so it'll get translated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes made

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants