Skip to content

refactor: centralize platform sdk connections#23

Merged
PastaPastaPasta merged 1 commit into
mainfrom
codex/centralize-platform-connections
May 17, 2026
Merged

refactor: centralize platform sdk connections#23
PastaPastaPasta merged 1 commit into
mainfrom
codex/centralize-platform-connections

Conversation

@PastaPastaPasta
Copy link
Copy Markdown
Member

@PastaPastaPasta PastaPastaPasta commented Apr 16, 2026

Summary

  • centralize trusted EvoSDK creation, shared settings, connect-with-retry, and Platform read helpers in src/platform/client.ts
  • route identity, DPNS, contract, and UI-side balance reads through the new Platform service without changing feature-level APIs

Testing

  • npm run build

This pull request was created by Codex.

Summary by CodeRabbit

Release Notes

  • New Features

    • Added automatic retry and client-side operation timeout protection for platform interactions.
  • Refactor

    • Centralized platform SDK connection management to improve consistency and reliability across identity, contract, and DPNS operations.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 16, 2026

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

This PR introduces a new src/platform/client.ts module that centralizes Dash Platform SDK connection, timeout enforcement, and retry handling. Five modules are then refactored to route through these shared helpers—contract.ts, dpns.ts, identity.ts, and main entry points—replacing scattered direct SDK instantiation with declarative, reusable patterns.

Changes

Platform SDK Client Centralization

Layer / File(s) Summary
Platform Client Foundation: Types, Factory, and Connection Management
src/platform/client.ts
Introduces PlatformNetwork type, PlatformIdentityKeyRecord interface, and PLATFORM_PUT_SETTINGS constant. Implements SDK factory logic selecting EvoSDK.mainnetTrusted or testnetTrusted by network; connectPlatformSdk connects with logging and retry; withConnectedPlatformSdk wraps callbacks with auto-connected SDK; withPlatformOperationTimeout enforces timeouts via Promise.race with cleanup.
Platform Client Helpers: Identity and Key Fetching
src/platform/client.ts
Exports paired helpers for identity retrieval (fetchIdentityWithSdk / fetchIdentity), balance/revision queries (getIdentityBalanceAndRevisionWithSdk / getIdentityBalanceAndRevision) with numeric coercion and 0 defaults, and public key record fetching (fetchIdentityPublicKeyRecordsWithSdk / fetchIdentityPublicKeyRecords) with validation and normalization.
Contract Publishing Refactor
src/platform/contract.ts
Updates publishContract to use withConnectedPlatformSdk and fetchIdentityWithSdk for SDK access and identity loading, replacing manual EvoSDK instantiation and sdk.identities.fetch calls while preserving contract creation and publish logic.
DPNS Operations Refactor
src/platform/dpns.ts
Refactors getIdentityPublicKeys to use fetchIdentityPublicKeyRecords with key field type conversions and hex/base64 data decoding; updates checkUsernameAvailability and checkMultipleAvailability to use withConnectedPlatformSdk for SDK access; rewrites registerDpnsName to delegate connection and identity retrieval through new helpers while keeping signer setup and return shapes unchanged.
Identity Operations Refactor
src/platform/identity.ts
Consolidates registerIdentity, topUpIdentity, updateIdentity, and sendToPlatformAddress to use withConnectedPlatformSdk, fetchIdentityWithSdk, getIdentityBalanceAndRevisionWithSdk, and withPlatformOperationTimeout instead of local SDK instantiation and helpers, while preserving key material formatting, error extraction, and validation logic. Adds stricter validation of fundFromAssetLock result shapes.
Main Contract Entry Points Integration
src/main.ts
Updates contract key upload and existing-identity lookup handlers to obtain identity balance via getIdentityBalanceAndRevision helper, treating balance as best-effort and continuing to fetch public keys if balance lookup fails.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • PastaPastaPasta/dash-bridge#21: Both PRs refactor src/platform/identity.ts identity operations to use centralized SDK connection and timeout handling instead of direct EvoSDK.*Trusted() instantiation.
  • PastaPastaPasta/dash-bridge#15: This PR's refactoring of sendToPlatformAddress in src/platform/identity.ts builds directly on the earlier introduction of that function, adding shared client helper usage and stricter result validation.

Poem

🐰 A rabbit hops through scattered SDK calls,
Gathers them into one cozy client hall,
Now connection, retry, and timeouts align,
Shared helpers spring forth—a refactor divine! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 47.62% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'refactor: centralize platform sdk connections' clearly and specifically describes the main change: centralizing Platform SDK connection logic into a shared module.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/centralize-platform-connections

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@PastaPastaPasta PastaPastaPasta force-pushed the codex/centralize-platform-connections branch from a645988 to 377b225 Compare May 17, 2026 20:24
@PastaPastaPasta PastaPastaPasta merged commit 26ddc07 into main May 17, 2026
2 of 3 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request May 17, 2026
8 tasks
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.

1 participant