-
Notifications
You must be signed in to change notification settings - Fork 77
feat: account overview, auto reload, and separate payment method page #2282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ygrishajev
merged 8 commits into
akash-network:main
from
jzsfkzm:features/1779-auto-top-up-settings
Dec 9, 2025
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8b586f5
feat: account overview, auto reload, and separate payment method page
jzsfkzm cdb6b11
fix: follow-up on Rabbit's PR feedback
jzsfkzm f0b7934
fix: follow-up on Yaro's PR feedback
jzsfkzm 2d9f383
fix: report errors instead of a console.error call
jzsfkzm 604fc71
fix: inject and mock button component too
jzsfkzm daa671e
fix: footer of payment method list a notch darker
jzsfkzm 88e74c0
fix: remove copy about limiting number of cards
jzsfkzm cc36d58
fix: add a progress indicator for payments methods
jzsfkzm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,7 +1,8 @@ | ||
| export const FeatureFlags = { | ||
| NOTIFICATIONS_ALERT_CREATE: "notifications_general_alerts_create", | ||
| NOTIFICATIONS_ALERT_UPDATE: "notifications_general_alerts_update", | ||
| ANONYMOUS_FREE_TRIAL: "anonymous_free_trial" | ||
| ANONYMOUS_FREE_TRIAL: "anonymous_free_trial", | ||
| AUTO_CREDIT_RELOAD: "auto_credit_reload" | ||
| } as const; | ||
|
|
||
| export type FeatureFlagValue = (typeof FeatureFlags)[keyof typeof FeatureFlags]; |
138 changes: 138 additions & 0 deletions
138
apps/deploy-web/src/components/billing-usage/AccountOverview/AccountOverview.tsx
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| import React, { useCallback, useMemo, useState } from "react"; | ||
| import { FormattedNumber } from "react-intl"; | ||
| import { Button, Card, CardContent, CardFooter, CardHeader, CardTitle, Snackbar, Switch } from "@akashnetwork/ui/components"; | ||
| import { LinearProgress } from "@mui/material"; | ||
| import { Plus } from "iconoir-react"; | ||
| import { useSnackbar } from "notistack"; | ||
|
|
||
| import { PaymentPopup } from "@src/components/billing-usage/PaymentPopup/PaymentPopup"; | ||
| import Layout from "@src/components/layout/Layout"; | ||
| import { Title } from "@src/components/shared/Title"; | ||
| import { PaymentSuccessAnimation } from "@src/components/user/payment/PaymentSuccessAnimation"; | ||
| import { useWalletBalance } from "@src/hooks/useWalletBalance"; | ||
| import { useDefaultPaymentMethodQuery, useWalletSettingsMutations, useWalletSettingsQuery } from "@src/queries"; | ||
|
|
||
| export const AccountOverview: React.FunctionComponent = () => { | ||
| const [showPaymentPopup, setShowPaymentPopup] = useState(false); | ||
| const [showPaymentSuccess, setShowPaymentSuccess] = useState<{ amount: string; show: boolean }>({ amount: "", show: false }); | ||
| const { enqueueSnackbar } = useSnackbar(); | ||
| const { data: defaultPaymentMethod, isLoading: isLoadingDefaultPaymentMethod } = useDefaultPaymentMethodQuery(); | ||
| const { balance: walletBalance, isLoading: isWalletBalanceLoading } = useWalletBalance(); | ||
| const { data: walletSettings } = useWalletSettingsQuery(); | ||
| const { updateWalletSettings, createWalletSettings } = useWalletSettingsMutations(); | ||
|
|
||
| const isLoading = isLoadingDefaultPaymentMethod; | ||
|
|
||
| const defaultPaymentMethodId = useMemo(() => { | ||
| return defaultPaymentMethod?.id; | ||
| }, [defaultPaymentMethod]); | ||
|
|
||
| const toggleAutoReload = useCallback( | ||
| async (autoReloadEnabled: boolean) => { | ||
| try { | ||
| const settings = { | ||
| autoReloadEnabled | ||
| }; | ||
|
|
||
| if (walletSettings) { | ||
| await updateWalletSettings.mutateAsync(settings); | ||
| } else { | ||
| await createWalletSettings.mutateAsync(settings); | ||
| } | ||
|
|
||
| enqueueSnackbar(<Snackbar title={`Auto Reload ${autoReloadEnabled ? "enabled" : "disabled"}`} iconVariant="success" />, { | ||
| variant: "success", | ||
| autoHideDuration: 3000 | ||
| }); | ||
| } catch (error: unknown) { | ||
| enqueueSnackbar(<Snackbar title="Failed to update Auto Reload settings" iconVariant="error" />, { variant: "error" }); | ||
| } | ||
| }, | ||
| [createWalletSettings, enqueueSnackbar, updateWalletSettings, walletSettings] | ||
| ); | ||
|
|
||
| const isReloadChangeDisabled = useMemo(() => { | ||
| return !defaultPaymentMethod || updateWalletSettings.isPending || createWalletSettings.isPending; | ||
| }, [defaultPaymentMethod, updateWalletSettings.isPending, createWalletSettings.isPending]); | ||
|
|
||
| if (isLoading) { | ||
| return ( | ||
| <Layout> | ||
| <div className="flex min-h-[50vh] items-center justify-center"> | ||
| <div className="flex flex-col items-center gap-4"> | ||
| <div className="h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent" /> | ||
| <p className="text-muted-foreground">Loading payment information...</p> | ||
| </div> | ||
| </div> | ||
| </Layout> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <div> | ||
| <Title subTitle>Account overview</Title> | ||
|
|
||
| <div className="pt-4"> | ||
| <div className="flex w-full flex-col gap-4 lg:flex-row lg:gap-8"> | ||
| <Card className="flex min-h-28 basis-1/2 flex-col"> | ||
| <CardHeader className="flex flex-row items-center justify-between pb-0"> | ||
| <CardTitle className="text-base">Credits Remaining</CardTitle> | ||
| </CardHeader> | ||
| {!walletBalance || isWalletBalanceLoading ? ( | ||
| <div className="flex flex-1 items-center"> | ||
| <LinearProgress color="primary" className="mx-auto w-11/12" /> | ||
| </div> | ||
| ) : ( | ||
| <> | ||
| <CardContent className="pb-0"> | ||
| <div className="mt-4 text-3xl font-bold"> | ||
| <FormattedNumber value={walletBalance.totalDeploymentGrantsUSD} style="currency" currency="USD" /> | ||
| </div> | ||
| </CardContent> | ||
| <CardFooter className="justify-end"> | ||
| <Button | ||
| variant="default" | ||
| size="icon" | ||
| className="h-8 w-8 text-xs" | ||
| onClick={() => setShowPaymentPopup(true)} | ||
| disabled={isWalletBalanceLoading || !defaultPaymentMethod} | ||
| > | ||
| <Plus /> | ||
| </Button> | ||
| </CardFooter> | ||
| </> | ||
| )} | ||
| </Card> | ||
| <Card className="flex min-h-28 basis-1/2 flex-col"> | ||
| <CardHeader className="flex flex-row items-center justify-between pb-0"> | ||
| <CardTitle className="text-base">Auto reload</CardTitle> | ||
| </CardHeader> | ||
| <CardContent className="pt-2"> | ||
| <div> | ||
| <div className="pt-4"> | ||
| <Switch checked={walletSettings?.autoReloadEnabled ?? false} onCheckedChange={toggleAutoReload} disabled={isReloadChangeDisabled} /> | ||
| </div> | ||
| <div className="pt-2 text-sm">Add funds automatically</div> | ||
| </div> | ||
| </CardContent> | ||
| </Card> | ||
| </div> | ||
|
|
||
| <PaymentSuccessAnimation | ||
| show={showPaymentSuccess.show} | ||
| amount={showPaymentSuccess.amount} | ||
| onComplete={() => setShowPaymentSuccess({ amount: "", show: false })} | ||
| /> | ||
| </div> | ||
|
|
||
| {showPaymentPopup && ( | ||
| <PaymentPopup | ||
| open={showPaymentPopup} | ||
| onClose={() => setShowPaymentPopup(false)} | ||
| selectedPaymentMethodId={defaultPaymentMethodId} | ||
| setShowPaymentSuccess={setShowPaymentSuccess} | ||
| /> | ||
| )} | ||
| </div> | ||
| ); | ||
| }; | ||
This file contains hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incomplete loading state check.
The
isLoadingvariable only checksisLoadingDefaultPaymentMethod, but the component also depends on wallet balance and wallet settings data. If these are still loading, the component might render with incomplete data.Consider whether other loading states should be included:
Or if wallet settings loading should also block the initial render, though that data has a default fallback (
walletSettings?.autoReloadEnabled ?? false).📝 Committable suggestion
🤖 Prompt for AI Agents