-
Notifications
You must be signed in to change notification settings - Fork 7
feat(samples/kotlin): add USD → USDC wallet payout flow #593
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
Open
pengying
wants to merge
1
commit into
06-16-fix_samples_kotlin_send_customer_email_for_usdb_embedded_wallets
Choose a base branch
from
06-16-feat_samples_kotlin_add_usd_usdc_wallet_payout_flow
base: 06-16-fix_samples_kotlin_send_customer_email_for_usdb_embedded_wallets
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
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,95 @@ | ||
| import { useState } from 'react' | ||
| import StepWizard from '../components/StepWizard' | ||
| import CreateCustomer from '../steps/CreateCustomer' | ||
| import CreateUsdcExternalAccount from '../steps/CreateUsdcExternalAccount' | ||
| import CreateQuote from '../steps/CreateQuote' | ||
| import SandboxFund from '../steps/SandboxFund' | ||
|
|
||
| export default function UsdcPayoutFlow() { | ||
| const [activeStep, setActiveStep] = useState(0) | ||
| const [customerId, setCustomerId] = useState<string | null>(null) | ||
| const [externalAccountId, setExternalAccountId] = useState<string | null>(null) | ||
| const [quoteId, setQuoteId] = useState<string | null>(null) | ||
| const [selectedNetwork, setSelectedNetwork] = useState('BASE') | ||
|
|
||
| const advance = () => setActiveStep((s) => s + 1) | ||
|
|
||
| const restartFromExternalAccount = () => { | ||
| setExternalAccountId(null) | ||
| setQuoteId(null) | ||
| setActiveStep(1) | ||
| } | ||
|
|
||
| const steps = [ | ||
| { | ||
| title: '1. Create Customer', | ||
| summary: customerId ? `ID: ${customerId}` : null, | ||
| content: ( | ||
| <CreateCustomer | ||
| disabled={activeStep !== 0} | ||
| onComplete={(data) => { | ||
| setCustomerId(data.id as string) | ||
| advance() | ||
| }} | ||
| /> | ||
| ), | ||
| }, | ||
| { | ||
| title: '2. Create USDC Wallet Account', | ||
| summary: externalAccountId ? `ID: ${externalAccountId}` : null, | ||
| content: ( | ||
| <CreateUsdcExternalAccount | ||
| customerId={customerId} | ||
| disabled={activeStep !== 1} | ||
| selectedNetwork={selectedNetwork} | ||
| onNetworkChange={setSelectedNetwork} | ||
| onComplete={(data) => { | ||
| setExternalAccountId(data.id as string) | ||
| advance() | ||
| }} | ||
| /> | ||
| ), | ||
| }, | ||
| { | ||
| title: '3. Create Quote', | ||
| summary: quoteId ? `ID: ${quoteId}` : null, | ||
| content: ( | ||
| <CreateQuote | ||
| customerId={customerId} | ||
| externalAccountId={externalAccountId} | ||
| destCurrency="USDC" | ||
| disabled={activeStep !== 2} | ||
| onComplete={(data) => { | ||
| setQuoteId((data.quoteId ?? data.id) as string) | ||
| advance() | ||
| }} | ||
| /> | ||
| ), | ||
| }, | ||
| { | ||
| title: '4. Simulate Funding (Sandbox Only)', | ||
| summary: activeStep > 3 ? 'Funded' : null, | ||
| content: ( | ||
| <SandboxFund | ||
| quoteId={quoteId} | ||
| disabled={activeStep !== 3} | ||
| onComplete={() => advance()} | ||
| /> | ||
| ), | ||
| }, | ||
| ] | ||
|
|
||
| return ( | ||
| <> | ||
| <StepWizard steps={steps} activeStep={activeStep} /> | ||
| {activeStep >= 1 && ( | ||
| <button | ||
| onClick={restartFromExternalAccount} | ||
| className="mt-6 px-4 py-2 bg-gray-700 hover:bg-gray-600 rounded text-sm font-medium text-gray-300" | ||
| > | ||
| Start New Payment | ||
| </button> | ||
| )} | ||
| </> | ||
| ) | ||
| } |
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
127 changes: 127 additions & 0 deletions
127
samples/frontend/src/steps/CreateUsdcExternalAccount.tsx
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,127 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { useState, useEffect } from 'react' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import JsonEditor from '../components/JsonEditor' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import ResponsePanel from '../components/ResponsePanel' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { apiPost } from '../lib/api' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| interface Props { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| customerId: string | null | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onComplete: (response: Record<string, unknown>) => void | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| disabled: boolean | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| selectedNetwork: string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onNetworkChange: (network: string) => void | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // USDC is settled to an on-chain wallet address. Each network maps to a Grid | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // wallet external-account type; EVM networks share the 0x address format. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const NETWORK_CONFIGS: Record<string, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| label: string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| accountType: string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| address: string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description: string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }> = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| BASE: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| label: "Base", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| accountType: "BASE_WALLET", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| address: "0xAbCDEF1234567890aBCdEf1234567890ABcDef12", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description: "USDC on Base", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ETHEREUM: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| label: "Ethereum", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| accountType: "ETHEREUM_WALLET", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| address: "0xAbCDEF1234567890aBCdEf1234567890ABcDef12", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description: "USDC on Ethereum", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| POLYGON: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| label: "Polygon", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| accountType: "POLYGON_WALLET", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| address: "0xAbCDEF1234567890aBCdEf1234567890ABcDef12", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description: "USDC on Polygon", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| SOLANA: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| label: "Solana", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| accountType: "SOLANA_WALLET", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| address: "7EYnhQoR9YM3N7UoaKRoA44Uy8JeaZV3qyouov87awMs", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description: "USDC on Solana", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| TRON: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| label: "Tron", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| accountType: "TRON_WALLET", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| address: "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description: "USDC on Tron", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export { NETWORK_CONFIGS } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export default function CreateUsdcExternalAccount({ customerId, onComplete, disabled, selectedNetwork, onNetworkChange }: Props) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const [body, setBody] = useState('') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const [response, setResponse] = useState<string | null>(null) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const [error, setError] = useState<string | null>(null) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const [loading, setLoading] = useState(false) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| useEffect(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const config = NETWORK_CONFIGS[selectedNetwork] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setBody(JSON.stringify({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| customerId: customerId ?? "<customer-id>", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| currency: "USDC", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| platformAccountId: `acct_${Math.random().toString(36).slice(2, 10)}`, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| accountInfo: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| accountType: config.accountType, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| address: config.address, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, null, 2)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, [customerId, selectedNetwork]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+62
to
+73
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Prompt To Fix With AIThis is a comment left during a code review.
Path: samples/frontend/src/steps/CreateUsdcExternalAccount.tsx
Line: 62-73
Comment:
`platformAccountId` regenerates a new random value every time the network selector changes, because it is computed inside the `useEffect`. Any edit the user makes to the JSON body is wiped on each network switch — including the ID they may have noted or copied.
```suggestion
const stablePlatformAccountId = useRef(`acct_${Math.random().toString(36).slice(2, 10)}`)
useEffect(() => {
const config = NETWORK_CONFIGS[selectedNetwork]
setBody(JSON.stringify({
customerId: customerId ?? "<customer-id>",
currency: "USDC",
platformAccountId: stablePlatformAccountId.current,
accountInfo: {
accountType: config.accountType,
address: config.address,
},
}, null, 2))
}, [customerId, selectedNetwork])
```
How can I resolve this? If you propose a fix, please make it concise. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const submit = async () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!customerId) return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setLoading(true) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setError(null) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setResponse(null) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const data = await apiPost<Record<string, unknown>>( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| `/api/customers/${customerId}/external-accounts`, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| JSON.parse(body) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const pretty = JSON.stringify(data, null, 2) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setResponse(pretty) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onComplete(data) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch (e) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setError((e as Error).message) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } finally { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setLoading(false) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const config = NETWORK_CONFIGS[selectedNetwork] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <p className="text-sm text-gray-400 mb-2"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Create a {config.description} wallet account for customer <code className="text-blue-400">{customerId ?? '...'}</code> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </p> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <div className="mb-3"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <label htmlFor="usdc-network" className="block text-sm font-medium text-gray-300 mb-1">Network</label> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <select | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| id="usdc-network" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| value={selectedNetwork} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onChange={(e) => onNetworkChange(e.target.value)} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| disabled={disabled || loading} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| className="w-full px-3 py-2 bg-gray-800 border border-gray-700 rounded text-sm text-gray-100 focus:outline-none focus:border-blue-500" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {Object.entries(NETWORK_CONFIGS).map(([code, cfg]) => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <option key={code} value={code}>{cfg.label}</option> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ))} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </select> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <JsonEditor value={body} onChange={setBody} disabled={disabled || loading} /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <button | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onClick={submit} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| disabled={disabled || loading} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| className="mt-2 px-4 py-2 bg-blue-600 hover:bg-blue-500 disabled:bg-gray-700 disabled:text-gray-500 rounded text-sm font-medium" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {loading ? 'Creating...' : 'Create External Account'} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </button> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <ResponsePanel response={response} error={error} /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
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
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.
destCurrencyis listed in theuseEffectdependency array but is never referenced inside the effect body — it only appears in the JSX label on line 59. The effect will re-run wheneverdestCurrencychanges (e.g., when the user picks a different country inPayoutFlow), but the regenerated body is identical to what was there before, silently discarding any edits the user made to the JSON.Prompt To Fix With AI