Repository navigation
feat(documents): let the user skip an optional token cost - #1124
Claudius-Maginificent wants to merge 9 commits into
Conversation
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
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
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. Comment |
|
🕓 Review not started yet because this PR is a draft.
Commit 6000157. Normal review starts when eligible; priority review starts as soon as a slot is available. |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
|
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 🤖 Co-authored by Claudius the Magnificent AI Agent |
thepastaclaw
left a comment
There was a problem hiding this comment.
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:
lowbygpt-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; agentsol-verifier - Phase 2 reviewers:
gpt-6.1-sol— general (completed, effort medium); agentphase2-reviewer,gpt-6.1-sol— rust-quality (completed, effort medium); agentphase2-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.
| )) | ||
| .color(Color32::DARK_RED), |
There was a problem hiding this comment.
🔴 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.
| )) | |
| .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)
…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
…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
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
Actual
The screen always attached the token payment. An optional token cost could not be left out.
Expected
Detailed discussion
src/ui/contracts_documents/document_action_screen.rs):token_paymentbuilds the token payment for a cost. It returns none without a cost, and none for an optional cost the user chose not to pay.pay_optional_token_costbacks the "Pay the token cost" checkbox inrender_token_cost_info. It resets to on whenever the selected action has no token cost.DocumentActionTokenCost::optionalcomes 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.Testing
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_screentests: 8 passed.cargo clippy --all-features --lib --tests -- -D warningsandcargo fmt --allpass.🤖 Co-authored by Claudius the Magnificent AI Agent
🤖 Generated with Claude Code
https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q