-
Notifications
You must be signed in to change notification settings - Fork 29
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
Introduce DecimalAmount
and refactor wallet controller to use it
#1434
Conversation
a7ce962
to
e20503e
Compare
It can be used to present amounts to the user since it carries with itself the number of decimal digits to display. It has the capability to be displayed to string and parsed from string and has serde support.
e20503e
to
173dd8c
Compare
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.
looks good
let mut tokens = BTreeMap::new(); | ||
for (currency, amount) in balances { | ||
let token_id = match currency { | ||
Currency::Coin => panic!("Removed just above"), | ||
Currency::Token(token_id) => token_id, | ||
}; | ||
|
||
let info = super::fetch_token_info(&self.rpc_client, token_id).await?; | ||
let decimals = info.token_number_of_decimals(); | ||
tokens.insert( | ||
token_id, | ||
DecimalAmount::from_amount_minimal(amount, decimals), | ||
); | ||
} |
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.
One other option I used in the read controller for fetching multiple pool infos from the node was to use FuturesUnordered and try_collect().await to await all of them at once instead of one by one.
DecimalAmount
which is likeAmount
with formatting information (number of decimals)Amount
was changed to use it under the hood