Skip to content

Conversation

stefanbitcr
Copy link
Contributor

@stefanbitcr stefanbitcr commented May 26, 2025

📝 Description

  • Display On Chain Balance
  • Display Credit Balance
  • Display Debit Balance
  • Show initials as avatar rather than stock images
  • Show logged in Keycloak account as user
  • Remove pages that aren't currently used
  • Use a single quote page for all different statuses (deleted other quote listing pages as they are duplicates)
  • Allow anon types for payee
  • Remove mock data
  • Refresh auth token
  • Only allow keyset activation for accepted quotes

✅ Checklist

Please ensure the following tasks are completed before requesting a review:

  • My code adheres to the style guidelines of this project.
  • I have run npm run lint or the equivalent linting command.
  • I have added or updated tests (if applicable).
  • My changes have been tested thoroughly in different browsers/resolutions (if applicable).
  • I have updated the documentation (if applicable).
  • I have checked that there are no console errors or warnings.
  • I have verified that the application builds without errors.
  • I have tested responsiveness for mobile and desktop views (if applicable).

@stefanbitcr stefanbitcr self-assigned this May 26, 2025
Copy link

cloudflare-workers-and-pages bot commented May 26, 2025

Deploying wildcat-dashboard with  Cloudflare Pages  Cloudflare Pages

Latest commit: 099660a
Status: ✅  Deploy successful!
Preview URL: https://da87dd1c.wildcat-dashboard.pages.dev
Branch Preview URL: https://stefan-update2.wildcat-dashboard.pages.dev

View logs

Copy link

codecov bot commented May 26, 2025

<AvatarImage src={user.avatar} alt={user.name} />
<AvatarFallback className="rounded-lg">{user.name}</AvatarFallback>
<div
className="w-full h-full flex items-center justify-center text-white font-semibold text-sm"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may use the custom background color directly with the bg- class utiltity to avoid creating extra variables and passing it down through properties, for example: bg-[#f59e0b]

Suggested change
className="w-full h-full flex items-center justify-center text-white font-semibold text-sm"
className="w-full h-full flex items-center justify-center text-white font-semibold text-sm bg-[#f59e0b]"

unit: string
}

export function BalanceText({ amount, unit, children }: PropsWithChildren<{ amount: string; unit: string }>) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the BalanceDisplay here to keep consistency

Suggested change
export function BalanceText({ amount, unit, children }: PropsWithChildren<{ amount: string; unit: string }>) {
export function BalanceText({ amount, unit, children }: PropsWithChildren<BalanceDisplay>) {

Comment on lines 134 to 139
function PageBody() {
const { data } = useSuspenseQuery({
queryKey: ["balances"],
queryFn: fetchBalances,
function isErrorResponse<T>(res: { data?: T; error?: unknown }): res is { data: undefined; error: unknown } {
return res.error !== undefined
}
Copy link

@cryptosalomao cryptosalomao May 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a special reason to stop using tanstack query here? If it's suspense mode, I understand that it may be tricky to handle multiple queries at once with it, but you could still use the useQueries hook to call multiple functions at once, this way you wouldn't have to handle all the individual state updates and errors, and could still access the status imperatively with isLoading, isError, isSuccess && data, etc.

For reference:
https://tanstack.com/query/latest/docs/framework/react/reference/useQueries

Comment on lines 171 to 226
if (creditResponse.status === "fulfilled" && !isErrorResponse(creditResponse.value)) {
const creditData = creditResponse.value.data
if (creditData && "amount" in creditData && "unit" in creditData) {
newBalances.credit = {
amount: String(creditData.amount),
unit: String(creditData.unit),
}
}
} else {
console.warn(
"Failed to fetch credit balance:",
creditResponse.status === "rejected" ? creditResponse.reason : creditResponse.value.error,
)
}

// Handle debit balance response
if (debitResponse.status === "fulfilled" && !isErrorResponse(debitResponse.value)) {
const debitData = debitResponse.value.data
if (debitData && "amount" in debitData && "unit" in debitData) {
newBalances.debit = {
amount: String(debitData.amount),
unit: String(debitData.unit),
}
}
} else {
console.warn(
"Failed to fetch debit balance:",
debitResponse.status === "rejected" ? debitResponse.reason : debitResponse.value.error,
)
}

if (onchainResponse.status === "fulfilled" && !isErrorResponse(onchainResponse.value)) {
const onchainData = onchainResponse.value.data
if (onchainData && typeof onchainData === "object" && "confirmed" in onchainData) {
console.log("Onchain balance:", onchainData.confirmed)
newBalances.bitcoin = {
amount: String(onchainData.confirmed),
unit: "BTC",
}
}
} else {
console.warn(
"Failed to fetch onchain balance:",
onchainResponse.status === "rejected" ? onchainResponse.reason : onchainResponse.value.error,
)
}

setBalances(newBalances)
} catch (error) {
const errorMessage = error instanceof Error ? error.message : "Unknown error occurred"
setError(errorMessage)
console.error("Failed to fetch balances:", error)
} finally {
setIsLoading(false)
}
}, [])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tend to think this is too complicated, because it has several statuses blocks to handle. Let me know if you found @tanstack/react-query not handy in here

useEffect(() => {
void fetchAllBalances()

const interval = setInterval(() => void fetchAllBalances(), 30000)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good here, just a suggestion to separate the decimals here for better readability xD

Suggested change
const interval = setInterval(() => void fetchAllBalances(), 30000)
const interval = setInterval(() => void fetchAllBalances(), 30_000)

Comment on lines 24 to 31
function getInitials(name?: string): string {
if (!name) return "?"
const words = name.trim().split(/\s+/)
if (words.length === 1) {
return words[0].substring(0, 2).toUpperCase()
}
return (words[0][0] + words[words.length - 1][0]).toUpperCase()
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe move this to it's own utils file? Not sure if it's an early optimization tho, please tell me. Also, we have this very same utility with a cleaner functional approach in our frontend repo:

https://github.com/BitcreditProtocol/E-Bill-frontend/blob/main/src/utils/strings.ts#L11

We have other util functions there too, so please feel free to use as many of those as you want to!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very clean, I ended up stealing it.

@cryptosalomao
Copy link

cryptosalomao commented May 26, 2025

Only a few things and quick improvements suggestions. The major thing is the use of tanstack query that has been reduced in here. It works with anything wrapped in a Promise, so you wouldn't have to handle all the individual statuses (fulfilled, pending, rejection, etc) manually.

I think it's worth the time to try and learn the basics of it to keep redundancy minimal:
https://tanstack.com/query/latest/docs/framework/react/guides/queries#query-basics

Excellent job!

@stefanbitcr
Copy link
Contributor Author

stefanbitcr commented May 26, 2025

@cryptosalomao Thank you for the review effort! I will take a look at tanstack, indeed my unfamiliarity with it (and react) might be overcomplicating things!

@cryptosalomao
Copy link

@cryptosalomao Thank you for the review effort! I will take a look at tanstack, indeed my unfamiliarity with it (and react) might be overcomplicating things!

You're welcome! I'm sure you'll find it easy after giving it a try. Let me know if you need extra help and want to jump on a call to address any questions you may have

@stefanbitcr stefanbitcr merged commit d804fbd into master May 29, 2025
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants