@@ -4,26 +4,39 @@ import compassCoffeeCard from '~/assets/gift-cards/compass.agi.cash.webp';
44import mapleCard from '~/assets/gift-cards/maple.agi.cash.webp' ;
55import pinkOwlCoffeeCard from '~/assets/gift-cards/pinkowl.agi.cash.webp' ;
66import pubkeyCard from '~/assets/gift-cards/pubkey.agi.cash.webp' ;
7+ import sfFreeCoffeeCard from '~/assets/gift-cards/sf-free-coffee.webp' ;
78import theShackCard from '~/assets/gift-cards/shack.agi.cash.webp' ;
89import theEpicurianTraderCard from '~/assets/gift-cards/theepicureantrader.agi.cash.webp' ;
910import { useAccounts } from '../accounts/account-hooks' ;
1011import {
1112 type GiftCardConfig ,
1213 JsonGiftCardConfigSchema ,
1314} from './gift-card-config' ;
15+ import {
16+ JsonOfferCardConfigSchema ,
17+ type OfferCardConfig ,
18+ } from './offer-card-config' ;
19+
20+ export type CardInfo = {
21+ url : string ;
22+ name : string ;
23+ image : string ;
24+ addCardDisclaimer ?: string ;
25+ } ;
1426
1527export type GiftCardInfo = GiftCardConfig & {
1628 image : string ;
1729} ;
1830
19- const GIFT_CARD_IMAGES : Record < string , string > = {
31+ const CARD_IMAGES : Record < string , string > = {
2032 'https://blockandbean.agi.cash' : blockAndBeanCard ,
2133 'https://pubkey.agi.cash' : pubkeyCard ,
2234 'https://maple.agi.cash' : mapleCard ,
2335 'https://compass.agi.cash' : compassCoffeeCard ,
2436 'https://pinkowl.agi.cash' : pinkOwlCoffeeCard ,
2537 'https://shack.agi.cash' : theShackCard ,
2638 'https://theepicureantrader.agi.cash' : theEpicurianTraderCard ,
39+ 'http://localhost:8104' : sfFreeCoffeeCard ,
2740} ;
2841
2942function loadGiftCardsFromEnv ( ) : GiftCardInfo [ ] {
@@ -33,11 +46,31 @@ function loadGiftCardsFromEnv(): GiftCardInfo[] {
3346 // Validated at build time by vite.config.ts — safe to throw here.
3447 return JsonGiftCardConfigSchema . parse ( raw ) . map ( ( card ) => ( {
3548 ...card ,
36- image : GIFT_CARD_IMAGES [ card . url ] ?? '' ,
49+ image : CARD_IMAGES [ card . url ] ?? '' ,
3750 } ) ) ;
3851}
3952
53+ type OfferCardInfo = OfferCardConfig & {
54+ image : string ;
55+ } ;
56+
57+ function loadOfferCardsFromEnv ( ) : OfferCardInfo [ ] {
58+ const raw = import . meta. env . VITE_OFFER_CARDS ;
59+ if ( ! raw ) return [ ] ;
60+
61+ return JsonOfferCardConfigSchema . parse ( raw ) . map ( ( card ) => {
62+ const image = CARD_IMAGES [ card . url ] ;
63+ if ( ! image ) {
64+ throw new Error (
65+ `Missing image for offer card: ${ card . url } . Add an entry to CARD_IMAGES.` ,
66+ ) ;
67+ }
68+ return { ...card , image } ;
69+ } ) ;
70+ }
71+
4072export const GIFT_CARDS : GiftCardInfo [ ] = loadGiftCardsFromEnv ( ) ;
73+ export const OFFER_CARDS : OfferCardInfo [ ] = loadOfferCardsFromEnv ( ) ;
4174
4275/**
4376 * Returns the gift card image for a given URL, if one exists.
@@ -53,6 +86,18 @@ export function getGiftCardByUrl(url: string): GiftCardInfo | undefined {
5386 return GIFT_CARDS . find ( ( card ) => card . url === url ) ;
5487}
5588
89+ /**
90+ * Returns card info (image, name, etc.) for a given mint URL,
91+ * regardless of whether it's a gift card or offer card.
92+ */
93+ export function getCardByUrl ( url : string ) : CardInfo | undefined {
94+ const giftCard = GIFT_CARDS . find ( ( card ) => card . url === url ) ;
95+ if ( giftCard ) return giftCard ;
96+ const offerCard = OFFER_CARDS . find ( ( card ) => card . url === url ) ;
97+ if ( offerCard ) return offerCard ;
98+ return undefined ;
99+ }
100+
56101/**
57102 * Returns gift cards that the user has not yet added.
58103 */
0 commit comments