diff --git a/src/commands/KeysCommand.ts b/src/commands/KeysCommand.ts index 3ba5522..d330726 100644 --- a/src/commands/KeysCommand.ts +++ b/src/commands/KeysCommand.ts @@ -126,7 +126,7 @@ export class KeysCommand { ); const keychainFiles = files.filter((f) => f.endsWith(".keychain.json")); - const keypairData = await Promise.all( + const keypairResults = await Promise.allSettled( keypairFiles.map(async (file) => { const name = file.replace(".json", ""); const signer = await Signer.load(name); @@ -139,6 +139,17 @@ export class KeysCommand { }) ); + const keypairData = keypairResults + .map((result, index) => { + if (result.status === "fulfilled") { + return result.value; + } + const name = keypairFiles[index]?.replace(".json", "") ?? "unknown"; + console.warn(`Warning: Failed to load keypair "${name}": ${result.reason}`); + return null; + }) + .filter((item): item is NonNullable => item !== null); + const keychainData = keychainFiles.map((file) => { const name = file.replace(".keychain.json", ""); const config = KeychainConfig.load(name); diff --git a/src/commands/PerpsCommand.ts b/src/commands/PerpsCommand.ts index 313872c..011523f 100644 --- a/src/commands/PerpsCommand.ts +++ b/src/commands/PerpsCommand.ts @@ -8,6 +8,7 @@ import { Config } from "../lib/Config.ts"; import { NumberConverter } from "../lib/NumberConverter.ts"; import { Output } from "../lib/Output.ts"; import { Signer } from "../lib/Signer.ts"; +import { DateConverter } from "../lib/DateConverter.ts"; export class PerpsCommand { public static register(program: Command): void { @@ -311,6 +312,12 @@ export class PerpsCommand { if (opts.leverage && opts.size) { throw new Error("Only one of --leverage or --size can be provided."); } + if (opts.leverage) { + const lev = Number(opts.leverage); + if (isNaN(lev) || lev < 1 || lev > 100) { + throw new Error("Leverage must be a number between 1 and 100."); + } + } if (opts.limit && (opts.tp || opts.sl)) { throw new Error( "--limit cannot be combined with --tp or --sl. Use 'perps set' after the limit order fills." @@ -904,14 +911,7 @@ export class PerpsCommand { } private static parseTimestamp(value: string): string { - if (/^\d+$/.test(value)) { - return value; - } - const ms = new Date(value).getTime(); - if (isNaN(ms)) { - throw new Error(`Invalid date: ${value}`); - } - return String(Math.floor(ms / 1000)); + return DateConverter.toUnixSeconds(value); } private static async history(opts: { diff --git a/src/commands/SpotCommand.ts b/src/commands/SpotCommand.ts index ab28856..ad883ca 100644 --- a/src/commands/SpotCommand.ts +++ b/src/commands/SpotCommand.ts @@ -18,6 +18,7 @@ import { Config } from "../lib/Config.ts"; import { NumberConverter } from "../lib/NumberConverter.ts"; import { Output } from "../lib/Output.ts"; import { Signer } from "../lib/Signer.ts"; +import { DateConverter } from "../lib/DateConverter.ts"; import { Swap } from "../lib/Swap.ts"; export class SpotCommand { @@ -400,6 +401,20 @@ export class SpotCommand { } const info = tokenMap.get(mint); if (!info) { + console.warn(`Warning: Token metadata not found for mint ${mint}. Displaying with limited info.`); + outputTokens.push({ + id: mint, + symbol: mint.slice(0, 8) + '...', + decimals: 0, + amount: Number(ata.amount), + rawAmount: ata.amount, + value: 0, + price: 0, + priceChange: 0, + isVerified: false, + scaledUiMultiplier: 1, + reclaimableLamports: ata.reclaimableLamports, + }); continue; } const multiplier = Swap.getScaledUiMultiplier(info); @@ -928,13 +943,6 @@ export class SpotCommand { } private static parseTimestamp(value: string): string { - if (/^\d+$/.test(value)) { - return new Date(Number(value) * 1000).toISOString(); - } - const ms = new Date(value).getTime(); - if (isNaN(ms)) { - throw new Error(`Invalid date: ${value}`); - } - return new Date(ms).toISOString(); + return DateConverter.toISO(value); } } diff --git a/src/lib/DateConverter.ts b/src/lib/DateConverter.ts new file mode 100644 index 0000000..5bd1822 --- /dev/null +++ b/src/lib/DateConverter.ts @@ -0,0 +1,31 @@ +export class DateConverter { + /** + * Parse a timestamp value and return an ISO string. + * Accepts Unix seconds (numeric string) or an ISO date string. + */ + static toISO(value: string): string { + if (/^\d+$/.test(value)) { + return new Date(Number(value) * 1000).toISOString(); + } + const ms = new Date(value).getTime(); + if (isNaN(ms)) { + throw new Error(`Invalid date: ${value}`); + } + return new Date(ms).toISOString(); + } + + /** + * Parse a timestamp value and return Unix seconds as a string. + * Accepts Unix seconds (numeric string) or an ISO date string. + */ + static toUnixSeconds(value: string): string { + if (/^\d+$/.test(value)) { + return value; + } + const ms = new Date(value).getTime(); + if (isNaN(ms)) { + throw new Error(`Invalid date: ${value}`); + } + return String(Math.floor(ms / 1000)); + } +}