feat: Updated disable-altpayments to altpayments#651
Conversation
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughReplaces the boolean Changesaltpayment prop refactor
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant HostApp
participant PayButton
participant Widget
participant AltpaymentWidget
participant SideShiftSocket
HostApp->>PayButton: altpayment="BTC"
PayButton->>Widget: pass altpayment
Widget->>Widget: parseAltpayment("BTC")
Widget->>AltpaymentWidget: preselectedCoin="BTC"
AltpaymentWidget->>SideShiftSocket: requestPairRate(selectedCoinNetwork)
SideShiftSocket-->>AltpaymentWidget: pair rate
AltpaymentWidget->>SideShiftSocket: create-altpayment-quote
SideShiftSocket-->>AltpaymentWidget: quote and shift state
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
react/lib/components/Widget/Widget.tsx (1)
255-257: 🧹 Nitpick | 🔵 Trivial | 💤 Low valueConsider consolidating
parseAltpaymentcalls.
parseAltpayment(altpayment)is called twice: once in the state initializer (line 256) and once in the memoizedaltpaymentConfig(line 312). While the memoization handles re-renders correctly, the initial render parses the same value twice.This is a minor optimization opportunity - you could initialize
internalUseAltpaymentfromaltpaymentConfig.autoStartby reordering the declarations, though this would require the memo to be defined first.Also applies to: 312-313
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@react/lib/components/Widget/Widget.tsx` around lines 255 - 257, The function `parseAltpayment` is being called twice on initial render: once in the state initializer for `internalUseAltpayment` (line 256) and again in the memoized `altpaymentConfig` definition (line 312). To consolidate these calls and avoid redundant parsing, reorder the declarations by moving the `altpaymentConfig` useMemo hook before the `internalUseAltpayment` useState hook, then update the useState initializer to use `altpaymentConfig.autoStart` instead of calling `parseAltpayment(altpayment).autoStart` directly. This ensures `parseAltpayment` is only called once during the initial render while maintaining the same functionality.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@react/lib/tests/util/altpayment.test.ts`:
- Around line 39-42: In the test case for parseAltpayment that checks
unrecognized tickers, add an additional expect statement that calls
parseAltpayment with the parameter 'blahInvalidTicker' and verifies it returns
defaultConfig, following the same pattern as the existing assertions for 'ETH'
and 'DOGE'.
In `@react/lib/util/altpayment.ts`:
- Around line 13-19: The boolean parsing logic in the altpayment utility has
both the truthy and falsy cases returning DEFAULT_CONFIG, which prevents
representing inverted boolean behavior. To fix this, the second condition that
checks for value being true or 'true' should return a different configuration
value instead of DEFAULT_CONFIG. This will allow altpayment=true and
altpayment=false to have distinct behaviors as intended by the PR's objective to
invert the semantics from the old disable-altpayments naming.
---
Nitpick comments:
In `@react/lib/components/Widget/Widget.tsx`:
- Around line 255-257: The function `parseAltpayment` is being called twice on
initial render: once in the state initializer for `internalUseAltpayment` (line
256) and again in the memoized `altpaymentConfig` definition (line 312). To
consolidate these calls and avoid redundant parsing, reorder the declarations by
moving the `altpaymentConfig` useMemo hook before the `internalUseAltpayment`
useState hook, then update the useState initializer to use
`altpaymentConfig.autoStart` instead of calling
`parseAltpayment(altpayment).autoStart` directly. This ensures `parseAltpayment`
is only called once during the initial render while maintaining the same
functionality.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 764fb3a9-c9b1-4441-8c14-b4e862634089
📒 Files selected for processing (17)
docs/README.mddocs/_sidebar.mddocs/zh-cn/README.mddocs/zh-cn/_sidebar.mddocs/zh-tw/README.mddocs/zh-tw/_sidebar.mdpaybutton/dev/demo/index.htmlpaybutton/dev/demo/paybutton-generator.htmlpaybutton/src/index.tsxreact/lib/components/PayButton/PayButton.tsxreact/lib/components/PaymentDialog/PaymentDialog.tsxreact/lib/components/Widget/AltpaymentWidget.tsxreact/lib/components/Widget/Widget.tsxreact/lib/components/Widget/WidgetContainer.tsxreact/lib/tests/util/altpayment.test.tsreact/lib/util/altpayment.tsreact/lib/util/index.ts
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Description
Expanded the 'altpayments' config functionality (renaming it in the process and inverting the true/false behaviour)
Test plan
Test everything, but especially the "altpayment" (Sideshift) payment flow. Try setting
altpaymentstotrue,false,xec,btc, andblahInvalidTickerto make sure it behaves as you'd expect.Summary by CodeRabbit
altpaymentinstead ofdisable-altpayment, with updated XEC/BCH/BTC examples.altpaymentvia dropdown options.altpayment(including automatic BTC preselection).altpaymentconfiguration parsing.