Skip to content

Commit 81cea6e

Browse files
committed
Fix linting, formatting, and type errors
1 parent d913fc4 commit 81cea6e

File tree

19 files changed

+53
-180
lines changed

19 files changed

+53
-180
lines changed

examples/testapp/src/pages/add-sub-account/components/SendCalls.tsx

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { TokenPaymentSuccess } from '@base-org/account';
2-
import { createBaseAccountSDK, payWithToken } from '@base-org/account';
2+
import { payWithToken } from '@base-org/account';
33
import { CheckCircleIcon, ExternalLinkIcon } from '@chakra-ui/icons';
44
import { Box, Button, Flex, HStack, Icon, Link, Text, VStack } from '@chakra-ui/react';
55
import { useCallback, useState } from 'react';
@@ -23,22 +23,16 @@ function stripChainPrefix(txHash: string): string {
2323

2424
function getBlockExplorerUrl(chainId: number, txHash: string): string {
2525
const hash = stripChainPrefix(txHash);
26-
26+
2727
const explorers: Record<number, string> = {
2828
8453: 'https://basescan.org/tx', // Base mainnet
2929
84532: 'https://sepolia.basescan.org/tx', // Base Sepolia
3030
};
31-
31+
3232
return `${explorers[chainId] || 'https://basescan.org/tx'}/${hash}`;
3333
}
3434

35-
export function SendCalls({
36-
sdk,
37-
subAccountAddress,
38-
}: {
39-
sdk: ReturnType<typeof createBaseAccountSDK>;
40-
subAccountAddress: string;
41-
}) {
35+
export function SendCalls() {
4236
const [paymentResult, setPaymentResult] = useState<TokenPaymentSuccess | null>(null);
4337
const [isLoading, setIsLoading] = useState(false);
4438
const [error, setError] = useState<string | null>(null);
@@ -124,7 +118,12 @@ export function SendCalls({
124118
_dark={{ bg: 'green.900', borderColor: 'green.700' }}
125119
>
126120
<HStack spacing={3} mb={6}>
127-
<Icon as={CheckCircleIcon} boxSize={6} color="green.600" _dark={{ color: 'green.400' }} />
121+
<Icon
122+
as={CheckCircleIcon}
123+
boxSize={6}
124+
color="green.600"
125+
_dark={{ color: 'green.400' }}
126+
/>
128127
<Text fontSize="xl" fontWeight="bold" color="green.800" _dark={{ color: 'green.200' }}>
129128
Payment Successful!
130129
</Text>

examples/testapp/src/pages/add-sub-account/index.page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export default function SubAccounts() {
9090
signerFn={getSubAccountSigner}
9191
/>
9292
<PersonalSign sdk={sdk} subAccountAddress={subAccountAddress} />
93-
<SendCalls sdk={sdk} subAccountAddress={subAccountAddress} />
93+
<SendCalls />
9494
<GrantSpendPermission sdk={sdk} subAccountAddress={subAccountAddress} />
9595
<SpendPermissions sdk={sdk} subAccountAddress={subAccountAddress} />
9696
<GenerateNewSigner />

examples/testapp/src/pages/pay-playground/constants/playground.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export const GET_PAYMENT_STATUS_QUICK_TIPS = [
117117
];
118118

119119
export const PAY_WITH_TOKEN_QUICK_TIPS = [
120-
'Amount is specified in the token\'s smallest unit (e.g., wei for ETH, or smallest unit for ERC20 tokens)',
120+
"Amount is specified in the token's smallest unit (e.g., wei for ETH, or smallest unit for ERC20 tokens)",
121121
'For USDC (6 decimals), 1 USDC = 1000000',
122122
'For tokens with 18 decimals, 1 token = 1000000000000000000',
123123
'Token can be a contract address or a supported symbol (e.g., "USDC", "WETH")',

examples/testapp/src/pages/pay-playground/hooks/useCodeExecution.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ import { useConsoleCapture } from './useConsoleCapture';
1010

1111
export const useCodeExecution = () => {
1212
const [isLoading, setIsLoading] = useState(false);
13-
const [result, setResult] = useState<PaymentResult | PaymentStatus | PayWithTokenResult | SwapResult | SwapQuote | SwapStatus | null>(null);
13+
const [result, setResult] = useState<
14+
PaymentResult | PaymentStatus | PayWithTokenResult | SwapResult | SwapQuote | SwapStatus | null
15+
>(null);
1416
const [error, setError] = useState<string | null>(null);
1517
const [consoleOutput, setConsoleOutput] = useState<string[]>([]);
1618
const { captureConsole } = useConsoleCapture();

examples/testapp/src/pages/pay-playground/index.page.tsx

Lines changed: 0 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,20 @@ import { CodeEditor, Header, Output, QuickTips } from './components';
33
import {
44
DEFAULT_GET_PAYMENT_STATUS_CODE,
55
DEFAULT_PAY_CODE,
6-
DEFAULT_PAY_WITH_TOKEN_CODE,
76
GET_PAYMENT_STATUS_QUICK_TIPS,
87
PAY_CODE_WITH_PAYER_INFO,
98
PAY_QUICK_TIPS,
10-
PAY_WITH_TOKEN_CODE_WITH_PAYER_INFO,
11-
PAY_WITH_TOKEN_PRESETS,
12-
PAY_WITH_TOKEN_QUICK_TIPS,
139
} from './constants';
1410
import { useCodeExecution } from './hooks';
15-
import { togglePayerInfoInCode, extractPaymasterUrl, updatePaymasterUrl } from './utils';
1611
import styles from './styles/Home.module.css';
1712

1813
function PayPlayground() {
1914
const [includePayerInfo, setIncludePayerInfo] = useState(false);
2015
const [payCode, setPayCode] = useState(DEFAULT_PAY_CODE);
2116
const [getPaymentStatusCode, setGetPaymentStatusCode] = useState(DEFAULT_GET_PAYMENT_STATUS_CODE);
22-
const [includePayerInfoToken, setIncludePayerInfoToken] = useState(false);
23-
const [payWithTokenCode, setPayWithTokenCode] = useState(DEFAULT_PAY_WITH_TOKEN_CODE);
24-
const [paymasterUrl, setPaymasterUrl] = useState('');
2517

2618
const payExecution = useCodeExecution();
2719
const getPaymentStatusExecution = useCodeExecution();
28-
const payWithTokenExecution = useCodeExecution();
2920

3021
const handlePayExecute = () => {
3122
payExecution.executeCode(payCode);
@@ -53,47 +44,6 @@ function PayPlayground() {
5344
getPaymentStatusExecution.reset();
5445
};
5546

56-
const handlePayWithTokenExecute = () => {
57-
payWithTokenExecution.executeCode(payWithTokenCode);
58-
};
59-
60-
const handlePayWithTokenReset = () => {
61-
setIncludePayerInfoToken(false);
62-
setPaymasterUrl('');
63-
setPayWithTokenCode(DEFAULT_PAY_WITH_TOKEN_CODE);
64-
payWithTokenExecution.reset();
65-
};
66-
67-
const handlePayerInfoTokenToggle = (checked: boolean) => {
68-
setIncludePayerInfoToken(checked);
69-
// Modify existing code to add/remove payerInfo instead of replacing it
70-
const modifiedCode = togglePayerInfoInCode(payWithTokenCode, checked);
71-
setPayWithTokenCode(modifiedCode);
72-
payWithTokenExecution.reset();
73-
};
74-
75-
const handlePaymasterUrlChange = (url: string) => {
76-
setPaymasterUrl(url);
77-
// Update the code with the new paymaster URL
78-
const updatedCode = updatePaymasterUrl(payWithTokenCode, url);
79-
setPayWithTokenCode(updatedCode);
80-
};
81-
82-
const handlePayWithTokenCodeChange = (code: string) => {
83-
setPayWithTokenCode(code);
84-
// Extract paymaster URL from code and sync the textbox
85-
const extractedUrl = extractPaymasterUrl(code);
86-
if (extractedUrl && extractedUrl !== paymasterUrl) {
87-
setPaymasterUrl(extractedUrl);
88-
}
89-
};
90-
91-
const handlePayWithTokenPresetChange = (code: string) => {
92-
// Apply the current paymasterUrl to the preset code (keep paymasterUrl intact)
93-
const updatedCode = paymasterUrl ? updatePaymasterUrl(code, paymasterUrl) : code;
94-
setPayWithTokenCode(updatedCode);
95-
};
96-
9747
// Watch for successful payment results and update getPaymentStatus code with the transaction ID
9848
useEffect(() => {
9949
if (
@@ -121,33 +71,6 @@ try {
12171
}
12272
}, [payExecution.result]);
12373

124-
// Watch for successful payWithToken results and update getPaymentStatus code with the transaction ID
125-
useEffect(() => {
126-
if (
127-
payWithTokenExecution.result &&
128-
'success' in payWithTokenExecution.result &&
129-
payWithTokenExecution.result.success &&
130-
payWithTokenExecution.result.id
131-
) {
132-
const transactionId = payWithTokenExecution.result.id;
133-
const updatedCode = `import { base } from '@base-org/account'
134-
135-
try {
136-
const result = await base.getPaymentStatus({
137-
id: '${transactionId}', // Automatically filled with your recent transaction
138-
testnet: true
139-
})
140-
141-
return result;
142-
} catch (error) {
143-
// This will catch network errors if any occur
144-
console.error('Failed to check payment status:', error.message);
145-
throw error;
146-
}`;
147-
setGetPaymentStatusCode(updatedCode);
148-
}
149-
}, [payWithTokenExecution.result]);
150-
15174
return (
15275
<div className={styles.container}>
15376
<Header />
@@ -184,43 +107,6 @@ try {
184107
</div>
185108
</section>
186109

187-
{/* payWithToken Section */}
188-
<section className={styles.section}>
189-
<h2 className={styles.sectionTitle}>payWithToken Function</h2>
190-
<p className={styles.sectionDescription}>Send ERC20 token payments on any supported chain</p>
191-
192-
<div className={styles.playground}>
193-
<div className={styles.leftColumn}>
194-
<CodeEditor
195-
code={payWithTokenCode}
196-
onChange={handlePayWithTokenCodeChange}
197-
onExecute={handlePayWithTokenExecute}
198-
onReset={handlePayWithTokenReset}
199-
isLoading={payWithTokenExecution.isLoading}
200-
includePayerInfo={includePayerInfoToken}
201-
onPayerInfoToggle={handlePayerInfoTokenToggle}
202-
showPayerInfoToggle={true}
203-
presets={PAY_WITH_TOKEN_PRESETS}
204-
transformPresetCode={togglePayerInfoInCode}
205-
paymasterUrl={paymasterUrl}
206-
onPaymasterUrlChange={handlePaymasterUrlChange}
207-
showPaymasterUrl={true}
208-
onPresetChange={handlePayWithTokenPresetChange}
209-
/>
210-
<QuickTips tips={PAY_WITH_TOKEN_QUICK_TIPS} />
211-
</div>
212-
213-
<div className={styles.rightColumn}>
214-
<Output
215-
result={payWithTokenExecution.result}
216-
error={payWithTokenExecution.error}
217-
consoleOutput={payWithTokenExecution.consoleOutput}
218-
isLoading={payWithTokenExecution.isLoading}
219-
/>
220-
</div>
221-
</div>
222-
</section>
223-
224110
{/* getPaymentStatus Section */}
225111
<section className={styles.section}>
226112
<h2 className={styles.sectionTitle}>getPaymentStatus Function</h2>

examples/testapp/src/pages/pay-playground/utils/codeSanitizer.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@ import * as acorn from 'acorn';
33
// Define the whitelist of allowed operations
44
export const WHITELIST = {
55
// Allowed SDK functions
6-
allowedFunctions: ['pay', 'getPaymentStatus', 'payWithToken', 'swap', 'getSwapQuote', 'getSwapStatus'],
6+
allowedFunctions: [
7+
'pay',
8+
'getPaymentStatus',
9+
'payWithToken',
10+
'swap',
11+
'getSwapQuote',
12+
'getSwapStatus',
13+
],
714

815
// Allowed object properties and methods
916
allowedObjects: {

examples/testapp/src/pages/pay-playground/utils/payerInfoTransform.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,12 @@ export function togglePayerInfoInCode(code: string, includePayerInfo: boolean):
4444
const afterBrace = code.substring(i);
4545

4646
// Check if we need a comma before payerInfo
47-
const needsComma = !beforeBrace.endsWith(',') &&
48-
!beforeBrace.endsWith('{') &&
49-
beforeBrace.length > 0;
47+
const needsComma =
48+
!beforeBrace.endsWith(',') && !beforeBrace.endsWith('{') && beforeBrace.length > 0;
5049

51-
return beforeBrace + (needsComma ? payerInfoBlock : payerInfoBlock.substring(1)) + afterBrace;
50+
return (
51+
beforeBrace + (needsComma ? payerInfoBlock : payerInfoBlock.substring(1)) + afterBrace
52+
);
5253
}
5354
}
5455
i++;
@@ -66,8 +67,8 @@ export function togglePayerInfoInCode(code: string, includePayerInfo: boolean):
6667

6768
// If that didn't work, try a simpler pattern
6869
if (modifiedCode === code) {
69-
// Fallback: match payerInfo property more broadly
70-
const fallbackRegex = /,\s*payerInfo\s*:\s*\{[^}]*\{[^}]*\}[^}]*\}/s;
70+
// Fallback: match payerInfo property more broadly (using [\s\S] instead of . with s flag)
71+
const fallbackRegex = /,\s*payerInfo\s*:\s*\{[^}]*\{[^}]*\}[^}]*\}/;
7172
modifiedCode = modifiedCode.replace(fallbackRegex, '');
7273
}
7374

@@ -86,4 +87,3 @@ export function togglePayerInfoInCode(code: string, includePayerInfo: boolean):
8687

8788
return code;
8889
}
89-

examples/testapp/src/pages/pay-playground/utils/paymasterTransform.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function extractPaymasterUrl(code: string): string | undefined {
1818
export function updatePaymasterUrl(code: string, paymasterUrl: string): string {
1919
// Check if paymaster already exists in the code
2020
const hasPaymaster = /paymaster\s*:\s*\{/.test(code);
21-
21+
2222
if (!hasPaymaster) {
2323
// If no paymaster exists, we need to add it
2424
// Find the payWithToken call and locate where to insert paymaster
@@ -43,16 +43,17 @@ export function updatePaymasterUrl(code: string, paymasterUrl: string): string {
4343
const afterBrace = code.substring(i);
4444

4545
// Check if we need a comma before paymaster
46-
const needsComma = !beforeBrace.endsWith(',') &&
47-
!beforeBrace.endsWith('{') &&
48-
beforeBrace.length > 0;
46+
const needsComma =
47+
!beforeBrace.endsWith(',') && !beforeBrace.endsWith('{') && beforeBrace.length > 0;
4948

5049
const paymasterBlock = `,
5150
paymaster: {
5251
url: '${paymasterUrl}'
5352
}`;
5453

55-
return beforeBrace + (needsComma ? paymasterBlock : paymasterBlock.substring(1)) + afterBrace;
54+
return (
55+
beforeBrace + (needsComma ? paymasterBlock : paymasterBlock.substring(1)) + afterBrace
56+
);
5657
}
5758
}
5859
i++;
@@ -68,4 +69,3 @@ export function updatePaymasterUrl(code: string, paymasterUrl: string): string {
6869

6970
return code;
7071
}
71-

packages/account-sdk/src/core/telemetry/logEvent.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ type CCAEventData = {
7171
testnet?: boolean;
7272
status?: string;
7373
periodInDays?: number;
74+
token?: string;
75+
chainId?: number;
7476
};
7577

7678
type AnalyticsEventData = {

packages/account-sdk/src/interface/payment/getPaymentStatus.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ describe('getPaymentStatus', () => {
8585
});
8686

8787
it('should decode ERC-3770 encoded IDs and ignore the legacy testnet flag', async () => {
88-
const transactionHash =
89-
'0xabc1230000000000000000000000000000000000000000000000000000000000';
88+
const transactionHash = '0xabc1230000000000000000000000000000000000000000000000000000000000';
9089
const mockReceipt = {
9190
jsonrpc: '2.0',
9291
id: 1,

0 commit comments

Comments
 (0)