UNPKG

@ledgerhq/live-common

Version:
34 lines 1.28 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useReverseAccounts = void 0; const react_1 = require("react"); const account_1 = require("../../../account"); const useReverseAccounts = ({ accounts, toAccount, fromAccount, fromParentAccount, fromCurrency, setFromAccount, setToAccount, }) => { const isSwapReversable = (0, react_1.useMemo)(() => { if (!toAccount || !fromCurrency) return false; const allAccounstWithSub = accounts ? (0, account_1.flattenAccounts)(accounts) : []; const isToSwappable = !!allAccounstWithSub.find(account => account.id === toAccount?.id); return isToSwappable; }, [toAccount, fromCurrency, accounts]); const reverseSwap = (0, react_1.useCallback)(() => { if (isSwapReversable === false) return; setFromAccount(toAccount); setToAccount(fromCurrency, fromAccount, fromParentAccount); }, [ toAccount, fromCurrency, fromAccount, fromParentAccount, setFromAccount, setToAccount, isSwapReversable, ]); return { isSwapReversable, reverseSwap, }; }; exports.useReverseAccounts = useReverseAccounts; //# sourceMappingURL=useReverseAccounts.js.map