-
Notifications
You must be signed in to change notification settings - Fork 1.6k
feat: appkit pay test exchange #4699
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
24 commits
Select commit
Hold shift + click to select a range
e25181b
chore: init test exchange project
lukaisailovic 3917075
chore: next setup
lukaisailovic da559d1
chore: migrate to tailwind v3
lukaisailovic 3e76798
chore: add screens
lukaisailovic a070264
chore: session creation
lukaisailovic cf74a53
chore: copy
lukaisailovic 97d9cc1
chore: add action screens
lukaisailovic 47d75e2
chore: update error copy
lukaisailovic d5b9340
chore: success txid
lukaisailovic 921cea0
chore: payment info
lukaisailovic f4ac372
fix: format
lukaisailovic 632b001
fix: format
lukaisailovic 58dd57e
fix: prettier
lukaisailovic 032ea6e
fix: build
lukaisailovic efa8273
Merge branch 'main' into feat/appkit-pay-test-exchange
lukaisailovic 837852b
fix: pnpm-lock
lukaisailovic 15c3f88
chore: remove comments
lukaisailovic c59da92
chore: provide real txid
lukaisailovic 20d41b1
fix: lint
lukaisailovic 52683d6
fix: lint
lukaisailovic 7613a93
fix: danger
lukaisailovic 4439a64
chore: readme
lukaisailovic 5ca6c7b
Merge branch 'main' into feat/appkit-pay-test-exchange
lukaisailovic 0d1a920
chore: update lockfile
lukaisailovic 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
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,43 @@ | ||
| # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
|
||
| # dependencies | ||
| /node_modules | ||
| /.pnp | ||
| .pnp.js | ||
| .yarn/install-state.gz | ||
|
|
||
| # testing | ||
| /coverage | ||
|
|
||
| # next.js | ||
| /.next/ | ||
| /out/ | ||
|
|
||
| # production | ||
| /build | ||
|
|
||
| # misc | ||
| .DS_Store | ||
| *.pem | ||
|
|
||
| # debug | ||
| npm-debug.log* | ||
| yarn-debug.log* | ||
| yarn-error.log* | ||
|
|
||
| # local env files | ||
| .env*.local | ||
|
|
||
| # vercel | ||
| .vercel | ||
|
|
||
| # typescript | ||
| *.tsbuildinfo | ||
| next-env.d.ts | ||
|
|
||
| # OpenNext | ||
| /.open-next | ||
|
|
||
| # wrangler files | ||
| .wrangler | ||
| .dev.vars* |
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,5 @@ | ||
| { | ||
| "files.associations": { | ||
| "wrangler.json": "jsonc" | ||
| } | ||
| } |
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,243 @@ | ||
| # AppKit Pay Test Exchange | ||
|
|
||
| A testing environment for simulating payment exchange interactions with **Reown AppKit Pay**. This application provides a controlled environment to test payment flows, session management, and various payment scenarios during development. | ||
|
|
||
| ## 🎯 Purpose | ||
|
|
||
| The Pay Test Exchange simulates a merchant/exchange interface that receives payment requests from AppKit Pay and allows developers to: | ||
|
|
||
| - Test payment session flows (pending → success/error states) | ||
| - Validate payment parameters (asset, amount, recipient) | ||
| - Simulate both successful and failed payment scenarios | ||
| - Debug payment integration issues in a controlled environment | ||
|
|
||
| ## ✨ Features | ||
|
|
||
| ### 🔄 Session Management | ||
|
|
||
| - **Automatic session creation** with pending status | ||
| - **Status transitions**: pending → success or error | ||
| - **Session validation** via URL parameters | ||
|
|
||
| ### 💳 Payment Information Display | ||
|
|
||
| - **Asset parsing**: Displays chain ID and token standard | ||
| - **Amount visualization**: Shows payment amounts clearly | ||
| - **Recipient validation**: Displays destination addresses | ||
|
|
||
| ### 🧪 Testing Controls | ||
|
|
||
| - **Success simulation**: Mark payments as successful | ||
| - **Error simulation**: Trigger payment failures | ||
| - **Real-time updates**: Immediate session status changes | ||
| - **Navigation handling**: Automatic redirects to result pages | ||
|
|
||
| ## 🚀 Getting Started | ||
|
|
||
| ### Prerequisites | ||
|
|
||
| - Node.js 18+ | ||
| - npm, yarn, pnpm, or bun | ||
| - Access to the Reown AppKit ecosystem | ||
|
|
||
| ### Installation | ||
|
|
||
| 1. **Install dependencies**: | ||
| ```bash | ||
| npm install | ||
| # or | ||
| yarn install | ||
| # or | ||
| pnpm install | ||
| # or | ||
| bun install | ||
| ``` | ||
|
|
||
| ### Development | ||
|
|
||
| 2. **Start the development server**: | ||
|
|
||
| ```bash | ||
| npm run dev | ||
| # or | ||
| yarn dev | ||
| # or | ||
| pnpm dev | ||
| # or | ||
| bun dev | ||
| ``` | ||
|
|
||
| 3. **Open the application**: | ||
| Visit [http://localhost:4001](http://localhost:4001) in your browser | ||
|
|
||
| ### Usage | ||
|
|
||
| #### Basic Payment Test | ||
|
|
||
| 1. **Navigate with session parameters**: | ||
|
|
||
| ``` | ||
| http://localhost:4001?sessionId=your-session-id&asset=eip155:1/erc20:0x123&amount=100&recipient=0xabc123 | ||
| ``` | ||
|
|
||
| 2. **Required parameters**: | ||
|
|
||
| - `sessionId`: Unique identifier for the payment session | ||
|
|
||
| 3. **Optional parameters**: | ||
| - `asset`: Asset identifier (format: `namespace:chainId/standard:address`) | ||
| - `amount`: Payment amount (in token units) | ||
| - `recipient`: Destination wallet address | ||
|
|
||
| #### Testing Payment Flows | ||
|
|
||
| 1. **Success Scenario**: | ||
|
|
||
| - Click "Complete Successfully" button | ||
| - Session status updates to `success` | ||
| - Redirected to success page | ||
|
|
||
| 2. **Error Scenario**: | ||
| - Click "Trigger Error" button | ||
| - Session status updates to `error` | ||
| - Redirected to error page | ||
|
|
||
| ## 🏗️ Architecture | ||
|
|
||
| ### Project Structure | ||
|
|
||
| ``` | ||
| apps/pay-test-exchange/ | ||
| ├── app/ | ||
| │ ├── api/ # API routes for session management | ||
| │ ├── error/ # Error result page | ||
| │ ├── success/ # Success result page | ||
| │ └── page.tsx # Main exchange interface | ||
| ├── components/ | ||
| │ ├── ui/ # Reusable UI components | ||
| │ ├── exchange-actions.tsx # Main control interface | ||
| │ ├── payment-info.tsx # Payment details display | ||
| │ └── error-screen.tsx # Error state component | ||
| ├── lib/ | ||
| │ ├── session-actions.ts # Session management logic | ||
| │ └── types.ts # TypeScript definitions | ||
| └── public/ | ||
| └── reown-logo.png # Branding assets | ||
| ``` | ||
|
|
||
| ### API Endpoints | ||
|
|
||
| - **POST** `/api/update` - Update session status | ||
| - **GET** `/api/status` - Get session status | ||
|
|
||
| ## 🔧 Configuration | ||
|
|
||
| ### Environment Setup | ||
|
|
||
| The application supports multiple deployment environments: | ||
|
|
||
| - **Development**: `npm run dev` (port 4001) | ||
| - **Production**: `npm run build && npm run start` | ||
| - **Cloudflare**: `npm run deploy` | ||
|
|
||
| ### Amount Validation | ||
|
|
||
| Test various amount formats: | ||
|
|
||
| ``` | ||
| - 1000000000000000000 # 1 ETH (18 decimals) | ||
| - 1000000 # 1 USDC (6 decimals) | ||
| - 500000000 # 0.5 SOL (9 decimals) | ||
| ``` | ||
|
|
||
| ### Error Conditions | ||
|
|
||
| Test error scenarios: | ||
|
|
||
| ``` | ||
| - Missing sessionId # Triggers error screen | ||
| - Invalid parameters # Tests parameter validation | ||
| - Network failures # Simulates API issues | ||
| ``` | ||
|
|
||
| ## 🚀 Deployment | ||
|
|
||
| ### Cloudflare Deployment | ||
|
|
||
| 1. **Build for Cloudflare**: | ||
|
|
||
| ```bash | ||
| npm run deploy | ||
| ``` | ||
|
|
||
| 2. **Preview deployment**: | ||
|
|
||
| ```bash | ||
| npm run preview | ||
| ``` | ||
|
|
||
| 3. **Generate Cloudflare types**: | ||
| ```bash | ||
| npm run cf-typegen | ||
| ``` | ||
|
|
||
| ## 🤝 Integration with AppKit Pay | ||
|
|
||
| This test exchange works in conjunction with: | ||
|
|
||
| - **AppKit Pay SDK**: For payment initiation | ||
| - **Payment Controllers**: For transaction handling | ||
| - **Wallet Adapters**: For multi-chain support | ||
| - **Session Management**: For state synchronization | ||
|
|
||
| ## 📋 API Reference | ||
|
|
||
| ### Session Status Updates | ||
|
|
||
| ```typescript | ||
| // Update session status | ||
| POST /api/update?sessionId={id} | ||
| { | ||
| "status": "success" | "error" | "pending" | ||
| } | ||
|
|
||
| // Get session status | ||
| GET /api/status?sessionId={id} | ||
| ``` | ||
|
|
||
| ### Payment Parameters | ||
|
|
||
| ```typescript | ||
| interface PaymentParams { | ||
| sessionId: string // Required: Unique session identifier | ||
| asset?: string // Optional: Asset identifier | ||
| amount?: string // Optional: Payment amount | ||
| recipient?: string // Optional: Destination address | ||
| } | ||
| ``` | ||
|
|
||
| ## 🔍 Troubleshooting | ||
|
|
||
| ### Common Issues | ||
|
|
||
| 1. **Missing sessionId**: Ensure URL includes valid `sessionId` parameter | ||
| 2. **Session not found**: Check session creation in network tab | ||
| 3. **Payment display issues**: Verify asset format and parameters | ||
| 4. **Navigation errors**: Check success/error page routing | ||
|
|
||
| ### Debug Mode | ||
|
|
||
| Enable detailed logging by checking browser console and network requests. | ||
|
|
||
| ## 📄 License | ||
|
|
||
| This project is part of the Reown AppKit ecosystem. See the main repository for license details. | ||
|
|
||
| ## 🆘 Support | ||
|
|
||
| For issues and questions: | ||
|
|
||
| - Check the main AppKit repository | ||
| - Review integration documentation | ||
| - Test with different parameter combinations | ||
| - Verify session management 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,20 @@ | ||
| import { getCloudflareContext } from '@opennextjs/cloudflare' | ||
| import type { NextRequest } from 'next/server' | ||
|
|
||
| export async function GET(request: NextRequest) { | ||
| const { env } = getCloudflareContext() | ||
|
|
||
| const sessionId = request.nextUrl.searchParams.get('sessionId') | ||
|
|
||
| if (!sessionId) { | ||
| return new Response('No sessionId provided', { status: 400 }) | ||
| } | ||
|
|
||
| const session = await env.SESSIONID_STORAGE.get(sessionId) | ||
|
|
||
| if (!session) { | ||
| return new Response('Session not found', { status: 404 }) | ||
| } | ||
|
|
||
| return new Response(session) | ||
| } |
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,51 @@ | ||
| import { getCloudflareContext } from '@opennextjs/cloudflare' | ||
| import { NextRequest } from 'next/server' | ||
|
|
||
| import { Session } from '@/lib/types' | ||
|
|
||
| interface UpdateSessionRequest { | ||
| status: Session['status'] | ||
| } | ||
|
|
||
| export async function POST(request: NextRequest) { | ||
| const { env } = getCloudflareContext() | ||
|
|
||
| const sessionId = request.nextUrl.searchParams.get('sessionId') | ||
|
|
||
| if (!sessionId) { | ||
| return new Response('No sessionId provided', { status: 400 }) | ||
| } | ||
|
|
||
| const sessionData = await env.SESSIONID_STORAGE.get(sessionId) | ||
|
|
||
| if (!sessionData) { | ||
| await env.SESSIONID_STORAGE.put( | ||
| sessionId, | ||
| JSON.stringify({ | ||
| status: 'pending', | ||
| createdAt: new Date().toISOString() | ||
| } as Session) | ||
| ) | ||
|
|
||
| return new Response('Session created', { status: 200 }) | ||
| } | ||
|
|
||
| const session = JSON.parse(sessionData) as Session | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion | ||
| const { status } = (await request.json()) as UpdateSessionRequest | ||
|
|
||
| if (status !== 'success' && status !== 'error') { | ||
| return new Response('Invalid status provided', { status: 400 }) | ||
| } | ||
|
|
||
| session.status = status | ||
| if (status === 'success') { | ||
| // Mock txid | ||
| session.txid = '0x9b629147b75dc0b275d478fa34d97c5d4a26926457540b15a5ce871df36c23fd' | ||
| } | ||
|
|
||
| await env.SESSIONID_STORAGE.put(sessionId, JSON.stringify(session)) | ||
|
|
||
| return new Response('Session updated', { status: 200 }) | ||
| } | ||
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,22 @@ | ||
| import { XCircle } from 'lucide-react' | ||
|
|
||
| import ActionResult from '@/components/action-result' | ||
|
|
||
| export default function ErrorActionPage() { | ||
| const description = ( | ||
| <> | ||
| <p>The session has been updated to reflect the error state.</p> | ||
| <br /> | ||
| <p>This test exchange has simulated a payment failure.</p> | ||
| </> | ||
| ) | ||
|
|
||
| return ( | ||
| <ActionResult | ||
| icon={<XCircle className="w-full h-full" />} | ||
| title="Payment Failed" | ||
| description={description} | ||
| iconClassName="text-red-500" | ||
| /> | ||
| ) | ||
| } |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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.
Uh oh!
There was an error while loading. Please reload this page.