Skip to content

Commit

Permalink
lint & prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
0age committed Feb 19, 2025
1 parent 8753e60 commit 671b5dd
Show file tree
Hide file tree
Showing 29 changed files with 213 additions and 212 deletions.
9 changes: 5 additions & 4 deletions docs/broadcast-payload.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This document describes the structure of the payload that is sent to the broadca

The broadcast server receives a payload with the following structure:

```typescript
````typescript
interface BroadcastRequest {
chainId: string;
compact: CompactMessage;
Expand Down Expand Up @@ -117,17 +117,18 @@ Example endpoint structure:
```typescript
app.post('/broadcast', async (req, res) => {
const { compact, sponsorSignature, allocatorSignature, context } = req.body;
// Validate signatures and process swap
// ...
res.json({ success: true });
});
```
````
## EIP-712 Type Definition
The Compact payload follows this exact EIP-712 type structure:
```solidity
Compact {
address arbiter;
Expand All @@ -150,4 +151,4 @@ Mandate {
uint256 scalingFactor;
bytes32 salt;
}
```
```
19 changes: 8 additions & 11 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import js from '@eslint/js'
import globals from 'globals'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'
import tseslint from 'typescript-eslint'
import js from '@eslint/js';
import globals from 'globals';
import reactHooks from 'eslint-plugin-react-hooks';
import reactRefresh from 'eslint-plugin-react-refresh';
import tseslint from 'typescript-eslint';

export default tseslint.config(
{ ignores: ['dist'] },
Expand All @@ -19,10 +19,7 @@ export default tseslint.config(
},
rules: {
...reactHooks.configs.recommended.rules,
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
'react-refresh/only-export-components': ['warn', { allowConstantExport: true }],
},
},
)
}
);
5 changes: 4 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='0.9em' font-size='90'>🤝</text></svg>" />
<link
rel="icon"
href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='0.9em' font-size='90'>🤝</text></svg>"
/>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>CompactX</title>
</head>
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "compactx",
"private": true,
"version": "0.0.0",
"author": "0age",
"version": "0.0.1",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"lint": "eslint . --max-warnings 0",
"preview": "vite preview",
"test": "dotenv -e .env.test -- vitest run",
"test:watch": "vitest",
Expand Down
2 changes: 1 addition & 1 deletion postcss.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ module.exports = {
tailwindcss: {},
autoprefixer: {},
},
}
};
6 changes: 3 additions & 3 deletions src/api/broadcast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,9 @@ export class BroadcastApiClient {
} catch (error) {
if (error instanceof Error) {
// Enhance error message with more context
const context = error.message.includes('signature') ?
' Please try again or check your wallet connection.' :
' This may be due to network issues or the broadcast service being unavailable.';
const context = error.message.includes('signature')
? ' Please try again or check your wallet connection.'
: ' This may be due to network issues or the broadcast service being unavailable.';
throw new Error(error.message + context);
}
throw new Error('Failed to broadcast message. Please try again later.');
Expand Down
15 changes: 9 additions & 6 deletions src/api/smallocator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,10 @@ export class SmallocatorClient {
* @param chainId - The chain ID
* @param lockId - The resource lock ID
*/
async getResourceLockBalance(chainId: string | number, lockId: string): Promise<ResourceLockBalance> {
async getResourceLockBalance(
chainId: string | number,
lockId: string
): Promise<ResourceLockBalance> {
return this.request<ResourceLockBalance>('GET', `/balance/${chainId}/${lockId}`);
}

Expand All @@ -300,22 +303,22 @@ export class SmallocatorClient {

// Use the compact.id as the resource lock ID
const lockId = request.compact.id;

// Get current balance
const balance = await this.getResourceLockBalance(request.chainId, lockId);

// Check if there's enough available balance
const requiredAmount = BigInt(request.compact.amount);
const availableBalance = BigInt(balance.balanceAvailableToAllocate);

// Always log the balance check results
console.log('Balance check:', {
required: requiredAmount.toString(),
available: availableBalance.toString(),
isDepositAndSwap: options.isDepositAndSwap,
witnessTypeString: request.compact.witnessTypeString
witnessTypeString: request.compact.witnessTypeString,
});

if (availableBalance < requiredAmount) {
const error = `Insufficient balance available to allocate. Required: ${requiredAmount.toString()}, Available: ${availableBalance.toString()}`;
console.error(error);
Expand Down
54 changes: 22 additions & 32 deletions src/components/AddCustomToken.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,21 @@ export function AddCustomToken() {

const validateForm = (): boolean => {
const errors: Partial<Record<keyof FormValues, string>> = {};

if (!formValues.address) {
errors.address = 'Please input token address';
} else if (!isAddress(formValues.address)) {
errors.address = 'Invalid address';
}

if (!formValues.name) {
errors.name = 'Please input token name';
}

if (!formValues.symbol) {
errors.symbol = 'Please input token symbol';
}

if (!formValues.decimals) {
errors.decimals = 'Please input token decimals';
} else if (formValues.decimals < 0 || formValues.decimals > 18) {
Expand Down Expand Up @@ -89,12 +89,14 @@ export function AddCustomToken() {
<div className="bg-[#0a0a0a] border border-gray-800 rounded-lg p-6 w-full max-w-md">
<div className="flex justify-between items-center mb-6">
<h2 className="text-xl font-semibold text-white">Add Custom Token</h2>
<button
onClick={handleClose}
className="text-gray-400 hover:text-gray-300"
>
<button onClick={handleClose} className="text-gray-400 hover:text-gray-300">
<svg className="w-6 h-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M6 18L18 6M6 6l12 12" />
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M6 18L18 6M6 6l12 12"
/>
</svg>
</button>
</div>
Expand All @@ -107,7 +109,7 @@ export function AddCustomToken() {
<input
type="text"
value={formValues.address || ''}
onChange={(e) => setFormValues(prev => ({ ...prev, address: e.target.value }))}
onChange={e => setFormValues(prev => ({ ...prev, address: e.target.value }))}
placeholder="0x..."
className="w-full px-3 py-2 bg-[#1a1a1a] border border-gray-700 rounded-lg focus:outline-none focus:ring-2 focus:ring-[#00ff00]/50 text-white"
/>
Expand All @@ -117,29 +119,23 @@ export function AddCustomToken() {
</div>

<div>
<label className="block text-sm font-medium text-gray-200 mb-1">
Token Name
</label>
<label className="block text-sm font-medium text-gray-200 mb-1">Token Name</label>
<input
type="text"
value={formValues.name || ''}
onChange={(e) => setFormValues(prev => ({ ...prev, name: e.target.value }))}
onChange={e => setFormValues(prev => ({ ...prev, name: e.target.value }))}
placeholder="Token Name"
className="w-full px-3 py-2 bg-[#1a1a1a] border border-gray-700 rounded-lg focus:outline-none focus:ring-2 focus:ring-[#00ff00]/50 text-white"
/>
{formErrors.name && (
<p className="mt-1 text-sm text-red-500">{formErrors.name}</p>
)}
{formErrors.name && <p className="mt-1 text-sm text-red-500">{formErrors.name}</p>}
</div>

<div>
<label className="block text-sm font-medium text-gray-200 mb-1">
Token Symbol
</label>
<label className="block text-sm font-medium text-gray-200 mb-1">Token Symbol</label>
<input
type="text"
value={formValues.symbol || ''}
onChange={(e) => setFormValues(prev => ({ ...prev, symbol: e.target.value }))}
onChange={e => setFormValues(prev => ({ ...prev, symbol: e.target.value }))}
placeholder="TOKEN"
className="w-full px-3 py-2 bg-[#1a1a1a] border border-gray-700 rounded-lg focus:outline-none focus:ring-2 focus:ring-[#00ff00]/50 text-white"
/>
Expand All @@ -149,13 +145,13 @@ export function AddCustomToken() {
</div>

<div>
<label className="block text-sm font-medium text-gray-200 mb-1">
Decimals
</label>
<label className="block text-sm font-medium text-gray-200 mb-1">Decimals</label>
<input
type="number"
value={formValues.decimals || ''}
onChange={(e) => setFormValues(prev => ({ ...prev, decimals: Number(e.target.value) }))}
onChange={e =>
setFormValues(prev => ({ ...prev, decimals: Number(e.target.value) }))
}
placeholder="18"
min="0"
max="18"
Expand All @@ -177,13 +173,7 @@ export function AddCustomToken() {
</div>
)}

{toast && (
<Toast
message={toast.message}
type={toast.type}
onClose={hideToast}
/>
)}
{toast && <Toast message={toast.message} type={toast.type} onClose={hideToast} />}
</>
);
}
11 changes: 7 additions & 4 deletions src/components/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ export function Modal({ title, open, onClose, children }: ModalProps) {
className="text-gray-400 hover:text-gray-300 transition-colors"
>
<svg className="w-6 h-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M6 18L18 6M6 6l12 12" />
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M6 18L18 6M6 6l12 12"
/>
</svg>
</button>
</div>
<div className="p-4">
{children}
</div>
<div className="p-4">{children}</div>
</div>
</div>
</div>
Expand Down
10 changes: 5 additions & 5 deletions src/components/NumberInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function NumberInput({
}: NumberInputProps) {
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const val = e.target.value;

// Allow empty input
if (!val) {
onChange('');
Expand Down Expand Up @@ -60,10 +60,10 @@ export function NumberInput({
onChange(val);
};

const baseClasses = "w-full px-3 py-2 bg-[#1a1a1a] text-white focus:outline-none focus:ring-2 focus:ring-[#00ff00]/50";
const variantClasses = variant === 'borderless'
? "border-0"
: "border border-gray-700 rounded-lg";
const baseClasses =
'w-full px-3 py-2 bg-[#1a1a1a] text-white focus:outline-none focus:ring-2 focus:ring-[#00ff00]/50';
const variantClasses =
variant === 'borderless' ? 'border-0' : 'border border-gray-700 rounded-lg';

return (
<input
Expand Down
15 changes: 8 additions & 7 deletions src/components/SegmentedControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ export function SegmentedControl<T extends string | number | boolean>({
columns = 1,
}: SegmentedControlProps<T>) {
const isGrid = columns > 1;

return (
<div
<div
className={`
inline-grid
${isGrid ? `grid-cols-3` : 'grid-cols-2'}
gap-1 p-1 rounded-lg border border-gray-800 bg-[#0a0a0a] w-full
`}
role="radiogroup"
role="radiogroup"
aria-label={ariaLabel}
>
{options.map((option) => {
{options.map(option => {
const isSelected = value === option.value;
return (
<div
Expand All @@ -36,9 +36,10 @@ export function SegmentedControl<T extends string | number | boolean>({
className={`
px-3 py-1.5 text-[0.75rem] rounded-md whitespace-nowrap cursor-pointer
flex items-center justify-center
${isSelected
? 'bg-[#00ff00]/10 text-[#00ff00] border border-[#00ff00]/30'
: 'bg-[#111111] text-gray-500 hover:text-gray-400 border border-gray-800'
${
isSelected
? 'bg-[#00ff00]/10 text-[#00ff00] border border-[#00ff00]/30'
: 'bg-[#111111] text-gray-500 hover:text-gray-400 border border-gray-800'
}
`}
>
Expand Down
8 changes: 2 additions & 6 deletions src/components/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@ export function Select({
const selectedOption = options.find(option => String(option.value) === String(value));

return (
<div
ref={selectRef}
className={`relative ${className}`}
style={style}
>
<div ref={selectRef} className={`relative ${className}`} style={style}>
<button
type="button"
onClick={() => !disabled && setIsOpen(!isOpen)}
Expand Down Expand Up @@ -75,7 +71,7 @@ export function Select({

{isOpen && !disabled && (
<div className="absolute z-50 w-full mt-1 bg-[#1a1a1a] border border-gray-700 rounded-md shadow-lg max-h-60 overflow-auto">
{options.map((option) => (
{options.map(option => (
<button
key={option.value}
type="button"
Expand Down
Loading

0 comments on commit 671b5dd

Please sign in to comment.