diff --git a/src/views/purse/PurseMessageHandler.tsx b/src/views/purse/PurseMessageHandler.tsx index 17c5ba4f..23d474e2 100644 --- a/src/views/purse/PurseMessageHandler.tsx +++ b/src/views/purse/PurseMessageHandler.tsx @@ -1,4 +1,4 @@ -import { UserCreditsEvent, UserCurrencyEvent, UserCurrencyUpdateEvent } from 'nitro-renderer'; +import { UserCreditsEvent, UserCurrencyEvent, UserCurrencyUpdateEvent, UserSubscriptionEvent } from 'nitro-renderer'; import { FC, useCallback } from 'react'; import { CreateMessageHook } from '../../hooks/messages/message-event'; import { Currency } from './common/Currency'; @@ -48,9 +48,27 @@ export const PurseMessageHandler: FC = props => }); }, [ dispatchPurseState ]); + const onUserSubscriptionEvent = useCallback((event: UserSubscriptionEvent) => + { + const parser = event.getParser(); + + switch(parser.name) + { + case 'habbo_club': + dispatchPurseState({ + type: PurseActions.SET_CLUB_SUBSCRIPTION, + payload: { + clubSubscription: parser + } + }); + return; + } + }, [ dispatchPurseState ]); + CreateMessageHook(UserCreditsEvent, onUserCreditsEvent); CreateMessageHook(UserCurrencyEvent, onUserCurrencyEvent); CreateMessageHook(UserCurrencyUpdateEvent, onUserCurrencyUpdateEvent); + CreateMessageHook(UserSubscriptionEvent, onUserSubscriptionEvent); return null; } diff --git a/src/views/purse/reducers/PurseReducer.tsx b/src/views/purse/reducers/PurseReducer.tsx index 1a84005f..3e9d5f5b 100644 --- a/src/views/purse/reducers/PurseReducer.tsx +++ b/src/views/purse/reducers/PurseReducer.tsx @@ -1,9 +1,11 @@ +import { UserSubscriptionParser } from 'nitro-renderer'; import { Reducer } from 'react'; import { Currency } from '../common/Currency'; export interface IPurseState { currencies: Currency[]; + clubSubscription: UserSubscriptionParser; } export interface IPurseAction @@ -12,6 +14,7 @@ export interface IPurseAction payload: { currency?: Currency; currencies?: Currency[]; + clubSubscription?: UserSubscriptionParser; } } @@ -19,10 +22,12 @@ export class PurseActions { public static SET_CURRENCY: string = 'PA_SET_CURRENCY'; public static SET_CURRENCIES: string = 'PA_SET_CURRENCIES'; + public static SET_CLUB_SUBSCRIPTION: string = 'PA_SET_CLUB_SUBSCRIPTION'; } export const initialPurse: IPurseState = { - currencies: [] + currencies: [], + clubSubscription: null } export const PurseReducer: Reducer = (state, action) => @@ -34,7 +39,7 @@ export const PurseReducer: Reducer = (state, action) let didSet = false; - const currencies = state.currencies.map((existing, index) => + const currencies = state.currencies.map(existing => { if(existing.type !== updated.type) return existing; @@ -50,7 +55,7 @@ export const PurseReducer: Reducer = (state, action) case PurseActions.SET_CURRENCIES: { const updated = action.payload.currencies; - const currencies = state.currencies.filter((existing, index) => + const currencies = state.currencies.filter(existing => { if(existing.type !== -1) return null; @@ -61,6 +66,11 @@ export const PurseReducer: Reducer = (state, action) return { ...state, currencies }; } + case PurseActions.SET_CLUB_SUBSCRIPTION: { + const clubSubscription = action.payload.clubSubscription; + + return { ...state, clubSubscription }; + } default: return state; }