Skip to content

Improve adapter - #693

Merged
feruzm merged 3 commits into
developfrom
adapter
Mar 5, 2026
Merged

Improve adapter#693
feruzm merged 3 commits into
developfrom
adapter

Conversation

@feruzm

@feruzmferuzm commented Mar 5, 2026

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • New Features
    • Broadcasts can now fall back to platform HiveSigner signing even when no access token is present, improving success for token-less flows.
    • Direct token-based broadcasts will attempt a HiveSigner fallback on auth failures, increasing reliability across environments.
    • Prefetch logic now only retrieves/stores tokens when available, reducing false failure states and enabling cleaner fallbacks.

@coderabbitai

coderabbitaiBot commented Mar 5, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 75d6ffe4-d113-4076-8495-557dd8c71b68

📥 Commits

Reviewing files that changed from the base of the PR and between aad698c and 03650f4.

📒 Files selected for processing (4)
  • packages/sdk/CHANGELOG.md
  • packages/sdk/package.json
  • packages/wallets/CHANGELOG.md
  • packages/wallets/package.json
✅ Files skipped from review due to trivial changes (3)
  • packages/wallets/package.json
  • packages/sdk/CHANGELOG.md
  • packages/wallets/CHANGELOG.md

📝 Walkthrough

Walkthrough

Allows broadcasts to try a direct API broadcast with a provided or prefetched access token first; if no token or the token-based broadcast fails with an auth-related error, the flow may fall back to an adapter-provided broadcastWithHiveSigner method. PlatformAdapter gains an optional HiveSigner method.

Changes

Cohort / File(s)Summary
HiveSigner fallback broadcasting
packages/sdk/src/modules/core/mutations/use-broadcast-mutation.ts
Reworked broadcast flow to: attempt direct API broadcast using a provided or prefetched token; on missing token or auth-related token failure, conditionally call adapter.broadcastWithHiveSigner when supported. Prefetch logic no longer treats missing token as a failure.
Platform adapter interface
packages/sdk/src/modules/core/types/platform-adapter.ts
Added optional `broadcastWithHiveSigner?: (username: string, ops: Operation[], keyType: "posting"
Version and changelogs
packages/sdk/CHANGELOG.md, packages/sdk/package.json, packages/wallets/CHANGELOG.md, packages/wallets/package.json
Bumped SDK and wallets package versions and added changelog entries for the patch release (2.0.22 / 1.5.50).

Sequence Diagram

sequenceDiagram
participant Client
participant Broadcast as Broadcast Mutation
participant API as Direct API
participant Adapter as Platform Adapter
participant HS as HiveSigner
Client->>Broadcast: broadcastTransaction(ops, keyType)
alt Token present or prefetched
Broadcast->>API: attemptDirectBroadcast(token, ops)
alt Direct broadcast succeeds
API-->>Broadcast: TransactionConfirmation
Broadcast-->>Client: Success
else Direct broadcast fails (auth)
API--XBroadcast: Auth Error
alt Adapter supports HiveSigner
Broadcast->>Adapter: broadcastWithHiveSigner(username, ops, keyType)
Adapter->>HS: open HiveSigner UI
HS-->>Adapter: TransactionConfirmation
Adapter-->>Broadcast: TransactionConfirmation
Broadcast-->>Client: Success
end
end
else No token available
alt Adapter supports HiveSigner
Broadcast->>Adapter: broadcastWithHiveSigner(username, ops, keyType)
Adapter->>HS: open HiveSigner UI
HS-->>Adapter: TransactionConfirmation
Adapter-->>Broadcast: TransactionConfirmation
Broadcast-->>Client: Success
end
end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • SDK error catching #660 — modifies SDK broadcast/auth flow and PlatformAdapter surface for HiveSigner/login, closely related to these changes.

Suggested labels

patch:sdk

Poem

🐰 I hopped through code with twitching whiskers,

Token tried, then slipped like slippery lickers.
HiveSigner smiled and opened the gate,
Signed the ops and saved the state.
Hop! Transaction — confirmed and great.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check nameStatusExplanationResolution
Title check❓ InconclusiveThe title 'Improve adapter' is vague and generic, using non-descriptive language that doesn't clearly convey what specific aspect of the adapter was improved.Consider using a more specific title that highlights the main improvement, such as 'Add HiveSigner fallback support to broadcast mutation' or 'Support token-less HiveSigner authentication in adapter'.
✅ Passed checks (2 passed)
Check nameStatusExplanation
Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage✅ PassedDocstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch adapter

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.

coderabbitai[bot]

This comment was marked as resolved.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
packages/sdk/src/modules/core/mutations/use-broadcast-mutation.ts (1)

370-377: Minor inefficiency: redundant token fetch when token is unavailable.

When getAccessToken returns null/undefined, prefetchedToken remains undefined. In broadcastWithMethod (line 105-107), fetchedToken !== undefined causes a second call to getAccessToken.

Consider storing the result unconditionally to signal "already checked":

♻️ Suggested fix to avoid redundant fetch
 // Pre-fetch token if available (will be reused in broadcast)
const token = await adapter.getAccessToken(username);
- if (token) {- prefetchedToken = token; // Store for reuse- }+ prefetchedToken = token ?? null; // Store result (including null) to avoid re-fetch
// When no token but adapter exists, don't skip —
// broadcastWithMethod can fall back to adapter.broadcastWithHiveSigner
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@packages/sdk/src/modules/core/mutations/use-broadcast-mutation.ts` around
lines 370 - 377, The current flow redundantly calls adapter.getAccessToken again
in broadcastWithMethod when the initial check returned null/undefined because
prefetchedToken is only set when a token exists; instead always assign the
result of adapter.getAccessToken(username) to prefetchedToken (even if null) in
the pre-fetch block so broadcastWithMethod can inspect prefetchedToken to know
the adapter has already been queried; update the logic around prefetchedToken
and the pre-fetching code that calls adapter.getAccessToken to store the result
unconditionally (references: adapter.getAccessToken, prefetchedToken,
broadcastWithMethod).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/sdk/src/modules/core/mutations/use-broadcast-mutation.ts`:
- Around line 370-377: The current flow redundantly calls adapter.getAccessToken
again in broadcastWithMethod when the initial check returned null/undefined
because prefetchedToken is only set when a token exists; instead always assign
the result of adapter.getAccessToken(username) to prefetchedToken (even if null)
in the pre-fetch block so broadcastWithMethod can inspect prefetchedToken to
know the adapter has already been queried; update the logic around
prefetchedToken and the pre-fetching code that calls adapter.getAccessToken to
store the result unconditionally (references: adapter.getAccessToken,
prefetchedToken, broadcastWithMethod).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 18b8392b-65a9-41f0-aaa3-748150b10cfe

📥 Commits

Reviewing files that changed from the base of the PR and between 045e755 and aad698c.

⛔ Files ignored due to path filters (6)
  • packages/sdk/dist/browser/index.js is excluded by !**/dist/**
  • packages/sdk/dist/browser/index.js.map is excluded by !**/dist/**, !**/*.map
  • packages/sdk/dist/node/index.cjs is excluded by !**/dist/**
  • packages/sdk/dist/node/index.cjs.map is excluded by !**/dist/**, !**/*.map
  • packages/sdk/dist/node/index.mjs is excluded by !**/dist/**
  • packages/sdk/dist/node/index.mjs.map is excluded by !**/dist/**, !**/*.map
📒 Files selected for processing (1)
  • packages/sdk/src/modules/core/mutations/use-broadcast-mutation.ts

@feruzmferuzm added patch Bug fixes and patches (1.0.0 → 1.0.1) and removed patch Bug fixes and patches (1.0.0 → 1.0.1) labels Mar 5, 2026
@feruzm
feruzm marked this pull request as draft March 5, 2026 17:39
@feruzm
feruzm marked this pull request as ready for review March 5, 2026 17:40
@feruzmferuzm added patch Bug fixes and patches (1.0.0 → 1.0.1) and removed patch Bug fixes and patches (1.0.0 → 1.0.1) labels Mar 5, 2026
@feruzm
feruzm merged commit 3639e1a into developMar 5, 2026
1 check passed
github-actionsBot added a commit that referenced this pull request Mar 5, 2026
github-actionsBot added a commit that referenced this pull request Mar 5, 2026
Sign up for freeto 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

@feruzm