2021-05-07 09:50:20 +02:00
|
|
|
import { UserCurrencyComposer } from 'nitro-renderer';
|
2021-06-22 11:52:47 +02:00
|
|
|
import { FC, useCallback, useEffect, useMemo, useReducer } from 'react';
|
2021-06-23 10:05:23 +02:00
|
|
|
import { GetConfiguration } from '../../api';
|
2021-06-22 11:52:47 +02:00
|
|
|
import { NotificationCenterEvent } from '../../events';
|
|
|
|
import { dispatchUiEvent } from '../../hooks/events';
|
2021-05-07 09:50:20 +02:00
|
|
|
import { SendMessageHook } from '../../hooks/messages/message-event';
|
2021-06-23 06:03:56 +02:00
|
|
|
import { SetLastCurrencies } from './common/CurrencyHelper';
|
2021-05-07 09:50:20 +02:00
|
|
|
import { PurseContextProvider } from './context/PurseContext';
|
2021-04-15 19:29:48 +02:00
|
|
|
import { CurrencyView } from './currency/CurrencyView';
|
2021-05-07 09:50:20 +02:00
|
|
|
import { PurseMessageHandler } from './PurseMessageHandler';
|
2021-04-15 19:29:48 +02:00
|
|
|
import { PurseViewProps } from './PurseView.types';
|
2021-05-07 09:50:20 +02:00
|
|
|
import { initialPurse, PurseReducer } from './reducers/PurseReducer';
|
2021-04-15 19:29:48 +02:00
|
|
|
|
2021-05-07 09:50:20 +02:00
|
|
|
export const PurseView: FC<PurseViewProps> = props =>
|
2021-04-15 19:29:48 +02:00
|
|
|
{
|
2021-05-07 09:50:20 +02:00
|
|
|
const [ purseState, dispatchPurseState ] = useReducer(PurseReducer, initialPurse);
|
|
|
|
const { currencies = [] } = purseState;
|
|
|
|
|
|
|
|
const displayedCurrencies = useMemo(() =>
|
2021-04-15 19:29:48 +02:00
|
|
|
{
|
2021-05-07 09:50:20 +02:00
|
|
|
return GetConfiguration<number[]>('system.currency.types', []);
|
2021-04-21 05:36:39 +02:00
|
|
|
}, []);
|
|
|
|
|
2021-04-15 19:29:48 +02:00
|
|
|
useEffect(() =>
|
|
|
|
{
|
|
|
|
SendMessageHook(new UserCurrencyComposer());
|
|
|
|
}, []);
|
|
|
|
|
2021-05-10 19:11:16 +02:00
|
|
|
SetLastCurrencies(currencies);
|
|
|
|
|
2021-06-22 11:52:47 +02:00
|
|
|
const toggleNotificationCenter = useCallback(() =>
|
|
|
|
{
|
|
|
|
dispatchUiEvent(new NotificationCenterEvent(NotificationCenterEvent.TOGGLE_NOTIFICATION_CENTER));
|
|
|
|
}, []);
|
|
|
|
|
2021-04-15 19:29:48 +02:00
|
|
|
return (
|
2021-05-07 09:50:20 +02:00
|
|
|
<PurseContextProvider value={ { purseState, dispatchPurseState }}>
|
|
|
|
<PurseMessageHandler />
|
2021-07-07 04:26:22 +02:00
|
|
|
<div className="nitro-purse rounded-bottom d-flex flex-row justify-content-between">
|
|
|
|
<div className="row row-cols-2 mx-0">
|
|
|
|
{ currencies && currencies.map((currency, index) =>
|
|
|
|
{
|
|
|
|
if(displayedCurrencies.indexOf(currency.type) === -1) return null;
|
2021-04-21 05:36:39 +02:00
|
|
|
|
2021-07-07 04:26:22 +02:00
|
|
|
return <CurrencyView key={ index } currency={ currency } />;
|
|
|
|
})}
|
|
|
|
</div>
|
|
|
|
{/*<div className="notification-button px-2" onClick={toggleNotificationCenter}>
|
2021-06-22 11:52:47 +02:00
|
|
|
<i className="fas fa-bars" />
|
2021-07-07 04:26:22 +02:00
|
|
|
</div>*/}
|
2021-04-15 19:29:48 +02:00
|
|
|
</div>
|
2021-05-07 09:50:20 +02:00
|
|
|
</PurseContextProvider>
|
2021-04-15 19:29:48 +02:00
|
|
|
);
|
|
|
|
}
|