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

Display rune symbol to right of amount #2871

Merged
merged 2 commits into from
Dec 18, 2023
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
24 changes: 13 additions & 11 deletions src/runes/pile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,28 @@ pub(crate) struct Pile {

impl Display for Pile {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
if let Some(symbol) = self.symbol {
write!(f, "{symbol}")?;
}

let cutoff = 10u128.pow(self.divisibility.into());

let whole = self.amount / cutoff;
let mut fractional = self.amount % cutoff;

if fractional == 0 {
return write!(f, "{whole}");
write!(f, "{whole}")?;
} else {
let mut width = usize::from(self.divisibility);
while fractional % 10 == 0 {
fractional /= 10;
width -= 1;
}

write!(f, "{whole}.{fractional:0>width$}")?;
}

let mut width = usize::from(self.divisibility);
while fractional % 10 == 0 {
fractional /= 10;
width -= 1;
if let Some(symbol) = self.symbol {
write!(f, "\u{00A0}{symbol}")?;
}

write!(f, "{whole}.{fractional:0>width$}")
Ok(())
}
}

Expand Down Expand Up @@ -143,7 +145,7 @@ mod tests {
symbol: Some('$'),
}
.to_string(),
"$0"
"0\u{00A0}$"
);
}
}
18 changes: 9 additions & 9 deletions src/subcommand/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2204,7 +2204,7 @@ mod tests {
}],
etching: Some(Etching {
rune: Some(rune),
symbol: Some('$'),
symbol: Some('%'),
..Default::default()
}),
..Default::default()
Expand All @@ -2229,7 +2229,7 @@ mod tests {
etching: txid,
rune,
supply: u128::max_value(),
symbol: Some('$'),
symbol: Some('%'),
timestamp: 2,
..Default::default()
}
Expand All @@ -2245,7 +2245,7 @@ mod tests {
format!("/rune/{rune}"),
StatusCode::OK,
format!(
r".*<title>Rune AAAAAAAAAAAAA</title>.*
".*<title>Rune AAAAAAAAAAAAA</title>.*
<h1>AAAAAAAAAAAAA</h1>
<iframe .* src=/preview/{txid}i0></iframe>
<dl>
Expand All @@ -2260,13 +2260,13 @@ mod tests {
<dt>etching transaction index</dt>
<dd>1</dd>
<dt>supply</dt>
<dd>\$340282366920938463463374607431768211455</dd>
<dd>340282366920938463463374607431768211455\u{00A0}%</dd>
<dt>burned</dt>
<dd>\$0</dd>
<dd>0\u{00A0}%</dd>
<dt>divisibility</dt>
<dd>0</dd>
<dt>symbol</dt>
<dd>\$</dd>
<dd>%</dd>
<dt>etching</dt>
<dd><a class=monospace href=/tx/{txid}>{txid}</a></dd>
<dt>parent</dt>
Expand Down Expand Up @@ -2310,7 +2310,7 @@ mod tests {
}],
etching: Some(Etching {
rune: Some(rune),
symbol: Some('$'),
symbol: Some('%'),
spacers: 1,
..Default::default()
}),
Expand All @@ -2336,7 +2336,7 @@ mod tests {
etching: txid,
rune,
supply: u128::max_value(),
symbol: Some('$'),
symbol: Some('%'),
timestamp: 2,
spacers: 1,
..Default::default()
Expand Down Expand Up @@ -2381,7 +2381,7 @@ mod tests {
StatusCode::OK,
".*<tr>
<td><a href=/rune/A•AAAAAAAAAAAA>A•AAAAAAAAAAAA</a></td>
<td>\\$340282366920938463463374607431768211455</td>
<td>340282366920938463463374607431768211455\u{00A0}%</td>
</tr>.*",
);
}
Expand Down
12 changes: 6 additions & 6 deletions src/templates/rune.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ mod tests {
rune: Rune(u128::max_value()),
spacers: 1,
supply: 123456789123456789,
symbol: Some('$'),
symbol: Some('%'),
timestamp: 0,
},
id: RuneId {
Expand All @@ -43,7 +43,7 @@ mod tests {
index: 0,
}),
},
r"<h1>B•CGDENLQRQWDSLRUGSNLBTMFIJAV</h1>
"<h1>B•CGDENLQRQWDSLRUGSNLBTMFIJAV</h1>
<iframe .* src=/preview/0{64}i0></iframe>
<dl>
<dt>id</dt>
Expand All @@ -59,15 +59,15 @@ mod tests {
<dt>open etching end</dt>
<dd><a href=/block/11>11</a></dd>
<dt>open etching limit</dt>
<dd>\$1.000000001</dd>
<dd>1.000000001\u{00A0}%</dd>
<dt>supply</dt>
<dd>\$123456789.123456789</dd>
<dd>123456789.123456789\u{00A0}%</dd>
<dt>burned</dt>
<dd>\$123456789.123456789</dd>
<dd>123456789.123456789\u{00A0}%</dd>
<dt>divisibility</dt>
<dd>9</dd>
<dt>symbol</dt>
<dd>\$</dd>
<dd>%</dd>
<dt>etching</dt>
<dd><a class=monospace href=/tx/0{64}>0{64}</a></dd>
<dt>parent</dt>
Expand Down
4 changes: 2 additions & 2 deletions tests/wallet/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ fn sending_rune_with_insufficient_balance_is_an_error() {
))
.rpc_server(&rpc_server)
.expected_exit_code(1)
.expected_stderr("error: insufficient `AAAAAAAAAAAAA` balance, only ¢1000 in wallet\n")
.expected_stderr("error: insufficient `AAAAAAAAAAAAA` balance, only 1000\u{00A0}¢ in wallet\n")
.run_and_extract_stdout();
}

Expand Down Expand Up @@ -878,7 +878,7 @@ fn error_messages_use_spaced_runes() {
)
.rpc_server(&rpc_server)
.expected_exit_code(1)
.expected_stderr("error: insufficient `A•AAAAAAAAAAAA` balance, only ¢1000 in wallet\n")
.expected_stderr("error: insufficient `A•AAAAAAAAAAAA` balance, only 1000\u{00A0}¢ in wallet\n")
.run_and_extract_stdout();

CommandBuilder::new("--chain regtest --index-runes wallet send --fee-rate 1 bcrt1qs758ursh4q9z627kt3pp5yysm78ddny6txaqgw 1F•OO")
Expand Down
Loading