Skip to content

Commit

Permalink
refactor: made budget backward compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
tobi-bams committed Oct 17, 2023
1 parent 432f6f7 commit 68c3cec
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/components/AddNodeModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const handleSubmit = async (
close: () => void,
sourceType: string,
successCallback: () => void,
setBudget: (value: number) => void,
setBudget: (value: number | null) => void,
): Promise<void> => {
const body: { [index: string]: unknown } = {}

Expand Down
6 changes: 5 additions & 1 deletion src/components/Stats/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ export const Stats = () => {
const [stats, setStats] = useState<TStats | null>(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(',')
Expand Down
4 changes: 2 additions & 2 deletions src/stores/useUserStore/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<UserStore, 'setIsAdmin' | 'setPubKey' | 'setBudget'> = {
Expand Down
6 changes: 4 additions & 2 deletions src/utils/setBudget/index.ts
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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)
}
}

0 comments on commit 68c3cec

Please sign in to comment.