Skip to content

fix: update pay button amount when paymentConfig changes - #49

Merged
AbdulazizAlrabiah merged 1 commit into
moyasar:mainfrom
HusnainMaroof:fix/stale-pay-button-amount
Nov 26, 2026
Merged

AbdulazizAlrabiah merged 1 commit into
moyasar:mainfrom
HusnainMaroof:fix/stale-pay-button-amount

Conversation

@HusnainMaroof

Copy link
Copy Markdown
Contributor

Fixes #48

Problem

The CreditCard and StcPay pay buttons cached the formatted amount in a module-level variable the first time they rendered. When paymentConfig.amount or paymentConfig.currency changed while the view stayed mounted, the button kept showing the first amount, while the payment request used the new one (e.g. "Pay $10.00" shown, $15.00 charged). SAR was not affected.

Changes

  • src/views/credit_card.tsx: remove the formattedAmount cache and its unmount reset; format the amount from the current paymentConfig on each render.
  • src/views/stc_pay/stc_pay_phone_number.tsx: same change (this cache was never reset).
  • Add regression tests for both views (src/__tests__/views/).
  • Add @testing-library/react-native and [email protected] (matching react) as dev dependencies, since there were no view tests before.

Testing

  • New tests fail on main (3/3) and pass with this change (3/3):
    • CreditCard: amount change (USD 1000 → 1500) updates the label
    • CreditCard: currency change (USD → KWD) updates the label
    • StcPay: amount change updates the label
  • yarn test: 219/219 passing
  • yarn typecheck: passing
  • yarn lint: 0 errors (no new warnings)
  • yarn prepare: passing

The CreditCard and STC Pay pay buttons cached the formatted amount in a
module-level variable, so changing paymentConfig.amount or currency while
the view was mounted kept showing the first amount, while the payment
used the new one. Format the amount from the current props on each render.

Fixes moyasar#48

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@AbdulazizAlrabiah AbdulazizAlrabiah self-assigned this Nov 12, 2026
@AbdulazizAlrabiah
AbdulazizAlrabiah self-requested a review November 12, 2026 19:35
@AbdulazizAlrabiah

Copy link
Copy Markdown
Collaborator

Thank you Husnain!

LGTM
@sultan-algarbi should we merge?

@AbdulazizAlrabiah
AbdulazizAlrabiah merged commit 08e6a10 into moyasar:main Nov 26, 2026
4 of 5 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.

CreditCard pay button shows a stale amount when paymentConfig changes (non-SAR currencies)

3 participants