Skip to content
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

feat: APP-368 add user balance error in buy credits form #2501

Open
wants to merge 7 commits into
base: feat-APP-204-buy-credits
Choose a base branch
from

Conversation

r41ph
Copy link
Contributor

@r41ph r41ph commented Oct 10, 2024

Description

https://regennetwork.atlassian.net/browse/APP-368

Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • provided a link to the relevant issue or specification
  • provided instructions on how to test
  • reviewed "Files changed" and left comments if necessary
  • confirmed all CI checks have passed

How to test

  1. Go to the marketplace and try to buy credits using a bigger amount that you have in your balance. You should see the error 'You don’t have enough CURRENCY_SELECTED' below the currency field: https://deploy-preview-2501--regen-marketplace.netlify.app/

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items
.

I have...

  • confirmed all author checklist items have been addressed
  • reviewed code correctness and readability
  • verified React components follow DRY principles
  • reviewed documentation is accurate
  • reviewed tests
  • manually tested (if applicable)

Copy link

netlify bot commented Oct 10, 2024

Deploy Preview for regen-website ready!

Name Link
🔨 Latest commit
🔍 Latest deploy log https://app.netlify.com/sites/regen-website/deploys/6707fe9feb72c60791c1cb77
😎 Deploy Preview https://deploy-preview-2501--regen-website.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@r41ph
Copy link
Contributor Author

r41ph commented Oct 10, 2024

@blushi

Relevant files:
web-marketplace/src/components/molecules/CreditsAmount/CreditsAmount.stories.tsx
web-marketplace/src/components/molecules/CreditsAmount/CurrencyInput.tsx
web-marketplace/src/components/organisms/BuyCreditsModal/BuyCreditsModal.tsx
web-marketplace/src/components/organisms/BuyCreditsModal/hooks/useFetchUserBalance.tsx
web-marketplace/src/components/organisms/ChooseCreditsForm/ChooseCreditsForm.constants.tsx
web-marketplace/src/components/organisms/ChooseCreditsForm/ChooseCreditsForm.schema.tsx
web-marketplace/src/components/organisms/ChooseCreditsForm/ChooseCreditsForm.tsx

@blushi
Copy link
Member

blushi commented Oct 10, 2024

@blushi

Relevant files: web-marketplace/src/components/molecules/CreditsAmount/CreditsAmount.stories.tsx web-marketplace/src/components/molecules/CreditsAmount/CurrencyInput.tsx web-marketplace/src/components/organisms/BuyCreditsModal/BuyCreditsModal.tsx web-marketplace/src/components/organisms/BuyCreditsModal/hooks/useFetchUserBalance.tsx web-marketplace/src/components/organisms/ChooseCreditsForm/ChooseCreditsForm.constants.tsx web-marketplace/src/components/organisms/ChooseCreditsForm/ChooseCreditsForm.schema.tsx web-marketplace/src/components/organisms/ChooseCreditsForm/ChooseCreditsForm.tsx

@r41ph you can also simply have the base branch for this PR be feat-APP-204-buy-credits so the diff is more readable (at least until my PR gets merged)

@r41ph r41ph changed the base branch from dev to feat-APP-204-buy-credits October 10, 2024 14:53
@r41ph
Copy link
Contributor Author

r41ph commented Oct 10, 2024

@r41ph you can also simply have the base branch for this PR be feat-APP-204-buy-credits so the diff is more readable (at least until my PR gets merged)

Got it, thanks! I've changed the base now

Comment on lines 11 to 12
selectedSellOrder?: UISellOrderInfo;
askDenom?: string;
Copy link
Member

Choose a reason for hiding this comment

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

what about refactoring this to only take askDenom as param?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't do that because this hook is used in BuyCreditsModal. Thought it'd be better to refactor it once we have deleted this buying flow.

Copy link
Member

Choose a reason for hiding this comment

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

it's only used once, so it would be really a small refactor:

const userBalance = useFetchUserBalance({ askDenom: selectedSellOrder?.askDenom });

@@ -99,11 +102,15 @@ export function ChooseCreditsForm({

const [spendingCap, setSpendingCap] = useState(0);
const [creditsAvailable, setCreditsAvailable] = useState(0);
// A big number here avoids the NOT_ENOUGH_BALANCE error on rendering
// the form until the actual user balance is fetched
const [userBalance, setUserBalance] = useState(10101010101010101);
Copy link
Member

Choose a reason for hiding this comment

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

this is a bit hacky, what about displaying a loading spinner instead of the form while we fetch the balance?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since the data we are fetching is related to validation for an error users may never encounter, I thought it'd be better to not block the UI from rendering, so users can interact with the form straight away. But yes, a loading animation is a more conventional solution.

@@ -3,3 +3,4 @@ import { msg } from '@lingui/macro';
export const MAX_AMOUNT = msg`Amount cannot exceed`;
export const MAX_CREDITS = msg`Credits cannot exceed`;
export const POSITIVE_NUMBER = msg`Must be positive`;
export const NOT_ENOUGH_BALANCE = msg`You don’t have enough`;
Copy link
Member

Choose a reason for hiding this comment

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

aren't we supposed to display You don’t have enough ${displayDenom}?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

oh I see, that assumes that all errors for this field will have the displayDenom at the end of the message.
I guess that works for now but that's not very reusable and also it gives less context for translating the content which could result in wrong translations.

@r41ph r41ph requested a review from blushi October 14, 2024 09:57
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.

2 participants