From 23c17577f185142e229d6b15e2356bac3d1c96d3 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Sun, 17 Dec 2023 16:09:06 +0800 Subject: [PATCH 1/2] Display rune symbol to right of amount --- src/runes/pile.rs | 24 +++++++++++++----------- src/subcommand/server.rs | 6 +++--- src/templates/rune.rs | 6 +++--- tests/wallet/send.rs | 4 ++-- 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/runes/pile.rs b/src/runes/pile.rs index 8300a0b271..b6796038df 100644 --- a/src/runes/pile.rs +++ b/src/runes/pile.rs @@ -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, "{symbol}")?; } - write!(f, "{whole}.{fractional:0>width$}") + Ok(()) } } @@ -143,7 +145,7 @@ mod tests { symbol: Some('$'), } .to_string(), - "$0" + "0$" ); } } diff --git a/src/subcommand/server.rs b/src/subcommand/server.rs index e2701da189..15b94bf936 100644 --- a/src/subcommand/server.rs +++ b/src/subcommand/server.rs @@ -2260,9 +2260,9 @@ mod tests {
etching transaction index
1
supply
-
\$340282366920938463463374607431768211455
+
340282366920938463463374607431768211455\$
burned
-
\$0
+
0\$
divisibility
0
symbol
@@ -2381,7 +2381,7 @@ mod tests { StatusCode::OK, ".* A•AAAAAAAAAAAA - \\$340282366920938463463374607431768211455 + 340282366920938463463374607431768211455\\$ .*", ); } diff --git a/src/templates/rune.rs b/src/templates/rune.rs index 8fc69df5e9..e6343d828d 100644 --- a/src/templates/rune.rs +++ b/src/templates/rune.rs @@ -59,11 +59,11 @@ mod tests {
open etching end
11
open etching limit
-
\$1.000000001
+
1.000000001\$
supply
-
\$123456789.123456789
+
123456789.123456789\$
burned
-
\$123456789.123456789
+
123456789.123456789\$
divisibility
9
symbol
diff --git a/tests/wallet/send.rs b/tests/wallet/send.rs index 19edc69134..d2d927e7e1 100644 --- a/tests/wallet/send.rs +++ b/tests/wallet/send.rs @@ -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¢ in wallet\n") .run_and_extract_stdout(); } @@ -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¢ in wallet\n") .run_and_extract_stdout(); CommandBuilder::new("--chain regtest --index-runes wallet send --fee-rate 1 bcrt1qs758ursh4q9z627kt3pp5yysm78ddny6txaqgw 1F•OO") From d4c435a28c39ca0bdf8eae4413ee454d0f71d571 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Mon, 18 Dec 2023 13:09:16 +0800 Subject: [PATCH 2/2] Add non-breaking space --- src/runes/pile.rs | 4 ++-- src/subcommand/server.rs | 18 +++++++++--------- src/templates/rune.rs | 12 ++++++------ tests/wallet/send.rs | 4 ++-- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/runes/pile.rs b/src/runes/pile.rs index b6796038df..4ba6822514 100644 --- a/src/runes/pile.rs +++ b/src/runes/pile.rs @@ -26,7 +26,7 @@ impl Display for Pile { } if let Some(symbol) = self.symbol { - write!(f, "{symbol}")?; + write!(f, "\u{00A0}{symbol}")?; } Ok(()) @@ -145,7 +145,7 @@ mod tests { symbol: Some('$'), } .to_string(), - "0$" + "0\u{00A0}$" ); } } diff --git a/src/subcommand/server.rs b/src/subcommand/server.rs index 15b94bf936..3c624f9ec1 100644 --- a/src/subcommand/server.rs +++ b/src/subcommand/server.rs @@ -2204,7 +2204,7 @@ mod tests { }], etching: Some(Etching { rune: Some(rune), - symbol: Some('$'), + symbol: Some('%'), ..Default::default() }), ..Default::default() @@ -2229,7 +2229,7 @@ mod tests { etching: txid, rune, supply: u128::max_value(), - symbol: Some('$'), + symbol: Some('%'), timestamp: 2, ..Default::default() } @@ -2245,7 +2245,7 @@ mod tests { format!("/rune/{rune}"), StatusCode::OK, format!( - r".*Rune AAAAAAAAAAAAA.* + ".*Rune AAAAAAAAAAAAA.*

AAAAAAAAAAAAA

@@ -2260,13 +2260,13 @@ mod tests {
etching transaction index
1
supply
-
340282366920938463463374607431768211455\$
+
340282366920938463463374607431768211455\u{00A0}%
burned
-
0\$
+
0\u{00A0}%
divisibility
0
symbol
-
\$
+
%
etching
{txid}
parent
@@ -2310,7 +2310,7 @@ mod tests { }], etching: Some(Etching { rune: Some(rune), - symbol: Some('$'), + symbol: Some('%'), spacers: 1, ..Default::default() }), @@ -2336,7 +2336,7 @@ mod tests { etching: txid, rune, supply: u128::max_value(), - symbol: Some('$'), + symbol: Some('%'), timestamp: 2, spacers: 1, ..Default::default() @@ -2381,7 +2381,7 @@ mod tests { StatusCode::OK, ".* A•AAAAAAAAAAAA - 340282366920938463463374607431768211455\\$ + 340282366920938463463374607431768211455\u{00A0}% .*", ); } diff --git a/src/templates/rune.rs b/src/templates/rune.rs index e6343d828d..36e67b9d5a 100644 --- a/src/templates/rune.rs +++ b/src/templates/rune.rs @@ -31,7 +31,7 @@ mod tests { rune: Rune(u128::max_value()), spacers: 1, supply: 123456789123456789, - symbol: Some('$'), + symbol: Some('%'), timestamp: 0, }, id: RuneId { @@ -43,7 +43,7 @@ mod tests { index: 0, }), }, - r"

B•CGDENLQRQWDSLRUGSNLBTMFIJAV

+ "

B•CGDENLQRQWDSLRUGSNLBTMFIJAV

id
@@ -59,15 +59,15 @@ mod tests {
open etching end
11
open etching limit
-
1.000000001\$
+
1.000000001\u{00A0}%
supply
-
123456789.123456789\$
+
123456789.123456789\u{00A0}%
burned
-
123456789.123456789\$
+
123456789.123456789\u{00A0}%
divisibility
9
symbol
-
\$
+
%
etching
0{64}
parent
diff --git a/tests/wallet/send.rs b/tests/wallet/send.rs index d2d927e7e1..cdbe0c22b0 100644 --- a/tests/wallet/send.rs +++ b/tests/wallet/send.rs @@ -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(); } @@ -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")