SIGN IN SIGN UP

perf(hooks): extract restorePurchases into useCallback for stable reference (#3172)

## Summary

Extracts the inline `restorePurchases` function from the `useIAP` hook's
return statement into a properly memoized `useCallback`.

## Problem

All other public functions returned by `useIAP` (e.g.
`finishTransaction`, `requestPurchase`, `fetchProducts`,
`validateReceipt`) are wrapped in `useCallback` to provide a stable
reference across renders. However, `restorePurchases` was defined as an
inline `async () => {}` directly in the return statement, causing it to
be recreated on every render.

This inconsistency means:
- Components that receive `restorePurchases` as a prop and use it in a
`useEffect` or `useCallback` dependency array will trigger unnecessary
re-runs
- Strict mode linting (e.g. `react-hooks/exhaustive-deps`) can flag its
usage since it's not stable
- It's inconsistent with the rest of the hook's API surface

## Changes
- Extracted `restorePurchases` into a `useCallback` with appropriate
dependencies `[getAvailablePurchasesInternal, invokeOnError]`
- Removed the now-outdated comment `// No local restorePurchases; use
the top-level helper via returned API`
- The return statement now references the stable `restorePurchases`
variable

## Why
Improves performance consistency and aligns `restorePurchases` with the
rest of the hook's API design.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Refactor**
* Updated restore flow: on iOS the app now performs a platform sync
before refreshing purchases. No change to public API or expected
behavior for end users.
* **Tests**
* Test suite updated to reflect the new iOS restore sequence and error
propagation scenarios.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
H
Hyo committed
1bbbbae207a4e4c439792652411caff07bf326bf
Parent: 4384366
Committed by GitHub <noreply@github.com> on 3/25/2026, 7:45:08 AM