Skip to content

Commit

Permalink
Add displayDecimals to the currency object.
Browse files Browse the repository at this point in the history
This helps the sender display the receiving currency amount correctly in their UI.

Protocol: uma-universal-money-address/protocol#7
  • Loading branch information
jklein24 committed Nov 15, 2023
1 parent 7aa5eb7 commit 94c895a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/currency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,34 @@ use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct Currency {
// The ISO 4217 currency code of the currency (eg. USD).
pub code: String,

// The full display name of the currency (eg. US Dollars).
pub name: String,

// The symbol of the currency (eg. $ for USD).
pub symbol: String,

// The estimated millisatoshis per smallest "unit" of this currency (eg. 1 cent in USD).
#[serde(rename = "multiplier")]
pub millisatoshi_per_unit: i64,

// The minimum amount of the currency that can be sent in a single transaction. This is in the
// smallest unit of the currency (eg. cents for USD).
#[serde(rename = "minSendable")]
pub min_sendable: i64,

// The maximum amount of the currency that can be sent in a single transaction. This is in the
// smallest unit of the currency (eg. cents for USD).
#[serde(rename = "maxSendable")]
pub max_sendable: i64,

// The number of digits after the decimal point for display on the sender side. For example,
// in USD, by convention, there are 2 digits for cents - $5.95. in this case, `displayDecimals`
// would be 2. Note that the multiplier is still always in the smallest unit (cents). This field
// is only for display purposes. The sender should assume zero if this field is omitted, unless
// they know the proper display format of the target currency.
#[serde(rename = "displayDecimals")]
pub display_decimals: Option<i64>,
}
1 change: 1 addition & 0 deletions src/uma_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ mod tests {
millisatoshi_per_unit: 34150,
min_sendable: 1,
max_sendable: 10000000,
display_decimals: Some(2),
}];

let response = get_lnurlp_response(
Expand Down

0 comments on commit 94c895a

Please sign in to comment.