From 68c3cece86219107ebcd9001a8d93d5fafaa3798 Mon Sep 17 00:00:00 2001 From: Oluwatobi Bamidele Date: Tue, 17 Oct 2023 23:13:26 +0100 Subject: [PATCH] refactor: made budget backward compatible --- src/components/AddNodeModal/index.tsx | 2 +- src/components/Stats/index.tsx | 6 +++++- src/stores/useUserStore/index.ts | 4 ++-- src/utils/setBudget/index.ts | 6 ++++-- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/components/AddNodeModal/index.tsx b/src/components/AddNodeModal/index.tsx index 19fb617a8..87f882f10 100644 --- a/src/components/AddNodeModal/index.tsx +++ b/src/components/AddNodeModal/index.tsx @@ -85,7 +85,7 @@ const handleSubmit = async ( close: () => void, sourceType: string, successCallback: () => void, - setBudget: (value: number) => void, + setBudget: (value: number | null) => void, ): Promise => { const body: { [index: string]: unknown } = {} diff --git a/src/components/Stats/index.tsx b/src/components/Stats/index.tsx index 76c334465..d2937a5fc 100644 --- a/src/components/Stats/index.tsx +++ b/src/components/Stats/index.tsx @@ -37,7 +37,11 @@ export const Stats = () => { const [stats, setStats] = useState(null) const [budget] = useUserStore((s) => [s.budget]) - function formatBudget(value: number) { + function formatBudget(value: number | null) { + if (value === null) { + return '?' + } + const stringBudget = value.toLocaleString() const splittedBudget = stringBudget.split(',') diff --git a/src/stores/useUserStore/index.ts b/src/stores/useUserStore/index.ts index 07f7749ad..50ea6acb6 100644 --- a/src/stores/useUserStore/index.ts +++ b/src/stores/useUserStore/index.ts @@ -5,8 +5,8 @@ export type UserStore = { pubKey: string setIsAdmin: (val: boolean) => void setPubKey: (val: string) => void - budget: number - setBudget: (val: number) => void + budget: number | null + setBudget: (val: number | null) => void } const defaultData: Omit = { diff --git a/src/utils/setBudget/index.ts b/src/utils/setBudget/index.ts index 3887aa056..4799f788b 100644 --- a/src/utils/setBudget/index.ts +++ b/src/utils/setBudget/index.ts @@ -1,6 +1,6 @@ import * as sphinx from 'sphinx-bridge-kevkevinpal' -export async function updateBudget(setBudget: (value: number) => void) { +export async function updateBudget(setBudget: (value: number | null) => void) { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore await sphinx.enable() @@ -9,7 +9,9 @@ export async function updateBudget(setBudget: (value: number) => void) { // @ts-ignore const budget = await sphinx.getBudget() - if (budget?.budget) { + if (budget?.msg === 'Invalid Action') { + setBudget(null) + } else if (budget?.budget) { setBudget(budget.budget) } }