From 94c895aedcb0fc20949d65547f6ab3f1b3f92f69 Mon Sep 17 00:00:00 2001 From: Jeremy Klein Date: Wed, 15 Nov 2023 10:59:05 -0800 Subject: [PATCH] Add displayDecimals to the currency object. This helps the sender display the receiving currency amount correctly in their UI. Protocol: https://github.com/uma-universal-money-address/protocol/pull/7 --- src/currency.rs | 21 +++++++++++++++++++++ src/uma_test.rs | 1 + 2 files changed, 22 insertions(+) diff --git a/src/currency.rs b/src/currency.rs index b108b04..f5fe90f 100644 --- a/src/currency.rs +++ b/src/currency.rs @@ -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, } diff --git a/src/uma_test.rs b/src/uma_test.rs index 8b32b01..260ea63 100644 --- a/src/uma_test.rs +++ b/src/uma_test.rs @@ -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(