@@ -17,9 +17,14 @@ var CancelCommand = &cli.Command{
1717 Action : func (cCtx * cli.Context ) error {
1818 ctx := cCtx .Context
1919 logger := common .LoggerFromContext (cCtx )
20+ environmentConfig , err := utils .GetEnvironmentConfig (cCtx )
21+ if err != nil {
22+ return fmt .Errorf ("failed to get environment config: %w" , err )
23+ }
24+ envName := environmentConfig .Name
2025
2126 // Get API client
22- apiClient , err := utils .NewBillingApiClient (cCtx )
27+ apiClient , err := utils .NewUserApiClient (cCtx )
2328 if err != nil {
2429 return fmt .Errorf ("failed to create API client: %w" , err )
2530 }
@@ -30,45 +35,32 @@ var CancelCommand = &cli.Command{
3035 return fmt .Errorf ("failed to check subscription status: %w" , err )
3136 }
3237
33- if subscription .Status != "active" {
34- logger .Info ("You don't have an active subscription." )
38+ if ! isSubscriptionActive ( subscription .Status ) {
39+ logger .Info ("You don't have an active subscription on %s." , envName )
3540 return nil
3641 }
3742
38- // Get developer address
39- developerAddr , err := utils .GetDeveloperAddress (cCtx )
43+ // Get contract caller for current environment
44+ caller , err := utils .GetContractCaller (cCtx )
4045 if err != nil {
41- return fmt .Errorf ("failed to get developer address : %w" , err )
46+ return fmt .Errorf ("failed to get contract caller : %w" , err )
4247 }
4348
44- // Check active apps across all networks
45- // Get private key for contract calls
46- privateKey , err := utils .GetPrivateKeyOrFail (cCtx )
49+ // Get developer address
50+ developerAddr , err := utils .GetDeveloperAddress (cCtx )
4751 if err != nil {
48- return fmt .Errorf ("failed to get private key : %w" , err )
52+ return fmt .Errorf ("failed to get developer address : %w" , err )
4953 }
5054
51- // Query all networks for active app counts
52- results , err := GetActiveAppCountsForAllNetworks (ctx , cCtx , developerAddr , privateKey , true )
55+ // Check active apps on current environment
56+ activeAppCount , err := caller . GetActiveAppCount (ctx , developerAddr )
5357 if err != nil {
54- return fmt .Errorf ("failed to query networks: %w" , err )
55- }
56-
57- // Calculate total active apps
58- totalActiveApps := uint32 (0 )
59- for _ , info := range results {
60- totalActiveApps += info .Count
58+ return fmt .Errorf ("failed to get active app count: %w" , err )
6159 }
6260
63- // If apps exist, show per-network breakdown and get confirmation
64- if totalActiveApps > 0 {
65- logger .Info ("You have active apps that will be suspended:" )
66- for env , info := range results {
67- if info .Count > 0 {
68- displayName := utils .GetEnvironmentDescription (env , env , false )
69- logger .Info (" • %s: %d app(s)" , displayName , info .Count )
70- }
71- }
61+ // If apps exist, show warning and get confirmation
62+ if activeAppCount > 0 {
63+ logger .Info ("You have %d active app(s) on %s that will be suspended." , activeAppCount , envName )
7264 logger .Info ("" )
7365
7466 confirmed , err := output .Confirm ("Continue?" )
@@ -81,37 +73,26 @@ var CancelCommand = &cli.Command{
8173 return nil
8274 }
8375
84- // Suspend apps on each network that has active apps
85- for env , info := range results {
86- if info .Count == 0 {
87- continue
88- }
89-
90- caller := info .Caller
91- logger .Info ("Suspending apps on %s..." , env )
92-
93- // Get only active apps for this developer on this network
94- activeApps , err := getActiveAppsByCreator (ctx , caller , developerAddr )
95- if err != nil {
96- return fmt .Errorf ("failed to get active apps for %s: %w" , env , err )
97- }
76+ // Get only active apps for this developer
77+ activeApps , err := getActiveAppsByCreator (ctx , caller , developerAddr )
78+ if err != nil {
79+ return fmt .Errorf ("failed to get active apps: %w" , err )
80+ }
9881
99- if len (activeApps ) == 0 {
100- logger .Info ("No active apps to suspend on %s" , env )
101- continue
102- }
82+ if len (activeApps ) > 0 {
83+ logger .Info ("Suspending apps..." )
10384
10485 // Suspend only active apps
10586 err = caller .Suspend (ctx , developerAddr , activeApps )
10687 if err != nil {
107- return fmt .Errorf ("failed to suspend apps on %s : %w" , env , err )
88+ return fmt .Errorf ("failed to suspend apps: %w" , err )
10889 }
10990
110- logger .Info ("✓ Apps suspended on %s" , env )
91+ logger .Info ("✓ Apps suspended" )
11192 }
11293 } else {
11394 // No active apps, just confirm cancellation
114- logger .Warn ("Canceling your subscription will prevent you from deploying new apps." )
95+ logger .Warn ("Canceling your subscription on %s will prevent you from deploying new apps." , envName )
11596 confirmed , err := output .Confirm ("Are you sure you want to cancel your subscription?" )
11697 if err != nil {
11798 return fmt .Errorf ("failed to get confirmation: %w" , err )
@@ -129,7 +110,7 @@ var CancelCommand = &cli.Command{
129110 return fmt .Errorf ("failed to cancel subscription: %w" , err )
130111 }
131112
132- logger .Info ("\n ✓ Subscription canceled successfully." )
113+ logger .Info ("\n ✓ Subscription canceled successfully for %s." , envName )
133114 return nil
134115 },
135116}
0 commit comments