-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: type errors in settings page and RadioButton component
- Fix type error in RadioButton component - Add proper id handling in RadioButton - Remove invalid page prop in settings page - Update type definitions for better type safety
- Loading branch information
Showing
29 changed files
with
661 additions
and
348 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -39,3 +39,6 @@ yarn-error.log* | |
|
||
# Storybook | ||
storybook-static | ||
|
||
# Instructions folder | ||
instructions/ |
This file contains 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,108 +1,113 @@ | ||
import { Provider } from "starknet"; | ||
import { DeploymentError, DeploymentErrorType, RetryConfig, Networks } from "../types"; | ||
import type { Provider } from "starknet"; | ||
import { | ||
DeploymentError, | ||
DeploymentErrorType, | ||
Networks, | ||
type RetryConfig, | ||
} from "../types"; | ||
|
||
class Logger { | ||
private formatMessage(level: string, message: any): string { | ||
const timestamp = new Date().toISOString(); | ||
return `[${timestamp}] ${level}: ${typeof message === 'string' ? message : JSON.stringify(message)}`; | ||
} | ||
|
||
info(message: any): void { | ||
console.log(this.formatMessage('INFO', message)); | ||
} | ||
|
||
warn(message: any): void { | ||
console.warn(this.formatMessage('WARN', message)); | ||
} | ||
|
||
error(message: any): void { | ||
console.error(this.formatMessage('ERROR', message)); | ||
} | ||
private formatMessage(level: string, message: unknown): string { | ||
const timestamp = new Date().toISOString(); | ||
return `[${timestamp}] ${level}: ${typeof message === "string" ? message : JSON.stringify(message)}`; | ||
} | ||
|
||
info(message: unknown): void { | ||
console.log(this.formatMessage("INFO", message)); | ||
} | ||
|
||
warn(message: unknown): void { | ||
console.warn(this.formatMessage("WARN", message)); | ||
} | ||
|
||
error(message: unknown): void { | ||
console.error(this.formatMessage("ERROR", message)); | ||
} | ||
} | ||
|
||
export const logger = new Logger(); | ||
|
||
const defaultRetryConfig: RetryConfig = { | ||
maxAttempts: 3, | ||
initialDelay: 1000, | ||
maxDelay: 10000, | ||
factor: 2 | ||
maxAttempts: 3, | ||
initialDelay: 1000, | ||
maxDelay: 10000, | ||
factor: 2, | ||
}; | ||
|
||
export async function withRetry<T>( | ||
operation: () => Promise<T>, | ||
config: RetryConfig = defaultRetryConfig, | ||
context: string | ||
operation: () => Promise<T>, | ||
context: string, | ||
config: RetryConfig = defaultRetryConfig, | ||
): Promise<T> { | ||
let delay = config.initialDelay; | ||
let attempt = 0; | ||
|
||
while (attempt < config.maxAttempts) { | ||
try { | ||
return await operation(); | ||
} catch (error: any) { | ||
attempt++; | ||
|
||
const errorType = classifyStarknetError(error); | ||
logger.warn({ | ||
message: `Retry attempt ${attempt}/${config.maxAttempts} for ${context}`, | ||
error: error.message, | ||
type: errorType | ||
}); | ||
|
||
if (attempt === config.maxAttempts || !isRetryableError(errorType)) { | ||
throw new DeploymentError(errorType, error.message); | ||
} | ||
|
||
await sleep(delay); | ||
delay = Math.min(delay * config.factor, config.maxDelay); | ||
} | ||
} | ||
|
||
throw new DeploymentError( | ||
DeploymentErrorType.UNKNOWN_ERROR, | ||
`Max retry attempts (${config.maxAttempts}) reached for ${context}` | ||
); | ||
let delay = config.initialDelay; | ||
let attempt = 1; | ||
|
||
while (attempt <= config.maxAttempts) { | ||
try { | ||
return await operation(); | ||
} catch (error: unknown) { | ||
attempt++; | ||
|
||
const errorType = classifyStarknetError(error as Error); | ||
logger.warn({ | ||
message: `Retry attempt ${attempt}/${config.maxAttempts} for ${context}`, | ||
error: (error as Error).message, | ||
type: errorType, | ||
}); | ||
|
||
if (attempt === config.maxAttempts || !isRetryableError(errorType)) { | ||
throw new DeploymentError(errorType, (error as Error).message); | ||
} | ||
|
||
await sleep(delay); | ||
delay = Math.min(delay * config.factor, config.maxDelay); | ||
} | ||
} | ||
|
||
throw new DeploymentError( | ||
DeploymentErrorType.UNKNOWN_ERROR, | ||
`Max retry attempts (${config.maxAttempts}) reached for ${context}`, | ||
); | ||
} | ||
|
||
function classifyStarknetError(error: any): DeploymentErrorType { | ||
const errorMsg = error.message.toLowerCase(); | ||
|
||
if (errorMsg.includes("insufficient max fee")) { | ||
return DeploymentErrorType.GAS_ERROR; | ||
} | ||
if (errorMsg.includes("invalid transaction nonce")) { | ||
return DeploymentErrorType.NONCE_ERROR; | ||
} | ||
if (errorMsg.includes("network") || errorMsg.includes("timeout")) { | ||
return DeploymentErrorType.NETWORK_ERROR; | ||
} | ||
if (errorMsg.includes("contract") || errorMsg.includes("class hash")) { | ||
return DeploymentErrorType.CONTRACT_ERROR; | ||
} | ||
if (errorMsg.includes("invalid") || errorMsg.includes("validation")) { | ||
return DeploymentErrorType.VALIDATION_ERROR; | ||
} | ||
return DeploymentErrorType.UNKNOWN_ERROR; | ||
function classifyStarknetError(error: Error): DeploymentErrorType { | ||
const errorMsg = error.message.toLowerCase(); | ||
|
||
if (errorMsg.includes("insufficient max fee")) { | ||
return DeploymentErrorType.GAS_ERROR; | ||
} | ||
if (errorMsg.includes("invalid transaction nonce")) { | ||
return DeploymentErrorType.NONCE_ERROR; | ||
} | ||
if (errorMsg.includes("network") || errorMsg.includes("timeout")) { | ||
return DeploymentErrorType.NETWORK_ERROR; | ||
} | ||
if (errorMsg.includes("contract") || errorMsg.includes("class hash")) { | ||
return DeploymentErrorType.CONTRACT_ERROR; | ||
} | ||
if (errorMsg.includes("invalid") || errorMsg.includes("validation")) { | ||
return DeploymentErrorType.VALIDATION_ERROR; | ||
} | ||
return DeploymentErrorType.UNKNOWN_ERROR; | ||
} | ||
|
||
function isRetryableError(errorType: DeploymentErrorType): boolean { | ||
return [ | ||
DeploymentErrorType.NETWORK_ERROR, | ||
DeploymentErrorType.GAS_ERROR, | ||
DeploymentErrorType.NONCE_ERROR | ||
].includes(errorType); | ||
return [ | ||
DeploymentErrorType.NETWORK_ERROR, | ||
DeploymentErrorType.GAS_ERROR, | ||
DeploymentErrorType.NONCE_ERROR, | ||
].includes(errorType); | ||
} | ||
|
||
export async function validateNetwork(provider: Provider): Promise<void> { | ||
try { | ||
await provider.getChainId(); | ||
} catch (error) { | ||
throw new DeploymentError( | ||
DeploymentErrorType.NETWORK_ERROR, | ||
"Failed to validate network connection" | ||
); | ||
} | ||
try { | ||
await provider.getChainId(); | ||
} catch (error) { | ||
throw new DeploymentError( | ||
DeploymentErrorType.NETWORK_ERROR, | ||
"Failed to validate network connection", | ||
); | ||
} | ||
} | ||
|
||
const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms)); | ||
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)); |
This file contains 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 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 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 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 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.