feat: support ?address= URL param for send-to-address deep linking#17
Conversation
Infer network from bech32m address prefix (tdash/dash) and pre-fill the send-to-platform-address screen, enabling shareable direct links. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
📝 WalkthroughWalkthroughThe PR enhances src/main.ts initialization logic to support URL-based deep-linking. It adds network inference from a bech32m-encoded address parameter (?address) that checks against MAINNET and TESTNET platform HRPs, and automatically switches the app to the appropriate network while pre-populating the send-to-address flow when a valid address is provided. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/main.ts (1)
128-132: Optional: avoid double bech32m decode in init flow.Line 115 decodes once for inference, then Line 129 calls
validatePlatformAddress(...), which decodes again. Caching a validated deep-link value ininit()would reduce duplication and keep the deep-link path single-pass.♻️ Proposed refactor
- const addressParam = urlParams.get('address')?.trim(); + const addressParam = urlParams.get('address')?.trim(); + let deepLinkAddress: string | undefined; if (addressParam) { try { const decoded = bech32m.decode(addressParam as `${string}1${string}`); if (decoded.prefix === MAINNET.platformHrp) network = 'mainnet'; else if (decoded.prefix === TESTNET.platformHrp) network = 'testnet'; + if (decoded.prefix === getNetwork(network).platformHrp) { + deepLinkAddress = addressParam; + } } catch { // Invalid address — will be ignored below } } @@ - if (addressParam && validatePlatformAddress(addressParam, network)) { + if (deepLinkAddress) { state = setMode(state, 'send_to_address'); - state = setRecipientPlatformAddress(state, addressParam); + state = setRecipientPlatformAddress(state, deepLinkAddress); }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/main.ts` around lines 128 - 132, The init flow currently decodes the bech32m deep-link twice (once earlier for inference and again via validatePlatformAddress(addressParam, network)); to avoid duplicate decoding, decode/validate the deep-link once in init() and cache the result (e.g., let decodedAddress or validatedAddress) and use that cached value for both the inference logic and when calling setMode/state updates; update the conditional to check the cached validation result instead of calling validatePlatformAddress a second time and pass the cached/decoded address to setRecipientPlatformAddress so the deep-link path is single-pass (refer to symbols addressParam, init(), validatePlatformAddress, setMode, setRecipientPlatformAddress).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/main.ts`:
- Around line 128-132: The init flow currently decodes the bech32m deep-link
twice (once earlier for inference and again via
validatePlatformAddress(addressParam, network)); to avoid duplicate decoding,
decode/validate the deep-link once in init() and cache the result (e.g., let
decodedAddress or validatedAddress) and use that cached value for both the
inference logic and when calling setMode/state updates; update the conditional
to check the cached validation result instead of calling validatePlatformAddress
a second time and pass the cached/decoded address to setRecipientPlatformAddress
so the deep-link path is single-pass (refer to symbols addressParam, init(),
validatePlatformAddress, setMode, setRecipientPlatformAddress).
thephez
left a comment
There was a problem hiding this comment.
Not sure address is the best name for the param?
Summary
Adds support for a
?address=URL query parameter that deep-links directly into the "Send to Platform Address" screen with the recipient address pre-filled. The correct network (testnet/mainnet) is automatically inferred from the bech32m address prefix (tdashvsdash), so no separate?network=param is needed.Highlights:
?address=<bech32m>ininit()and auto-navigate to send-to-address mode with the address pre-populatedtdash1...→ testnet,dash1...→ mainnet), falling back to the existing?network=paramExample URLs
https://bridge.example.com/?address=tdash1qqqqqxs856en8
https://bridge.example.com/?address=dash1qqqqqxs856en8
Summary by CodeRabbit