@multiversx/sdk-dapp-liquidity 2.3.0-alpha.4 → 2.3.0-alpha.5
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/package.json +1 -1
- package/reactjs/components/BridgeForm/Deposit.js +1 -1
- package/reactjs/components/BridgeForm/Deposit.mjs +149 -146
- package/reactjs/components/BridgeForm/Transfer.js +1 -1
- package/reactjs/components/BridgeForm/Transfer.mjs +169 -163
- package/reactjs/hooks/useBalances.js +1 -1
- package/reactjs/hooks/useBalances.mjs +16 -15
- package/reactjs/hooks/useBridgeFormik.js +1 -1
- package/reactjs/hooks/useBridgeFormik.mjs +14 -14
- package/reactjs/hooks/useDebounce.js +1 -1
- package/reactjs/hooks/useDebounce.mjs +6 -6
- package/reactjs/hooks/useFetchTokens.js +1 -1
- package/reactjs/hooks/useFetchTokens.mjs +19 -14
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
2
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("@reown/appkit/react"),d=require("axios"),l=require("react"),b=require("../../helpers/getApiURL.js"),p=require("../context/useWeb3App.js"),h=()=>{const{address:t,isConnected:s}=i.useAppKitAccount(),{nativeAuthToken:c}=p.useWeb3App(),u=async a=>{const n=`${b.getApiURL()}/user/balance/${t}?chainId=${a}`;try{const{data:r}=await d.get(n,{headers:{Authorization:`Bearer ${c}`}});return r.reduce((e,o)=>(e[o.tokenAddress]=o.balance,e),{})}catch(r){throw new Error(`Error fetching balances: ${r}`)}};return{getBalances:l.useCallback(async({tokens:a,chainId:n})=>{const r=await u(n);return a.map(e=>!s||!t||!e.chainId?{tokenId:e.address,balance:"0"}:{tokenId:e.address,balance:r[e.address]??"0"})},[s,t,c])}};exports.useBalances=h;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { useAppKitAccount as
|
|
2
|
-
import
|
|
3
|
-
import { useCallback as
|
|
4
|
-
import { getApiURL as
|
|
5
|
-
import { useWeb3App as
|
|
6
|
-
const
|
|
7
|
-
const {
|
|
8
|
-
const n = `${
|
|
1
|
+
import { useAppKitAccount as i } from "@reown/appkit/react";
|
|
2
|
+
import u from "axios";
|
|
3
|
+
import { useCallback as l } from "react";
|
|
4
|
+
import { getApiURL as p } from "../../helpers/getApiURL.mjs";
|
|
5
|
+
import { useWeb3App as m } from "../context/useWeb3App.mjs";
|
|
6
|
+
const $ = () => {
|
|
7
|
+
const { address: a, isConnected: s } = i(), { nativeAuthToken: o } = m(), d = async (t) => {
|
|
8
|
+
const n = `${p()}/user/balance/${a}?chainId=${t}`;
|
|
9
9
|
try {
|
|
10
|
-
const { data: r } = await
|
|
10
|
+
const { data: r } = await u.get(n, {
|
|
11
11
|
headers: {
|
|
12
|
-
Authorization: `Bearer ${
|
|
12
|
+
Authorization: `Bearer ${o}`
|
|
13
13
|
}
|
|
14
14
|
});
|
|
15
15
|
return r.reduce(
|
|
16
|
-
(e,
|
|
16
|
+
(e, c) => (e[c.tokenAddress] = c.balance, e),
|
|
17
17
|
{}
|
|
18
18
|
);
|
|
19
19
|
} catch (r) {
|
|
@@ -21,9 +21,9 @@ const w = () => {
|
|
|
21
21
|
}
|
|
22
22
|
};
|
|
23
23
|
return {
|
|
24
|
-
getBalances:
|
|
24
|
+
getBalances: l(
|
|
25
25
|
async ({ tokens: t, chainId: n }) => {
|
|
26
|
-
const r = await
|
|
26
|
+
const r = await d(n);
|
|
27
27
|
return t.map((e) => !s || !a || !e.chainId ? {
|
|
28
28
|
tokenId: e.address,
|
|
29
29
|
balance: "0"
|
|
@@ -32,10 +32,11 @@ const w = () => {
|
|
|
32
32
|
balance: r[e.address] ?? "0"
|
|
33
33
|
});
|
|
34
34
|
},
|
|
35
|
-
|
|
35
|
+
// nativeAuthToken is used inside fetchBalances (auth header); config is not used.
|
|
36
|
+
[s, a, o]
|
|
36
37
|
)
|
|
37
38
|
};
|
|
38
39
|
};
|
|
39
40
|
export {
|
|
40
|
-
|
|
41
|
+
$ as useBalances
|
|
41
42
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const J=require("formik"),d=require("react"),a=require("yup"),K=require("./validation/useAmountSchema.js"),Q=require("./validation/useSecondAmountSchema.js"),X=require("../../api/confirmRate.js"),Y=require("../../helpers/assertConfirmRateData.js"),Z=require("../../helpers/assertRateConfirmationMatchesIntent.js"),B=require("../../helpers/getApiURL.js"),R=require("../../helpers/isValidAddressForChainType.js"),j=require("../../types/errors.js"),M=require("../../types/providerType.js"),oo=require("../context/useWeb3App.js");var D=(r=>(r.firstToken="firstToken",r.firstAmount="firstAmount",r.secondToken="secondToken",r.secondAmount="secondAmount",r.fromChainId="fromChainId",r.toChainId="toChainId",r))(D||{});const ro=({sender:r,receiver:c,firstToken:h,firstAmount:I,secondToken:C,secondAmount:l,fromChainId:p,toChainId:A,setForceRefetchRate:S,rate:o,onSubmit:O,isMvxConnected:P,senderChainType:q,receiverChainType:v})=>{const u=d.useRef(),{nativeAuthToken:k}=oo.useWeb3App(),[V,_]=d.useState(void 0),g=!r||!q?!0:R.isValidAddressForChainType(r,q),T=!c||!v?!0:R.isValidAddressForChainType(c,v),$=r&&!g?`Invalid ${q} sender address`:void 0,w=c&&!T?`Invalid ${v} receiver address`:void 0,F={firstAmount:"",secondAmount:"",fromChainId:p??"",toChainId:A??""},b=()=>{f.setTouched({},!1),f.setErrors({}),
|
|
2
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const J=require("formik"),d=require("react"),a=require("yup"),K=require("./validation/useAmountSchema.js"),Q=require("./validation/useSecondAmountSchema.js"),X=require("../../api/confirmRate.js"),Y=require("../../helpers/assertConfirmRateData.js"),Z=require("../../helpers/assertRateConfirmationMatchesIntent.js"),B=require("../../helpers/getApiURL.js"),R=require("../../helpers/isValidAddressForChainType.js"),j=require("../../types/errors.js"),M=require("../../types/providerType.js"),oo=require("../context/useWeb3App.js");var D=(r=>(r.firstToken="firstToken",r.firstAmount="firstAmount",r.secondToken="secondToken",r.secondAmount="secondAmount",r.fromChainId="fromChainId",r.toChainId="toChainId",r))(D||{});const ro=({sender:r,receiver:c,firstToken:h,firstAmount:I,secondToken:C,secondAmount:l,fromChainId:p,toChainId:A,setForceRefetchRate:S,rate:o,onSubmit:O,isMvxConnected:P,senderChainType:q,receiverChainType:v})=>{const u=d.useRef(),{nativeAuthToken:k}=oo.useWeb3App(),[V,_]=d.useState(void 0),g=!r||!q?!0:R.isValidAddressForChainType(r,q),T=!c||!v?!0:R.isValidAddressForChainType(c,v),$=r&&!g?`Invalid ${q} sender address`:void 0,w=c&&!T?`Invalid ${v} receiver address`:void 0,F={firstAmount:"",secondAmount:"",fromChainId:p??"",toChainId:A??""},b=()=>{f.setTouched({},!1),f.setErrors({}),n("firstAmount",""),n("secondAmount","")},L=async t=>{var y,E;if(!u.current){u.current=!0,_(void 0);try{if(!g||!T){u.current=!1;return}Y.assertConfirmRateData({nativeAuthToken:k,orderId:o==null?void 0:o.orderId,fromChainId:t.fromChainId,toChainId:t.toChainId,sender:r,receiver:c});const{data:i}=await X.confirmRate({url:B.getApiURL(),nativeAuthToken:k??"",body:{tokenIn:((y=t.firstToken)==null?void 0:y.address)??"",amountIn:(I==null?void 0:I.toString())??"",fromChainId:t.fromChainId??"",tokenOut:((E=t.secondToken)==null?void 0:E.address)??"",toChainId:t.toChainId??"",amountOut:(l==null?void 0:l.toString())??"",sender:r??"",receiver:c??"",fee:(o==null?void 0:o.fee)??"0",provider:(o==null?void 0:o.provider)??M.ProviderType.None,orderId:(o==null?void 0:o.orderId)??""}}),s=i;if(!s||s.length===0){u.current=!1;return}Z.assertRateConfirmationMatchesIntent({fromChainId:t.fromChainId??"",sender:r??""},s),b(),O({transactions:s,provider:(o==null?void 0:o.provider)??M.ProviderType.None})}catch(i){console.error("Error confirming rate:",i),i instanceof j.ConfirmRateError||i instanceof j.MissingConfirmRateDataError?_(i.message):S==null||S(s=>s+1)}finally{u.current=!1}}},f=J.useFormik({initialValues:F,validationSchema:a.object().shape({firstAmount:K.useAmountSchema({isMvxConnected:P}),firstToken:a.object().required(),secondAmount:Q.useSecondAmountSchema(),secondToken:a.object().required(),fromChainId:a.string().required(),toChainId:a.string().required()}),onSubmit:L}),{errors:e,touched:m,handleBlur:N,handleSubmit:U,handleChange:W,setFieldValue:n,setFieldTouched:x}=f;d.useEffect(()=>{n("firstToken",h,!0)},[h,n]),d.useEffect(()=>{n("secondToken",C,!0)},[C,n]),d.useEffect(()=>{n("fromChainId",p,!0)},[p,n]),d.useEffect(()=>{n("toChainId",A,!0)},[A,n]);const z="secondAmount"in e&&"secondAmount"in m?e.secondAmount:void 0,G="firstAmount"in e&&"firstAmount"in m?e.firstAmount:void 0,H="fromChainId"in e&&"fromChainId"in m?e.fromChainId:void 0;return{formik:f,errors:e,touched:m,firstToken:h,secondToken:C,firstAmountError:G,secondAmountError:z,fromChainError:H,senderAddressError:$,receiverAddressError:w,confirmRateError:V,handleBlur:N,handleChange:W,handleSubmit:U,setFieldValue:n,resetSwapForm:b,setFieldTouched:x}};exports.BridgeFormikValuesEnum=D;exports.useBridgeFormik=ro;
|
|
@@ -36,7 +36,7 @@ const So = ({
|
|
|
36
36
|
fromChainId: p ?? "",
|
|
37
37
|
toChainId: A ?? ""
|
|
38
38
|
}, q = () => {
|
|
39
|
-
f.setTouched({}, !1), f.setErrors({}),
|
|
39
|
+
f.setTouched({}, !1), f.setErrors({}), n("firstAmount", ""), n("secondAmount", "");
|
|
40
40
|
}, P = async (t) => {
|
|
41
41
|
var R, w;
|
|
42
42
|
if (!m.current) {
|
|
@@ -100,27 +100,27 @@ const So = ({
|
|
|
100
100
|
}),
|
|
101
101
|
onSubmit: P
|
|
102
102
|
}), {
|
|
103
|
-
errors:
|
|
103
|
+
errors: i,
|
|
104
104
|
touched: c,
|
|
105
105
|
handleBlur: U,
|
|
106
106
|
handleSubmit: W,
|
|
107
107
|
handleChange: z,
|
|
108
|
-
setFieldValue:
|
|
108
|
+
setFieldValue: n,
|
|
109
109
|
setFieldTouched: G
|
|
110
110
|
} = f;
|
|
111
111
|
u(() => {
|
|
112
|
-
|
|
113
|
-
}, [a]), u(() => {
|
|
114
|
-
|
|
115
|
-
}, [I]), u(() => {
|
|
116
|
-
|
|
117
|
-
}, [p]), u(() => {
|
|
118
|
-
|
|
119
|
-
}, [A]);
|
|
120
|
-
const H = "secondAmount" in
|
|
112
|
+
n("firstToken", a, !0);
|
|
113
|
+
}, [a, n]), u(() => {
|
|
114
|
+
n("secondToken", I, !0);
|
|
115
|
+
}, [I, n]), u(() => {
|
|
116
|
+
n("fromChainId", p, !0);
|
|
117
|
+
}, [p, n]), u(() => {
|
|
118
|
+
n("toChainId", A, !0);
|
|
119
|
+
}, [A, n]);
|
|
120
|
+
const H = "secondAmount" in i && "secondAmount" in c ? i.secondAmount : void 0, J = "firstAmount" in i && "firstAmount" in c ? i.firstAmount : void 0, K = "fromChainId" in i && "fromChainId" in c ? i.fromChainId : void 0;
|
|
121
121
|
return {
|
|
122
122
|
formik: f,
|
|
123
|
-
errors:
|
|
123
|
+
errors: i,
|
|
124
124
|
touched: c,
|
|
125
125
|
firstToken: a,
|
|
126
126
|
secondToken: I,
|
|
@@ -133,7 +133,7 @@ const So = ({
|
|
|
133
133
|
handleBlur: U,
|
|
134
134
|
handleChange: z,
|
|
135
135
|
handleSubmit: W,
|
|
136
|
-
setFieldValue:
|
|
136
|
+
setFieldValue: n,
|
|
137
137
|
resetSwapForm: q,
|
|
138
138
|
setFieldTouched: G
|
|
139
139
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
2
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react"),u=(e,t)=>{const[s,c]=n.useState(e),o=()=>{const r=setTimeout(()=>c(e),t);return()=>clearTimeout(r)};return n.useEffect(o,[e,t]),s};exports.useDebounce=u;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { useState as r, useEffect as n } from "react";
|
|
2
|
-
const
|
|
3
|
-
const [
|
|
2
|
+
const a = (e, t) => {
|
|
3
|
+
const [s, c] = r(e);
|
|
4
4
|
return n(() => {
|
|
5
|
-
const
|
|
6
|
-
return () => clearTimeout(
|
|
7
|
-
}, [t]),
|
|
5
|
+
const o = setTimeout(() => c(e), t);
|
|
6
|
+
return () => clearTimeout(o);
|
|
7
|
+
}, [e, t]), s;
|
|
8
8
|
};
|
|
9
9
|
export {
|
|
10
|
-
|
|
10
|
+
a as useDebounce
|
|
11
11
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react"),A=require("./useAccount.js"),m=require("./useBridgeApiChainId.js"),
|
|
2
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react"),A=require("./useAccount.js"),m=require("./useBridgeApiChainId.js"),v=require("../../constants/index.js"),S=require("../context/useWeb3App.js"),j=require("../queries/useGetAllTokens.query.js"),B=require("../queries/useGetMvxTokensBalances.query.js"),h=require("../queries/useGetNonMvxTokensBalances.query.js"),w=({mvxAddress:u,mvxApiURL:f,refetchTrigger:d})=>{const l=m.useBridgeApiChainId(),T=A.useAccount(),{nativeAuthToken:g,bridgeOnly:I}=S.useWeb3App(),_=B.useInvalidateMvxTokensBalancesQuery(),k=h.useInvalidateEvmTokensBalances(),{data:s,isLoading:L,isError:M}=j.useGetAllTokensQuery({nativeAuthToken:g,bridgeOnly:I}),o=a.useMemo(()=>s==null?void 0:s.filter(e=>!v.MVX_CHAIN_IDS.includes(e.chainId.toString())&&e.chainId.toLowerCase()!=="fiat"),[s]),r=a.useMemo(()=>s==null?void 0:s.filter(e=>v.MVX_CHAIN_IDS.includes(e.chainId.toString())),[s]),{data:t,isLoading:q,isError:b}=h.useGetNonMvxTokensBalancesQuery({tokens:o??[],chainId:l}),{data:i,isLoading:E,isError:C}=B.useGetMvxTokensBalancesQuery({tokens:r??[],mvxAddress:u,apiURL:f}),p=a.useMemo(()=>r==null?void 0:r.map(e=>{const n=i==null?void 0:i.find(c=>c.address.toLowerCase()===e.address.toLowerCase());return n?{...n,balance:n.balance.toString()}:{...e,balance:"0"}}),[r,i]),y=a.useMemo(()=>o==null?void 0:o.map(e=>{const n=t==null?void 0:t.find(c=>c.address.toLowerCase()===e.address.toLowerCase()&&c.chainId.toLowerCase()===e.chainId.toLowerCase());return n?{...n,balance:n.balance.toString()}:{...e,balance:"0"}}),[o,t]);return a.useEffect(()=>{u&&_()},[d,u,_]),a.useEffect(()=>{T.address&&k()},[d,l,T.address,k]),{isTokensLoading:L,isTokensError:M,isLoadingEvmTokensBalances:q,isErrorEvmTokensBalances:b,evmTokensWithBalances:y,isLoadingMvxTokensBalances:E,isErrorMvxTokensBalances:C,mvxTokensWithBalances:p,tokens:s}};exports.useFetchTokens=w;
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import { useMemo as c, useEffect as
|
|
1
|
+
import { useMemo as c, useEffect as T } from "react";
|
|
2
2
|
import { useAccount as y } from "./useAccount.mjs";
|
|
3
3
|
import { useBridgeApiChainId as A } from "./useBridgeApiChainId.mjs";
|
|
4
|
-
import { MVX_CHAIN_IDS as
|
|
4
|
+
import { MVX_CHAIN_IDS as L } from "../../constants/index.mjs";
|
|
5
5
|
import { useWeb3App as Q } from "../context/useWeb3App.mjs";
|
|
6
6
|
import { useGetAllTokensQuery as S } from "../queries/useGetAllTokens.query.mjs";
|
|
7
7
|
import { useInvalidateMvxTokensBalancesQuery as x, useGetMvxTokensBalancesQuery as N } from "../queries/useGetMvxTokensBalances.query.mjs";
|
|
8
8
|
import { useInvalidateEvmTokensBalances as W, useGetNonMvxTokensBalancesQuery as G } from "../queries/useGetNonMvxTokensBalances.query.mjs";
|
|
9
9
|
const X = ({
|
|
10
10
|
mvxAddress: d,
|
|
11
|
-
mvxApiURL:
|
|
11
|
+
mvxApiURL: B,
|
|
12
12
|
refetchTrigger: u
|
|
13
13
|
}) => {
|
|
14
|
-
const l = A(), m = y(), { nativeAuthToken:
|
|
14
|
+
const l = A(), m = y(), { nativeAuthToken: v, bridgeOnly: g } = Q(), f = x(), p = W(), {
|
|
15
15
|
data: a,
|
|
16
16
|
isLoading: h,
|
|
17
17
|
isError: k
|
|
18
18
|
} = S({
|
|
19
|
-
nativeAuthToken:
|
|
20
|
-
bridgeOnly:
|
|
19
|
+
nativeAuthToken: v,
|
|
20
|
+
bridgeOnly: g
|
|
21
21
|
}), s = c(
|
|
22
22
|
() => a == null ? void 0 : a.filter(
|
|
23
|
-
(e) => !
|
|
23
|
+
(e) => !L.includes(e.chainId.toString()) && e.chainId.toLowerCase() !== "fiat"
|
|
24
24
|
),
|
|
25
25
|
[a]
|
|
26
26
|
), o = c(
|
|
27
27
|
() => a == null ? void 0 : a.filter(
|
|
28
|
-
(e) =>
|
|
28
|
+
(e) => L.includes(e.chainId.toString())
|
|
29
29
|
),
|
|
30
30
|
[a]
|
|
31
31
|
), {
|
|
@@ -42,7 +42,7 @@ const X = ({
|
|
|
42
42
|
} = N({
|
|
43
43
|
tokens: o ?? [],
|
|
44
44
|
mvxAddress: d,
|
|
45
|
-
apiURL:
|
|
45
|
+
apiURL: B
|
|
46
46
|
}), M = c(() => o == null ? void 0 : o.map((e) => {
|
|
47
47
|
const n = i == null ? void 0 : i.find(
|
|
48
48
|
(t) => t.address.toLowerCase() === e.address.toLowerCase()
|
|
@@ -66,11 +66,16 @@ const X = ({
|
|
|
66
66
|
balance: "0"
|
|
67
67
|
};
|
|
68
68
|
}), [s, r]);
|
|
69
|
-
return
|
|
70
|
-
d &&
|
|
71
|
-
}, [u, d]),
|
|
72
|
-
m.address &&
|
|
73
|
-
}, [
|
|
69
|
+
return T(() => {
|
|
70
|
+
d && f();
|
|
71
|
+
}, [u, d, f]), T(() => {
|
|
72
|
+
m.address && p();
|
|
73
|
+
}, [
|
|
74
|
+
u,
|
|
75
|
+
l,
|
|
76
|
+
m.address,
|
|
77
|
+
p
|
|
78
|
+
]), {
|
|
74
79
|
isTokensLoading: h,
|
|
75
80
|
isTokensError: k,
|
|
76
81
|
isLoadingEvmTokensBalances: E,
|