forked from blockscout/blockscout
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
API v1 bridgedtokenlist endpoint (blockscout#9506)
* bridgedtokenlist API endpoint * Change spec for bridged_token_usd_cap function * Fix review comments * Return bridged_token_usd_cap as string
- Loading branch information
Showing
12 changed files
with
206 additions
and
3,491 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
24 changes: 24 additions & 0 deletions
24
apps/block_scout_web/lib/block_scout_web/views/bridged_tokens_view.ex
This file contains 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,24 @@ | ||
defmodule BlockScoutWeb.BridgedTokensView do | ||
use BlockScoutWeb, :view | ||
|
||
alias Explorer.Chain.{BridgedToken, CurrencyHelper, Token} | ||
|
||
@doc """ | ||
Calculates capitalization of the bridged token in USD. | ||
""" | ||
@spec bridged_token_usd_cap(BridgedToken.t(), Token.t()) :: String.t() | ||
def bridged_token_usd_cap(bridged_token, token) do | ||
usd_cap = | ||
if bridged_token.custom_cap do | ||
bridged_token.custom_cap | ||
else | ||
if bridged_token.exchange_rate && token.total_supply do | ||
Decimal.mult(bridged_token.exchange_rate, CurrencyHelper.divide_decimals(token.total_supply, token.decimals)) | ||
else | ||
Decimal.new(0) | ||
end | ||
end | ||
|
||
usd_cap |> Decimal.to_float() |> :erlang.float_to_binary([:compact, decimals: 20]) | ||
end | ||
end |
This file contains 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.