Skip to content

feat(documents): let the user skip an optional token cost - #1124

Draft
Claudius-Maginificent wants to merge 9 commits into
fix/protocol14-signing-key-selectionfrom
feat/document-optional-token-cost
Draft

Claudius-Maginificent wants to merge 9 commits into
fix/protocol14-signing-key-selectionfrom
feat/document-optional-token-cost

Conversation

@Claudius-Maginificent

Copy link
Copy Markdown
Collaborator

TL;DR: When a contract marks a document action's token cost as optional (protocol 14), the document action screen offers "Pay the token cost". With it turned off, the action carries no token payment and the identity pays the network fee in credits. A required token cost is always paid, as before.

Stacked atop #1117.

User story

As a user, when a document action's token cost is optional, I want to choose not to pay it, so that I can pay the network fee in credits instead (DOC-011).

Scenario

Base flow

  1. Connect to a protocol 14 network. Open a document action whose document type declares an optional token cost for that action.
  2. Turn off "Pay the token cost" and send the action.

Actual

The screen always attached the token payment. An optional token cost could not be left out.

Expected

  • "Pay the token cost" appears under the token cost only when that cost is optional. It is on by default, so nothing changes unless the user turns it off.
  • With it off, the action carries no token payment. The identity pays the network fee in credits, and no gas sponsorship applies.
  • A required token cost is always paid, whatever the option was set to for another document type.

Detailed discussion

  • Token payment (src/ui/contracts_documents/document_action_screen.rs):
    • token_payment builds the token payment for a cost. It returns none without a cost, and none for an optional cost the user chose not to pay.
    • All six document actions (create, delete, purchase, replace, set price, transfer) build their token payment through it, instead of six copies of the same construction.
  • Option: pay_optional_token_cost backs the "Pay the token cost" checkbox in render_token_cost_info. It resets to on whenever the selected action has no token cost.
  • Protocol: DocumentActionTokenCost::optional comes from the Platform pin in chore(deps)!: update Platform to v5.1-dev 063589bf and follow the network's protocol version #1114. Only protocol 14 contracts can declare it, so the option never appears for older contracts and needs no capability gate.
  • Docs: user story DOC-011.
  • Scope: split out of the document action fees PR (feat(documents): agree to document action fees before broadcasting #1122). The two touch the same document actions but are independent; either can merge first.

Testing

  • New unit test: ui::contracts_documents::document_action_screen::tests::an_optional_token_cost_is_paid_only_when_the_user_chooses_to. A required cost is always paid; an optional cost only while the option is on; no cost means no payment.
  • document_action_screen tests: 8 passed.
  • cargo clippy --all-features --lib --tests -- -D warnings and cargo fmt --all pass.
  • No live network or GUI flows were run.

🤖 Co-authored by Claudius the Magnificent AI Agent

🤖 Generated with Claude Code

https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q

lklimek and others added 2 commits October 25, 2026 11:01
When a document type marks an action's token cost as optional (protocol
version 14), the document action screen offers "Pay the token cost".
With it off, the action carries no token payment and the identity pays
the network fee in credits; a required token cost is always paid. Adds
user story DOC-011.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
…onal token cost branch

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
@coderabbitai

coderabbitai Bot commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@thepastaclaw

thepastaclaw commented Oct 25, 2026 •

Copy link
Copy Markdown
Collaborator

🕓 Review not started yet because this PR is a draft.

  • Request normal review — click when the PR is ready for review.
  • Request priority review — click to move this review to the front of the queue.

Commit 6000157. Normal review starts when eligible; priority review starts as soon as a slot is available.

@Claudius-Maginificent

Copy link
Copy Markdown
Collaborator Author

Next steps: the updated #1117 head is merged into this branch locally and verified (fmt, clippy, area tests); it will be pushed right after #1117. Once #1117 merges, this PR gets retargeted to v1.0-dev and goes through the normal review gate.

🤖 Co-authored by Claudius the Magnificent AI Agent

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Final validation — Phase 2 only (no Phase 1 for this repository)

The shared payment helper correctly omits optional token payments, but two UI-state defects remain. The payment summary still describes token sponsorship after the user opts out, and resetting the completed screen leaves the opt-out choice active for the next action. The supplied CI snapshot has all code checks skipped because the PR is draft, so it provides no additional validation.

🔴 2 blocking

1 finding(s) not shown inline (the lines are not part of this PR's diff)

🔴 Blocking: Reset the optional token-cost choice when starting a new action
src/ui/contracts_documents/document_action_screen.rs:236-258

reset_screen() clears the selected contract, document type, inputs, and broadcast state, but it does not restore pay_optional_token_cost. After a user disables payment, completes an action, and selects the reset flow, the next optional-cost action starts with payment disabled even though the option is enabled by default for a new screen. That stale choice can cause the next action to omit its optional token payment unless the user notices and re-enables the checkbox.

        self.recipient_id_input.clear();
        self.fetched_documents.clear();
        self.pay_optional_token_cost = true;

source: gpt-6.1-sol (phase2-reviewer: rust-quality)

Review provenance

Source: reviewer 1: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: low by gpt-6.1-sol (effort low) — This is a small, self-contained UI and payment-construction change with focused tests, and its correctness is straightforward to verify despite affecting whether an optional token payment is included.
  • Phase 1 reviewers: not run (disabled for this repository)
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort medium); agent phase2-reviewer, gpt-6.1-sol — rust-quality (completed, effort medium); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.

In `src/ui/contracts_documents/document_action_screen.rs`:
- [BLOCKING] src/ui/contracts_documents/document_action_screen.rs:919-931: Show the credit-fee outcome when an optional token cost is disabled
  When an optional cost is unchecked, `token_payment_for` correctly returns `None`, so the action carries no token payment and the identity pays the network fee in credits without sponsorship. However, this summary is rendered unconditionally from `token_creation_cost.gas_fees_paid_by`, so it can still say that tokens will be paid and that the contract owner will pay gas. The user therefore sees payment information that contradicts the transition being sent immediately before broadcast.
- [BLOCKING] src/ui/contracts_documents/document_action_screen.rs:236-258: Reset the optional token-cost choice when starting a new action
  `reset_screen()` clears the selected contract, document type, inputs, and broadcast state, but it does not restore `pay_optional_token_cost`. After a user disables payment, completes an action, and selects the reset flow, the next optional-cost action starts with payment disabled even though the option is enabled by default for a new screen. That stale choice can cause the next action to omit its optional token payment unless the user notices and re-enables the checkbox.

Comment on lines 930 to 931
))
.color(Color32::DARK_RED),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Blocking: Show the credit-fee outcome when an optional token cost is disabled

When an optional cost is unchecked, token_payment_for correctly returns None, so the action carries no token payment and the identity pays the network fee in credits without sponsorship. However, this summary is rendered unconditionally from token_creation_cost.gas_fees_paid_by, so it can still say that tokens will be paid and that the contract owner will pay gas. The user therefore sees payment information that contradicts the transition being sent immediately before broadcast.

Suggested change
))
.color(Color32::DARK_RED),
let cost_description = if token_creation_cost.optional && !self.pay_optional_token_cost {
"The optional token cost will not be paid.\nThe network fee will be paid by you in credits."
.to_owned()
} else {
format!(
"Token cost: {} \"{}\" tokens.\nTokens will be {}.\nGas fees will be paid by {}.",
token_amount, token_name, token_effect_string, gas_fees_paid_by_string
)
};
ui.label(RichText::new(cost_description).color(Color32::DARK_RED));

source: gpt-6.1-sol (phase2-reviewer: general, rust-quality)

lklimek and others added 2 commits October 26, 2026 20:34
…tional-token-cost

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
…t-optional-token-cost

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
lklimek and others added 2 commits October 30, 2026 11:44
…l-token-cost

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WunYYhY7P2FJqHVgkHiXtT
…l-token-cost

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WunYYhY7P2FJqHVgkHiXtT
@Claudius-Maginificent Claudius-Maginificent added priority: low Low priority — nice to have priority: medium Medium priority and removed priority: low Low priority — nice to have labels Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority: medium Medium priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants