let the wallet be renamed from settings
the PATCH route already accepted a name; nothing in the UI ever sent one. adds an inline editor on the settings header (pencil → input, enter saves, escape cancels) and a rename mutation. renaming touches only the label, so it needs neither the passphrase nor an unlocked wallet. the route took the name unvalidated — it now trims and refuses a blank one, with a 64-char cap matched on create so a name you can create is one you can type back. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -160,6 +160,14 @@ async function handleWallets(ctx: OfficerContext, seg: string[]): Promise<Respon
|
||||
}
|
||||
if (req.method === 'PATCH') {
|
||||
const patch = await body<{ name?: string; defaultBip?: number; config?: Record<string, unknown> }>(req);
|
||||
// A rename goes through the same rule as a create: trimmed, and never blank. Without this a stray
|
||||
// empty string would leave a wallet with no name anywhere in the UI and no way to type one back.
|
||||
if (patch.name !== undefined) {
|
||||
const name = patch.name.trim();
|
||||
if (!name) return badRequest('name cannot be empty');
|
||||
if (name.length > 64) return badRequest('name is too long (64 characters max)');
|
||||
patch.name = name;
|
||||
}
|
||||
const updated = await updateWallet(userId, walletId, patch);
|
||||
invalidate(walletId);
|
||||
return updated ? json({ wallet: updated }) : json({ error: 'wallet not found' }, 404);
|
||||
@@ -377,6 +385,8 @@ async function createWalletRoute(ctx: OfficerContext): Promise<Response> {
|
||||
}
|
||||
const b = await body<CreateBody>(ctx.req);
|
||||
if (!b.name?.trim()) return badRequest('name is required');
|
||||
// Same cap as the rename route, so a name you can create is always a name you can type back.
|
||||
if (b.name.trim().length > 64) return badRequest('name is too long (64 characters max)');
|
||||
if (!b.kind || !(KINDS as readonly string[]).includes(b.kind)) {
|
||||
return badRequest(`kind must be one of ${KINDS.join(', ')}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user