Skip to content

Conversation

@joaquim-verges
Copy link
Member

@joaquim-verges joaquim-verges commented May 20, 2025

Fixed TOOL-4529

Summary

  • add allowedSmsCountryCodes option for in-app and ecosystem wallets
  • filter the country selector to only show those countries
  • include tests for the new behaviour

Testing

  • pnpm test (fails: connect EHOSTUNREACH)

PR-Codex overview

This PR introduces a new feature to limit selectable countries for SMS login by adding an allowedSmsCountryCodes option. This allows customization of the country codes displayed in the country selector.

Detailed summary

  • Added allowedSmsCountryCodes option to limit selectable countries for SMS login.
  • Updated ConnectWalletSocialOptions.tsx to utilize allowedSmsCountryCodes.
  • Modified CountrySelector.tsx to filter supported countries based on allowedCountryCodes.
  • Enhanced InputSelectionUI.test.tsx to test filtering based on allowedSmsCountryCodes.
  • Adjusted InputSelectionUI.tsx to initialize country code based on allowedSmsCountryCodes.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Summary by CodeRabbit

  • New Features

    • Added the ability to restrict selectable countries during SMS-based login by specifying allowed country codes.
    • The country selection dropdown now only displays countries from the allowed list, if provided.
  • Tests

    • Added tests to verify that the country selector correctly filters options based on allowed country codes.

@joaquim-verges joaquim-verges requested a review from a team as a code owner May 20, 2025 03:24
@joaquim-verges joaquim-verges requested a review from a team as a code owner May 20, 2025 03:24
@changeset-bot
Copy link

changeset-bot bot commented May 20, 2025

🦋 Changeset detected

Latest commit: 0f4fa25

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
thirdweb Patch
@thirdweb-dev/wagmi-adapter Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented May 20, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 22, 2025 5:12am
login ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 22, 2025 5:12am
thirdweb_playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 22, 2025 5:12am
thirdweb-www ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 22, 2025 5:12am
wallet-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 22, 2025 5:12am

@graphite-app
Copy link
Contributor

graphite-app bot commented May 20, 2025

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • merge-queue - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

@github-actions github-actions bot added packages SDK Involves changes to the thirdweb SDK labels May 20, 2025
@joaquim-verges joaquim-verges changed the title Implement allowedSmsCountryCodes option [SDK] Implement allowedSmsCountryCodes option May 20, 2025
@linear
Copy link

linear bot commented May 20, 2025

@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 20, 2025

"""

Walkthrough

This update introduces a new configuration option, allowedSmsCountryCodes, to restrict which countries appear in the SMS login country selector. The change spans type definitions, UI components, and tests, ensuring that only specified countries are selectable for SMS-based authentication. No breaking changes or removals are included.

Changes

File(s) Change Summary
.changeset/limited-country-dropdown.md Documents the addition of the allowedSmsCountryCodes option for SMS login country selection.
packages/thirdweb/src/react/web/wallets/in-app/CountrySelector.tsx Adds allowedCountryCodes prop; filters country list in the selector based on this prop if provided.
packages/thirdweb/src/react/web/wallets/in-app/InputSelectionUI.tsx Adds allowedSmsCountryCodes prop; initializes selection and passes allowed codes to CountrySelector.
packages/thirdweb/src/react/web/wallets/shared/ConnectWalletSocialOptions.tsx Passes allowedSmsCountryCodes from wallet config to InputSelectionUI when rendering phone login input.
packages/thirdweb/src/wallets/ecosystem/types.ts Adds optional allowedSmsCountryCodes property to the auth object in EcosystemWalletCreationOptions type.
packages/thirdweb/src/wallets/in-app/core/wallet/types.ts Adds optional allowedSmsCountryCodes property to the auth object in InAppWalletCreationOptions type.
packages/thirdweb/src/react/web/wallets/in-app/InputSelectionUI.test.tsx Adds a test verifying the country selector filters options based on allowedSmsCountryCodes.

Sequence Diagram(s)

sequenceDiagram
    participant App
    participant WalletConfig
    participant InputSelectionUI
    participant CountrySelector

    App->>WalletConfig: Get auth config (with allowedSmsCountryCodes)
    App->>InputSelectionUI: Render with allowedSmsCountryCodes prop
    InputSelectionUI->>CountrySelector: Pass allowedCountryCodes prop
    CountrySelector->>CountrySelector: Filter country list by allowedCountryCodes
    CountrySelector-->>InputSelectionUI: Render filtered selector
Loading

Assessment against linked issues

Objective Addressed Explanation
Add allowedCountryCodes flag to restrict countries shown in phone login country selector (TOOL-4529)
Ensure allowedCountryCodes works alongside defaultSmsCountryCode without breaking existing logic
Provide ability to configure allowed countries via wallet config and pass to UI components
"""

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9a2e664 and 0f4fa25.

📒 Files selected for processing (1)
  • packages/thirdweb/src/react/web/wallets/in-app/CountrySelector.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/thirdweb/src/react/web/wallets/in-app/CountrySelector.tsx
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: E2E Tests (pnpm, esbuild)
  • GitHub Check: E2E Tests (pnpm, webpack)
  • GitHub Check: Unit Tests
  • GitHub Check: Build Packages
  • GitHub Check: E2E Tests (pnpm, vite)
  • GitHub Check: Size
  • GitHub Check: Lint Packages
  • GitHub Check: Analyze (javascript)
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (1)
packages/thirdweb/src/react/web/wallets/in-app/InputSelectionUI.tsx (1)

32-34: Improved validation needed for allowedSmsCountryCodes first element.

While the current implementation checks if allowedSmsCountryCodes exists and is non-empty, it doesn't validate that the first element is a valid SupportedSmsCountry before passing it to getCountrySelector.

Although getCountrySelector has a fallback to "US +1" if the country is not found, it would be better to add explicit validation:

-      : props.allowedSmsCountryCodes && props.allowedSmsCountryCodes.length > 0
-        ? getCountrySelector(props.allowedSmsCountryCodes[0])
+      : props.allowedSmsCountryCodes?.length > 0 && props.allowedSmsCountryCodes[0]
+        ? getCountrySelector(props.allowedSmsCountryCodes[0])
         : "US +1",

This suggestion is based on a previous review comment by graphite-app[bot] and would ensure robust handling of potentially invalid input.

🧹 Nitpick comments (1)
packages/thirdweb/src/react/web/wallets/in-app/CountrySelector.tsx (1)

32-43: Implementation looks good!

The filtering logic correctly handles the allowedCountryCodes prop to show only allowed countries when specified. The fallback to all countries (or US as a last resort) maintains backward compatibility.

A minor readability suggestion:

Consider refactoring the nested ternary expression to a more explicit if-else structure for improved readability:

-  const supportedCountriesForSms =
-    allowedCountryCodes && allowedCountryCodes.length > 0
-      ? supportedSmsCountries.filter((c) =>
-          allowedCountryCodes.includes(c.countryIsoCode as SupportedSmsCountry),
-        )
-      : supportedSmsCountries ?? [
-          {
-            countryIsoCode: "US",
-            countryName: "United States",
-            phoneNumberCode: 1,
-          },
-        ];
+  let supportedCountriesForSms;
+  if (allowedCountryCodes && allowedCountryCodes.length > 0) {
+    supportedCountriesForSms = supportedSmsCountries.filter((c) =>
+      allowedCountryCodes.includes(c.countryIsoCode as SupportedSmsCountry)
+    );
+  } else {
+    supportedCountriesForSms = supportedSmsCountries ?? [
+      {
+        countryIsoCode: "US",
+        countryName: "United States",
+        phoneNumberCode: 1,
+      },
+    ];
+  }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between a3072c4 and 9fb9635.

📒 Files selected for processing (7)
  • .changeset/limited-country-dropdown.md (1 hunks)
  • packages/thirdweb/src/react/web/wallets/in-app/CountrySelector.tsx (1 hunks)
  • packages/thirdweb/src/react/web/wallets/in-app/InputSelectionUI.test.tsx (1 hunks)
  • packages/thirdweb/src/react/web/wallets/in-app/InputSelectionUI.tsx (2 hunks)
  • packages/thirdweb/src/react/web/wallets/shared/ConnectWalletSocialOptions.tsx (1 hunks)
  • packages/thirdweb/src/wallets/ecosystem/types.ts (1 hunks)
  • packages/thirdweb/src/wallets/in-app/core/wallet/types.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/thirdweb/src/react/web/wallets/in-app/InputSelectionUI.tsx (1)
packages/thirdweb/src/react/web/wallets/in-app/CountrySelector.tsx (1)
  • getCountrySelector (11-19)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: E2E Tests (pnpm, esbuild)
  • GitHub Check: Lint Packages
  • GitHub Check: E2E Tests (pnpm, vite)
  • GitHub Check: Build Packages
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (6)
.changeset/limited-country-dropdown.md (1)

1-5: LGTM - Well-structured changeset!

The changeset properly documents the new feature that allows limiting selectable countries for SMS login using the allowedSmsCountryCodes option, clearly indicating it works alongside the existing defaultSmsCountryCode option.

packages/thirdweb/src/react/web/wallets/shared/ConnectWalletSocialOptions.tsx (1)

454-456: LGTM - Properly implemented new feature!

The implementation correctly passes the allowedSmsCountryCodes configuration from the wallet to the InputSelectionUI component, following the same pattern as the existing defaultSmsCountryCode prop.

packages/thirdweb/src/wallets/ecosystem/types.ts (1)

22-26: LGTM - Well-documented type addition!

The addition of the allowedSmsCountryCodes property to the EcosystemWalletCreationOptions type is well-placed and includes clear JSDoc documentation explaining its purpose. The type SupportedSmsCountry[] is appropriate for this use case.

packages/thirdweb/src/wallets/in-app/core/wallet/types.ts (1)

86-90: LGTM - Consistent type implementation!

The addition of the allowedSmsCountryCodes property to the InAppWalletCreationOptions type maintains consistency with the ecosystem wallet implementation. The property is properly typed and documented with clear JSDoc comments.

packages/thirdweb/src/react/web/wallets/in-app/InputSelectionUI.test.tsx (1)

46-67: Well-structured test for the new feature!

The test correctly verifies that the country selector filters options based on the allowedSmsCountryCodes prop, checking both the inclusion of allowed countries (India, Brazil) and the exclusion of non-allowed countries (United States).

packages/thirdweb/src/react/web/wallets/in-app/InputSelectionUI.tsx (1)

75-75: LGTM! Properly passing allowedSmsCountryCodes to CountrySelector.

The component correctly passes the allowedSmsCountryCodes prop to the CountrySelector component as allowedCountryCodes, ensuring the filtering behavior is applied throughout the component hierarchy.

@github-actions
Copy link
Contributor

github-actions bot commented May 22, 2025

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
thirdweb (esm) 56.64 KB (0%) 1.2 s (0%) 171 ms (+137.16% 🔺) 1.4 s
thirdweb (cjs) 309.36 KB (0%) 6.2 s (0%) 560 ms (+4.37% 🔺) 6.8 s
thirdweb (minimal + tree-shaking) 5.69 KB (0%) 114 ms (0%) 56 ms (+1128.3% 🔺) 170 ms
thirdweb/chains (tree-shaking) 531 B (0%) 11 ms (0%) 17 ms (+862.75% 🔺) 27 ms
thirdweb/react (minimal + tree-shaking) 19.5 KB (0%) 390 ms (0%) 69 ms (+438.45% 🔺) 459 ms

@codecov
Copy link

codecov bot commented May 22, 2025

Codecov Report

Attention: Patch coverage is 57.14286% with 9 lines in your changes missing coverage. Please review.

Project coverage is 55.63%. Comparing base (6104401) to head (0f4fa25).
Report is 31 commits behind head on main.

Files with missing lines Patch % Lines
...b/src/react/web/wallets/in-app/CountrySelector.tsx 46.15% 7 Missing ⚠️
.../web/wallets/shared/ConnectWalletSocialOptions.tsx 0.00% 2 Missing ⚠️

❌ Your patch status has failed because the patch coverage (57.14%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7090      +/-   ##
==========================================
- Coverage   55.81%   55.63%   -0.18%     
==========================================
  Files         900      902       +2     
  Lines       57848    58148     +300     
  Branches     4067     4094      +27     
==========================================
+ Hits        32288    32353      +65     
- Misses      25454    25690     +236     
+ Partials      106      105       -1     
Flag Coverage Δ
packages 55.63% <57.14%> (-0.18%) ⬇️
Files with missing lines Coverage Δ
.../src/react/web/wallets/in-app/InputSelectionUI.tsx 63.96% <100.00%> (+1.69%) ⬆️
.../web/wallets/shared/ConnectWalletSocialOptions.tsx 35.61% <0.00%> (-0.17%) ⬇️
...b/src/react/web/wallets/in-app/CountrySelector.tsx 90.19% <46.15%> (+0.61%) ⬆️

... and 24 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

codex packages SDK Involves changes to the thirdweb SDK

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants