UNPKG

@yak-spirit/yak-swap-ui

Version:

A reusable React component for swapping with Yield Yak Router. The YY Router can be found [here](https://github.com/yieldyak/yak-aggregator).

37 lines (36 loc) 2.12 kB
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime"; import { useSnapshot } from 'valtio'; import SpiritLoader from '../../../components/shared/SpiritLoader.js'; import { swapState } from '../../../state/index.js'; import { Transition } from 'react-transition-group'; const duration = 300; const defaultStyle = { transition: `opacity ${duration}ms ease-in-out`, opacity: 0, }; const transitionStyles = { entering: { opacity: 1 }, entered: { opacity: 1 }, exiting: { opacity: 0 }, exited: { opacity: 0 }, }; const SwapCardInputsSwapper = () => { const swapSnap = useSnapshot(swapState); const swapSelects = () => { const tokenIn = swapState.tokenIn; swapState.tokenIn = swapState.tokenOut; swapState.tokenOut = tokenIn; swapState.amountIn = swapState.amountOut; swapState.amountOut = 0; }; return (_jsxs(_Fragment, { children: [_jsx(Transition, { in: swapSnap.loading, timeout: duration, children: (state) => (_jsx("div", { className: "absolute", style: { ...defaultStyle, // @ts-expect-error ...transitionStyles[state], }, children: _jsx(SpiritLoader, { size: "small" }, void 0) }, void 0)) }, void 0), _jsx(Transition, { in: !swapSnap.loading, timeout: duration, children: (state) => (_jsx("div", { className: "absolute", style: { ...defaultStyle, // @ts-expect-error ...transitionStyles[state], }, children: _jsx("button", { onClick: swapSelects, disabled: swapSnap.loading, type: "button", className: "btn btn-ghost", children: _jsx("svg", { xmlns: "http://www.w3.org/2000/svg", className: "h-6 w-6", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: _jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M7 16V4m0 0L3 8m4-4l4 4m6 0v12m0 0l4-4m-4 4l-4-4" }, void 0) }, void 0) }, void 0) }, void 0)) }, void 0)] }, void 0)); }; export default SwapCardInputsSwapper;