UNPKG

@yoroi/exchange

Version:

The Exchange package of Yoroi SDK

38 lines 1.18 kB
import * as React from 'react'; import { ExchangeActionType, exchangeDefaultState, exchangeReducer, exchangeInitialExchangeContext } from '../state/state'; export const ExchangeCtx = /*#__PURE__*/React.createContext(exchangeInitialExchangeContext); export const ExchangeProvider = _ref => { let { children, initialState, manager } = _ref; const [state, dispatch] = React.useReducer(exchangeReducer, { ...exchangeDefaultState, ...initialState }); const actions = React.useRef({ orderTypeChanged: orderType => dispatch({ type: ExchangeActionType.OrderTypeChanged, orderType }), amountInputChanged: (amount, canExchange) => dispatch({ type: ExchangeActionType.AmountInputChanged, amount, canExchange }), providerIdChanged: providerId => dispatch({ type: ExchangeActionType.ProviderIdChanged, providerId }) }).current; const context = React.useMemo(() => ({ ...state, ...actions, ...manager }), [state, actions, manager]); return /*#__PURE__*/React.createElement(ExchangeCtx.Provider, { value: context }, children); }; //# sourceMappingURL=ExchangeProvider.js.map