Skip to content

refactor: WebViewManager/Handler improvements#18

Merged
andreydobrikov merged 4 commits intomainfrom
feature/webviewmanager-refactror
Mar 13, 2026
Merged

refactor: WebViewManager/Handler improvements#18
andreydobrikov merged 4 commits intomainfrom
feature/webviewmanager-refactror

Conversation

@andreydobrikov
Copy link
Collaborator

This pull request refactors wallet creation, connection, recovery, and signing logic in the EmbeddedWalletManager to centralize error handling and response parsing. The main improvement is the introduction of a generic UnwrapResult<TData> helper method, which simplifies and unifies how results and errors from iframe responses are handled. Additionally, minor changes were made to how asynchronous calls are triggered in the iframe handler and webview handler.

Refactoring wallet operation methods:

  • Introduced a generic UnwrapResult<TData> method to extract data from successful iframe responses or throw a PrivyWalletException with a detailed error message, replacing repetitive error handling logic in wallet creation, connection, recovery, RPC request, and signing methods. (SDK/Runtime/EmbeddedWallet/EmbeddedWalletManager.cs)
  • Updated CreateEthereumWallet, CreateSolanaWallet, CreateAdditionalWallet, ConnectWallet, RecoverWalletThenTryConnecting, RPC request, and signing methods to use UnwrapResult<TData>, significantly reducing duplicated code and improving maintainability. (SDK/Runtime/EmbeddedWallet/EmbeddedWalletManager.cs) [1] [2] [3]

Asynchronous call improvements:

  • Changed calls to _webViewManager.PingReadyUntilSuccessful() in both InjectIframe and OnPageLoaded to use discard assignment (_ = ...), clarifying that the result is intentionally ignored and improving code clarity. (SDK/Runtime/EmbeddedWallet/BrowserDomIframeHandler.cs, SDK/Runtime/EmbeddedWallet/WebviewHandler.cs) [1] [2]

Generic SendRequest - less code duplication
Proper disposal
Cancellation token handling
void Task -> Task as void is an antipattern that swallows exceptions.
Format changes
@lucasloisp lucasloisp changed the title WebViewManager/Handler improvements refactor: WebViewManager/Handler improvements Mar 13, 2026
//Wallet Methods
//TBD
internal async Task<IframeResponse> CreateEthereumWallet(string accessToken, string solanaAddress = null)
public void Dispose()
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should cancel in-flight requests first (the ones in _requestResponseMap) and only dispose disposeCts after.

Task.Delay in each request is linked to the _disposeCts so that should go first.

@andreydobrikov andreydobrikov merged commit f9c45fe into main Mar 13, 2026
4 checks passed
@andreydobrikov andreydobrikov deleted the feature/webviewmanager-refactror branch March 13, 2026 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants