@@ -36,6 +36,7 @@ import { DropdownInputButton } from '../buttons/DropdownInputButton'
3636import { KavButtons } from '../buttons/KavButtons'
3737import { AlertCardUi4 } from '../cards/AlertCard'
3838import { EdgeCard } from '../cards/EdgeCard'
39+ import { ErrorCard } from '../cards/ErrorCard'
3940import { EdgeAnim } from '../common/EdgeAnim'
4041import { EdgeTouchableOpacity } from '../common/EdgeTouchableOpacity'
4142import { SceneWrapper } from '../common/SceneWrapper'
@@ -118,6 +119,13 @@ export const GiftCardPurchaseScene: React.FC<Props> = props => {
118119 footer : string
119120 } | null > ( null )
120121
122+ // Warning state for product unavailable
123+ const [ productUnavailable , setProductUnavailable ] =
124+ React . useState < boolean > ( false )
125+
126+ // Error state for unexpected errors
127+ const [ error , setError ] = React . useState < unknown > ( null )
128+
121129 // Fetch allowed tokens from Phaze API
122130 const { data : tokenQueryResult } = useQuery ( {
123131 queryKey : [ 'phazeTokens' , account ?. id , isReady ] ,
@@ -195,8 +203,10 @@ export const GiftCardPurchaseScene: React.FC<Props> = props => {
195203
196204 // Handle amount text change for variable range
197205 const handleAmountChange = useHandler ( ( text : string ) => {
198- // Clear minimum warning when user modifies amount
206+ // Clear warnings/errors when user modifies amount
199207 setMinimumWarning ( null )
208+ setProductUnavailable ( false )
209+ setError ( null )
200210
201211 // Only allow numbers and decimal point
202212 const cleaned = text . replace ( / [ ^ 0 - 9 . ] / g, '' )
@@ -216,6 +226,8 @@ export const GiftCardPurchaseScene: React.FC<Props> = props => {
216226 const handleMaxPress = useHandler ( ( ) => {
217227 if ( hasVariableRange ) {
218228 setMinimumWarning ( null )
229+ setProductUnavailable ( false )
230+ setError ( null )
219231 setAmountText ( String ( maxVal ) )
220232 setSelectedAmount ( maxVal )
221233 }
@@ -259,8 +271,10 @@ export const GiftCardPurchaseScene: React.FC<Props> = props => {
259271 )
260272
261273 if ( result != null ) {
262- // Clear minimum warning when user modifies amount
274+ // Clear warnings/errors when user modifies amount
263275 setMinimumWarning ( null )
276+ setProductUnavailable ( false )
277+ setError ( null )
264278 setSelectedAmount ( result . amount )
265279 setAmountText ( String ( result . amount ) )
266280 }
@@ -496,8 +510,20 @@ export const GiftCardPurchaseScene: React.FC<Props> = props => {
496510 } catch ( err : unknown ) {
497511 debugLog ( 'phaze' , 'Order creation error:' , err )
498512
499- // Check for minimum amount error from API
513+ // Clear previous warnings/errors
514+ setMinimumWarning ( null )
515+ setProductUnavailable ( false )
516+ setError ( null )
517+
500518 const errorMessage = err instanceof Error ? err . message : ''
519+
520+ // Check for product unavailable error
521+ if ( errorMessage . includes ( 'Product is unavailable' ) ) {
522+ setProductUnavailable ( true )
523+ return
524+ }
525+
526+ // Check for minimum amount error from API
501527 const minimumMatch = / M i n i m u m c a r t c o s t s h o u l d b e a b o v e : ( [ \d . ] + ) / . exec (
502528 errorMessage
503529 )
@@ -515,7 +541,8 @@ export const GiftCardPurchaseScene: React.FC<Props> = props => {
515541 )
516542 } )
517543 } else {
518- showError ( err )
544+ // Show ErrorCard for other errors
545+ setError ( err )
519546 }
520547 } finally {
521548 setIsCreatingOrder ( false )
@@ -632,6 +659,8 @@ export const GiftCardPurchaseScene: React.FC<Props> = props => {
632659 style = { styles . maxButton }
633660 onPress = { ( ) => {
634661 setMinimumWarning ( null )
662+ setProductUnavailable ( false )
663+ setError ( null )
635664 const maxDenom =
636665 sortedDenominations [ sortedDenominations . length - 1 ]
637666 setSelectedAmount ( maxDenom )
@@ -668,14 +697,22 @@ export const GiftCardPurchaseScene: React.FC<Props> = props => {
668697 ) }
669698 </ EdgeAnim >
670699
671- { /* Minimum Amount Warning */ }
672- { minimumWarning != null ? (
700+ { /* Warnings/Errors - product unavailable takes precedence */ }
701+ { productUnavailable ? (
702+ < AlertCardUi4
703+ type = "warning"
704+ title = { lstrings . gift_card_product_unavailable_title }
705+ body = { lstrings . gift_card_product_unavailable_warning }
706+ />
707+ ) : minimumWarning != null ? (
673708 < AlertCardUi4
674709 type = "warning"
675710 title = { lstrings . gift_card_minimum_warning_title }
676711 header = { minimumWarning . header }
677712 footer = { minimumWarning . footer }
678713 />
714+ ) : error != null ? (
715+ < ErrorCard error = { error } />
679716 ) : null }
680717
681718 { /* Product Description Card */ }
0 commit comments