Skip to content

Commit

Permalink
Add mint progress field to rune.html (#3748)
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptoni9n authored May 24, 2024
1 parent abd7f6c commit aba1d7a
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/index/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ impl RuneEntry {
.unwrap_or_default()
}

pub fn max_supply(&self) -> u128 {
self.premine
+ self.terms.and_then(|terms| terms.cap).unwrap_or_default()
* self
.terms
.and_then(|terms| terms.amount)
.unwrap_or_default()
}

pub fn pile(&self, amount: u128) -> Pile {
Pile {
amount,
Expand Down
2 changes: 2 additions & 0 deletions src/subcommand/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3007,6 +3007,8 @@ mod tests {
<dd>no</dd>
<dt>supply</dt>
<dd>340282366920938463463374607431768211455\u{A0}%</dd>
<dt>mint progress</dt>
<dd>100%</dd>
<dt>premine</dt>
<dd>340282366920938463463374607431768211455\u{A0}%</dd>
<dt>premine percentage</dt>
Expand Down
2 changes: 2 additions & 0 deletions src/templates/rune.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ mod tests {
</dd>
<dt>supply</dt>
<dd>100.123456889\u{A0}%</dd>
<dt>mint progress</dt>
<dd>99.01%</dd>
<dt>premine</dt>
<dd>0.123456789\u{A0}%</dd>
<dt>premine percentage</dt>
Expand Down
2 changes: 2 additions & 0 deletions templates/rune.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ <h1>{{ self.entry.spaced_rune }}</h1>
%% }
<dt>supply</dt>
<dd>{{ self.entry.pile(self.entry.supply()) }}</dd>
<dt>mint progress</dt>
<dd>{{ Decimal { value: ((self.entry.supply() as f64 / self.entry.max_supply() as f64) * 10000.0) as u128, scale: 2 } }}%</dd>
<dt>premine</dt>
<dd>{{ self.entry.pile(self.entry.premine) }}</dd>
<dt>premine percentage</dt>
Expand Down
14 changes: 12 additions & 2 deletions tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use {
executable_path::executable_path,
mockcore::TransactionTemplate,
ord::{
api, chain::Chain, outgoing::Outgoing, subcommand::runes::RuneInfo, wallet::batch,
InscriptionId, RuneEntry,
api, chain::Chain, decimal::Decimal, outgoing::Outgoing, subcommand::runes::RuneInfo,
wallet::batch, InscriptionId, RuneEntry,
},
ordinals::{
Artifact, Charm, Edict, Pile, Rarity, Rune, RuneId, Runestone, Sat, SatPoint, SpacedRune,
Expand Down Expand Up @@ -321,6 +321,14 @@ fn batch(core: &mockcore::Handle, ord: &TestServer, batchfile: batch::File) -> E

let RuneId { block, tx } = id;

let supply_int = supply.to_integer(divisibility).unwrap();
let premine_int = premine.to_integer(divisibility).unwrap();

let mint_progress = Decimal {
value: ((premine_int as f64 / supply_int as f64) * 10000.0) as u128,
scale: 2,
};

ord.assert_response_regex(
format!("/rune/{rune}"),
format!(
Expand All @@ -334,6 +342,8 @@ fn batch(core: &mockcore::Handle, ord: &TestServer, batchfile: batch::File) -> E
{}
<dt>supply</dt>
<dd>{premine} {symbol}</dd>
<dt>mint progress</dt>
<dd>{mint_progress}%</dd>
<dt>premine</dt>
<dd>{premine} {symbol}</dd>
<dt>premine percentage</dt>
Expand Down

0 comments on commit aba1d7a

Please sign in to comment.