@multiversx/sdk-dapp-liquidity 2.3.0-alpha.3 → 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
- package/reactjs/init/init.d.ts +1 -0
- package/reactjs/init/init.js +1 -1
- package/reactjs/init/init.mjs +32 -32
|
@@ -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,
|
package/reactjs/init/init.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export type InitOptions = {
|
|
|
16
16
|
suiFeaturedWalletIds?: string[];
|
|
17
17
|
expectedSuiAddress?: string;
|
|
18
18
|
disableInjectedDiscoveryInMobileDapp?: boolean;
|
|
19
|
+
disableSuiAutoReconnect?: boolean;
|
|
19
20
|
};
|
|
20
21
|
export declare enum SuiMethods {
|
|
21
22
|
SIGN_TRANSACTION = "sui_signTransaction",
|
package/reactjs/init/init.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("@reown/appkit/networks"),
|
|
2
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("@reown/appkit/networks"),x=require("@reown/appkit/react"),h=require("@reown/appkit-adapter-wagmi"),N=require("viem/chains"),C=require("./isMobileInjectedDappBrowser.js"),U=require("../../constants/index.js"),k=require("../../store/inMemoryStore.js"),E=require("../adapters/SuiAdapter.js");function _(e){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const i in e)if(i!=="default"){const c=Object.getOwnPropertyDescriptor(e,i);Object.defineProperty(n,i,c.get?c:{enumerable:!0,get:()=>e[i]})}}return n.default=e,Object.freeze(n)}const y=_(N),j=a.defineChain({id:"mainnet",name:"SUI Mainnet",nativeCurrency:{name:"SUI",symbol:"SUI",decimals:9},rpcUrls:{default:{http:["https://fullnode.mainnet.sui.io:443"]}},blockExplorers:{default:{name:"SUI Explorer",url:"https://explorer.sui.io/"}},chainNamespace:"sui",caipNetworkId:"sui:mainnet"}),D=a.defineChain({id:"testnet",name:"SUI Testnet",nativeCurrency:{name:"SUI",symbol:"SUI",decimals:9},rpcUrls:{default:{http:["https://fullnode.testnet.sui.io:443"]}},blockExplorers:{default:{name:"SUI Explorer",url:"https://explorer.sui.io/?network=testnet"}},chainNamespace:"sui",caipNetworkId:"sui:testnet"}),O=a.defineChain({id:"devnet",name:"SUI Devnet",nativeCurrency:{name:"SUI",symbol:"SUI",decimals:9},rpcUrls:{default:{http:["https://fullnode.devnet.sui.io:443"]}},blockExplorers:{default:{name:"SUI Explorer",url:"https://explorer.sui.io/?network=devnet"}},chainNamespace:"sui",caipNetworkId:"sui:devnet"}),b={mainnet:j,testnet:D,devnet:O};var g=(e=>(e.SIGN_TRANSACTION="sui_signTransaction",e.SIGN_AND_EXECUTE_TRANSACTION="sui_signAndExecuteTransaction",e.SIGN_PERSONAL_MESSAGE="sui_signPersonalMessage",e))(g||{});async function M(e){var m,I,f,S,v;const n=k.InMemoryStore.getInstance();n.setItem("apiURL",e.apiURL),n.setItem("bridgeURL",e.bridgeURL),n.setItem("mvxApiURL",e.mvxApiURL),n.setItem("mvxExplorerAddress",e.mvxExplorerAddress),n.setItem("mvxChainId",e.mvxChainId);const i={...y},c=Object.values(i).filter(t=>e.acceptedChainIDs.includes(t.id.toString())&&!U.MVX_CHAIN_IDS.includes(t.id.toString())).map(t=>t),d=[a.mainnet,a.bsc,a.bscTestnet,...c],o=[...d];if(e.suiEnvironment){const t=b[e.suiEnvironment];o.push(t)}const u=!!e.disableInjectedDiscoveryInMobileDapp&&C.isMobileInjectedDappBrowser(),A=u||!!e.disableSuiAutoReconnect,l=new h.WagmiAdapter({...e.adapterConfig,ssr:e.adapterConfig.ssr??!0,projectId:e.appKitOptions.projectId,networks:d,...u?{multiInjectedProviderDiscovery:!1}:{}}),p=[l];if(e.suiEnvironment){const t=b[e.suiEnvironment],r=t.caipNetworkId??`sui:${t.id}`;p.push(new E.SuiAdapter({explicitCaipChains:[r],expectedSuiAddress:e.expectedSuiAddress}))}const s=x.createAppKit({...e.appKitOptions,adapters:p,networks:[o[0],...o.slice(1)],...u?{enableEIP6963:!1,enableInjected:!1}:{}});if(await s.ready(),e.suiEnvironment&&!A){const t=await s.getUniversalProvider(),r=(I=(m=t==null?void 0:t.session)==null?void 0:m.namespaces)==null?void 0:I.sui;if((f=r==null?void 0:r.accounts)!=null&&f.length&&!s.getCaipAddress("sui")){const w=(S=r.accounts[0])==null?void 0:S.split(":").pop();(!e.expectedSuiAddress||w===e.expectedSuiAddress)&&await((v=s.syncWalletConnectAccount)==null?void 0:v.call(s))}}return{config:l.wagmiConfig,appKit:s,options:e,supportedChains:o,reconnectOnMount:!u}}exports.SuiMethods=g;exports.init=M;
|
package/reactjs/init/init.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { defineChain as c, mainnet as
|
|
1
|
+
import { defineChain as c, mainnet as w, bsc as N, bscTestnet as h } from "@reown/appkit/networks";
|
|
2
2
|
import { createAppKit as C } from "@reown/appkit/react";
|
|
3
3
|
import { WagmiAdapter as E } from "@reown/appkit-adapter-wagmi";
|
|
4
|
-
import * as
|
|
5
|
-
import { isMobileInjectedDappBrowser as
|
|
6
|
-
import { MVX_CHAIN_IDS as
|
|
7
|
-
import { InMemoryStore as
|
|
8
|
-
import { SuiAdapter as
|
|
9
|
-
const
|
|
4
|
+
import * as g from "viem/chains";
|
|
5
|
+
import { isMobileInjectedDappBrowser as k } from "./isMobileInjectedDappBrowser.mjs";
|
|
6
|
+
import { MVX_CHAIN_IDS as b } from "../../constants/index.mjs";
|
|
7
|
+
import { InMemoryStore as y } from "../../store/inMemoryStore.mjs";
|
|
8
|
+
import { SuiAdapter as _ } from "../adapters/SuiAdapter.mjs";
|
|
9
|
+
const D = c({
|
|
10
10
|
id: "mainnet",
|
|
11
11
|
name: "SUI Mainnet",
|
|
12
12
|
nativeCurrency: { name: "SUI", symbol: "SUI", decimals: 9 },
|
|
@@ -18,7 +18,7 @@ const _ = c({
|
|
|
18
18
|
},
|
|
19
19
|
chainNamespace: "sui",
|
|
20
20
|
caipNetworkId: "sui:mainnet"
|
|
21
|
-
}),
|
|
21
|
+
}), R = c({
|
|
22
22
|
id: "testnet",
|
|
23
23
|
name: "SUI Testnet",
|
|
24
24
|
nativeCurrency: { name: "SUI", symbol: "SUI", decimals: 9 },
|
|
@@ -48,29 +48,29 @@ const _ = c({
|
|
|
48
48
|
},
|
|
49
49
|
chainNamespace: "sui",
|
|
50
50
|
caipNetworkId: "sui:devnet"
|
|
51
|
-
}),
|
|
52
|
-
mainnet:
|
|
53
|
-
testnet:
|
|
51
|
+
}), S = {
|
|
52
|
+
mainnet: D,
|
|
53
|
+
testnet: R,
|
|
54
54
|
devnet: T
|
|
55
55
|
};
|
|
56
|
-
var
|
|
57
|
-
async function
|
|
58
|
-
var
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
const
|
|
62
|
-
(t) => e.acceptedChainIDs.includes(t.id.toString()) && !
|
|
56
|
+
var j = /* @__PURE__ */ ((e) => (e.SIGN_TRANSACTION = "sui_signTransaction", e.SIGN_AND_EXECUTE_TRANSACTION = "sui_signAndExecuteTransaction", e.SIGN_PERSONAL_MESSAGE = "sui_signPersonalMessage", e))(j || {});
|
|
57
|
+
async function W(e) {
|
|
58
|
+
var l, m, p, I, f;
|
|
59
|
+
const i = y.getInstance();
|
|
60
|
+
i.setItem("apiURL", e.apiURL), i.setItem("bridgeURL", e.bridgeURL), i.setItem("mvxApiURL", e.mvxApiURL), i.setItem("mvxExplorerAddress", e.mvxExplorerAddress), i.setItem("mvxChainId", e.mvxChainId);
|
|
61
|
+
const v = { ...g }, x = Object.values(v).filter(
|
|
62
|
+
(t) => e.acceptedChainIDs.includes(t.id.toString()) && !b.includes(t.id.toString())
|
|
63
63
|
).map((t) => t), o = [
|
|
64
|
-
U,
|
|
65
64
|
w,
|
|
66
65
|
N,
|
|
66
|
+
h,
|
|
67
67
|
...x
|
|
68
68
|
], r = [...o];
|
|
69
69
|
if (e.suiEnvironment) {
|
|
70
|
-
const t =
|
|
70
|
+
const t = S[e.suiEnvironment];
|
|
71
71
|
r.push(t);
|
|
72
72
|
}
|
|
73
|
-
const a = !!e.disableInjectedDiscoveryInMobileDapp &&
|
|
73
|
+
const a = !!e.disableInjectedDiscoveryInMobileDapp && k(), A = a || !!e.disableSuiAutoReconnect, d = new E({
|
|
74
74
|
...e.adapterConfig,
|
|
75
75
|
ssr: e.adapterConfig.ssr ?? !0,
|
|
76
76
|
projectId: e.appKitOptions.projectId,
|
|
@@ -78,10 +78,10 @@ async function K(e) {
|
|
|
78
78
|
...a ? { multiInjectedProviderDiscovery: !1 } : {}
|
|
79
79
|
}), u = [d];
|
|
80
80
|
if (e.suiEnvironment) {
|
|
81
|
-
const t =
|
|
81
|
+
const t = S[e.suiEnvironment], n = t.caipNetworkId ?? `sui:${t.id}`;
|
|
82
82
|
u.push(
|
|
83
|
-
new
|
|
84
|
-
explicitCaipChains: [
|
|
83
|
+
new _({
|
|
84
|
+
explicitCaipChains: [n],
|
|
85
85
|
expectedSuiAddress: e.expectedSuiAddress
|
|
86
86
|
})
|
|
87
87
|
);
|
|
@@ -90,13 +90,13 @@ async function K(e) {
|
|
|
90
90
|
...e.appKitOptions,
|
|
91
91
|
adapters: u,
|
|
92
92
|
networks: [r[0], ...r.slice(1)],
|
|
93
|
-
...a ? { enableEIP6963: !1 } : {}
|
|
93
|
+
...a ? { enableEIP6963: !1, enableInjected: !1 } : {}
|
|
94
94
|
});
|
|
95
|
-
if (await s.ready(), e.suiEnvironment) {
|
|
96
|
-
const t = await s.getUniversalProvider(),
|
|
97
|
-
if ((
|
|
98
|
-
const
|
|
99
|
-
(!e.expectedSuiAddress ||
|
|
95
|
+
if (await s.ready(), e.suiEnvironment && !A) {
|
|
96
|
+
const t = await s.getUniversalProvider(), n = (m = (l = t == null ? void 0 : t.session) == null ? void 0 : l.namespaces) == null ? void 0 : m.sui;
|
|
97
|
+
if ((p = n == null ? void 0 : n.accounts) != null && p.length && !s.getCaipAddress("sui")) {
|
|
98
|
+
const U = (I = n.accounts[0]) == null ? void 0 : I.split(":").pop();
|
|
99
|
+
(!e.expectedSuiAddress || U === e.expectedSuiAddress) && await ((f = s.syncWalletConnectAccount) == null ? void 0 : f.call(s));
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
102
|
return {
|
|
@@ -108,6 +108,6 @@ async function K(e) {
|
|
|
108
108
|
};
|
|
109
109
|
}
|
|
110
110
|
export {
|
|
111
|
-
|
|
112
|
-
|
|
111
|
+
j as SuiMethods,
|
|
112
|
+
W as init
|
|
113
113
|
};
|