-
Notifications
You must be signed in to change notification settings - Fork 513
Added 'High-Value Assets' component. #654
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| import { CurrencyDollarIcon } from "./icons"; | ||
| import { Tooltip } from "./tooltip"; | ||
| import { highValueAssetDefinitions as assets, staticRoot } from "../const"; | ||
| import { | ||
| calculateCirculatingDollarAmount, | ||
| formatDollarAmount, | ||
| } from "../lib/high-value-assets"; | ||
|
|
||
| export const highValueAssets = (t, assetData = {}) => { | ||
| const rows = assets | ||
| .map((asset, index) => { | ||
| const data = assetData[asset.asset_id] || {}; | ||
|
|
||
| return { | ||
| asset, | ||
| dollarAmount: calculateCirculatingDollarAmount(data.asset, data.price), | ||
| index, | ||
| }; | ||
| }) | ||
| .sort((left, right) => { | ||
| if (left.dollarAmount == null) { | ||
| return right.dollarAmount == null ? left.index - right.index : 1; | ||
| } | ||
| if (right.dollarAmount == null) return -1; | ||
|
|
||
| return right.dollarAmount - left.dollarAmount || left.index - right.index; | ||
| }); | ||
|
|
||
| return ( | ||
| <div className="high-value-assets-table"> | ||
| <div className="table-header"> | ||
| <div className="table-header-icon-container"> | ||
| <CurrencyDollarIcon /> | ||
| </div> | ||
| <h1 className="table-header-title">{t`High-Value Assets`}</h1> | ||
| <Tooltip | ||
| iconSrc={`${staticRoot}img/icons/tooltip.svg`} | ||
| text={t`This panel shows the circulating value of high-value assets on Liquid.`} | ||
| /> | ||
| </div> | ||
|
|
||
| <div className="high-value-assets-body"> | ||
| {rows.map(({ asset, dollarAmount }) => { | ||
| return ( | ||
| <a | ||
| className="high-value-assets-listing" | ||
| href={`asset/${asset.asset_id}`} | ||
| key={asset.asset_id} | ||
| > | ||
| <div className="high-value-assets-icon"> | ||
| <img | ||
| src={`${staticRoot}img/icons/${asset.icon || "hva-default.svg"}`} | ||
| alt="" | ||
| /> | ||
| </div> | ||
| <p className="high-value-assets-listing-name">{asset.name}</p> | ||
| <p className="high-value-assets-circulating-dollar-amount"> | ||
| {formatDollarAmount(dollarAmount)} | ||
| </p> | ||
| </a> | ||
| ); | ||
| })} | ||
| </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> | ||
| </div> | ||
| ); | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| const value = n => n == null ? 0 : Number(n) | ||
|
|
||
| export const getPriceFeedApiBase = (apiBase, fallbackOrigin) => { | ||
| let url | ||
|
|
||
| try { | ||
| url = new URL(apiBase, fallbackOrigin) | ||
| } catch (_) { | ||
| return null | ||
| } | ||
|
|
||
| return `${url.origin}/price` | ||
| } | ||
|
|
||
| export const calculateCirculatingDollarAmount = (asset, price) => { | ||
| if (!asset || !price || price.price_usd == null || !Number.isFinite(Number(price.price_usd))) return null | ||
|
|
||
| const { chain_stats = {}, mempool_stats = {} } = asset | ||
| , precision = asset.precision == null ? 0 : Number(asset.precision) | ||
| , issuedAmount = value(chain_stats.issued_amount) + value(mempool_stats.issued_amount) | ||
| , burnedAmount = value(chain_stats.burned_amount) + value(mempool_stats.burned_amount) | ||
| , hasBlindedIssuances = chain_stats.has_blinded_issuances || mempool_stats.has_blinded_issuances | ||
| , circulatingAmount = issuedAmount - burnedAmount | ||
|
|
||
| if ( | ||
| hasBlindedIssuances || | ||
| !Number.isFinite(circulatingAmount) || | ||
| circulatingAmount < 0 || | ||
| !Number.isInteger(precision) || | ||
| precision < 0 | ||
| ) return null | ||
|
|
||
| const dollarAmount = circulatingAmount / Math.pow(10, precision) * Number(price.price_usd) | ||
| return Number.isFinite(dollarAmount) ? dollarAmount : null | ||
| } | ||
|
|
||
| export const formatDollarAmount = amount => { | ||
| if (!Number.isFinite(amount)) return 'N/A' | ||
|
|
||
| const units = [ | ||
| [ 1e12, 'T' ], | ||
| [ 1e9, 'B' ], | ||
| [ 1e6, 'M' ], | ||
| [ 1e3, 'K' ] | ||
| ] | ||
| const unit = units.find(([ divisor ]) => Math.abs(amount) >= divisor) | ||
|
|
||
| return unit | ||
| ? `$${(amount / unit[0]).toFixed(1)}${unit[1]}` | ||
| : `$${amount.toFixed(1)}` | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.