-
Notifications
You must be signed in to change notification settings - Fork 46
Add Capacitor session example #2355
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| scarb 2.9.4 | ||
| starknet-foundry 0.38.3 | ||
| nodejs v20.11.1 | ||
| nodejs 22.22.0 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| # Cartridge + Capacitor Session Example | ||
|
|
||
| This example shows how to create and use a Controller session inside a | ||
| Capacitor app. It uses the web session provider and opens the authorization | ||
| URL in the system browser on native platforms. | ||
|
|
||
| ## Setup | ||
|
|
||
| From the repo root: | ||
|
|
||
| ```bash | ||
| pnpm install | ||
| ``` | ||
|
|
||
| Run the web version: | ||
|
|
||
| ```bash | ||
| pnpm -C examples/capacitor dev | ||
| ``` | ||
|
|
||
| Build for Capacitor: | ||
|
|
||
| ```bash | ||
| pnpm -C examples/capacitor build | ||
| ``` | ||
|
|
||
| Initialize native projects (first time): | ||
|
|
||
| ```bash | ||
| pnpm -C examples/capacitor exec -- cap add ios | ||
| pnpm -C examples/capacitor exec -- cap add android | ||
| ``` | ||
|
|
||
| Sync updates after builds: | ||
|
|
||
| ```bash | ||
| pnpm -C examples/capacitor exec -- cap sync | ||
| ``` | ||
|
|
||
| ## Live reload on device | ||
|
|
||
| The Capacitor CLI expects the dev server on port 3000 by default. This example | ||
| configures Vite to use port 3000, so just run: | ||
|
|
||
| ```bash | ||
| pnpm -C examples/capacitor dev | ||
| pnpm -C examples/capacitor exec -- cap run ios -l --external | ||
| ``` | ||
|
|
||
| ## Deep link setup (required for session redirect) | ||
|
|
||
| The session flow redirects back to the app using the custom scheme | ||
| `cartridge-session://session`. | ||
|
|
||
| ### iOS | ||
|
|
||
| 1. Open the iOS project: `pnpm -C examples/capacitor exec -- cap open ios` | ||
| 2. In Xcode, select the App target → **Info** → **URL Types** | ||
| 3. Add a new URL type with **URL Schemes** set to `cartridge-session` | ||
|
|
||
| ### Android | ||
|
|
||
| Add an intent filter for the custom scheme in | ||
| `android/app/src/main/AndroidManifest.xml`: | ||
|
|
||
| ```xml | ||
| <intent-filter> | ||
| <action android:name=\"android.intent.action.VIEW\" /> | ||
| <category android:name=\"android.intent.category.DEFAULT\" /> | ||
| <category android:name=\"android.intent.category.BROWSABLE\" /> | ||
| <data android:scheme=\"cartridge-session\" android:host=\"session\" /> | ||
| </intent-filter> | ||
| ``` | ||
|
|
||
| ## Notes | ||
|
|
||
| - The provider opens the session URL with `window.open`. In native builds we | ||
| intercept it with `@capacitor/browser` to ensure the system browser opens. | ||
| - After authorizing the session in the browser, return to the app to complete | ||
| the flow. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import { CapacitorConfig } from "@capacitor/cli"; | ||
|
|
||
| const config: CapacitorConfig = { | ||
| appId: "gg.cartridge.controller.capacitor", | ||
| appName: "Cartridge Session", | ||
| webDir: "dist", | ||
| }; | ||
|
|
||
| export default config; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| <!doctype html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <title>Cartridge Session + Capacitor</title> | ||
| <style> | ||
| :root { | ||
| font-family: "SF Mono", Menlo, Consolas, "Liberation Mono", monospace; | ||
| color: #101827; | ||
| background: #f6f7fb; | ||
| } | ||
| body { | ||
| margin: 0; | ||
| padding: 32px; | ||
| } | ||
| .card { | ||
| max-width: 720px; | ||
| background: #fff; | ||
| border-radius: 16px; | ||
| padding: 24px; | ||
| box-shadow: 0 10px 30px rgba(16, 24, 39, 0.08); | ||
| } | ||
| h1 { | ||
| margin: 0 0 12px 0; | ||
| font-size: 22px; | ||
| } | ||
| p { | ||
| margin: 0 0 16px 0; | ||
| color: #4b5563; | ||
| line-height: 1.5; | ||
| } | ||
| button { | ||
| border: 0; | ||
| border-radius: 10px; | ||
| padding: 12px 16px; | ||
| font-weight: 600; | ||
| cursor: pointer; | ||
| margin-right: 10px; | ||
| } | ||
| #connect { | ||
| background: #2563eb; | ||
| color: white; | ||
| } | ||
| #execute { | ||
| background: #10b981; | ||
| color: white; | ||
| } | ||
| #status { | ||
| margin-top: 16px; | ||
| padding: 12px; | ||
| border-radius: 10px; | ||
| background: #f3f4f6; | ||
| font-size: 13px; | ||
| white-space: pre-wrap; | ||
| } | ||
| .hint { | ||
| font-size: 12px; | ||
| color: #6b7280; | ||
| } | ||
| </style> | ||
| </head> | ||
| <body> | ||
| <div class="card"> | ||
| <h1>Capacitor Session Example</h1> | ||
| <p> | ||
| Registers a Controller session and uses it to submit a test transfer on | ||
| Sepolia. | ||
| </p> | ||
| <button id="connect">Connect Session</button> | ||
| <button id="execute" disabled>Execute Transfer</button> | ||
| <div id="status">Idle</div> | ||
| <p class="hint"> | ||
| On mobile, a browser window will open for authorization. After approval, | ||
| return to the app to continue. | ||
| </p> | ||
| </div> | ||
| <script type="module" src="/src/main.ts"></script> | ||
| </body> | ||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| App/build | ||
| App/Pods | ||
| App/output | ||
| App/App/public | ||
| DerivedData | ||
| xcuserdata | ||
|
|
||
| # Cordova plugins for Capacitor | ||
| capacitor-cordova-ios-plugins | ||
|
|
||
| # Generated Config files | ||
| App/App/capacitor.config.json | ||
| App/App/config.xml |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This version works fine too, I'll update our ci/vercel in another PR