diff --git a/backend/libraries/chat_events/src/message_content_internal.rs b/backend/libraries/chat_events/src/message_content_internal.rs index cd417cc5e7..d0adca602a 100644 --- a/backend/libraries/chat_events/src/message_content_internal.rs +++ b/backend/libraries/chat_events/src/message_content_internal.rs @@ -791,6 +791,7 @@ impl From for CompletedCryptoTransactionInternal { mod nns { use super::*; use ic_ledger_types::AccountIdentifier; + use serde::Deserializer; use types::nns::{CryptoAccount, Tokens}; #[derive(Serialize, Deserialize, Clone, Debug)] @@ -825,9 +826,9 @@ mod nns { pub ledger: CanisterId, #[serde(rename = "k", alias = "token")] pub token: Cryptocurrency, - #[serde(rename = "a", alias = "amount")] + #[serde(rename = "a", alias = "amount", deserialize_with = "deserialize_amount")] pub amount: u64, - #[serde(rename = "e", alias = "fee")] + #[serde(rename = "e", alias = "fee", deserialize_with = "deserialize_amount")] pub fee: u64, #[serde(rename = "f", alias = "from")] pub from: CryptoAccountInternal, @@ -843,6 +844,27 @@ mod nns { pub block_index: u64, } + fn deserialize_amount<'de, D: Deserializer<'de>>(d: D) -> Result { + let amount = AmountCombined::deserialize(d)?; + Ok(amount.into()) + } + + #[derive(Serialize, Deserialize, Clone, Debug)] + #[serde(untagged)] + pub enum AmountCombined { + Old { e8s: u64 }, + New(u64), + } + + impl From for u64 { + fn from(value: AmountCombined) -> Self { + match value { + AmountCombined::Old { e8s } => e8s, + AmountCombined::New(a) => a, + } + } + } + impl From for types::nns::CompletedCryptoTransaction { fn from(value: CompletedCryptoTransactionInternal) -> Self { Self {