()
| 12 | import { useAuthContext } from '../../contexts/AuthContext'; |
| 13 | |
| 14 | export const CoreOptionList = (): ReactElement => { |
| 15 | const { user, isLoggedIn } = useAuthContext(); |
| 16 | const { selectedProduct } = useBuyCoresContext(); |
| 17 | const [isLoadingNative, setLoadingNative] = useState(false); |
| 18 | const { data: prices, isPending: isPendingPrices } = useQuery( |
| 19 | coresPricesQueryOptions({ |
| 20 | user, |
| 21 | isLoggedIn, |
| 22 | }), |
| 23 | ); |
| 24 | |
| 25 | useEffect(() => { |
| 26 | promisifyEventListener<void, 'true' | 'false'>( |
| 27 | 'iap-loading', |
| 28 | ({ detail }) => { |
| 29 | setLoadingNative(stringToBoolean(detail)); |
| 30 | }, |
| 31 | { |
| 32 | once: false, |
| 33 | }, |
| 34 | ).catch(() => { |
| 35 | setLoadingNative(false); |
| 36 | }); |
| 37 | |
| 38 | return () => { |
| 39 | globalThis?.eventControllers?.['iap-loading']?.abort(); |
| 40 | }; |
| 41 | }, []); |
| 42 | |
| 43 | return ( |
| 44 | <ul className="mt-4 flex flex-col gap-2" role="radiogroup"> |
| 45 | {isPendingPrices && |
| 46 | new Array(9).fill(null).map((_, index) => { |
| 47 | // eslint-disable-next-line react/no-array-index-key |
| 48 | return <CoreOptionButtonPlaceholder key={index} />; |
| 49 | })} |
| 50 | {!isPendingPrices && |
| 51 | prices?.map((price) => { |
| 52 | return ( |
| 53 | <CoreOptionButton |
| 54 | key={price.priceId} |
| 55 | id={price.priceId} |
| 56 | label={price.metadata.title} |
| 57 | cores={price.metadata.coresValue} |
| 58 | priceFormatted={price.price.formatted} |
| 59 | isLoading={ |
| 60 | isLoadingNative && price.priceId === selectedProduct?.id |
| 61 | } |
| 62 | // prevent clicks while native iap is loading |
| 63 | isDisabled={isLoadingNative} |
| 64 | /> |
| 65 | ); |
| 66 | })} |
| 67 | </ul> |
| 68 | ); |
| 69 | }; |
nothing calls this directly
no test coverage detected