Skip to content

fix(chat): keep the token quarks and receiver on cash messages - #1806

Merged
bmc08gt merged 3 commits into
code/cashfrom
fix/chat-cash-token-quarks
Oct 19, 2026
Merged

bmc08gt merged 3 commits into
code/cashfrom
fix/chat-cash-token-quarks

Conversation

@bmc08gt

@bmc08gt bmc08gt commented Oct 18, 2026

Copy link
Copy Markdown
Collaborator

Incoming cash messages lose two fields from CashContent: the token amount, and, once stored, the receiver.

Token quarks. ProtobufToLocal maps nativeAmount, currency and mint from CryptoPaymentAmount but drops quarks, the amount of the mint that actually moved. iOS keeps it (ExchangedFiat.onChainAmount). Send Back needs it to return exactly what was received. MessageContent.Cash gains tokenQuarks: Long?, parsed from the proto and stored in MessageContentSerialized.Cash.

Receiver. receiver is parsed into MessageContent.Cash but MessageContentSerialized.Cash has no field for it, so it is gone after the DB round trip. In a group it names who was paid. It is now stored as base58, the same way as intentId. The KDoc on receiver said "null for DM cash". The proto says it is always set in a group and set on newer DM messages, so the KDoc now says that.

Both new serialized fields are nullable with defaults, so rows stored before this decode to null. Callers should read null as unknown, not zero. Old rows pick the values up the next time the message is fetched. The existing serialized quarks field holds the fiat value and is unchanged. Cash content is stored as JSON, so there is no Room migration.

asContent() now writes tokenQuarks to the proto's quarks when known, falling back to the fiat quarks as before, and sets receiver when known. Nothing sends cash content from the client today, so this has no effect yet.

Tests cover the proto mapping in both directions, the converter round trip, a legacy cash row without the new fields decoding to null, and the entity mapper with and without values.

Incoming cash messages mapped nativeAmount, currency and mint from
CryptoPaymentAmount but dropped its quarks, the on-chain token amount of
the mint. Send Back needs it to return the exact amount received.

MessageContent.Cash gains tokenQuarks: Long?, parsed from the proto and
persisted in MessageContentSerialized.Cash. It is nullable and defaulted
because rows stored before this have no value; callers must treat null
as unknown, not zero. The existing quarks field (the fiat value) is
unchanged, so no Room migration is needed. The reverse proto mapping
writes tokenQuarks when known and falls back to the fiat quarks as before.
The cash receiver was parsed from the proto but never stored, so it was
lost on the DB round trip. That matters in groups, where it names who
was paid.

MessageContentSerialized.Cash gains a nullable base58 receiver, encoded
like intentId, so rows stored before this still decode to null. The
reverse proto mapping now sets the receiver when known. The KDoc on
MessageContent.Cash.receiver now matches the proto: always set in a
group, set on new DM messages and unset on older ones.
@bmc08gt bmc08gt self-assigned this Oct 18, 2026
@github-actions github-actions Bot added area: network gRPC, connectivity, API, exchange rates type: fix Bug fix labels Oct 18, 2026
@bmc08gt
bmc08gt merged commit 55d3717 into code/cash Oct 19, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: network gRPC, connectivity, API, exchange rates type: fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant