@multiversx/sdk-dapp-liquidity 2.1.1-alpha.0 → 2.3.0-alpha.0
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/helpers/assertConfirmRateData.d.ts +19 -0
- package/helpers/assertConfirmRateData.js +2 -0
- package/helpers/assertConfirmRateData.mjs +29 -0
- package/helpers/isValidAddressForChainType.js +1 -1
- package/helpers/isValidAddressForChainType.mjs +28 -16
- package/helpers/tests/assertConfirmRateData.spec.d.ts +1 -0
- package/helpers/tests/assertConfirmRateData.spec.js +2 -0
- package/helpers/tests/assertConfirmRateData.spec.mjs +77 -0
- package/helpers/tests/assertRateConfirmationMatchesIntent.spec.js +1 -1
- package/helpers/tests/assertRateConfirmationMatchesIntent.spec.mjs +3 -3
- package/helpers/tests/isValidAddressForChainType.spec.js +1 -1
- package/helpers/tests/isValidAddressForChainType.spec.mjs +49 -15
- package/package.json +1 -6
- package/reactjs/adapters/SuiAdapter.js +1 -1
- package/reactjs/adapters/SuiAdapter.mjs +91 -88
- package/reactjs/components/BridgeForm/Deposit.js +1 -1
- package/reactjs/components/BridgeForm/Deposit.mjs +250 -247
- package/reactjs/components/BridgeForm/Transfer.js +1 -1
- package/reactjs/components/BridgeForm/Transfer.mjs +228 -225
- package/reactjs/hooks/useBridgeFormik.d.ts +1 -0
- package/reactjs/hooks/useBridgeFormik.js +1 -1
- package/reactjs/hooks/useBridgeFormik.mjs +97 -84
- package/reactjs/hooks/useNamespaceAddress.d.ts +19 -0
- package/reactjs/hooks/useNamespaceAddress.js +2 -0
- package/reactjs/hooks/useNamespaceAddress.mjs +16 -0
- package/types/errors.d.ts +15 -0
- package/types/errors.js +1 -1
- package/types/errors.mjs +12 -0
|
@@ -94,6 +94,7 @@ export declare const useBridgeFormik: ({ sender, receiver, firstToken, firstAmou
|
|
|
94
94
|
fromChainError: string | undefined;
|
|
95
95
|
senderAddressError: string | undefined;
|
|
96
96
|
receiverAddressError: string | undefined;
|
|
97
|
+
confirmRateError: string | undefined;
|
|
97
98
|
handleBlur: {
|
|
98
99
|
(e: React.FocusEvent<any, Element>): void;
|
|
99
100
|
<T = any>(fieldOrEvent: T): T extends string ? (e: any) => void : void;
|
|
@@ -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 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({}),e("firstAmount",""),e("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:n,touched:m,handleBlur:N,handleSubmit:U,handleChange:W,setFieldValue:e,setFieldTouched:x}=f;d.useEffect(()=>{e("firstToken",h,!0)},[h]),d.useEffect(()=>{e("secondToken",C,!0)},[C]),d.useEffect(()=>{e("fromChainId",p,!0)},[p]),d.useEffect(()=>{e("toChainId",A,!0)},[A]);const z="secondAmount"in n&&"secondAmount"in m?n.secondAmount:void 0,G="firstAmount"in n&&"firstAmount"in m?n.firstAmount:void 0,H="fromChainId"in n&&"fromChainId"in m?n.fromChainId:void 0;return{formik:f,errors:n,touched:m,firstToken:h,secondToken:C,firstAmountError:G,secondAmountError:z,fromChainError:H,senderAddressError:$,receiverAddressError:w,confirmRateError:V,handleBlur:N,handleChange:W,handleSubmit:U,setFieldValue:e,resetSwapForm:b,setFieldTouched:x}};exports.BridgeFormikValuesEnum=D;exports.useBridgeFormik=ro;
|
|
@@ -1,131 +1,144 @@
|
|
|
1
|
-
import { useFormik as
|
|
2
|
-
import { useRef as
|
|
3
|
-
import { object as k, string as
|
|
4
|
-
import { useAmountSchema as
|
|
5
|
-
import { useSecondAmountSchema as
|
|
6
|
-
import { confirmRate as
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import { useFormik as Q } from "formik";
|
|
2
|
+
import { useRef as V, useState as X, useEffect as u } from "react";
|
|
3
|
+
import { object as k, string as y } from "yup";
|
|
4
|
+
import { useAmountSchema as Y } from "./validation/useAmountSchema.mjs";
|
|
5
|
+
import { useSecondAmountSchema as Z } from "./validation/useSecondAmountSchema.mjs";
|
|
6
|
+
import { confirmRate as _ } from "../../api/confirmRate.mjs";
|
|
7
|
+
import { assertConfirmRateData as F } from "../../helpers/assertConfirmRateData.mjs";
|
|
8
|
+
import { assertRateConfirmationMatchesIntent as B } from "../../helpers/assertRateConfirmationMatchesIntent.mjs";
|
|
9
|
+
import { getApiURL as oo } from "../../helpers/getApiURL.mjs";
|
|
10
|
+
import { isValidAddressForChainType as D } from "../../helpers/isValidAddressForChainType.mjs";
|
|
11
|
+
import { ConfirmRateError as ro, MissingConfirmRateDataError as no } from "../../types/errors.mjs";
|
|
12
|
+
import { ProviderType as M } from "../../types/providerType.mjs";
|
|
13
|
+
import { useWeb3App as io } from "../context/useWeb3App.mjs";
|
|
14
|
+
var to = /* @__PURE__ */ ((r) => (r.firstToken = "firstToken", r.firstAmount = "firstAmount", r.secondToken = "secondToken", r.secondAmount = "secondAmount", r.fromChainId = "fromChainId", r.toChainId = "toChainId", r))(to || {});
|
|
15
|
+
const So = ({
|
|
16
|
+
sender: r,
|
|
15
17
|
receiver: e,
|
|
16
|
-
firstToken:
|
|
17
|
-
firstAmount:
|
|
18
|
-
secondToken:
|
|
19
|
-
secondAmount:
|
|
18
|
+
firstToken: a,
|
|
19
|
+
firstAmount: h,
|
|
20
|
+
secondToken: I,
|
|
21
|
+
secondAmount: C,
|
|
20
22
|
fromChainId: p,
|
|
21
23
|
toChainId: A,
|
|
22
24
|
setForceRefetchRate: l,
|
|
23
|
-
rate:
|
|
24
|
-
onSubmit:
|
|
25
|
-
isMvxConnected:
|
|
26
|
-
senderChainType:
|
|
27
|
-
receiverChainType:
|
|
25
|
+
rate: o,
|
|
26
|
+
onSubmit: N,
|
|
27
|
+
isMvxConnected: O,
|
|
28
|
+
senderChainType: S,
|
|
29
|
+
receiverChainType: v
|
|
28
30
|
}) => {
|
|
29
|
-
const
|
|
31
|
+
const m = V(), { nativeAuthToken: g } = io(), [$, T] = X(
|
|
32
|
+
void 0
|
|
33
|
+
), E = !r || !S ? !0 : D(r, S), b = !e || !v ? !0 : D(e, v), j = r && !E ? `Invalid ${S} sender address` : void 0, x = e && !b ? `Invalid ${v} receiver address` : void 0, L = {
|
|
30
34
|
firstAmount: "",
|
|
31
35
|
secondAmount: "",
|
|
32
36
|
fromChainId: p ?? "",
|
|
33
37
|
toChainId: A ?? ""
|
|
34
|
-
},
|
|
35
|
-
|
|
36
|
-
}, P = async (
|
|
37
|
-
var
|
|
38
|
-
if (!
|
|
39
|
-
|
|
38
|
+
}, q = () => {
|
|
39
|
+
f.setTouched({}, !1), f.setErrors({}), i("firstAmount", ""), i("secondAmount", "");
|
|
40
|
+
}, P = async (t) => {
|
|
41
|
+
var R, w;
|
|
42
|
+
if (!m.current) {
|
|
43
|
+
m.current = !0, T(void 0);
|
|
40
44
|
try {
|
|
41
|
-
if (!
|
|
42
|
-
|
|
45
|
+
if (!E || !b) {
|
|
46
|
+
m.current = !1;
|
|
43
47
|
return;
|
|
44
48
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
49
|
+
F({
|
|
50
|
+
nativeAuthToken: g,
|
|
51
|
+
orderId: o == null ? void 0 : o.orderId,
|
|
52
|
+
fromChainId: t.fromChainId,
|
|
53
|
+
toChainId: t.toChainId,
|
|
54
|
+
sender: r,
|
|
55
|
+
receiver: e
|
|
56
|
+
});
|
|
57
|
+
const { data: d } = await _({
|
|
58
|
+
url: oo(),
|
|
59
|
+
nativeAuthToken: g ?? "",
|
|
48
60
|
body: {
|
|
49
|
-
tokenIn: ((
|
|
50
|
-
amountIn: (
|
|
51
|
-
fromChainId:
|
|
52
|
-
tokenOut: ((
|
|
53
|
-
toChainId:
|
|
54
|
-
amountOut: (
|
|
55
|
-
sender:
|
|
61
|
+
tokenIn: ((R = t.firstToken) == null ? void 0 : R.address) ?? "",
|
|
62
|
+
amountIn: (h == null ? void 0 : h.toString()) ?? "",
|
|
63
|
+
fromChainId: t.fromChainId ?? "",
|
|
64
|
+
tokenOut: ((w = t.secondToken) == null ? void 0 : w.address) ?? "",
|
|
65
|
+
toChainId: t.toChainId ?? "",
|
|
66
|
+
amountOut: (C == null ? void 0 : C.toString()) ?? "",
|
|
67
|
+
sender: r ?? "",
|
|
56
68
|
receiver: e ?? "",
|
|
57
|
-
fee: (
|
|
58
|
-
provider: (
|
|
59
|
-
orderId: (
|
|
69
|
+
fee: (o == null ? void 0 : o.fee) ?? "0",
|
|
70
|
+
provider: (o == null ? void 0 : o.provider) ?? M.None,
|
|
71
|
+
orderId: (o == null ? void 0 : o.orderId) ?? ""
|
|
60
72
|
}
|
|
61
|
-
}),
|
|
62
|
-
if (!
|
|
63
|
-
|
|
73
|
+
}), s = d;
|
|
74
|
+
if (!s || s.length === 0) {
|
|
75
|
+
m.current = !1;
|
|
64
76
|
return;
|
|
65
77
|
}
|
|
66
|
-
|
|
67
|
-
{ fromChainId:
|
|
68
|
-
|
|
69
|
-
),
|
|
70
|
-
transactions:
|
|
71
|
-
provider: (
|
|
78
|
+
B(
|
|
79
|
+
{ fromChainId: t.fromChainId ?? "", sender: r ?? "" },
|
|
80
|
+
s
|
|
81
|
+
), q(), N({
|
|
82
|
+
transactions: s,
|
|
83
|
+
provider: (o == null ? void 0 : o.provider) ?? M.None
|
|
72
84
|
});
|
|
73
|
-
} catch (
|
|
74
|
-
console.error("Error confirming rate:",
|
|
85
|
+
} catch (d) {
|
|
86
|
+
console.error("Error confirming rate:", d), d instanceof ro || d instanceof no ? T(d.message) : l == null || l((s) => s + 1);
|
|
75
87
|
} finally {
|
|
76
|
-
|
|
88
|
+
m.current = !1;
|
|
77
89
|
}
|
|
78
90
|
}
|
|
79
|
-
},
|
|
80
|
-
initialValues:
|
|
91
|
+
}, f = Q({
|
|
92
|
+
initialValues: L,
|
|
81
93
|
validationSchema: k().shape({
|
|
82
|
-
firstAmount:
|
|
94
|
+
firstAmount: Y({ isMvxConnected: O }),
|
|
83
95
|
firstToken: k().required(),
|
|
84
|
-
secondAmount:
|
|
96
|
+
secondAmount: Z(),
|
|
85
97
|
secondToken: k().required(),
|
|
86
|
-
fromChainId:
|
|
87
|
-
toChainId:
|
|
98
|
+
fromChainId: y().required(),
|
|
99
|
+
toChainId: y().required()
|
|
88
100
|
}),
|
|
89
101
|
onSubmit: P
|
|
90
102
|
}), {
|
|
91
103
|
errors: n,
|
|
92
|
-
touched:
|
|
104
|
+
touched: c,
|
|
93
105
|
handleBlur: U,
|
|
94
106
|
handleSubmit: W,
|
|
95
107
|
handleChange: z,
|
|
96
108
|
setFieldValue: i,
|
|
97
|
-
setFieldTouched:
|
|
98
|
-
} =
|
|
109
|
+
setFieldTouched: G
|
|
110
|
+
} = f;
|
|
99
111
|
u(() => {
|
|
100
|
-
i("firstToken",
|
|
101
|
-
}, [
|
|
102
|
-
i("secondToken",
|
|
103
|
-
}, [
|
|
112
|
+
i("firstToken", a, !0);
|
|
113
|
+
}, [a]), u(() => {
|
|
114
|
+
i("secondToken", I, !0);
|
|
115
|
+
}, [I]), u(() => {
|
|
104
116
|
i("fromChainId", p, !0);
|
|
105
117
|
}, [p]), u(() => {
|
|
106
118
|
i("toChainId", A, !0);
|
|
107
119
|
}, [A]);
|
|
108
|
-
const
|
|
120
|
+
const H = "secondAmount" in n && "secondAmount" in c ? n.secondAmount : void 0, J = "firstAmount" in n && "firstAmount" in c ? n.firstAmount : void 0, K = "fromChainId" in n && "fromChainId" in c ? n.fromChainId : void 0;
|
|
109
121
|
return {
|
|
110
|
-
formik:
|
|
122
|
+
formik: f,
|
|
111
123
|
errors: n,
|
|
112
|
-
touched:
|
|
113
|
-
firstToken:
|
|
114
|
-
secondToken:
|
|
115
|
-
firstAmountError:
|
|
116
|
-
secondAmountError:
|
|
117
|
-
fromChainError:
|
|
118
|
-
senderAddressError:
|
|
119
|
-
receiverAddressError:
|
|
124
|
+
touched: c,
|
|
125
|
+
firstToken: a,
|
|
126
|
+
secondToken: I,
|
|
127
|
+
firstAmountError: J,
|
|
128
|
+
secondAmountError: H,
|
|
129
|
+
fromChainError: K,
|
|
130
|
+
senderAddressError: j,
|
|
131
|
+
receiverAddressError: x,
|
|
132
|
+
confirmRateError: $,
|
|
120
133
|
handleBlur: U,
|
|
121
134
|
handleChange: z,
|
|
122
135
|
handleSubmit: W,
|
|
123
136
|
setFieldValue: i,
|
|
124
|
-
resetSwapForm:
|
|
125
|
-
setFieldTouched:
|
|
137
|
+
resetSwapForm: q,
|
|
138
|
+
setFieldTouched: G
|
|
126
139
|
};
|
|
127
140
|
};
|
|
128
141
|
export {
|
|
129
|
-
|
|
130
|
-
|
|
142
|
+
to as BridgeFormikValuesEnum,
|
|
143
|
+
So as useBridgeFormik
|
|
131
144
|
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ChainType } from '../../types/chainType';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns the connected wallet address scoped to the AppKit namespace that corresponds
|
|
5
|
+
* to the given chain type, preventing a stale SUI address from leaking into EVM form
|
|
6
|
+
* fields (and vice-versa) during namespace switches.
|
|
7
|
+
*
|
|
8
|
+
* Mapping:
|
|
9
|
+
* ChainType.sui → 'sui' namespace
|
|
10
|
+
* ChainType.evm → 'eip155' namespace
|
|
11
|
+
* ChainType.mvx → undefined (MVX addresses come from the dApp's own auth layer)
|
|
12
|
+
* all others → undefined
|
|
13
|
+
*
|
|
14
|
+
* Because hooks must be called unconditionally and before derived values in the same
|
|
15
|
+
* component, call this hook at the top of the component and pass the chain type that
|
|
16
|
+
* will be resolved later (it can be undefined on first render — the hook reads both
|
|
17
|
+
* namespaces unconditionally and picks based on chainType).
|
|
18
|
+
*/
|
|
19
|
+
export declare function useNamespaceAddress(chainType: ChainType | undefined): string | undefined;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@reown/appkit/react"),s=require("../../types/chainType.js");function u(c){const t=e.useAppKitAccount({namespace:"sui"}),n=e.useAppKitAccount({namespace:"eip155"});switch(c){case s.ChainType.sui:return t.address;case s.ChainType.evm:return n.address;default:return}}exports.useNamespaceAddress=u;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { useAppKitAccount as e } from "@reown/appkit/react";
|
|
2
|
+
import { ChainType as s } from "../../types/chainType.mjs";
|
|
3
|
+
function a(c) {
|
|
4
|
+
const t = e({ namespace: "sui" }), r = e({ namespace: "eip155" });
|
|
5
|
+
switch (c) {
|
|
6
|
+
case s.sui:
|
|
7
|
+
return t.address;
|
|
8
|
+
case s.evm:
|
|
9
|
+
return r.address;
|
|
10
|
+
default:
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export {
|
|
15
|
+
a as useNamespaceAddress
|
|
16
|
+
};
|
package/types/errors.d.ts
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
1
|
export declare class RateConfirmationMismatchError extends Error {
|
|
2
2
|
constructor(message: string);
|
|
3
3
|
}
|
|
4
|
+
/**
|
|
5
|
+
* Thrown when a required system token (nativeAuthToken, orderId) is missing before
|
|
6
|
+
* calling confirmRate. Generic message — not shown verbatim to end users.
|
|
7
|
+
*/
|
|
8
|
+
export declare class ConfirmRateError extends Error {
|
|
9
|
+
constructor(message: string);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Thrown when a required form field (fromChainId, toChainId, sender, receiver) is
|
|
13
|
+
* missing or empty before calling confirmRate. Message names the missing field so it
|
|
14
|
+
* can be displayed to the user.
|
|
15
|
+
*/
|
|
16
|
+
export declare class MissingConfirmRateDataError extends Error {
|
|
17
|
+
constructor(message: string);
|
|
18
|
+
}
|
package/types/errors.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class
|
|
2
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class o extends Error{constructor(r){super(r),this.name="RateConfirmationMismatchError"}}class e extends Error{constructor(r){super(r),this.name="ConfirmRateError"}}class s extends Error{constructor(r){super(r),this.name="MissingConfirmRateDataError"}}exports.ConfirmRateError=e;exports.MissingConfirmRateDataError=s;exports.RateConfirmationMismatchError=o;
|
package/types/errors.mjs
CHANGED
|
@@ -3,6 +3,18 @@ class o extends Error {
|
|
|
3
3
|
super(r), this.name = "RateConfirmationMismatchError";
|
|
4
4
|
}
|
|
5
5
|
}
|
|
6
|
+
class s extends Error {
|
|
7
|
+
constructor(r) {
|
|
8
|
+
super(r), this.name = "ConfirmRateError";
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
class a extends Error {
|
|
12
|
+
constructor(r) {
|
|
13
|
+
super(r), this.name = "MissingConfirmRateDataError";
|
|
14
|
+
}
|
|
15
|
+
}
|
|
6
16
|
export {
|
|
17
|
+
s as ConfirmRateError,
|
|
18
|
+
a as MissingConfirmRateDataError,
|
|
7
19
|
o as RateConfirmationMismatchError
|
|
8
20
|
};
|