Repository navigation
Feat/mwa v2 - #289
Feat/mwa v2#289
Conversation
…ame on #288 auth fix Rebased onto main (PR #288 CAIP-2 chain fix). Dropped the obsolete authorize+token rework (#1/#2) and chain-edge diagnostics (#9) since #288's reauthorize+chain supersedes them; kept the additive work: - get_capabilities features[] parsing + SupportsCloneAuthorization/SupportsSignInWithSolana - sign_and_send_transactions (no fallback; throws NotSupportedException on -32601 via MwaRpcException) - DisconnectWallet() renamed to Deauthorize() Needs a Unity compile + on-device re-test. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…lias Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
WalkthroughThe SDK is upgraded to MWA 2.0 by adding Sign-In-With-Solana ( ChangesMWA 2.0 Feature Upgrade
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related issues
Possibly related PRs
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 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 |
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 10
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
Runtime/codebase/SolanaMobileStack/SolanaMobileWalletAdapter.cs (1)
703-703:⚠️ Potential issue | 🟠 Major | ⚡ Quick winDeauthorize path can still trigger wallet discovery/chooser.
DeauthorizeImplcallsResolveWalletPackage(), but that resolver is documented to fall through to discovery/native picker. This conflicts with the disconnect rule to avoid chooser UI and can prompt users during logout.Suggested fix
- string targetPackage = await ResolveWalletPackage(); + // Disconnect must be cache-only; never trigger discovery/picker. + string targetPackage = await _walletSelectionCache.GetSelectedWalletPackage();🤖 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 `@Runtime/codebase/SolanaMobileStack/SolanaMobileWalletAdapter.cs` at line 703, The DeauthorizeImpl method is calling ResolveWalletPackage() at line 703, but this method triggers wallet discovery and native picker UI, which should not occur during deauthorization. Instead of calling ResolveWalletPackage(), retrieve the already-authorized wallet package directly from the current session state or a stored field that holds the active wallet package from the authorization flow. This ensures deauthorization completes without prompting the user with any UI chooser.Tests/EditMode/MwaAuthCache/PlayerPrefsAuthCacheTests.cs (1)
138-148:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winTest doesn't validate idempotency as claimed.
The test name is
Clear_OnEmptyCache_IsIdempotentbut only callsClear()once. To properly test idempotency (multiple invocations produce the same result without error), callClear()at least twice:await cache.Clear(); + await cache.Clear(); // second call must also succeed Assert.IsNull(await cache.Get());The comment mentions "Logout() and Deauthorize() can both call Clear in a row", so the test should verify this scenario.
🤖 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 `@Tests/EditMode/MwaAuthCache/PlayerPrefsAuthCacheTests.cs` around lines 138 - 148, The test method Clear_OnEmptyCache_IsIdempotent does not actually test idempotency because it only calls Clear() once. To properly validate idempotency and verify that back-to-back invocations are safe (as mentioned in the comment), add a second await cache.Clear() call immediately after the first one, before the final assertion. This will demonstrate that calling Clear() multiple times in succession on an empty cache produces consistent results without errors.
🤖 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 `@docs/mwa-best-practices.md`:
- Line 45: The documentation shows minimal examples of async void event handlers
(OnConnectOrContinue and OnLogout) without exception handling. Add a note or
clarification in the documentation explaining that while these are simplified
examples, production code should wrap the await calls in try-catch blocks to
prevent unhandled exceptions from crashing the application. Reference both event
handlers and explain the best practice of including error handling similar to
the catch block pattern shown in the comment.
- Line 39: The continueLabel.text assignment uses C# 8.0 range syntax (addr[..4]
and addr[^4..]) which is incompatible with Unity 2019.4. Replace the range
operators with substring method calls: use addr.Substring(0, 4) for the first 4
characters and addr.Substring(addr.Length - 4) for the last 4 characters. This
ensures compatibility with the target Unity version while maintaining the same
string truncation behavior.
In `@docs/mwa-quick-start.md`:
- Around line 58-60: The documentation guidance for checking cached sessions
shows `MwaSession.HasCachedSession()` being called without await, but since the
method returns Task<bool> it must be awaited in an async context. Update the
code example in the best practices guidance to demonstrate calling
MwaSession.HasCachedSession() with await and show it within an appropriate async
method or context to prevent readers from copying code that will result in a
compile-time error.
In
`@Runtime/codebase/SolanaMobileStack/JsonRpcClient/Responses/CapabilitiesResult.cs`:
- Around line 94-100: The ReadJson method in MixedStringArrayConverter currently
accepts any JSON token type and coerces it to a string via ToString(), which
allows invalid schema values like objects, arrays, and booleans to silently
contaminate the result array. Modify the token processing loop where result[i]
is assigned to first validate that each token is either null or of type
JTokenType.String; for any other token type, throw a JsonSerializationException
with a descriptive error message indicating the unsupported type was
encountered, rather than blindly calling ToString() on the token.
In
`@Runtime/codebase/SolanaMobileStack/JsonRpcClient/Responses/CloneAuthorizationResult.cs`:
- Line 14: The `[RequiredMember]` attribute is a C# 11 feature not supported by
Unity, which only supports C# 9.0 and will cause compilation errors. Remove all
occurrences of the `[RequiredMember]` attribute from the affected classes
(CloneAuthorizationResult, SignedResult, SignAndSendResult, AuthorizationResult,
and others mentioned in the comment). Replace this compile-time validation with
runtime validation by adding property validation logic in constructors or
initialization methods to ensure required properties are properly initialized
before use.
In
`@Runtime/codebase/SolanaMobileStack/JsonRpcClient/Responses/SignAndSendResult.cs`:
- Around line 22-24: In the SignatureBytes property of the SignAndSendResult
class, add validation for each signature entry before calling
Convert.FromBase64String instead of relying on the default exception behavior.
Check each element in the Signatures collection for null or invalid base64
content, and when an invalid entry is encountered, throw a structured
serialization exception that includes both the problematic entry and its index
position in the list to provide clear context for debugging.
In `@Runtime/codebase/SolanaMobileStack/MobileWalletAdapterClient.cs`:
- Around line 85-90: The SignAndSendTransactions method lacks a null guard for
the transactions parameter, which causes a crash during request construction
when transactions.Select(...) is called in
PrepareSignAndSendTransactionsRequest. Add a null check at the start of the
SignAndSendTransactions method to validate that transactions is not null and
throw ArgumentNullException if it is, providing a clear and predictable API
contract. Apply the same null guard fix to any other similar transaction signing
entry-point methods in this class.
In `@Runtime/codebase/SolanaMobileStack/MwaRpcException.cs`:
- Around line 48-61: The MwaErrorCodes class is missing the NotCloned error code
that is defined in the MWA 2.0 specification. Add a new constant declaration for
NotCloned with the value -5 in the MwaErrorCodes class, positioning it between
the NotSubmitted constant (value -4) and the TooManyPayloads constant (value -6)
to maintain proper ordering of the error codes.
In `@Runtime/codebase/SolanaMobileStack/SolanaMobileWalletAdapter.cs`:
- Around line 533-537: The LoginWithSignIn method does not validate that the
payload parameter is non-null before passing it to LoginWithSignInImpl, which
will crash with a NullReferenceException when LoginWithSignInImpl attempts to
read multiple fields from the payload. Add a null check at the beginning of the
LoginWithSignIn method to validate the payload parameter and throw an
ArgumentNullException if it is null, ensuring the method fails gracefully with a
clear error message rather than a crash later during execution.
- Around line 476-484: The ParseDataSignatures method does not handle exceptions
that can be thrown by Convert.FromBase64String when processing malformed base64
data in the wallet response. Wrap the Convert.FromBase64String call in a
try-catch block to gracefully handle FormatException (or more broadly, any
exception from base64 decoding), and assign null to result[i] when the
conversion fails, allowing the method to return safely without breaking the
SignAndSendTxResult contract.
---
Outside diff comments:
In `@Runtime/codebase/SolanaMobileStack/SolanaMobileWalletAdapter.cs`:
- Line 703: The DeauthorizeImpl method is calling ResolveWalletPackage() at line
703, but this method triggers wallet discovery and native picker UI, which
should not occur during deauthorization. Instead of calling
ResolveWalletPackage(), retrieve the already-authorized wallet package directly
from the current session state or a stored field that holds the active wallet
package from the authorization flow. This ensures deauthorization completes
without prompting the user with any UI chooser.
In `@Tests/EditMode/MwaAuthCache/PlayerPrefsAuthCacheTests.cs`:
- Around line 138-148: The test method Clear_OnEmptyCache_IsIdempotent does not
actually test idempotency because it only calls Clear() once. To properly
validate idempotency and verify that back-to-back invocations are safe (as
mentioned in the comment), add a second await cache.Clear() call immediately
after the first one, before the final assertion. This will demonstrate that
calling Clear() multiple times in succession on an empty cache produces
consistent results without errors.
🪄 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: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 539114b5-a4bf-4ff5-89f2-019a884cce5e
📒 Files selected for processing (38)
Runtime/Plugins/SolanaMobileStack/Android/MwaChooserHelper.javaRuntime/codebase/SolanaMobileStack/Interfaces/IAdapterOperations.csRuntime/codebase/SolanaMobileStack/JsonRpcClient/JsonRequest.csRuntime/codebase/SolanaMobileStack/JsonRpcClient/Responses/AuthorizationResult.csRuntime/codebase/SolanaMobileStack/JsonRpcClient/Responses/CapabilitiesResult.csRuntime/codebase/SolanaMobileStack/JsonRpcClient/Responses/CloneAuthorizationResult.csRuntime/codebase/SolanaMobileStack/JsonRpcClient/Responses/CloneAuthorizationResult.cs.metaRuntime/codebase/SolanaMobileStack/JsonRpcClient/Responses/Response.csRuntime/codebase/SolanaMobileStack/JsonRpcClient/Responses/SignAndSendResult.csRuntime/codebase/SolanaMobileStack/JsonRpcClient/Responses/SignAndSendResult.cs.metaRuntime/codebase/SolanaMobileStack/JsonRpcClient/Responses/SignAndSendTxResult.csRuntime/codebase/SolanaMobileStack/JsonRpcClient/Responses/SignAndSendTxResult.cs.metaRuntime/codebase/SolanaMobileStack/JsonRpcClient/Responses/SignInResult.csRuntime/codebase/SolanaMobileStack/JsonRpcClient/Responses/SignInResult.cs.metaRuntime/codebase/SolanaMobileStack/JsonRpcClient/SignInPayload.csRuntime/codebase/SolanaMobileStack/JsonRpcClient/SignInPayload.cs.metaRuntime/codebase/SolanaMobileStack/MobileWalletAdapterClient.csRuntime/codebase/SolanaMobileStack/MwaAuthCache/IMwaAuthCache.csRuntime/codebase/SolanaMobileStack/MwaRpcException.csRuntime/codebase/SolanaMobileStack/MwaRpcException.cs.metaRuntime/codebase/SolanaMobileStack/MwaSession.csRuntime/codebase/SolanaMobileStack/MwaSession.cs.metaRuntime/codebase/SolanaMobileStack/SolanaMobileWalletAdapter.csRuntime/codebase/SolanaWalletAdapter.csTests/EditMode/Contracts/IAdapterOperationsContractTests.csTests/EditMode/JsonRpc/CapabilitiesResultTests.csTests/EditMode/MwaAuthCache/PlayerPrefsAuthCacheTests.csTests/EditMode/MwaClient/MobileWalletAdapterClientTests.csdocs.metadocs/mwa-best-practices.mddocs/mwa-best-practices.md.metadocs/mwa-cache-guide.mddocs/mwa-cache-guide.md.metadocs/mwa-method-reference.mddocs/mwa-method-reference.md.metadocs/mwa-quick-start.mddocs/mwa-quick-start.md.metapackage.json
| Because returning users reconnect silently, a landing screen should show **Continue** + | ||
| **Logout** for them instead of a bare **Connect**. Check before any adapter exists with | ||
| `MwaSession.HasCachedSession()` — see [Best Practices](mwa-best-practices.md). |
There was a problem hiding this comment.
Call the cached-session helper asynchronously.
MwaSession.HasCachedSession() is documented as Task<bool> in the method reference, so this guidance should show await/an async context; otherwise readers will copy a compile-time mismatch.
🤖 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 `@docs/mwa-quick-start.md` around lines 58 - 60, The documentation guidance for
checking cached sessions shows `MwaSession.HasCachedSession()` being called
without await, but since the method returns Task<bool> it must be awaited in an
async context. Update the code example in the best practices guidance to
demonstrate calling MwaSession.HasCachedSession() with await and show it within
an appropriate async method or context to prevent readers from copying code that
will result in a compile-time error.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
♻️ Duplicate comments (1)
docs/mwa-best-practices.md (1)
44-44:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winReplace the C# 8 range syntax in this sample.
If this doc still targets Unity 2019.4,
addr[..4]/addr[^4..]won’t compile; useSubstringor call out a newer minimum Unity/C# version. This is the same compatibility issue previously flagged.♻️ Proposed fix
- continueLabel.text = $"Continue as {addr[..4]}…{addr[^4..]}"; + continueLabel.text = $"Continue as {addr.Substring(0, 4)}…{addr.Substring(addr.Length - 4)}";🤖 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 `@docs/mwa-best-practices.md` at line 44, The code sample in the continueLabel.text assignment uses C# 8 range syntax (addr[..4] and addr[^4..]) which is incompatible with Unity 2019.4. Replace this range syntax with traditional Substring method calls instead: addr[..4] should become addr.Substring(0, 4) and addr[^4..] should become addr.Substring(addr.Length - 4) to ensure the sample compiles on the documented minimum Unity/C# version.
🤖 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.
Duplicate comments:
In `@docs/mwa-best-practices.md`:
- Line 44: The code sample in the continueLabel.text assignment uses C# 8 range
syntax (addr[..4] and addr[^4..]) which is incompatible with Unity 2019.4.
Replace this range syntax with traditional Substring method calls instead:
addr[..4] should become addr.Substring(0, 4) and addr[^4..] should become
addr.Substring(addr.Length - 4) to ensure the sample compiles on the documented
minimum Unity/C# version.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 6b851dd7-a1f1-4afe-9806-fecc6bcf9789
📒 Files selected for processing (6)
Runtime/codebase/SolanaMobileStack/JsonRpcClient/Responses/CapabilitiesResult.csRuntime/codebase/SolanaMobileStack/JsonRpcClient/Responses/SignAndSendResult.csRuntime/codebase/SolanaMobileStack/MobileWalletAdapterClient.csRuntime/codebase/SolanaMobileStack/MwaRpcException.csRuntime/codebase/SolanaMobileStack/SolanaMobileWalletAdapter.csdocs/mwa-best-practices.md
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (5)
Runtime/codebase/SolanaMobileStack/SolanaMobileWalletAdapter.cs (4)
426-436:⚠️ Potential issue | 🟠 Major | ⚡ Quick winValidate
transactionsbefore serialization inSignAndSendTransactionsImpl.Line 435 dereferences
transactionsvia.Select(...)without guarding null/empty input, so caller mistakes becomeNullReferenceExceptioninstead of a controlled result.Suggested fix
private async Task<SignAndSendTxResult> SignAndSendTransactionsImpl( Transaction[] transactions, SignAndSendTransactionsOptions options) { + if (transactions == null || transactions.Length == 0) + { + return new SignAndSendTxResult.Failed + { + Code = MwaErrorCodes.InvalidParams, + Message = "[MWA] SignAndSendTransactions: at least one transaction is required" + }; + } + SignAndSendResult res = null;🤖 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 `@Runtime/codebase/SolanaMobileStack/SolanaMobileWalletAdapter.cs` around lines 426 - 436, The SignAndSendTransactionsImpl method dereferences the transactions parameter via .Select() without first validating that it is not null or empty, which can cause a NullReferenceException instead of returning a controlled error result. Add validation at the start of the SignAndSendTransactionsImpl method to check if transactions is null or empty, and return an appropriate SignAndSendTxResult indicating failure if validation fails, before proceeding to the RunPrivileged call.
632-637:⚠️ Potential issue | 🟠 Major | ⚡ Quick winSIWS fallback can sign a message for one address but return another address.
Line 634 prefers
payload.Address; Line 623 returnspublicKey.Key. If these differ, the signed SIWS message and returned identity diverge, breaking verifier assumptions.Suggested fix
private static string BuildSiwsMessage(SignInPayload p, string addressBase58) { - var address = !string.IsNullOrEmpty(p.Address) ? p.Address : addressBase58; + if (!string.IsNullOrEmpty(p.Address) && !string.Equals(p.Address, addressBase58, StringComparison.Ordinal)) + throw new ArgumentException("[MWA] SignInPayload.address must match the authorized account", nameof(p)); + var address = addressBase58;Also applies to: 621-624
🤖 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 `@Runtime/codebase/SolanaMobileStack/SolanaMobileWalletAdapter.cs` around lines 632 - 637, The BuildSiwsMessage method uses p.Address if available (falling back to addressBase58) to build the SIWS message, but the caller returns publicKey.Key instead. This creates a mismatch where the signed message and returned identity diverge. Ensure consistency by using the same address value that was actually used in BuildSiwsMessage as the return value. Modify the code around lines 621-624 to return the address that was passed to or resolved within BuildSiwsMessage (the value matching what line 634 used), rather than always returning publicKey.Key.
729-735:⚠️ Potential issue | 🟠 Major | ⚡ Quick win
DeauthorizeWalletcan still trigger picker UI due to package resolution path.Line 734 uses
ResolveWalletPackage(), whose documented behavior includes native picker fallback. That conflicts with the no-chooser disconnect behavior described in Line 729–733.Suggested fix
- string targetPackage = await ResolveWalletPackage(); + // Deauthorize should be cache-only: never trigger discovery/picker UI. + string targetPackage = await _walletSelectionCache.GetSelectedWalletPackage();🤖 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 `@Runtime/codebase/SolanaMobileStack/SolanaMobileWalletAdapter.cs` around lines 729 - 735, The DeauthorizeWallet method's call to ResolveWalletPackage() at line 734 can trigger the native picker UI as a fallback behavior, which directly contradicts the documented no-chooser requirement stated in the comments on lines 729–733. Modify the ResolveWalletPackage invocation in DeauthorizeWallet to ensure it does not fall back to the OS wallet chooser (either by using a non-fallback variant of the method, passing a parameter to disable fallback, or wrapping the call to catch the fallback scenario and skip remote revoke while clearing local state as documented). The goal is to ensure deauthorization never shows the picker UI, maintaining the intended disconnect behavior.
347-352:⚠️ Potential issue | 🟠 Major | ⚡ Quick winPreserve RPC code/data on authorize failures instead of throwing generic exceptions.
At Line 351 and Line 572, throwing
Exceptiondrops wallet errorCode/Data, which regresses the typed error contract introduced elsewhere in this adapter.Suggested fix
if (!result.WasSuccessful) { - Debug.LogError(result.Error.Message); - throw new Exception(result.Error.Message); + Debug.LogError($"[MWA] Login failed ({result.Error?.Code}): {result.Error?.Message}"); + throw new MwaRpcException( + result.Error?.Code ?? 0, + result.Error?.Message ?? "[MWA] Login failed", + result.Error?.Data); }if (!result.WasSuccessful) - throw new Exception(result.Error?.Message ?? "[MWA] LoginWithSignIn: authorize failed"); + throw new MwaRpcException( + result.Error?.Code ?? 0, + result.Error?.Message ?? "[MWA] LoginWithSignIn: authorize failed", + result.Error?.Data);Also applies to: 571-573
🤖 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 `@Runtime/codebase/SolanaMobileStack/SolanaMobileWalletAdapter.cs` around lines 347 - 352, The code is throwing a generic Exception that only includes the error message, which drops the wallet error Code and Data fields that should be preserved per the typed error contract. Replace the generic Exception throws (in the authorization failure handling blocks where result.WasSuccessful is false) with an exception type that captures and preserves all error fields from result.Error, including Code and Data. This needs to be done at both the location with StartAndExecute and the other location mentioned in the comment, ensuring the typed error contract is maintained throughout the adapter.Tests/EditMode/MwaAuthCache/PlayerPrefsAuthCacheTests.cs (1)
139-147:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winIdempotency test only performs one
Clear()call.Line 145 executes
Clear()once, so this test no longer validates the “back-to-back” idempotency case it describes. Add a second call before asserting state.Suggested fix
public async Task Clear_OnEmptyCache_IsIdempotent() { var cache = new PlayerPrefsAuthCache(); // DisconnectWallet() and DeauthorizeWallet() can both call Clear in a row, // so back-to-back invocations on an empty cache must be safe. await cache.Clear(); + await cache.Clear(); Assert.IsNull(await cache.Get()); }🤖 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 `@Tests/EditMode/MwaAuthCache/PlayerPrefsAuthCacheTests.cs` around lines 139 - 147, The test method Clear_OnEmptyCache_IsIdempotent only invokes Clear() once, but the test's purpose and comment indicate it should verify back-to-back idempotency. Add a second call to cache.Clear() before the Assert.IsNull assertion to properly test that successive Clear() invocations on an empty cache are safe and idempotent.
🤖 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 `@Runtime/codebase/Web3.cs`:
- Around line 307-311: The code in the prefab assignment block (lines 307–310)
assumes that both solanaWalletAdapterOptions and its nested
solanaWalletAdapterWebGLOptions are non-null without guards, which causes null
reference exceptions on non-WebGL setups. Add null checks to ensure
solanaWalletAdapterOptions is not null and solanaWalletAdapterWebGLOptions is
not null before attempting to access or assign the walletAdapterUIPrefab and
walletAdapterButtonPrefab properties on those objects.
---
Outside diff comments:
In `@Runtime/codebase/SolanaMobileStack/SolanaMobileWalletAdapter.cs`:
- Around line 426-436: The SignAndSendTransactionsImpl method dereferences the
transactions parameter via .Select() without first validating that it is not
null or empty, which can cause a NullReferenceException instead of returning a
controlled error result. Add validation at the start of the
SignAndSendTransactionsImpl method to check if transactions is null or empty,
and return an appropriate SignAndSendTxResult indicating failure if validation
fails, before proceeding to the RunPrivileged call.
- Around line 632-637: The BuildSiwsMessage method uses p.Address if available
(falling back to addressBase58) to build the SIWS message, but the caller
returns publicKey.Key instead. This creates a mismatch where the signed message
and returned identity diverge. Ensure consistency by using the same address
value that was actually used in BuildSiwsMessage as the return value. Modify the
code around lines 621-624 to return the address that was passed to or resolved
within BuildSiwsMessage (the value matching what line 634 used), rather than
always returning publicKey.Key.
- Around line 729-735: The DeauthorizeWallet method's call to
ResolveWalletPackage() at line 734 can trigger the native picker UI as a
fallback behavior, which directly contradicts the documented no-chooser
requirement stated in the comments on lines 729–733. Modify the
ResolveWalletPackage invocation in DeauthorizeWallet to ensure it does not fall
back to the OS wallet chooser (either by using a non-fallback variant of the
method, passing a parameter to disable fallback, or wrapping the call to catch
the fallback scenario and skip remote revoke while clearing local state as
documented). The goal is to ensure deauthorization never shows the picker UI,
maintaining the intended disconnect behavior.
- Around line 347-352: The code is throwing a generic Exception that only
includes the error message, which drops the wallet error Code and Data fields
that should be preserved per the typed error contract. Replace the generic
Exception throws (in the authorization failure handling blocks where
result.WasSuccessful is false) with an exception type that captures and
preserves all error fields from result.Error, including Code and Data. This
needs to be done at both the location with StartAndExecute and the other
location mentioned in the comment, ensuring the typed error contract is
maintained throughout the adapter.
In `@Tests/EditMode/MwaAuthCache/PlayerPrefsAuthCacheTests.cs`:
- Around line 139-147: The test method Clear_OnEmptyCache_IsIdempotent only
invokes Clear() once, but the test's purpose and comment indicate it should
verify back-to-back idempotency. Add a second call to cache.Clear() before the
Assert.IsNull assertion to properly test that successive Clear() invocations on
an empty cache are safe and idempotent.
🪄 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: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 7802dcbd-fc58-4c1c-9425-b0a7e5391559
📒 Files selected for processing (14)
README.mdRuntime/codebase/SolanaMobileStack/MwaAuthCache/IMwaAuthCache.csRuntime/codebase/SolanaMobileStack/MwaSession.csRuntime/codebase/SolanaMobileStack/SolanaMobileWalletAdapter.csRuntime/codebase/SolanaWalletAdapter.csRuntime/codebase/Web3.csTests/EditMode/MwaAuthCache/PlayerPrefsAuthCacheTests.csTests/EditMode/MwaClient/MobileWalletAdapterClientTests.csdocs/installation.mddocs/installation.md.metadocs/mwa-best-practices.mddocs/mwa-cache-guide.mddocs/mwa-method-reference.mddocs/mwa-quick-start.md
| if (solanaWalletAdapterOptions.solanaWalletAdapterWebGLOptions.walletAdapterUIPrefab == null) | ||
| solanaWalletAdapterOptions.solanaWalletAdapterWebGLOptions.walletAdapterUIPrefab = Resources.Load<GameObject>("SolanaUnitySDK/WalletAdapterUI"); | ||
| if (solanaWalletAdapterOptions.solanaWalletAdapterWebGLOptions.walletAdapterButtonPrefab == null) | ||
| solanaWalletAdapterOptions.solanaWalletAdapterWebGLOptions.walletAdapterButtonPrefab = Resources.Load<GameObject>("SolanaUnitySDK/WalletAdapterButton"); | ||
| return new SolanaWalletAdapter(solanaWalletAdapterOptions, rpcCluster, customRpc, webSocketsRpc, false); |
There was a problem hiding this comment.
Guard adapter options before WebGL prefab dereference.
Line 307–310 assumes solanaWalletAdapterOptions and solanaWalletAdapterWebGLOptions are non-null; on non-WebGL setups this can throw before login starts.
Suggested fix
private SolanaWalletAdapter CreateWalletAdapter()
{
- if (solanaWalletAdapterOptions.solanaWalletAdapterWebGLOptions.walletAdapterUIPrefab == null)
- solanaWalletAdapterOptions.solanaWalletAdapterWebGLOptions.walletAdapterUIPrefab = Resources.Load<GameObject>("SolanaUnitySDK/WalletAdapterUI");
- if (solanaWalletAdapterOptions.solanaWalletAdapterWebGLOptions.walletAdapterButtonPrefab == null)
- solanaWalletAdapterOptions.solanaWalletAdapterWebGLOptions.walletAdapterButtonPrefab = Resources.Load<GameObject>("SolanaUnitySDK/WalletAdapterButton");
+ if (solanaWalletAdapterOptions == null)
+ throw new InvalidOperationException("[Solana SDK] solanaWalletAdapterOptions is not configured.");
+#if UNITY_WEBGL
+ solanaWalletAdapterOptions.solanaWalletAdapterWebGLOptions ??= new SolanaWalletAdapterWebGLOptions();
+ if (solanaWalletAdapterOptions.solanaWalletAdapterWebGLOptions.walletAdapterUIPrefab == null)
+ solanaWalletAdapterOptions.solanaWalletAdapterWebGLOptions.walletAdapterUIPrefab = Resources.Load<GameObject>("SolanaUnitySDK/WalletAdapterUI");
+ if (solanaWalletAdapterOptions.solanaWalletAdapterWebGLOptions.walletAdapterButtonPrefab == null)
+ solanaWalletAdapterOptions.solanaWalletAdapterWebGLOptions.walletAdapterButtonPrefab = Resources.Load<GameObject>("SolanaUnitySDK/WalletAdapterButton");
+#endif
return new SolanaWalletAdapter(solanaWalletAdapterOptions, rpcCluster, customRpc, webSocketsRpc, false);
}🤖 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 `@Runtime/codebase/Web3.cs` around lines 307 - 311, The code in the prefab
assignment block (lines 307–310) assumes that both solanaWalletAdapterOptions
and its nested solanaWalletAdapterWebGLOptions are non-null without guards,
which causes null reference exceptions on non-WebGL setups. Add null checks to
ensure solanaWalletAdapterOptions is not null and
solanaWalletAdapterWebGLOptions is not null before attempting to access or
assign the walletAdapterUIPrefab and walletAdapterButtonPrefab properties on
those objects.
|
when is this coming out? |
▎ No breaking API changes: DisconnectWallet() was renamed to Deauthorize() but kept as an [Obsolete] alias that forwards to it, so existing consumers keep compiling. Includes a native Android change
▎ (MwaChooserHelper.java) and a cache-invalidation step that forces pre-fix users to re-authorize once on upgrade.
┌────────┬─────────┬────────────────┬────────────────────────┐⚠️ Core Change │ Issue │
│ Status │ Type │
├────────┼─────────┼────────────────┼────────────────────────┤
│ Ready │ Feature │ Yes │ Link (Issue link here) │
└────────┴─────────┴────────────────┴────────────────────────┘
Problem
The SDK's Mobile Wallet Adapter implementation predated MWA 2.0 and was missing most of the protocol surface that modern on-device wallets expect. Concretely:
than our app — and Seed Vault binds authorization to the caller. The first signing call after connect re-prompted.
Solution
Layered MWA 2.0 parity onto the hardened association transport (transport left untouched):
with a sign_messages fallback), plus ReconnectWallet().
Unauthorized / Failed) instead of throwing, since those outcomes are expected and carry data. Other methods stay exception-based via MwaRpcException (numeric Code + optional Data).
Connect.
Before & After Screenshots
N/A — no UI surface in the SDK itself. Behavior verified on-device (Seeker / Seed Vault, Phantom): silent reauth after first connect, correct-network signing, and all new methods exercised via a test-suite
Other changes (e.g. bug fixes, small refactors)
Deploy Notes
Pure Unity package change — installed via UPM git URL. Includes a native Android change (MwaChooserHelper.java); consumers must rebuild the Android player (IL2CPP / ARM64). On first launch after upgrade,
pre-fix cached auth is invalidated, so existing users re-authorize once.
New scripts:
New dependencies:
Summary by CodeRabbit
New Features
SignAndSendTransactionswith optional submission options and typed results.MwaSessioncached-session helpers.DeauthorizeWalletand aLoginWalletAdapter(SignInPayload)one-call flow.Bug Fixes
Documentation
Tests