-
-
Notifications
You must be signed in to change notification settings - Fork 273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(trading): trading account #16719
Conversation
It will work, but I don't think it's the right approach. What if I go from ETH swap form directly to the POL swap form (shouldn't be possible at this time but might be in the future)? This new code won't be called so the account won't reset. |
3ee8821
to
754a984
Compare
7e9ebf1
to
67c7384
Compare
WalkthroughThis pull request refactors the Assessment against linked issues
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
754a984
to
fd8a7ce
Compare
67c7384
to
e2945a9
Compare
Thanks for the feedback. I have updated the code to make it more resilient. I used |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still feels a little weird to me, but I have no better fix now
fd8a7ce
to
c742054
Compare
dd96ba4
to
64bfaa4
Compare
64bfaa4
to
4b393d7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🔭 Outside diff range comments (1)
packages/suite/src/middlewares/wallet/tradingMiddleware.ts (1)
192-202
: Explicit Logging for Missing Account in Trading MiddlewareOur review confirms that the
getAccountAccordingToRoute
function can returnundefined
when no matching account is found (e.g., if no account matches the trading account keys). In the current middleware, sinceinvityAPI.createInvityAPIKey
is called only whenaccount
exists, the absence of explicit logging makes it harder to diagnose missing account scenarios. Adding an explicit warning—as shown in the diff—is a valuable improvement to aid debugging and ensure robustness.
- The function may return
undefined
if the account isn’t found in either the sell or exchange case.- The middleware silently skips the API key creation when
account
is falsy.- Adding error handling (with a warning and early return) clarifies the flow and eases troubleshooting.
🔗 Analysis chain
Add error handling for undefined account.
The code should handle the case where
getAccountAccordingToRoute
returns undefined to prevent potential issues.if ( action.type === TRADING_EXCHANGE.SET_TRADING_ACCOUNT_KEY || action.type === TRADING_SELL.SET_TRADING_ACCOUNT_KEY ) { const account = getAccountAccordingToRoute(newState); - if (account) { + if (!account) { + console.warn('No account found when updating invityAPIKey'); + return action; + } - } invityAPI.createInvityAPIKey(account.descriptor); }Let's verify if this edge case can occur:
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check if getAccountAccordingToRoute can return undefined # Search for calls to getAccountAccordingToRoute and check error handling rg -A 5 "getAccountAccordingToRoute" --type ts # Search for potential undefined account handling in tests rg -A 5 "getAccountAccordingToRoute.*undefined" --type tsLength of output: 1926
Script:
#!/bin/bash # Display the full implementation of getAccountAccordingToRoute to inspect potential undefined returns. sed -n '/export const getAccountAccordingToRoute/,/};/p' packages/suite/src/middlewares/wallet/tradingMiddleware.tsLength of output: 821
🧹 Nitpick comments (1)
packages/suite/src/middlewares/wallet/tradingMiddleware.ts (1)
149-153
: Add a comment explaining the clearing of both account keys.While the logic to clear both sell and exchange account keys is correct, it would be helpful to add a comment explaining why both keys need to be cleared when the suite account changes. This helps future maintainers understand the reasoning.
- // clear the account key in the Sell and Swap section when the route is not trading + // Clear both sell and exchange account keys when the suite account changes to prevent + // stale account selections from being used in either trading section if (isSuiteAccountChanged && (tradingExchangeAccountKey || tradingSellAccountKey)) {
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/suite/src/middlewares/wallet/tradingMiddleware.ts
(3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (8)
- GitHub Check: run-desktop-tests (@group=wallet, trezor-user-env-unix bitcoin-regtest)
- GitHub Check: run-desktop-tests (@group=settings, trezor-user-env-unix bitcoin-regtest)
- GitHub Check: run-desktop-tests (@group=device-management, trezor-user-env-unix)
- GitHub Check: Setup and Cache Dependencies
- GitHub Check: run-desktop-tests (@group=suite, trezor-user-env-unix)
- GitHub Check: build-web
- GitHub Check: build-web
- GitHub Check: Analyze with CodeQL (javascript)
🔇 Additional comments (4)
packages/suite/src/middlewares/wallet/tradingMiddleware.ts (4)
4-4
: LGTM!The import of
ACCOUNTS_MODULE_PREFIX
is appropriate for detecting account changes.
47-49
: LGTM! Clear and descriptive variable naming.The renamed variables
tradingExchangeAccountKey
andtradingSellAccountKey
improve code readability by clearly indicating their purpose.
51-53
: LGTM! Improved action type detection.The boolean flags improve code readability and make the account change detection more reliable by using
ACCOUNTS_MODULE_PREFIX
.
160-160
: LGTM! Simplified route change condition.Using the
isRouteChange
flag improves code readability without changing the underlying logic.
Description
Fixed a bad selected (cachec) account in the trading section (Swap, Sell)
Related Issue
Resolve #16701
Waiting for merging - #16681