Comfy-Org / Comfy-Org/ComfyUI_frontend
refactor: deduplicate handleAddCreditCard and handleConfirmTransition in SubscriptionRequiredDialogContentWorkspace.vue
- Dominant language
- TypeScript
- Stars
- 2k
- Forks
- 699
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 490
Description
## Summary
`src/platform/workspace/components/SubscriptionRequiredDialogContentWorkspace.vue` has two nearly identical ~50-line functions:
- `handleAddCreditCard` (lines 209-261)
- `handleConfirmTransition` (lines 263-315)
The only difference is the fallback error message string. Both follow the same try/catch/subscribe/window.open/billingOp pattern.
## Fix
Extract a shared helper within the file:
```ts
async function executeSubscription(fallbackErrorKey: string) {
if (!selectedTierKey.value) return
isSubscribing.value = true
try {
const planSlug = getApiPlanSlug(selectedTierKey.value, selectedBillingCycle.value)
if (!planSlug) return
const response = await subscribe(planSlug, successUrl, failedUrl)
// ... shared response handling
} catch (error) {
const message = error instanceof Error ? error.message : t(fallbackErrorKey)
toast.add({ severity: 'error', summary: t('g.error'), detail: message })
} finally {
isSubscribing.value = false
}
}
```
Then both handlers become one-liners calling `executeSubscription()` with different error keys.
## References
- PR: https://github.com/Comfy-Org/ComfyUI_frontend/pull/9901
- Review: https://github.com/Comfy-Org/ComfyUI_frontend/pull/9901#pullrequestreview-3963889519
┆Issue is synchronized with this [Notion page](https://www.notion.so/Issue-10457-refactor-deduplicate-handleAddCreditCard-and-handleConfirmTransition-in-Subscription-32d6d73d36508166835be90baf3b2cd5) by [Unito](https://www.unito.io)
Contributor guide
Assessment
This issue has not been assessed yet.