@gardenfi/swap 0.0.1-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +65 -0
- package/dist/index.cjs +1 -0
- package/dist/index.js +5 -0
- package/dist/index10.cjs +1 -0
- package/dist/index10.js +33 -0
- package/dist/index11.cjs +1 -0
- package/dist/index11.js +36 -0
- package/dist/index12.cjs +1 -0
- package/dist/index12.js +65 -0
- package/dist/index13.cjs +1 -0
- package/dist/index13.js +33 -0
- package/dist/index14.cjs +1 -0
- package/dist/index14.js +190 -0
- package/dist/index15.cjs +1 -0
- package/dist/index15.js +51 -0
- package/dist/index16.cjs +1 -0
- package/dist/index16.js +313 -0
- package/dist/index17.cjs +1 -0
- package/dist/index17.js +29 -0
- package/dist/index18.cjs +1 -0
- package/dist/index18.js +17 -0
- package/dist/index19.cjs +1 -0
- package/dist/index19.js +229 -0
- package/dist/index20.cjs +1 -0
- package/dist/index20.js +15 -0
- package/dist/index21.cjs +1 -0
- package/dist/index21.js +92 -0
- package/dist/index22.cjs +1 -0
- package/dist/index22.js +143 -0
- package/dist/index23.cjs +1 -0
- package/dist/index23.js +22 -0
- package/dist/index24.cjs +1 -0
- package/dist/index24.js +20 -0
- package/dist/index25.cjs +1 -0
- package/dist/index25.js +108 -0
- package/dist/index26.cjs +1 -0
- package/dist/index26.js +85 -0
- package/dist/index27.cjs +1 -0
- package/dist/index27.js +15 -0
- package/dist/index28.cjs +1 -0
- package/dist/index28.js +54 -0
- package/dist/index29.cjs +1 -0
- package/dist/index29.js +63 -0
- package/dist/index3.cjs +1 -0
- package/dist/index3.js +7 -0
- package/dist/index30.cjs +1 -0
- package/dist/index30.js +44 -0
- package/dist/index31.cjs +1 -0
- package/dist/index31.js +43 -0
- package/dist/index4.cjs +1 -0
- package/dist/index4.js +26 -0
- package/dist/index5.cjs +1 -0
- package/dist/index5.js +250 -0
- package/dist/index6.cjs +1 -0
- package/dist/index6.js +98 -0
- package/dist/index7.cjs +1 -0
- package/dist/index7.js +51 -0
- package/dist/index8.cjs +1 -0
- package/dist/index8.js +51 -0
- package/dist/index9.cjs +1 -0
- package/dist/index9.js +101 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/lib/GardenComponent.d.ts +6 -0
- package/dist/src/lib/common/AddressDetails.d.ts +8 -0
- package/dist/src/lib/common/ChainsToolTip.d.ts +8 -0
- package/dist/src/lib/common/Modal.d.ts +9 -0
- package/dist/src/lib/common/ModalComponent.d.ts +7 -0
- package/dist/src/lib/common/Navbar.d.ts +10 -0
- package/dist/src/lib/common/SwapInput.d.ts +17 -0
- package/dist/src/lib/components/CreateSwap.d.ts +4 -0
- package/dist/src/lib/components/SwapSavingsAndAddresses.d.ts +10 -0
- package/dist/src/lib/components/SwapWidget.d.ts +7 -0
- package/dist/src/lib/components/assetSelection/AssetModal.d.ts +8 -0
- package/dist/src/lib/components/assetSelection/AvailableChainsSidebar.d.ts +11 -0
- package/dist/src/lib/components/feesAndRateDetails/FeeAndRateDetails.d.ts +3 -0
- package/dist/src/lib/components/feesAndRateDetails/InputAddress.d.ts +3 -0
- package/dist/src/lib/components/feesAndRateDetails/InputAddressAndFeeRateDetails.d.ts +3 -0
- package/dist/src/lib/components/transactions/SwapInfo.d.ts +12 -0
- package/dist/src/lib/components/transactions/TransactionHistory.d.ts +7 -0
- package/dist/src/lib/components/transactions/TransactionRow.d.ts +11 -0
- package/dist/src/lib/components/transactions/TransactionSkeleton.d.ts +3 -0
- package/dist/src/lib/components/transactions/Transactions.d.ts +4 -0
- package/dist/src/lib/constants/animations.d.ts +7 -0
- package/dist/src/lib/constants/constants.d.ts +29 -0
- package/dist/src/lib/constants/network.d.ts +0 -0
- package/dist/src/lib/hooks/useSwap.d.ts +29 -0
- package/dist/src/lib/store/assetStore.d.ts +23 -0
- package/dist/src/lib/store/swapStore.d.ts +79 -0
- package/dist/src/lib/store/transactionHistoryStore.d.ts +17 -0
- package/dist/src/lib/store/viewPortStore.d.ts +17 -0
- package/dist/src/lib/types/types.d.ts +54 -0
- package/dist/src/lib/utils/utils.d.ts +14 -0
- package/dist/style.css +1 -0
- package/package.json +62 -0
package/README.md
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# @gardenfi/swap
|
|
2
|
+
|
|
3
|
+
A lightweight, ready-to-use `<Garden />` component that wires up `GardenProvider` and exposes `useGarden` for consuming apps. Designed to drop into any React app and get all Garden features via the provider and hooks.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
yarn add @gardenfi/swap
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```tsx
|
|
14
|
+
import React from 'react';
|
|
15
|
+
import { Garden, useGarden } from '@gardenfi/swap';
|
|
16
|
+
|
|
17
|
+
export default function App() {
|
|
18
|
+
const config = {
|
|
19
|
+
environment: 'mainnet',
|
|
20
|
+
// wallets or htlc configs here
|
|
21
|
+
} as any;
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<Garden config={config}>
|
|
25
|
+
<MySwapUI />
|
|
26
|
+
</Garden>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function MySwapUI() {
|
|
31
|
+
const { getQuote, swapAndInitiate, pendingOrders } = useGarden();
|
|
32
|
+
// ...
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Scripts
|
|
38
|
+
|
|
39
|
+
- `yarn build`
|
|
40
|
+
- `yarn dev` (watch build)
|
|
41
|
+
- `yarn link`
|
|
42
|
+
|
|
43
|
+
## Local linking
|
|
44
|
+
|
|
45
|
+
From repo root:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
yarn link:all
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
To unlink:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
yarn unlink:all
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Publishing
|
|
58
|
+
|
|
59
|
+
This package follows the root workspace publish scripts. Use:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
yarn publish:affected
|
|
63
|
+
# or for beta
|
|
64
|
+
yarn publish:affected:beta
|
|
65
|
+
```
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});;/* empty css */const e=require("./index3.cjs");exports.GardenComponent=e.GardenComponent;
|
package/dist/index.js
ADDED
package/dist/index10.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),l=require("./index18.cjs"),c=require("./index19.cjs"),d=require("./index6.cjs"),i=require("./index16.cjs"),u=()=>{const{closeAssetModal:o,isAssetModalOpen:n,modalOpenFor:s}=d.assetInfoStore(),{setAsset:r}=i.useSwap();return e.useEffect(()=>{const t=a=>{a.key==="Escape"&&n&&o()};return window.addEventListener("keydown",t),()=>{window.removeEventListener("keydown",t)}},[n,o]),e.createElement(e.Fragment,null,e.createElement(l.ResponsiveModal,{open:n,onClose:()=>o()},e.createElement(c,{onSelect:t=>{s&&r(s,t)}})))};exports.Modal=u;
|
package/dist/index10.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import o, { useEffect as m } from "react";
|
|
2
|
+
import { ResponsiveModal as l } from "./index18.js";
|
|
3
|
+
import i from "./index19.js";
|
|
4
|
+
import { assetInfoStore as d } from "./index6.js";
|
|
5
|
+
import { useSwap as c } from "./index16.js";
|
|
6
|
+
const M = () => {
|
|
7
|
+
const { closeAssetModal: t, isAssetModalOpen: n, modalOpenFor: r } = d(), { setAsset: s } = c();
|
|
8
|
+
return m(() => {
|
|
9
|
+
const e = (a) => {
|
|
10
|
+
a.key === "Escape" && n && t();
|
|
11
|
+
};
|
|
12
|
+
return window.addEventListener("keydown", e), () => {
|
|
13
|
+
window.removeEventListener("keydown", e);
|
|
14
|
+
};
|
|
15
|
+
}, [n, t]), /* @__PURE__ */ o.createElement(o.Fragment, null, /* @__PURE__ */ o.createElement(
|
|
16
|
+
l,
|
|
17
|
+
{
|
|
18
|
+
open: n,
|
|
19
|
+
onClose: () => t()
|
|
20
|
+
},
|
|
21
|
+
/* @__PURE__ */ o.createElement(
|
|
22
|
+
i,
|
|
23
|
+
{
|
|
24
|
+
onSelect: (e) => {
|
|
25
|
+
r && s(r, e);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
)
|
|
29
|
+
));
|
|
30
|
+
};
|
|
31
|
+
export {
|
|
32
|
+
M as Modal
|
|
33
|
+
};
|
package/dist/index11.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@gardenfi/orderbook"),i=require("@gardenfi/utils"),a={minError:(t,n)=>`Minimum amount is ${t} ${n}`,maxError:(t,n)=>`Maximum amount is ${t} ${n}`,outHigh:"Output amount too high",outLow:"Output amount too less",insufficientLiquidity:!0,insufficientBalance:!0,none:"",invalidFomAssset:"Invalid From Asset",invalidToAsset:"Invalid To Asset"};var r=(t=>(t.input="input",t.output="output",t))(r||{});const o={[i.Network.MAINNET]:{api:"https://api.garden.finance",explorer:"https://explorer.garden.finance"},[i.Network.TESTNET]:{api:"https://testnet.api.garden.finance",explorer:"https://testnet-explorer.garden.finance"},[i.Network.LOCALNET]:{api:"",explorer:""}},s=i.Network.TESTNET,u=t=>o[t],c=t=>e.isEVM(t.chain)||e.isSolana(t.chain)||e.isStarknet(t.chain)||e.isSui(t.chain)?"~30s":e.isBitcoin(t.chain)?"~10m":"";exports.API_ENDPOINTS=o;exports.DEFAULT_NETWORK=s;exports.Errors=a;exports.IOType=r;exports.getApiEndpoint=u;exports.getTimeEstimates=c;
|
package/dist/index11.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { isEVM as r, isSolana as e, isStarknet as o, isSui as a, isBitcoin as s } from "@gardenfi/orderbook";
|
|
2
|
+
import { Network as i } from "@gardenfi/utils";
|
|
3
|
+
const E = {
|
|
4
|
+
minError: (t, n) => `Minimum amount is ${t} ${n}`,
|
|
5
|
+
maxError: (t, n) => `Maximum amount is ${t} ${n}`,
|
|
6
|
+
outHigh: "Output amount too high",
|
|
7
|
+
outLow: "Output amount too less",
|
|
8
|
+
insufficientLiquidity: !0,
|
|
9
|
+
insufficientBalance: !0,
|
|
10
|
+
none: "",
|
|
11
|
+
invalidFomAssset: "Invalid From Asset",
|
|
12
|
+
invalidToAsset: "Invalid To Asset"
|
|
13
|
+
};
|
|
14
|
+
var u = /* @__PURE__ */ ((t) => (t.input = "input", t.output = "output", t))(u || {});
|
|
15
|
+
const p = {
|
|
16
|
+
[i.MAINNET]: {
|
|
17
|
+
api: "https://api.garden.finance",
|
|
18
|
+
explorer: "https://explorer.garden.finance"
|
|
19
|
+
},
|
|
20
|
+
[i.TESTNET]: {
|
|
21
|
+
api: "https://testnet.api.garden.finance",
|
|
22
|
+
explorer: "https://testnet-explorer.garden.finance"
|
|
23
|
+
},
|
|
24
|
+
[i.LOCALNET]: {
|
|
25
|
+
api: "",
|
|
26
|
+
explorer: ""
|
|
27
|
+
}
|
|
28
|
+
}, T = i.TESTNET, f = (t) => p[t], h = (t) => r(t.chain) || e(t.chain) || o(t.chain) || a(t.chain) ? "~30s" : s(t.chain) ? "~10m" : "";
|
|
29
|
+
export {
|
|
30
|
+
p as API_ENDPOINTS,
|
|
31
|
+
T as DEFAULT_NETWORK,
|
|
32
|
+
E as Errors,
|
|
33
|
+
u as IOType,
|
|
34
|
+
f as getApiEndpoint,
|
|
35
|
+
h as getTimeEstimates
|
|
36
|
+
};
|
package/dist/index12.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const g=require("@gardenfi/orderbook"),m=require("zustand"),h=m.create((s,c)=>({transactions:[],isLoading:!1,perPage:4,totalItems:0,fetchTransactions:async(o,a)=>{s({isLoading:!0});try{const t=c().perPage,f=Object.values(a).filter(r=>r!=="").map(async r=>{try{const e=await o.getOrders({from_owner:r,per_page:t,status:g.OrderLifecycle.fulfilled});return e.ok?{orders:e.val.data,totalItems:e.val.total_items??0}:(console.error(`Failed to fetch transactions for address ${r}: ${e.error}`),{orders:[],totalItems:0})}catch(e){return console.error(`Failed to fetch transactions for address ${r}: ${e}`),{orders:[],totalItems:0}}}),u=await Promise.all(f),n=[];let i=0;const d=new Set;for(const r of u){if(r.orders.length===0){console.error("failed to fetch transactions ❌",r.orders);continue}i+=r.totalItems;for(const e of r.orders??[]){const l=e.order_id??e.order_id??JSON.stringify(e);d.has(l)||(d.add(l),n.push(e))}}n.sort((r,e)=>new Date(e.created_at).getTime()-new Date(r.created_at).getTime()),s({transactions:n,totalItems:i})}catch(t){console.error("Unexpected error in fetchTransactions",t)}finally{s({isLoading:!1})}},loadMore:async(o,a)=>{s(t=>({perPage:t.perPage+4})),await c().fetchTransactions(o,a)}}));module.exports=h;
|
package/dist/index12.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { OrderLifecycle as u } from "@gardenfi/orderbook";
|
|
2
|
+
import { create as g } from "zustand";
|
|
3
|
+
const w = g(
|
|
4
|
+
(o, c) => ({
|
|
5
|
+
transactions: [],
|
|
6
|
+
isLoading: !1,
|
|
7
|
+
perPage: 4,
|
|
8
|
+
totalItems: 0,
|
|
9
|
+
fetchTransactions: async (s, a) => {
|
|
10
|
+
o({ isLoading: !0 });
|
|
11
|
+
try {
|
|
12
|
+
const t = c().perPage, f = Object.values(a).filter(
|
|
13
|
+
(r) => r !== ""
|
|
14
|
+
).map(async (r) => {
|
|
15
|
+
try {
|
|
16
|
+
const e = await s.getOrders({
|
|
17
|
+
from_owner: r,
|
|
18
|
+
per_page: t,
|
|
19
|
+
status: u.fulfilled
|
|
20
|
+
});
|
|
21
|
+
return e.ok ? {
|
|
22
|
+
orders: e.val.data,
|
|
23
|
+
totalItems: e.val.total_items ?? 0
|
|
24
|
+
} : (console.error(
|
|
25
|
+
`Failed to fetch transactions for address ${r}: ${e.error}`
|
|
26
|
+
), { orders: [], totalItems: 0 });
|
|
27
|
+
} catch (e) {
|
|
28
|
+
return console.error(
|
|
29
|
+
`Failed to fetch transactions for address ${r}: ${e}`
|
|
30
|
+
), { orders: [], totalItems: 0 };
|
|
31
|
+
}
|
|
32
|
+
}), m = await Promise.all(f), n = [];
|
|
33
|
+
let i = 0;
|
|
34
|
+
const d = /* @__PURE__ */ new Set();
|
|
35
|
+
for (const r of m) {
|
|
36
|
+
if (r.orders.length === 0) {
|
|
37
|
+
console.error("failed to fetch transactions ❌", r.orders);
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
i += r.totalItems;
|
|
41
|
+
for (const e of r.orders ?? []) {
|
|
42
|
+
const l = e.order_id ?? e.order_id ?? JSON.stringify(e);
|
|
43
|
+
d.has(l) || (d.add(l), n.push(e));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
n.sort(
|
|
47
|
+
(r, e) => new Date(e.created_at).getTime() - new Date(r.created_at).getTime()
|
|
48
|
+
), o({
|
|
49
|
+
transactions: n,
|
|
50
|
+
totalItems: i
|
|
51
|
+
});
|
|
52
|
+
} catch (t) {
|
|
53
|
+
console.error("Unexpected error in fetchTransactions", t);
|
|
54
|
+
} finally {
|
|
55
|
+
o({ isLoading: !1 });
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
loadMore: async (s, a) => {
|
|
59
|
+
o((t) => ({ perPage: t.perPage + 4 })), await c().fetchTransactions(s, a);
|
|
60
|
+
}
|
|
61
|
+
})
|
|
62
|
+
);
|
|
63
|
+
export {
|
|
64
|
+
w as default
|
|
65
|
+
};
|
package/dist/index13.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const t=require("react"),m=require("./index6.cjs"),w=require("./index12.cjs"),o=require("./index17.cjs"),p=require("@gardenfi/react-hooks"),f=require("@gardenfi/garden-book"),g=require("./index26.cjs"),S=require("./index27.cjs"),q=()=>{const{transactions:c,isLoading:u}=w(),{allAssets:s}=m.assetInfoStore(),{pendingOrders:a}=p.useGarden(),i=t.useMemo(()=>c.filter(e=>o.getAssetFromSwap(e.source_swap,s)&&o.getAssetFromSwap(e.destination_swap,s)),[c,s]),l=t.useMemo(()=>(a==null?void 0:a.filter(e=>o.getAssetFromSwap(e.source_swap,s)&&o.getAssetFromSwap(e.destination_swap,s)))??[],[a,s]),n=t.useMemo(()=>[...l,...i],[l,i]);return t.createElement("div",{className:"flex w-full flex-col overflow-y-auto scrollbar-hide"},u?t.createElement(S.TransactionsSkeleton,null):n.length===0?t.createElement(f.Typography,{size:"h5",className:"py-4 text-center"},"No transactions found."):n.map((e,r)=>t.createElement("div",{key:e.order_id||r,className:"w-full"},t.createElement(g.TransactionRow,{order:e,status:e.status,isLast:r===n.length-1,isFirst:r===0}))))};module.exports=q;
|
package/dist/index13.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import e, { useMemo as i } from "react";
|
|
2
|
+
import { assetInfoStore as p } from "./index6.js";
|
|
3
|
+
import u from "./index12.js";
|
|
4
|
+
import { getAssetFromSwap as a } from "./index17.js";
|
|
5
|
+
import { useGarden as w } from "@gardenfi/react-hooks";
|
|
6
|
+
import { Typography as d } from "@gardenfi/garden-book";
|
|
7
|
+
import { TransactionRow as y } from "./index26.js";
|
|
8
|
+
import { TransactionsSkeleton as T } from "./index27.js";
|
|
9
|
+
const x = () => {
|
|
10
|
+
const { transactions: l, isLoading: f } = u(), { allAssets: s } = p(), { pendingOrders: o } = w(), c = i(
|
|
11
|
+
() => l.filter(
|
|
12
|
+
(t) => a(t.source_swap, s) && a(t.destination_swap, s)
|
|
13
|
+
),
|
|
14
|
+
[l, s]
|
|
15
|
+
), m = i(
|
|
16
|
+
() => (o == null ? void 0 : o.filter(
|
|
17
|
+
(t) => a(t.source_swap, s) && a(t.destination_swap, s)
|
|
18
|
+
)) ?? [],
|
|
19
|
+
[o, s]
|
|
20
|
+
), r = i(() => [...m, ...c], [m, c]);
|
|
21
|
+
return /* @__PURE__ */ e.createElement("div", { className: "flex w-full flex-col overflow-y-auto scrollbar-hide" }, f ? /* @__PURE__ */ e.createElement(T, null) : r.length === 0 ? /* @__PURE__ */ e.createElement(d, { size: "h5", className: "py-4 text-center" }, "No transactions found.") : r.map((t, n) => /* @__PURE__ */ e.createElement("div", { key: t.order_id || n, className: "w-full" }, /* @__PURE__ */ e.createElement(
|
|
22
|
+
y,
|
|
23
|
+
{
|
|
24
|
+
order: t,
|
|
25
|
+
status: t.status,
|
|
26
|
+
isLast: n === r.length - 1,
|
|
27
|
+
isFirst: n === 0
|
|
28
|
+
}
|
|
29
|
+
))));
|
|
30
|
+
};
|
|
31
|
+
export {
|
|
32
|
+
x as default
|
|
33
|
+
};
|
package/dist/index14.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),t=require("@gardenfi/garden-book"),M=require("./index6.cjs"),D=require("@number-flow/react"),I=require("./index20.cjs"),L=require("./index17.cjs"),i=require("./index11.cjs"),R=({type:l,amount:p,asset:n,onChange:f,price:x,error:u,balance:s,timeEstimate:E,loading:w})=>{const[N,g]=e.useState(!1),[b,o]=e.useState(!0),[d,T]=e.useState(!1),[k,v]=e.useState(!1),{openAssetModal:O,openModal:A,chains:m}=M.assetInfoStore(),h=e.useRef(null),y=e.useMemo(()=>{if(n)return m==null?void 0:m.find(a=>a.chain===n.chain)},[n,m]),F=l===i.IOType.input?"Send":"Receive",z=a=>{let r=a.target.value;if(!/^[0-9]*\.?[0-9]*$/.test(r)){o(!1),setTimeout(()=>{o(!0)},800);return}o(!1),r.startsWith(".")&&(r="0"+r);const c=r.split(".");if(r==="-")return;if(c.length>2){setTimeout(()=>{o(!0)},800);return}const C=(c[1]||"").length;n&&C>n.decimals&&c[1]?f(c[0]+"."+c[1].slice(0,n.decimals)):f(r)},q=()=>{if(l===i.IOType.input&&s&&n){const a=s.toString();f(a)}},S=()=>{A(l===i.IOType.input?i.IOType.input:i.IOType.output),O()};return e.useEffect(()=>{o(!0)},[n,N]),e.useEffect(()=>{let a;return w?a=setTimeout(()=>{v(!0)},300):v(!1),()=>{a&&clearTimeout(a)}},[w]),e.createElement(e.Fragment,null,e.createElement("div",{className:"flex flex-col gap-2 rounded-2xl bg-white p-4"},e.createElement("div",{className:"flex justify-between"},e.createElement("div",{className:"flex gap-3"},e.createElement(t.Typography,{size:"h5",weight:"medium",onClick:()=>h.current.focus()},F),e.createElement("div",{className:"flex gap-2"},p&&Number(x)!==0&&e.createElement(t.Typography,{size:"h5",weight:"regular"},e.createElement("span",{className:"text-mid-grey"},"~$",L.formatAmount(x,0,3))))),l===i.IOType.input&&(u?e.createElement(t.Typography,{size:"h5",weight:"regular",className:"!text-error-red"},u):s!==void 0&&!Number.isNaN(s)?e.createElement("div",{className:"flex cursor-pointer items-center gap-1",onClick:q},e.createElement(t.WalletIcon,{className:"h-2.5 w-2.5"}),e.createElement(t.Typography,{size:"h5",weight:"regular"},s)):e.createElement(e.Fragment,null)),l===i.IOType.output&&(u?e.createElement(t.Typography,{size:"h5",weight:"regular",className:"!text-error-red"},u):E&&e.createElement("div",{className:"flex items-end gap-1"},e.createElement(t.TimerIcon,{className:"h-4"}),e.createElement(t.Typography,{size:"h5",weight:"regular",className:"!leading-none"},E)))),e.createElement("div",{className:"flex h-6 justify-between sm:h-7"},e.createElement(t.Typography,{size:"h3",breakpoints:{sm:"h2"},weight:"medium"},e.createElement("div",{className:"relative w-[150px] max-w-[150px] md:w-[200px] md:max-w-[200px]"},e.createElement("div",{className:I.clsx("relative flex w-full items-center",!d&&"cursor-text"),onClick:a=>{d||(a.preventDefault(),g(!0),setTimeout(()=>{var r;(r=h.current)==null||r.focus()},0))}},N?e.createElement("input",{ref:h,className:I.clsx("w-full bg-transparent py-[1px] text-start font-[inherit] outline-none",d&&"pointer-events-none"),style:{fontKerning:"none"},inputMode:"decimal",value:p,onChange:z,onFocus:()=>g(!0),onBlur:()=>g(!1)}):e.createElement(D,{value:Number(p)||0,locales:"en-US",style:{fontKerning:"none",width:"100%"},format:{useGrouping:!1,minimumFractionDigits:0,maximumFractionDigits:20},"aria-hidden":"true",animated:b,onAnimationsStart:()=>{T(!0)},onAnimationsFinish:()=>{T(!1)},className:`w-full text-start font-[inherit] tracking-normal duration-200 ease-in-out ${k?"opacity-75":""}`,willChange:!0})))),n?e.createElement(t.TokenInfo,{symbol:n.symbol,tokenLogo:n.logo||"",chainLogo:y==null?void 0:y.iconUrl,onClick:S}):e.createElement("div",{className:"flex cursor-pointer items-center gap-1",onClick:S},e.createElement(t.Typography,{size:"h3",breakpoints:{sm:"h2"},weight:"regular"},"Select token"),e.createElement(t.KeyboardDownIcon,{className:"w-5"})))))};exports.SwapInput=R;
|
package/dist/index14.js
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import e, { useState as f, useRef as R, useMemo as K, useEffect as I } from "react";
|
|
2
|
+
import { Typography as i, WalletIcon as $, TimerIcon as j, TokenInfo as B, KeyboardDownIcon as U } from "@gardenfi/garden-book";
|
|
3
|
+
import { assetInfoStore as W } from "./index6.js";
|
|
4
|
+
import G from "@number-flow/react";
|
|
5
|
+
import { clsx as A } from "./index20.js";
|
|
6
|
+
import { formatAmount as q } from "./index17.js";
|
|
7
|
+
import { IOType as a } from "./index11.js";
|
|
8
|
+
const Z = ({
|
|
9
|
+
type: l,
|
|
10
|
+
amount: p,
|
|
11
|
+
asset: t,
|
|
12
|
+
onChange: d,
|
|
13
|
+
price: w,
|
|
14
|
+
error: c,
|
|
15
|
+
balance: s,
|
|
16
|
+
timeEstimate: N,
|
|
17
|
+
loading: v
|
|
18
|
+
}) => {
|
|
19
|
+
const [b, g] = f(!1), [F, o] = f(!0), [h, k] = f(!1), [T, y] = f(!1), { openAssetModal: z, openModal: C, chains: u } = W(), x = R(null), E = K(() => {
|
|
20
|
+
if (t)
|
|
21
|
+
return u == null ? void 0 : u.find((n) => n.chain === t.chain);
|
|
22
|
+
}, [t, u]), D = l === a.input ? "Send" : "Receive", L = (n) => {
|
|
23
|
+
let r = n.target.value;
|
|
24
|
+
if (!/^[0-9]*\.?[0-9]*$/.test(r)) {
|
|
25
|
+
o(!1), setTimeout(() => {
|
|
26
|
+
o(!0);
|
|
27
|
+
}, 800);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
o(!1), r.startsWith(".") && (r = "0" + r);
|
|
31
|
+
const m = r.split(".");
|
|
32
|
+
if (r === "-") return;
|
|
33
|
+
if (m.length > 2) {
|
|
34
|
+
setTimeout(() => {
|
|
35
|
+
o(!0);
|
|
36
|
+
}, 800);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const O = (m[1] || "").length;
|
|
40
|
+
t && O > t.decimals && m[1] ? d(m[0] + "." + m[1].slice(0, t.decimals)) : d(r);
|
|
41
|
+
}, M = () => {
|
|
42
|
+
if (l === a.input && s && t) {
|
|
43
|
+
const n = s.toString();
|
|
44
|
+
d(n);
|
|
45
|
+
}
|
|
46
|
+
}, S = () => {
|
|
47
|
+
C(l === a.input ? a.input : a.output), z();
|
|
48
|
+
};
|
|
49
|
+
return I(() => {
|
|
50
|
+
o(!0);
|
|
51
|
+
}, [t, b]), I(() => {
|
|
52
|
+
let n;
|
|
53
|
+
return v ? n = setTimeout(() => {
|
|
54
|
+
y(!0);
|
|
55
|
+
}, 300) : y(!1), () => {
|
|
56
|
+
n && clearTimeout(n);
|
|
57
|
+
};
|
|
58
|
+
}, [v]), /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement("div", { className: "flex flex-col gap-2 rounded-2xl bg-white p-4" }, /* @__PURE__ */ e.createElement("div", { className: "flex justify-between" }, /* @__PURE__ */ e.createElement("div", { className: "flex gap-3" }, /* @__PURE__ */ e.createElement(
|
|
59
|
+
i,
|
|
60
|
+
{
|
|
61
|
+
size: "h5",
|
|
62
|
+
weight: "medium",
|
|
63
|
+
onClick: () => x.current.focus()
|
|
64
|
+
},
|
|
65
|
+
D
|
|
66
|
+
), /* @__PURE__ */ e.createElement("div", { className: "flex gap-2" }, p && Number(w) !== 0 && /* @__PURE__ */ e.createElement(i, { size: "h5", weight: "regular" }, /* @__PURE__ */ e.createElement("span", { className: "text-mid-grey" }, "~$", q(w, 0, 3))))), l === a.input && (c ? /* @__PURE__ */ e.createElement(
|
|
67
|
+
i,
|
|
68
|
+
{
|
|
69
|
+
size: "h5",
|
|
70
|
+
weight: "regular",
|
|
71
|
+
className: "!text-error-red"
|
|
72
|
+
},
|
|
73
|
+
c
|
|
74
|
+
) : s !== void 0 && !Number.isNaN(s) ? /* @__PURE__ */ e.createElement(
|
|
75
|
+
"div",
|
|
76
|
+
{
|
|
77
|
+
className: "flex cursor-pointer items-center gap-1",
|
|
78
|
+
onClick: M
|
|
79
|
+
},
|
|
80
|
+
/* @__PURE__ */ e.createElement($, { className: "h-2.5 w-2.5" }),
|
|
81
|
+
/* @__PURE__ */ e.createElement(i, { size: "h5", weight: "regular" }, s)
|
|
82
|
+
) : /* @__PURE__ */ e.createElement(e.Fragment, null)), l === a.output && (c ? /* @__PURE__ */ e.createElement(
|
|
83
|
+
i,
|
|
84
|
+
{
|
|
85
|
+
size: "h5",
|
|
86
|
+
weight: "regular",
|
|
87
|
+
className: "!text-error-red"
|
|
88
|
+
},
|
|
89
|
+
c
|
|
90
|
+
) : N && /* @__PURE__ */ e.createElement("div", { className: "flex items-end gap-1" }, /* @__PURE__ */ e.createElement(j, { className: "h-4" }), /* @__PURE__ */ e.createElement(
|
|
91
|
+
i,
|
|
92
|
+
{
|
|
93
|
+
size: "h5",
|
|
94
|
+
weight: "regular",
|
|
95
|
+
className: "!leading-none"
|
|
96
|
+
},
|
|
97
|
+
N
|
|
98
|
+
)))), /* @__PURE__ */ e.createElement("div", { className: "flex h-6 justify-between sm:h-7" }, /* @__PURE__ */ e.createElement(
|
|
99
|
+
i,
|
|
100
|
+
{
|
|
101
|
+
size: "h3",
|
|
102
|
+
breakpoints: {
|
|
103
|
+
sm: "h2"
|
|
104
|
+
},
|
|
105
|
+
weight: "medium"
|
|
106
|
+
},
|
|
107
|
+
/* @__PURE__ */ e.createElement("div", { className: "relative w-[150px] max-w-[150px] md:w-[200px] md:max-w-[200px]" }, /* @__PURE__ */ e.createElement(
|
|
108
|
+
"div",
|
|
109
|
+
{
|
|
110
|
+
className: A(
|
|
111
|
+
"relative flex w-full items-center",
|
|
112
|
+
!h && "cursor-text"
|
|
113
|
+
),
|
|
114
|
+
onClick: (n) => {
|
|
115
|
+
h || (n.preventDefault(), g(!0), setTimeout(() => {
|
|
116
|
+
var r;
|
|
117
|
+
(r = x.current) == null || r.focus();
|
|
118
|
+
}, 0));
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
b ? /* @__PURE__ */ e.createElement(
|
|
122
|
+
"input",
|
|
123
|
+
{
|
|
124
|
+
ref: x,
|
|
125
|
+
className: A(
|
|
126
|
+
"w-full bg-transparent py-[1px] text-start font-[inherit] outline-none",
|
|
127
|
+
h && "pointer-events-none"
|
|
128
|
+
),
|
|
129
|
+
style: { fontKerning: "none" },
|
|
130
|
+
inputMode: "decimal",
|
|
131
|
+
value: p,
|
|
132
|
+
onChange: L,
|
|
133
|
+
onFocus: () => g(!0),
|
|
134
|
+
onBlur: () => g(!1)
|
|
135
|
+
}
|
|
136
|
+
) : /* @__PURE__ */ e.createElement(
|
|
137
|
+
G,
|
|
138
|
+
{
|
|
139
|
+
value: Number(p) || 0,
|
|
140
|
+
locales: "en-US",
|
|
141
|
+
style: { fontKerning: "none", width: "100%" },
|
|
142
|
+
format: {
|
|
143
|
+
useGrouping: !1,
|
|
144
|
+
minimumFractionDigits: 0,
|
|
145
|
+
maximumFractionDigits: 20
|
|
146
|
+
},
|
|
147
|
+
"aria-hidden": "true",
|
|
148
|
+
animated: F,
|
|
149
|
+
onAnimationsStart: () => {
|
|
150
|
+
k(!0);
|
|
151
|
+
},
|
|
152
|
+
onAnimationsFinish: () => {
|
|
153
|
+
k(!1);
|
|
154
|
+
},
|
|
155
|
+
className: `w-full text-start font-[inherit] tracking-normal duration-200 ease-in-out ${T ? "opacity-75" : ""}`,
|
|
156
|
+
willChange: !0
|
|
157
|
+
}
|
|
158
|
+
)
|
|
159
|
+
))
|
|
160
|
+
), t ? /* @__PURE__ */ e.createElement(
|
|
161
|
+
B,
|
|
162
|
+
{
|
|
163
|
+
symbol: t.symbol,
|
|
164
|
+
tokenLogo: t.logo || "",
|
|
165
|
+
chainLogo: E == null ? void 0 : E.iconUrl,
|
|
166
|
+
onClick: S
|
|
167
|
+
}
|
|
168
|
+
) : /* @__PURE__ */ e.createElement(
|
|
169
|
+
"div",
|
|
170
|
+
{
|
|
171
|
+
className: "flex cursor-pointer items-center gap-1",
|
|
172
|
+
onClick: S
|
|
173
|
+
},
|
|
174
|
+
/* @__PURE__ */ e.createElement(
|
|
175
|
+
i,
|
|
176
|
+
{
|
|
177
|
+
size: "h3",
|
|
178
|
+
breakpoints: {
|
|
179
|
+
sm: "h2"
|
|
180
|
+
},
|
|
181
|
+
weight: "regular"
|
|
182
|
+
},
|
|
183
|
+
"Select token"
|
|
184
|
+
),
|
|
185
|
+
/* @__PURE__ */ e.createElement(U, { className: "w-5" })
|
|
186
|
+
))));
|
|
187
|
+
};
|
|
188
|
+
export {
|
|
189
|
+
Z as SwapInput
|
|
190
|
+
};
|
package/dist/index15.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),o=require("./index5.cjs"),s=require("framer-motion"),u=require("./index21.cjs"),d=require("./index22.cjs"),l=()=>{const{inputAsset:n,outputAsset:a,inputAmount:t,outputAmount:i}=o.swapStore(),r=e.useMemo(()=>!!(n&&a&&t&&i&&Number(t)!==0&&Number(i)!==0),[n,a,t,i]);return e.createElement(s.AnimatePresence,{mode:"wait"},r&&e.createElement(s.motion.div,{variants:{hidden:{opacity:0,height:0,transition:{duration:.3,delay:.2,ease:"easeOut"}},visible:{opacity:1,height:"auto",pointerEvents:"auto",transition:{duration:.3,delay:.2,ease:"easeOut"}},exit:{opacity:0,height:0,transition:{duration:.3,delay:.2,ease:"easeOut"}}},initial:"hidden",animate:"visible",exit:"exit",className:"flex flex-col mt-3 overflow-hidden"},e.createElement(u.InputAddress,null),e.createElement(d.FeesAndRateDetails,null)))};exports.InputAddressAndFeeRateDetails=l;
|
package/dist/index15.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import e, { useMemo as r } from "react";
|
|
2
|
+
import { swapStore as s } from "./index5.js";
|
|
3
|
+
import { AnimatePresence as u, motion as m } from "framer-motion";
|
|
4
|
+
import { InputAddress as l } from "./index21.js";
|
|
5
|
+
import { FeesAndRateDetails as d } from "./index22.js";
|
|
6
|
+
const v = () => {
|
|
7
|
+
const { inputAsset: a, outputAsset: o, inputAmount: t, outputAmount: i } = s(), n = r(() => !!(a && o && // !error.inputError &&
|
|
8
|
+
// !error.outputError &&
|
|
9
|
+
// !error.liquidityError &&
|
|
10
|
+
t && i && Number(t) !== 0 && Number(i) !== 0), [
|
|
11
|
+
a,
|
|
12
|
+
o,
|
|
13
|
+
// error.inputError,
|
|
14
|
+
// error.outputError,
|
|
15
|
+
// error.liquidityError,
|
|
16
|
+
t,
|
|
17
|
+
i
|
|
18
|
+
]);
|
|
19
|
+
return /* @__PURE__ */ e.createElement(u, { mode: "wait" }, n && /* @__PURE__ */ e.createElement(
|
|
20
|
+
m.div,
|
|
21
|
+
{
|
|
22
|
+
variants: {
|
|
23
|
+
hidden: {
|
|
24
|
+
opacity: 0,
|
|
25
|
+
height: 0,
|
|
26
|
+
transition: { duration: 0.3, delay: 0.2, ease: "easeOut" }
|
|
27
|
+
},
|
|
28
|
+
visible: {
|
|
29
|
+
opacity: 1,
|
|
30
|
+
height: "auto",
|
|
31
|
+
pointerEvents: "auto",
|
|
32
|
+
transition: { duration: 0.3, delay: 0.2, ease: "easeOut" }
|
|
33
|
+
},
|
|
34
|
+
exit: {
|
|
35
|
+
opacity: 0,
|
|
36
|
+
height: 0,
|
|
37
|
+
transition: { duration: 0.3, delay: 0.2, ease: "easeOut" }
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
initial: "hidden",
|
|
41
|
+
animate: "visible",
|
|
42
|
+
exit: "exit",
|
|
43
|
+
className: "flex flex-col mt-3 overflow-hidden"
|
|
44
|
+
},
|
|
45
|
+
/* @__PURE__ */ e.createElement(l, null),
|
|
46
|
+
/* @__PURE__ */ e.createElement(d, null)
|
|
47
|
+
));
|
|
48
|
+
};
|
|
49
|
+
export {
|
|
50
|
+
v as InputAddressAndFeeRateDetails
|
|
51
|
+
};
|
package/dist/index16.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("react"),pr=require("./index5.cjs"),t=require("./index11.cjs"),w=require("@gardenfi/orderbook"),fr=require("lodash.debounce"),Z=require("@gardenfi/core"),mr=require("@gardenfi/react-hooks"),Q=require("bignumber.js"),$=require("./index17.cjs"),dr=()=>{var W;const{inputAmount:l,outputAmount:y,inputAsset:r,outputAsset:n,isSwapping:B,isApproving:rr,rate:tr,error:v,btcAddress:h,tokenPrices:er,isFetchingQuote:or,isEditBTCAddress:nr,networkFees:R,setIsSwapping:T,setAmount:a,setRate:L,setError:u,swapAssets:sr,setAsset:ir,setIsFetchingQuote:C,isComparisonVisible:M,setIsValidBitcoinAddress:F,setTokenPrices:d,clearSwapState:N,setBtcAddress:V,setIsComparisonVisible:ur,currentNetwork:P}=pr.swapStore(),{swap:j,getQuote:_,garden:o}=mr.useGarden(),m=f.useRef(null),A=f.useMemo(()=>!!(r&&n&&(w.isBitcoin(r.chain)||w.isBitcoin(n.chain))),[r,n]),x=f.useMemo(()=>A?h?Z.validateBTCAddress(h,P):!1:!0,[h,A]),D=f.useMemo(()=>!!(r&&y&&l&&n&&x&&!v.inputError&&!v.outputError&&!v.liquidityError&&!v.insufficientBalanceError),[r,y,l,n,v,x]),H=f.useMemo(()=>A?!!(D&&h):D,[D,A,h]),{minAmount:b,maxAmount:I}=f.useMemo(()=>{const e={minAmount:0,maxAmount:0};return!r||!n||!r.min_amount||!r.max_amount?e:{minAmount:$.formatAmount(r.min_amount,r.decimals,r.decimals),maxAmount:$.formatAmount(r.max_amount,r.decimals,r.decimals)}},[r,n]),S=f.useMemo(()=>fr(async(e,c,p,i)=>{var K,z,J,X,Y;if(!_||B)return;C({input:i,output:!i}),m.current&&m.current.abort(),m.current=new AbortController;const q=i?p.decimals:c.decimals,E=new Q(e).multipliedBy(10**q),s=await _({fromAsset:c,toAsset:p,amount:E.toNumber(),isExactOut:i,options:{request:{signal:m.current.signal}}});if(!s||!s.ok){if((K=s==null?void 0:s.error)!=null&&K.includes("AbortError")){u({liquidityError:t.Errors.none}),C({input:!1,output:!1});return}else(z=s==null?void 0:s.error)!=null&&z.includes("insufficient liquidity")?(u({liquidityError:t.Errors.insufficientLiquidity}),a(i?t.IOType.input:t.IOType.output,"")):(J=s==null?void 0:s.error)!=null&&J.includes("output amount too less")?(u({outputError:t.Errors.outLow}),a(t.IOType.input,"")):(X=s==null?void 0:s.error)!=null&&X.includes("output amount too high")?(u({outputError:t.Errors.outHigh}),a(t.IOType.input,"")):(Y=s==null?void 0:s.error)!=null&&Y.includes("invalid from_asset")?(u({outputError:t.Errors.invalidFomAssset}),a(t.IOType.input,"")):a(i?t.IOType.input:t.IOType.output,"");C({input:!1,output:!1}),d({input:"0",output:"0"});return}const O=i?s.val[0].source.display:s.val[0].destination.display;let G=Number(O);c.symbol==="USDC"&&p.symbol==="USDC"&&(G=Number(O)+R);const ar=G/Number(e);L(ar),a(i?t.IOType.input:t.IOType.output,O),C({input:!1,output:!1}),d({input:s.val[0].source.value.toString(),output:s.val[0].destination.value.toString()}),u({liquidityError:t.Errors.none})},500),[_,C,L,a,d,u,B,R]),k=f.useCallback(async(e,c,p,i)=>{S(e,c,p,i)},[S]),g=f.useCallback(async e=>{a(t.IOType.input,e);const c=Number(e);if(!c){S.cancel(),m.current&&m.current.abort(),a(t.IOType.output,""),d({input:"0",output:"0"}),u({inputError:t.Errors.none,liquidityError:t.Errors.none});return}if(r&&b&&c<b){u({inputError:t.Errors.minError(b.toString(),r==null?void 0:r.symbol)}),a(t.IOType.output,""),d({input:"0",output:"0"}),S.cancel(),m.current&&m.current.abort();return}if(r&&I&&c>I){u({inputError:t.Errors.maxError(I.toString(),r==null?void 0:r.symbol)}),a(t.IOType.output,""),S.cancel(),m.current&&m.current.abort();return}u({inputError:t.Errors.none}),!(!r||!n||!Number(e))&&k(e,r,n,!1)},[r,n,b,I,k,S,a,u,d]),cr=async e=>{a(t.IOType.output,e);const c=Number(e);if(!c){S.cancel(),m.current&&m.current.abort(),a(t.IOType.input,""),u({outputError:t.Errors.none});return}u({outputError:t.Errors.none}),!(!r||!n||!c)&&k(e,r,n,!0)},U=f.useMemo(()=>{var c,p,i,q;if(!r||!n||!l||l==="0"||!y||y==="0")return null;const e={evm:{check:E=>w.isEVM(E),address:(c=o==null?void 0:o.htlcs.evm)==null?void 0:c.htlcActorAddress},starknet:{check:E=>w.isStarknet(E),address:(p=o==null?void 0:o.htlcs.starknet)==null?void 0:p.htlcActorAddress},solana:{check:E=>w.isSolana(E),address:(i=o==null?void 0:o.htlcs.solana)==null?void 0:i.htlcActorAddress},sui:{check:E=>w.isSui(E),address:(q=o==null?void 0:o.htlcs.sui)==null?void 0:q.htlcActorAddress}};for(const[E,{check:s,address:O}]of Object.entries(e))if((s(r.chain)||s(n.chain))&&!O)return E;return null},[r,n,l,y,o]),lr=async()=>{if(U||!H||!j||!r||!n)return;T(!0);const e=new Q(l).multipliedBy(10**r.decimals).toFixed(),c=new Q(y).multipliedBy(10**n.decimals).toFixed();try{const p=await j({fromAsset:r,toAsset:n,sendAmount:e,receiveAmount:c,...A&&{addresses:{bitcoin:h}}});if(!p.ok){p.error.includes("destination amount too high")?k(l,r,n,!1):console.error("failed to create order ❌",p.error),T(!1);return}if(console.log("orderCreated ✅",p.val),w.isBitcoin(r.chain)){const i=await(o==null?void 0:o.getOrder(p.val));if(!(i!=null&&i.val)||i!=null&&i.error){console.error("failed to get order ❌",i==null?void 0:i.error),T(!1);return}if(o){N();return}T(!1),N();return}T(!1),N()}catch(p){throw console.error("failed to create order ❌",p),T(!1),p}};return f.useEffect(()=>{if(!r||!n||!l||B||M)return;const e=setInterval(()=>{k(l,r,n,!1)},5e3);return()=>clearInterval(e)},[l,r,n,k,B,M]),f.useEffect(()=>{!r||!n||(u({inputError:""}),g(l))},[r,g,u]),f.useEffect(()=>{if(y=="0"||!y||l=="0"||!l){d({input:"0",output:"0"});return}},[l,y,d,u]),f.useEffect(()=>{if(!l||!b||!I)return;const e=Number(l);if(e){if(e<b&&r){u({inputError:t.Errors.minError(b.toString(),r.symbol)}),d({input:"0",output:"0"}),a(t.IOType.output,"");return}if(e>I&&r){u({inputError:t.Errors.maxError(I.toString(),r.symbol)}),d({input:"0",output:"0"}),a(t.IOType.output,"");return}}},[l,b,I,r,u,d,g,a]),f.useEffect(()=>{u({insufficientBalanceError:t.Errors.none})},[u,r,n,l]),f.useEffect(()=>{var e,c;(e=o==null?void 0:o.htlcs.bitcoin)!=null&&e.htlcActorAddress&&V((c=o==null?void 0:o.htlcs.bitcoin)==null?void 0:c.htlcActorAddress)},[(W=o==null?void 0:o.htlcs.bitcoin)==null?void 0:W.htlcActorAddress,V]),f.useEffect(()=>{if(!A){F(!0);return}const e=h?Z.validateBTCAddress(h,P):!1;F(e)},[h,A,F]),{inputAmount:l,outputAmount:y,inputAsset:r,outputAsset:n,tokenPrices:er,rate:tr,error:v,isEditBTCAddress:nr,loading:or,validSwap:H,isSwapping:B,isApproving:rr,isBitcoinSwap:A,needsWalletConnection:U,btcAddress:h,controller:m,isComparisonVisible:M,setBtcAddress:V,swapAssets:sr,handleInputAmountChange:g,handleOutputAmountChange:cr,handleSwapClick:lr,setAsset:ir,clearSwapState:N,setIsComparisonVisible:ur}};exports.useSwap=dr;
|