-
Notifications
You must be signed in to change notification settings - Fork 220
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
fix: add display_currency_decimal method #3445
fix: add display_currency_decimal method #3445
Conversation
The Or how about removing |
84e5ef8
to
36e9d8b
Compare
36e9d8b
to
7510b2e
Compare
|
||
newtype_ops! { [Tari] {add sub} {:=} Self Self } | ||
newtype_ops! { [Tari] {mul div rem} {:=} Self f64 } | ||
#[derive( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
newtype-ops
looks unmaintained. How about using derive_more
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah if we're already using derive_more
now and it's easy to remove newtype_ops
I think that's fine
It's also possible to remove pub struct TariFormat {
MicroTari,
Tari,
Auto,
}
pub struct FormattedTari {
format: TariFormat,
separator: Option<char>,
}
impl MicroTari {
pub fn formatted(&self, format: TariFormat, separator: Option<char>) -> FormattedTari {
FormattedTari {
format,
separator,
}
}
}
impl Display for FormattedTari { /* etc. */ } What do you think? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good, just a few small things
#[error("Tari value convert error `{0}`")] | ||
TariConvertError(#[from] TariConvertError), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#[error("Tari value convert error `{0}`")] | |
TariConvertError(#[from] TariConvertError), | |
#[error("Tari value conversion error `{0}`")] | |
TariConversionError(#[from] TariConversionError), |
Err(MicroTariError::ParseError("value cannot be negative".to_string())) | ||
} else { | ||
Ok(MicroTari::from(Tari::from(v.max(0.0)))) | ||
// TODO: Check. It can't be `NaN` anymore. Still we need `.max(0.0)` check? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this comment still current?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No idea, why we compare the unsigned value with 0.0
🤷♂️ I left the comment to double-check it together. How about removing that max
call?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, right, it's another one. I've removed it, because if a value is not less than 0.0 (greater or equal 0.0) it's always a win in max(0.0)
comparison. I guess we had it to handle the f64::NaN
case, but Decimal
doesn't support NaN
values at all and that comparison doesn't make sense anymore. If I'm correct about why we had that max(0.0)
call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
impl From<Tari> for MicroTari { | ||
fn from(v: Tari) -> Self { | ||
MicroTari((v.0 * 1e6) as u64) | ||
MicroTari((v.0 * 1_000_000u32).try_into().unwrap()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unwrap?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the past, the value could be truncated silently, I thought it's better to panic here, but probably even better to replace the trait to TryFrom
.
|
||
newtype_ops! { [Tari] {add sub} {:=} Self Self } | ||
newtype_ops! { [Tari] {mul div rem} {:=} Self f64 } | ||
#[derive( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah if we're already using derive_more
now and it's easy to remove newtype_ops
I think that's fine
v.0 | ||
} | ||
} | ||
pub type TariConvertError = DecimalConvertError; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub type TariConvertError = DecimalConvertError; | |
pub type TariConversionError = DecimalConvertError; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would have preferred to remove this function completely, but this is an improvement
* development: fix: add display_currency_decimal method (tari-project#3445) fix: add sanity checks to prepare_new_block (tari-project#3448) test: profile wallet sqlite database operations (tari-project#3451) test: create cucumber test directory if necessary (tari-project#3452) chore: improve cucumber tags and run time speed (tari-project#3439)
Description
The inner type of
Tari
changed fromf64
todecimal_rs::Decimal
.Also,
display_currency
method was replaced withformat_currency
that adds separators to formatted strings.Motivation and Context
display_currency
method forces us to usef64
that is not accurate for finance calculations.How Has This Been Tested?
Updated unit tests.
TODO: Smoke test: run the wallet and the node.