@imtbl/sdk 1.52.0 → 1.52.1-alpha.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/dist/{blockchain_data-T7u5Hp0U.js → blockchain_data-DBBTvmmb.js} +2 -2
- package/dist/blockchain_data.d.ts +34 -3202
- package/dist/blockchain_data.js +3 -3
- package/dist/browser/checkout/{AddFundsWidget-DuG1OWEM.js → AddFundsWidget-SdKqlUUr.js} +124 -49
- package/dist/browser/checkout/{BridgeWidget-2D-8F1Vq.js → BridgeWidget-Bx1DFMXg.js} +11 -9
- package/dist/browser/checkout/{CheckoutWidget-Bvnur5WZ.js → CheckoutWidget-B1pE8Gc2.js} +81 -35
- package/dist/browser/checkout/{OnRampWidget-B4UV_TYW.js → OnRampWidget-bmvseWX-.js} +20 -12
- package/dist/browser/checkout/{SaleWidget-BQMUaWlZ.js → SaleWidget-Ddos1DHm.js} +9 -9
- package/dist/browser/checkout/{SpendingCapHero-BsQQYO_D.js → SpendingCapHero-BKdEyvIl.js} +1 -1
- package/dist/browser/checkout/{SwapWidget-BK7sTJ6u.js → SwapWidget-CrEzJos9.js} +12 -10
- package/dist/browser/checkout/{TextInputForm-Cy6sTMjr.js → TextInputForm-BvZsFFRK.js} +1 -1
- package/dist/browser/checkout/{TopUpView-Dw-JH0Q5.js → TopUpView-CojeMjuL.js} +1 -1
- package/dist/browser/checkout/{WalletWidget-t6i1V-G5.js → WalletWidget-DcoX5T7s.js} +7 -6
- package/dist/browser/checkout/{auto-track-CMv29U8a.js → auto-track-CPy9e41Q.js} +1 -1
- package/dist/browser/checkout/{balance-Dt4oB1G1.js → balance-_0wiNzA1.js} +2 -2
- package/dist/browser/checkout/{index-D2zks65E.js → index-2yp2sttp.js} +2 -2
- package/dist/browser/checkout/{index-BRzBLTux.js → index-4LGmzy2P.js} +1 -1
- package/dist/browser/checkout/{index-Zraoakam.js → index-BjnD8v8p.js} +1 -1
- package/dist/browser/checkout/{index-DmXFGYTM.js → index-BpduNNVl.js} +1 -1
- package/dist/browser/checkout/{index-D4zR0DRy.js → index-CPLIXtyA.js} +1 -1
- package/dist/browser/checkout/{index-CMBbtkDe.js → index-CcR4tO_g.js} +1 -1
- package/dist/browser/checkout/{index-5qc7Vsg4.js → index-DnQfQojQ.js} +63 -46
- package/dist/browser/checkout/{index-DwTyassh.js → index-Dv7_L5sJ.js} +1 -1
- package/dist/browser/checkout/{index.umd-CCwq6cRd.js → index.umd-LRNZ8nMO.js} +1 -1
- package/dist/browser/checkout/{retry-C_l6vh-l.js → retry-TNKwGgHJ.js} +1 -1
- package/dist/browser/checkout/sdk.js +5 -5
- package/dist/browser/checkout/widgets-esm.js +1 -1
- package/dist/browser/checkout/widgets.js +279 -128
- package/dist/{checkout-DxDRj3k-.js → checkout-BoEdWIoM.js} +7 -6
- package/dist/checkout.d.ts +38 -10
- package/dist/checkout.js +5 -5
- package/dist/{config-Dj7PQqL4.js → config-4V88kddG.js} +1 -1
- package/dist/config.js +1 -1
- package/dist/{index-8m8-bJcZ.js → index-5q3Doq32.js} +1 -1
- package/dist/{index-1bjDCdo5.js → index-CAL1gWlu.js} +4 -4
- package/dist/{index-XxjQ6oVx.js → index-D0T-P8dM.js} +53 -53
- package/dist/{index-D4eU2e1C.js → index-DDE1ZfXv.js} +1 -1
- package/dist/{index-BxF866Mh.js → index-Dg5cqGBu.js} +1 -1
- package/dist/{index-snMwBaY-.js → index-Dqva106f.js} +1 -1
- package/dist/index.browser.js +5 -5
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +66 -61
- package/dist/index.d.ts +266 -3404
- package/dist/index.js +14 -14
- package/dist/{minting_backend-DfBB5ptf.js → minting_backend-x7gO9bio.js} +3 -3
- package/dist/minting_backend.d.ts +312 -228
- package/dist/minting_backend.js +5 -5
- package/dist/{orderbook-CnmzmGtG.js → orderbook-BUiL0rqz.js} +1 -1
- package/dist/orderbook.js +2 -2
- package/dist/{passport-B8WhzCZf.js → passport-DGaas7w4.js} +10 -6
- package/dist/passport.d.ts +3 -1
- package/dist/passport.js +4 -4
- package/dist/{webhook-DzAoMhRT.js → webhook-Be5S01dB.js} +1 -1
- package/dist/webhook.js +2 -2
- package/dist/{x-DbbHwlbW.js → x-7ExOXsHk.js} +3 -3
- package/dist/x.js +4 -4
- package/package.json +1 -1
package/dist/blockchain_data.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { A as APIError, B as BlockchainData } from './index-
|
|
2
|
-
export { i as Types } from './index-
|
|
3
|
-
import './index-
|
|
1
|
+
export { A as APIError, B as BlockchainData } from './index-D0T-P8dM.js';
|
|
2
|
+
export { i as Types } from './index-Dqva106f.js';
|
|
3
|
+
import './index-5q3Doq32.js';
|
|
4
4
|
import 'axios';
|
|
5
5
|
import 'lru-memorise';
|
|
6
6
|
import 'global-const';
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { r as reactExports, l as useTranslation, n as jsxs, j as jsx, M as MenuItem, aG as motion, aH as listVariants, aI as listItemVariants, a as Box, a7 as Drawer, V as ViewContext, E as EventTargetContext, p as ViewActions, K as SharedViews, Y as HeaderNavigation, bh as amountInputValidation, o as Body, cK as OverflowPopoverMenu, a2 as SimpleLayout, T as TokenFilterTypes, x as getL2ChainId,
|
|
2
|
-
import { T as TextInputForm } from './TextInputForm-
|
|
1
|
+
import { r as reactExports, l as useTranslation, n as jsxs, j as jsx, M as MenuItem, aG as motion, aH as listVariants, aI as listItemVariants, a as Box, a7 as Drawer, V as ViewContext, E as EventTargetContext, p as ViewActions, K as SharedViews, Y as HeaderNavigation, F as orchestrationEvents, I as IMTBLWidgetEvents, bh as amountInputValidation, o as Body, cK as OverflowPopoverMenu, a2 as SimpleLayout, T as TokenFilterTypes, x as getL2ChainId, cL as commonjsGlobal, cM as requireSecp256k1$1, cN as requireLib_commonjs, cO as require$$0$3, cP as requireDist$1, cQ as bech32$2, cR as bnExports$1, cS as require$$0$4, cT as getAugmentedNamespace, cU as require$$0$5, cV as minimalisticAssert, cW as require$$2, cX as hash$6, ah as viewReducer, ai as initialViewState, t as useAnalytics, cY as sendAddFundsCloseEvent, ak as ErrorView, U as UserJourney } from './index-DnQfQojQ.js';
|
|
2
|
+
import { T as TextInputForm } from './TextInputForm-BvZsFFRK.js';
|
|
3
3
|
|
|
4
4
|
const initialAddFundsState = {
|
|
5
5
|
checkout: null,
|
|
6
6
|
provider: null,
|
|
7
|
-
allowedTokens:
|
|
7
|
+
allowedTokens: [],
|
|
8
8
|
squid: null,
|
|
9
|
+
chains: [],
|
|
10
|
+
balances: [],
|
|
9
11
|
};
|
|
10
12
|
var AddFundsActions;
|
|
11
13
|
(function (AddFundsActions) {
|
|
@@ -13,6 +15,8 @@ var AddFundsActions;
|
|
|
13
15
|
AddFundsActions["SET_PROVIDER"] = "SET_PROVIDER";
|
|
14
16
|
AddFundsActions["SET_ALLOWED_TOKENS"] = "SET_ALLOWED_TOKENS";
|
|
15
17
|
AddFundsActions["SET_SQUID"] = "SET_SQUID";
|
|
18
|
+
AddFundsActions["SET_CHAINS"] = "SET_CHAINS";
|
|
19
|
+
AddFundsActions["SET_BALANCES"] = "SET_BALANCES";
|
|
16
20
|
})(AddFundsActions || (AddFundsActions = {}));
|
|
17
21
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
18
22
|
const AddFundsContext = reactExports.createContext({
|
|
@@ -42,15 +46,20 @@ const addFundsReducer = (state, action) => {
|
|
|
42
46
|
...state,
|
|
43
47
|
squid: action.payload.squid,
|
|
44
48
|
};
|
|
49
|
+
case AddFundsActions.SET_CHAINS:
|
|
50
|
+
return {
|
|
51
|
+
...state,
|
|
52
|
+
chains: action.payload.chains,
|
|
53
|
+
};
|
|
54
|
+
case AddFundsActions.SET_BALANCES:
|
|
55
|
+
return {
|
|
56
|
+
...state,
|
|
57
|
+
balances: action.payload.balances,
|
|
58
|
+
};
|
|
45
59
|
default:
|
|
46
60
|
return state;
|
|
47
61
|
}
|
|
48
62
|
};
|
|
49
|
-
const useAddFundsValues = (overrides = {}) => {
|
|
50
|
-
const [addFundsState, addFundsDispatch] = reactExports.useReducer(addFundsReducer, { ...initialAddFundsState, ...overrides });
|
|
51
|
-
const values = reactExports.useMemo(() => ({ addFundsState, addFundsDispatch }), [addFundsState, addFundsDispatch]);
|
|
52
|
-
return values;
|
|
53
|
-
};
|
|
54
63
|
|
|
55
64
|
var AddFundsWidgetViews;
|
|
56
65
|
(function (AddFundsWidgetViews) {
|
|
@@ -133,19 +142,20 @@ showBridgeOption, visible, onClose, onPayWithCard, }) {
|
|
|
133
142
|
} }) }) }) }));
|
|
134
143
|
}
|
|
135
144
|
|
|
136
|
-
function AddFunds({ checkout, provider,
|
|
145
|
+
function AddFunds({ checkout, provider, toAmount, toTokenAddress, showBackButton = false, showOnrampOption = true, showSwapOption = true, showBridgeOption = true, onBackButtonClick, onCloseButtonClick, }) {
|
|
137
146
|
console.log('provider', provider);
|
|
138
147
|
console.log('showOnrampOption', showOnrampOption);
|
|
139
148
|
console.log('showSwapOption', showSwapOption);
|
|
140
149
|
console.log('showBridgeOption', showBridgeOption);
|
|
150
|
+
const showBack = showBackButton || !!onBackButtonClick;
|
|
141
151
|
const { addFundsDispatch } = reactExports.useContext(AddFundsContext);
|
|
142
152
|
const { viewDispatch } = reactExports.useContext(ViewContext);
|
|
143
153
|
const { eventTargetState: { eventTarget }, } = reactExports.useContext(EventTargetContext);
|
|
144
154
|
const [showOptionsDrawer, setShowOptionsDrawer] = reactExports.useState(false);
|
|
145
155
|
const [onRampAllowedTokens, setOnRampAllowedTokens] = reactExports.useState([]);
|
|
146
156
|
const [allowedTokens, setAllowedTokens] = reactExports.useState([]);
|
|
147
|
-
const [
|
|
148
|
-
const [
|
|
157
|
+
const [currentToAmount, setCurrentToAmount] = reactExports.useState(toAmount || '0');
|
|
158
|
+
const [currentToTokenAddress, setCurrentToTokenAddress] = reactExports.useState();
|
|
149
159
|
const showErrorView = reactExports.useCallback((error) => {
|
|
150
160
|
viewDispatch({
|
|
151
161
|
payload: {
|
|
@@ -170,8 +180,9 @@ function AddFunds({ checkout, provider, amount, tokenAddress, showOnrampOption =
|
|
|
170
180
|
});
|
|
171
181
|
if (tokenResponse?.tokens.length > 0) {
|
|
172
182
|
setAllowedTokens(tokenResponse.tokens);
|
|
173
|
-
const token = tokenResponse.tokens.find((t) => t.address ===
|
|
174
|
-
|
|
183
|
+
const token = tokenResponse.tokens.find((t) => t.address === toTokenAddress)
|
|
184
|
+
|| tokenResponse.tokens[0];
|
|
185
|
+
setCurrentToTokenAddress(token);
|
|
175
186
|
addFundsDispatch({
|
|
176
187
|
payload: {
|
|
177
188
|
type: AddFundsActions.SET_ALLOWED_TOKENS,
|
|
@@ -185,7 +196,7 @@ function AddFunds({ checkout, provider, amount, tokenAddress, showOnrampOption =
|
|
|
185
196
|
}
|
|
186
197
|
};
|
|
187
198
|
fetchTokens();
|
|
188
|
-
}, [checkout,
|
|
199
|
+
}, [checkout, toTokenAddress]);
|
|
189
200
|
reactExports.useEffect(() => {
|
|
190
201
|
if (!checkout) {
|
|
191
202
|
showErrorView(new Error('Checkout object is missing'));
|
|
@@ -211,43 +222,47 @@ function AddFunds({ checkout, provider, amount, tokenAddress, showOnrampOption =
|
|
|
211
222
|
setShowOptionsDrawer(true);
|
|
212
223
|
};
|
|
213
224
|
const updateAmount = (value) => {
|
|
214
|
-
|
|
225
|
+
setCurrentToAmount(value);
|
|
215
226
|
};
|
|
216
|
-
const isSelected = (token) => token.address ===
|
|
217
|
-
const isDisabled = !
|
|
227
|
+
const isSelected = (token) => token.address === currentToTokenAddress;
|
|
228
|
+
const isDisabled = !currentToTokenAddress || !toAmount || parseFloat(toAmount) <= 0;
|
|
218
229
|
const handleTokenChange = (token) => {
|
|
219
|
-
|
|
230
|
+
setCurrentToTokenAddress(token);
|
|
220
231
|
};
|
|
221
232
|
// const handleReviewClick = () => {
|
|
222
233
|
// console.log('handle review click');
|
|
223
234
|
// };
|
|
224
235
|
const onPayWithCard = (paymentType) => {
|
|
225
236
|
console.log('paymentType', paymentType);
|
|
226
|
-
console.log('=== toTokenAddress',
|
|
237
|
+
console.log('=== toTokenAddress', currentToTokenAddress);
|
|
227
238
|
console.log('=== toAmount', toAmount);
|
|
228
239
|
if (paymentType === OptionTypes.SWAP) {
|
|
229
240
|
orchestrationEvents.sendRequestSwapEvent(eventTarget, IMTBLWidgetEvents.IMTBL_ADD_FUNDS_WIDGET_EVENT, {
|
|
230
|
-
toTokenAddress:
|
|
241
|
+
toTokenAddress: currentToTokenAddress?.address ?? '',
|
|
231
242
|
amount: toAmount ?? '',
|
|
232
243
|
fromTokenAddress: '',
|
|
233
244
|
});
|
|
234
245
|
}
|
|
235
246
|
else {
|
|
236
247
|
const data = {
|
|
237
|
-
tokenAddress:
|
|
248
|
+
tokenAddress: currentToTokenAddress?.address ?? '',
|
|
238
249
|
amount: toAmount ?? '',
|
|
239
250
|
};
|
|
240
251
|
orchestrationEvents.sendRequestOnrampEvent(eventTarget, IMTBLWidgetEvents.IMTBL_ADD_FUNDS_WIDGET_EVENT, data);
|
|
241
252
|
}
|
|
242
253
|
};
|
|
243
254
|
const checkShowOnRampOption = () => {
|
|
244
|
-
if (showOnrampOption &&
|
|
245
|
-
const token = onRampAllowedTokens.find((t) => t.address?.toLowerCase()
|
|
255
|
+
if (showOnrampOption && currentToTokenAddress) {
|
|
256
|
+
const token = onRampAllowedTokens.find((t) => t.address?.toLowerCase()
|
|
257
|
+
=== currentToTokenAddress.address?.toLowerCase());
|
|
246
258
|
return !!token;
|
|
247
259
|
}
|
|
248
260
|
return false;
|
|
249
261
|
};
|
|
250
|
-
return (jsx(SimpleLayout, { header: (jsx(HeaderNavigation, { title: "Add",
|
|
262
|
+
return (jsx(SimpleLayout, { header: (jsx(HeaderNavigation, { title: "Add", onCloseButtonClick: onCloseButtonClick, showBack: showBack, onBackButtonClick: () => {
|
|
263
|
+
orchestrationEvents.sendRequestGoBackEvent(eventTarget, IMTBLWidgetEvents.IMTBL_ADD_FUNDS_WIDGET_EVENT, {});
|
|
264
|
+
onBackButtonClick?.();
|
|
265
|
+
} })), children: jsxs(Box, { sx: {
|
|
251
266
|
display: 'flex',
|
|
252
267
|
flexDirection: 'column',
|
|
253
268
|
justifyContent: 'space-between',
|
|
@@ -256,14 +271,14 @@ function AddFunds({ checkout, provider, amount, tokenAddress, showOnrampOption =
|
|
|
256
271
|
display: 'flex',
|
|
257
272
|
justifyContent: 'center',
|
|
258
273
|
marginTop: 'base.spacing.x10',
|
|
259
|
-
}, children: jsxs(Box, { sx: { width: 'base.spacing.x40' }, children: [jsx(Box, { sx: { marginBottom: 'base.spacing.x3' }, children: jsx(TextInputForm, { testId: "add-funds-amount", type: "number", value:
|
|
274
|
+
}, children: jsxs(Box, { sx: { width: 'base.spacing.x40' }, children: [jsx(Box, { sx: { marginBottom: 'base.spacing.x3' }, children: jsx(TextInputForm, { testId: "add-funds-amount", type: "number", value: currentToAmount, validator: amountInputValidation, onTextInputChange: (value) => updateAmount(value), textAlign: "right", inputMode: "decimal" }) }), jsxs(Box, { sx: {
|
|
260
275
|
display: 'flex',
|
|
261
276
|
borderRadius: 'base.borderRadius.x20',
|
|
262
277
|
alignItems: 'center',
|
|
263
278
|
gap: 'base.spacing.x5',
|
|
264
279
|
justifyContent: 'center',
|
|
265
280
|
border: '1px solid grey',
|
|
266
|
-
}, children: [jsx(Body, { size: "large", weight: "bold", children:
|
|
281
|
+
}, children: [jsx(Body, { size: "large", weight: "bold", children: currentToTokenAddress?.name ?? '' }), jsx(OverflowPopoverMenu, { testId: "add-funds-tokens-menu", children: allowedTokens.map((token) => (jsx(MenuItem, { onClick: () => handleTokenChange(token), selected: isSelected(token), children: jsx(MenuItem.Label, { children: token.name }) }, token.address))) })] })] }) }), jsxs(MenuItem, { size: "small", emphasized: true, disabled: isDisabled, sx: {
|
|
267
282
|
opacity: isDisabled ? 0.5 : 1,
|
|
268
283
|
cursor: isDisabled ? 'not-allowed' : 'pointer',
|
|
269
284
|
}, onClick: () => {
|
|
@@ -164104,44 +164119,60 @@ class Squid extends TokensChains_1.TokensChains {
|
|
|
164104
164119
|
Squid_1 = dist$2.Squid = Squid;
|
|
164105
164120
|
|
|
164106
164121
|
const SQUID_SDK_BASE_URL = 'https://apiplus.squidrouter.com';
|
|
164122
|
+
const SQUID_API_BASE_URL = 'https://api.squidrouter.com/v1';
|
|
164107
164123
|
|
|
164108
|
-
const useSquid = () => {
|
|
164124
|
+
const useSquid = (checkout) => {
|
|
164109
164125
|
const [squid, setSquid] = reactExports.useState(null);
|
|
164126
|
+
const squidConfig = reactExports.useCallback(async () => {
|
|
164127
|
+
try {
|
|
164128
|
+
return (await checkout?.config?.remote.getConfig('squid'));
|
|
164129
|
+
}
|
|
164130
|
+
catch (err) {
|
|
164131
|
+
// eslint-disable-next-line no-console
|
|
164132
|
+
console.error('Unable to fetch squid config: ', err);
|
|
164133
|
+
}
|
|
164134
|
+
return undefined;
|
|
164135
|
+
}, [checkout]);
|
|
164110
164136
|
reactExports.useEffect(() => {
|
|
164111
|
-
if (squid) {
|
|
164137
|
+
if (squid || !squidConfig) {
|
|
164112
164138
|
return;
|
|
164113
164139
|
}
|
|
164114
164140
|
const initialiseSquid = async () => {
|
|
164141
|
+
const config = await squidConfig();
|
|
164142
|
+
if (!config?.integratorId)
|
|
164143
|
+
return;
|
|
164115
164144
|
const squidSDK = new Squid_1({
|
|
164116
164145
|
baseUrl: SQUID_SDK_BASE_URL,
|
|
164117
|
-
integratorId:
|
|
164146
|
+
integratorId: config.integratorId,
|
|
164118
164147
|
});
|
|
164119
164148
|
await squidSDK.init();
|
|
164120
164149
|
setSquid(squidSDK);
|
|
164121
164150
|
};
|
|
164122
164151
|
initialiseSquid();
|
|
164123
|
-
}, []);
|
|
164152
|
+
}, [squidConfig]);
|
|
164124
164153
|
return squid;
|
|
164125
164154
|
};
|
|
164126
164155
|
|
|
164127
|
-
|
|
164128
|
-
const
|
|
164129
|
-
const
|
|
164130
|
-
|
|
164131
|
-
|
|
164132
|
-
|
|
164133
|
-
|
|
164134
|
-
|
|
164135
|
-
|
|
164136
|
-
|
|
164137
|
-
|
|
164138
|
-
|
|
164139
|
-
|
|
164140
|
-
|
|
164141
|
-
|
|
164142
|
-
}
|
|
164156
|
+
const fetchChains = async () => {
|
|
164157
|
+
const url = `${SQUID_API_BASE_URL}/chains`;
|
|
164158
|
+
const response = await fetch(url, {
|
|
164159
|
+
method: 'GET',
|
|
164160
|
+
headers: {
|
|
164161
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
164162
|
+
'Content-Type': 'application/json',
|
|
164163
|
+
},
|
|
164164
|
+
});
|
|
164165
|
+
const data = await response.json();
|
|
164166
|
+
const chains = data.chains.map((chain) => ({
|
|
164167
|
+
id: chain.chainId.toString(),
|
|
164168
|
+
name: chain.chainName,
|
|
164169
|
+
iconUrl: chain.chainIconURI,
|
|
164170
|
+
type: chain.chainType,
|
|
164171
|
+
}));
|
|
164172
|
+
return chains;
|
|
164173
|
+
};
|
|
164143
164174
|
|
|
164144
|
-
function AddFundsWidget({ checkout, web3Provider, showOnrampOption = true, showSwapOption = true, showBridgeOption = true,
|
|
164175
|
+
function AddFundsWidget({ checkout, web3Provider, showOnrampOption = true, showSwapOption = true, showBridgeOption = true, toTokenAddress, toAmount, showBackButton, }) {
|
|
164145
164176
|
const [viewState, viewDispatch] = reactExports.useReducer(viewReducer, {
|
|
164146
164177
|
...initialViewState,
|
|
164147
164178
|
view: { type: AddFundsWidgetViews.ADD_FUNDS },
|
|
@@ -164153,7 +164184,51 @@ function AddFundsWidget({ checkout, web3Provider, showOnrampOption = true, showS
|
|
|
164153
164184
|
viewState,
|
|
164154
164185
|
viewDispatch,
|
|
164155
164186
|
}), [viewState, viewReducer]);
|
|
164156
|
-
const
|
|
164187
|
+
const [addFundsState, addFundsDispatch] = reactExports.useReducer(addFundsReducer, initialAddFundsState);
|
|
164188
|
+
const addFundsReducerValues = reactExports.useMemo(() => ({
|
|
164189
|
+
addFundsState,
|
|
164190
|
+
addFundsDispatch,
|
|
164191
|
+
}), [addFundsState, addFundsDispatch]);
|
|
164192
|
+
const squid = useSquid(checkout);
|
|
164193
|
+
reactExports.useEffect(() => {
|
|
164194
|
+
(async () => {
|
|
164195
|
+
const chains = await fetchChains();
|
|
164196
|
+
addFundsDispatch({
|
|
164197
|
+
payload: {
|
|
164198
|
+
type: AddFundsActions.SET_CHAINS,
|
|
164199
|
+
chains,
|
|
164200
|
+
},
|
|
164201
|
+
});
|
|
164202
|
+
})();
|
|
164203
|
+
}, []);
|
|
164204
|
+
reactExports.useEffect(() => {
|
|
164205
|
+
if (!addFundsState.squid || !addFundsState.chains || !addFundsState.provider)
|
|
164206
|
+
return;
|
|
164207
|
+
(async () => {
|
|
164208
|
+
const chainIds = addFundsState.chains.map((chain) => chain.id);
|
|
164209
|
+
const fromAddress = await addFundsState.provider?.getSigner().getAddress();
|
|
164210
|
+
const balances = await addFundsState.squid?.getAllBalances({
|
|
164211
|
+
chainIds,
|
|
164212
|
+
evmAddress: fromAddress,
|
|
164213
|
+
});
|
|
164214
|
+
addFundsDispatch({
|
|
164215
|
+
payload: {
|
|
164216
|
+
type: AddFundsActions.SET_BALANCES,
|
|
164217
|
+
balances: balances?.evmBalances ?? [],
|
|
164218
|
+
},
|
|
164219
|
+
});
|
|
164220
|
+
})();
|
|
164221
|
+
}, [addFundsState.squid, addFundsState.chains, addFundsState.provider]);
|
|
164222
|
+
reactExports.useEffect(() => {
|
|
164223
|
+
if (!squid || addFundsState.squid)
|
|
164224
|
+
return;
|
|
164225
|
+
addFundsDispatch({
|
|
164226
|
+
payload: {
|
|
164227
|
+
type: AddFundsActions.SET_SQUID,
|
|
164228
|
+
squid,
|
|
164229
|
+
},
|
|
164230
|
+
});
|
|
164231
|
+
}, [squid]);
|
|
164157
164232
|
reactExports.useEffect(() => {
|
|
164158
164233
|
if (!web3Provider)
|
|
164159
164234
|
return;
|
|
@@ -164175,7 +164250,7 @@ function AddFundsWidget({ checkout, web3Provider, showOnrampOption = true, showS
|
|
|
164175
164250
|
});
|
|
164176
164251
|
}, [checkout]);
|
|
164177
164252
|
const { eventTargetState: { eventTarget }, } = reactExports.useContext(EventTargetContext);
|
|
164178
|
-
return (jsx(ViewContext.Provider, { value: viewReducerValues, children: jsxs(
|
|
164253
|
+
return (jsx(ViewContext.Provider, { value: viewReducerValues, children: jsxs(AddFundsContext.Provider, { value: addFundsReducerValues, children: [viewState.view.type === AddFundsWidgetViews.ADD_FUNDS && (jsx(AddFunds, { checkout: checkout, provider: web3Provider, toTokenAddress: toTokenAddress, toAmount: toAmount, showBackButton: showBackButton, showOnrampOption: showOnrampOption, showSwapOption: showSwapOption, showBridgeOption: showBridgeOption, onCloseButtonClick: () => sendAddFundsCloseEvent(eventTarget) })), viewState.view.type === SharedViews.ERROR_VIEW && (jsx(ErrorView, { actionText: t('views.ERROR_VIEW.actionText'), onActionClick: () => undefined, onCloseClick: () => sendAddFundsCloseEvent(eventTarget), errorEventAction: () => {
|
|
164179
164254
|
page({
|
|
164180
164255
|
userJourney: UserJourney.ADD_FUNDS,
|
|
164181
164256
|
screen: 'Error',
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { bz as axios, bA as defineReadOnly, bB as getStatic, bC as Signer, bD as Provider, bE as getAddress, bF as Logger, bG as getContractAddress, bH as Interface, bI as shallowCopy, bJ as VoidSigner, bK as Indexed, bL as deepCopy, bM as isHexString, bN as checkResultErrors, bO as resolveProperties, ar as BigNumber, bP as accessListify, bQ as arrayify, j as jsx, _ as _objectWithoutProperties, ap as cloneElementWithCssProp, o as Body, k as _defineProperty, J as CheckoutErrorType, bR as IMMUTABLE_API_BASE_URL, r as reactExports, I as IMTBLWidgetEvents, b0 as BridgeEventType, n as jsxs, bS as ShimmerBox, M as MenuItem, aL as Stack, l as useTranslation, d as Button, a as Box, bT as PASSPORT_URL, ag as Link, bU as getChainIdBySlug, P as getChainImage, bV as networkName, O as FramedImage, bd as Icon, t as useAnalytics, U as UserJourney, aN as Divider, V as ViewContext, aB as Fragment, p as ViewActions, a8 as useWalletConnect, aa as isWalletConnectProvider, bc as Logo, bW as RawImage, bX as AXELAR_SCAN_URL, G as isNativeToken, W as getTokenImageByAddress, bY as getNativeSymbolByChainSlug, X as calculateCryptoToFiat, E as EventTargetContext, w as isPassportProvider, y as getL1ChainId, T as TokenFilterTypes, x as getL2ChainId, bZ as WalletProviderRdns, b_ as Web3Provider, b$ as useInjectedProviders, Y as HeaderNavigation, a1 as FooterLogo, c0 as WalletDrawer, a2 as SimpleLayout, c1 as getChainSlugById, c2 as JsonRpcProvider, c3 as DEFAULT_TRANSACTIONS_RETRY_POLICY, aj as LoadingView, aX as ChainId, c4 as getChainNameById, u as useTheme, a6 as Heading, a4 as getWalletProviderNameByProvider, c5 as isAddressSanctioned, K as SharedViews, c6 as isMetaMaskProvider, a3 as WalletProviderName, a7 as Drawer, B as ButtCon, $ as ButtonNavigationStyles, A as tokenValueFormat, v as formatZeroAmount, bf as NATIVE, bh as amountInputValidation, b6 as getRemoteImage, bb as CloudImage, c7 as ETH_TOKEN_SYMBOL, z as Environment, c8 as GasEstimateType, bl as DEFAULT_TOKEN_DECIMALS, bg as DEFAULT_QUOTE_REFRESH_INTERVAL, c9 as addChainChangedListener, ca as removeChainChangedListener, bn as IMX_TOKEN_SYMBOL, cb as dist, cc as CHECKOUT_CDN_BASE_URL, ab as heroBackGroundStyles, ac as heroImageStyles, cd as Badge, ae as SimpleTextBody, bo as FooterButton, ce as getEthTokenImage, cf as WITHDRAWAL_CLAIM_GAS_LIMIT, be as getDefaultTokenImage, ah as viewReducer, ai as initialViewState, cg as BridgeConfiguration, ch as ImmutableConfiguration, ci as TokenBridge, bq as StatusView, aJ as StatusType, ak as ErrorView, cj as ServiceUnavailableErrorView, ck as ServiceType, cl as ETH_SEPOLIA_TO_ZKEVM_TESTNET, cm as ETH_SEPOLIA_TO_ZKEVM_DEVNET, cn as ETH_MAINNET_TO_ZKEVM_MAINNET } from './index-
|
|
2
|
-
import { B as BridgeWidgetViews, C as CryptoFiatContext, f as formatUnits, a as CryptoFiatActions, p as parseUnits, T as TopUpView, b as CryptoFiatProvider } from './TopUpView-
|
|
3
|
-
import { T as TokenImage, r as retry, u as useInterval } from './retry-
|
|
4
|
-
import { A as Accordion, S as SelectForm, T as TransactionRejected, g as getAllowedBalances, F as Fees, N as NetworkSwitchDrawer, W as WalletApproveHero } from './balance-
|
|
5
|
-
import { T as TextInputForm } from './TextInputForm-
|
|
1
|
+
import { bz as axios, bA as defineReadOnly, bB as getStatic, bC as Signer, bD as Provider, bE as getAddress, bF as Logger, bG as getContractAddress, bH as Interface, bI as shallowCopy, bJ as VoidSigner, bK as Indexed, bL as deepCopy, bM as isHexString, bN as checkResultErrors, bO as resolveProperties, ar as BigNumber, bP as accessListify, bQ as arrayify, j as jsx, _ as _objectWithoutProperties, ap as cloneElementWithCssProp, o as Body, k as _defineProperty, J as CheckoutErrorType, bR as IMMUTABLE_API_BASE_URL, r as reactExports, I as IMTBLWidgetEvents, b0 as BridgeEventType, n as jsxs, bS as ShimmerBox, M as MenuItem, aL as Stack, l as useTranslation, d as Button, a as Box, bT as PASSPORT_URL, ag as Link, bU as getChainIdBySlug, P as getChainImage, bV as networkName, O as FramedImage, bd as Icon, t as useAnalytics, U as UserJourney, aN as Divider, V as ViewContext, aB as Fragment, p as ViewActions, a8 as useWalletConnect, aa as isWalletConnectProvider, bc as Logo, bW as RawImage, bX as AXELAR_SCAN_URL, G as isNativeToken, W as getTokenImageByAddress, bY as getNativeSymbolByChainSlug, X as calculateCryptoToFiat, E as EventTargetContext, w as isPassportProvider, y as getL1ChainId, T as TokenFilterTypes, x as getL2ChainId, bZ as WalletProviderRdns, b_ as Web3Provider, b$ as useInjectedProviders, Y as HeaderNavigation, a1 as FooterLogo, c0 as WalletDrawer, a2 as SimpleLayout, c1 as getChainSlugById, c2 as JsonRpcProvider, c3 as DEFAULT_TRANSACTIONS_RETRY_POLICY, aj as LoadingView, aX as ChainId, c4 as getChainNameById, u as useTheme, a6 as Heading, a4 as getWalletProviderNameByProvider, c5 as isAddressSanctioned, K as SharedViews, c6 as isMetaMaskProvider, a3 as WalletProviderName, a7 as Drawer, B as ButtCon, $ as ButtonNavigationStyles, F as orchestrationEvents, A as tokenValueFormat, v as formatZeroAmount, bf as NATIVE, bh as amountInputValidation, b6 as getRemoteImage, bb as CloudImage, c7 as ETH_TOKEN_SYMBOL, z as Environment, c8 as GasEstimateType, bl as DEFAULT_TOKEN_DECIMALS, bg as DEFAULT_QUOTE_REFRESH_INTERVAL, c9 as addChainChangedListener, ca as removeChainChangedListener, bn as IMX_TOKEN_SYMBOL, cb as dist, cc as CHECKOUT_CDN_BASE_URL, ab as heroBackGroundStyles, ac as heroImageStyles, cd as Badge, ae as SimpleTextBody, bo as FooterButton, ce as getEthTokenImage, cf as WITHDRAWAL_CLAIM_GAS_LIMIT, be as getDefaultTokenImage, ah as viewReducer, ai as initialViewState, cg as BridgeConfiguration, ch as ImmutableConfiguration, ci as TokenBridge, bq as StatusView, aJ as StatusType, ak as ErrorView, cj as ServiceUnavailableErrorView, ck as ServiceType, cl as ETH_SEPOLIA_TO_ZKEVM_TESTNET, cm as ETH_SEPOLIA_TO_ZKEVM_DEVNET, cn as ETH_MAINNET_TO_ZKEVM_MAINNET } from './index-DnQfQojQ.js';
|
|
2
|
+
import { B as BridgeWidgetViews, C as CryptoFiatContext, f as formatUnits, a as CryptoFiatActions, p as parseUnits, T as TopUpView, b as CryptoFiatProvider } from './TopUpView-CojeMjuL.js';
|
|
3
|
+
import { T as TokenImage, r as retry, u as useInterval } from './retry-TNKwGgHJ.js';
|
|
4
|
+
import { A as Accordion, S as SelectForm, T as TransactionRejected, g as getAllowedBalances, F as Fees, N as NetworkSwitchDrawer, W as WalletApproveHero } from './balance-_0wiNzA1.js';
|
|
5
|
+
import { T as TextInputForm } from './TextInputForm-BvZsFFRK.js';
|
|
6
6
|
|
|
7
7
|
// This module is intended to unwrap Axios default export as named.
|
|
8
8
|
// Keep top-level export same with static properties
|
|
@@ -2435,7 +2435,7 @@ function WalletAndNetworkSelector() {
|
|
|
2435
2435
|
}, environment: environment }), jsx(Box, { sx: submitButtonWrapperStyles, children: jsx(Button, { testId: `${testId$1}-submit-button`, size: "large", onClick: handleSubmitDetails, children: t('views.WALLET_NETWORK_SELECTION.submitButton.text') }) })] }))] }));
|
|
2436
2436
|
}
|
|
2437
2437
|
|
|
2438
|
-
function WalletNetworkSelectionView() {
|
|
2438
|
+
function WalletNetworkSelectionView({ showBackButton, }) {
|
|
2439
2439
|
const { t } = useTranslation();
|
|
2440
2440
|
const { viewDispatch } = reactExports.useContext(ViewContext);
|
|
2441
2441
|
const { eventTargetState: { eventTarget } } = reactExports.useContext(EventTargetContext);
|
|
@@ -2453,7 +2453,9 @@ function WalletNetworkSelectionView() {
|
|
|
2453
2453
|
view: { type: BridgeWidgetViews.TRANSACTIONS },
|
|
2454
2454
|
},
|
|
2455
2455
|
});
|
|
2456
|
-
}, testId: "move-transactions-button" }))
|
|
2456
|
+
}, testId: "move-transactions-button" })), showBack: showBackButton, onBackButtonClick: () => {
|
|
2457
|
+
orchestrationEvents.sendRequestGoBackEvent(eventTarget, IMTBLWidgetEvents.IMTBL_BRIDGE_WIDGET_EVENT, {});
|
|
2458
|
+
} })), footer: jsx(FooterLogo, {}), children: jsx(WalletAndNetworkSelector, {}) }));
|
|
2457
2459
|
}
|
|
2458
2460
|
|
|
2459
2461
|
function validateToken(fromToken) {
|
|
@@ -3870,7 +3872,7 @@ function ClaimWithdrawal({ transaction }) {
|
|
|
3870
3872
|
: handleWithdrawalClaimClick({ forceChangeAccount: true })), children: loading || txProcessing ? (jsx(Button.Icon, { icon: "Loading", sx: { width: 'base.icon.size.400' } })) : t(`views.CLAIM_WITHDRAWAL.${hasWithdrawError ? 'footer.retryText' : 'footer.buttonText'}`) }) }), jsx(FooterLogo, {})] })), children: [jsxs(SimpleTextBody, { heading: `${t('views.CLAIM_WITHDRAWAL.content.heading')} ${getChainNameById(getL1ChainId(checkout.config))}`, children: [jsx(Box, { sx: { display: 'flex', flexWrap: 'wrap', pb: 'base.spacing.x1' }, children: t('views.CLAIM_WITHDRAWAL.content.body') }), jsxs(Box, { children: [t('views.CLAIM_WITHDRAWAL.content.body2'), jsx(EllipsizedText, { text: transaction.details.to_address.toLowerCase() ?? '' })] })] }), jsx(NotEnoughEthToWithdraw, { visible: showNotEnoughEthDrawer, onClose: () => setShowNotEnoughEthDrawer(false), onChangeAccount: () => handleWithdrawalClaimClick({ forceChangeAccount: true }) })] }));
|
|
3871
3873
|
}
|
|
3872
3874
|
|
|
3873
|
-
function BridgeWidget({ checkout, web3Provider, config, amount, tokenAddress, }) {
|
|
3875
|
+
function BridgeWidget({ checkout, web3Provider, config, amount, tokenAddress, showBackButton, }) {
|
|
3874
3876
|
const { t } = useTranslation();
|
|
3875
3877
|
const { environment, isOnRampEnabled, isSwapEnabled, isBridgeEnabled, theme, } = config;
|
|
3876
3878
|
const defaultTokenImage = getDefaultTokenImage(checkout.config.environment, theme);
|
|
@@ -3964,7 +3966,7 @@ function BridgeWidget({ checkout, web3Provider, config, amount, tokenAddress, })
|
|
|
3964
3966
|
});
|
|
3965
3967
|
})();
|
|
3966
3968
|
}, [web3Provider]);
|
|
3967
|
-
return (jsx(ViewContext.Provider, { value: viewReducerValues, children: jsx(BridgeContext.Provider, { value: bridgeReducerValues, children: jsxs(CryptoFiatProvider, { environment: environment, children: [viewState.view.type === BridgeWidgetViews.WALLET_NETWORK_SELECTION && (jsx(WalletNetworkSelectionView, {})), viewState.view.type === BridgeWidgetViews.BRIDGE_FORM && (jsx(Bridge, { amount: amount, tokenAddress: tokenAddress, defaultTokenImage: defaultTokenImage, theme: theme })), viewState.view.type === BridgeWidgetViews.BRIDGE_REVIEW && (jsx(BridgeReview, {})), viewState.view.type === BridgeWidgetViews.IN_PROGRESS && (jsx(MoveInProgress, { transactionHash: viewState.view.transactionHash, isTransfer: viewState.view.isTransfer })), viewState.view.type === BridgeWidgetViews.BRIDGE_FAILURE
|
|
3969
|
+
return (jsx(ViewContext.Provider, { value: viewReducerValues, children: jsx(BridgeContext.Provider, { value: bridgeReducerValues, children: jsxs(CryptoFiatProvider, { environment: environment, children: [viewState.view.type === BridgeWidgetViews.WALLET_NETWORK_SELECTION && (jsx(WalletNetworkSelectionView, { showBackButton: showBackButton })), viewState.view.type === BridgeWidgetViews.BRIDGE_FORM && (jsx(Bridge, { amount: amount, tokenAddress: tokenAddress, defaultTokenImage: defaultTokenImage, theme: theme })), viewState.view.type === BridgeWidgetViews.BRIDGE_REVIEW && (jsx(BridgeReview, {})), viewState.view.type === BridgeWidgetViews.IN_PROGRESS && (jsx(MoveInProgress, { transactionHash: viewState.view.transactionHash, isTransfer: viewState.view.isTransfer })), viewState.view.type === BridgeWidgetViews.BRIDGE_FAILURE
|
|
3968
3970
|
&& (jsx(StatusView, { testId: "bridge-fail", statusText: t('views.BRIDGE_FAILURE.bridgeFailureText.statusText'), actionText: t('views.BRIDGE_FAILURE.bridgeFailureText.actionText'), onActionClick: goBackToReview, statusType: StatusType.FAILURE, onRenderEvent: () => {
|
|
3969
3971
|
let reason = '';
|
|
3970
3972
|
if (viewState.view.type === BridgeWidgetViews.BRIDGE_FAILURE) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as reactExports, cD as PostMessageHandler, j as jsx, I as IMTBLWidgetEvents, E as EventTargetContext, cE as PostMessageHandlerEventType, cF as CheckoutEventType, cG as CheckoutSuccessEventType, b_ as Web3Provider, l as useTranslation, ak as ErrorView, n as jsxs, aj as LoadingView, a as Box, aB as Fragment, z as Environment, cH as CHECKOUT_APP_URL, cI as CheckoutFlowType, cJ as ENV_DEVELOPMENT } from './index-
|
|
1
|
+
import { r as reactExports, cD as PostMessageHandler, j as jsx, I as IMTBLWidgetEvents, E as EventTargetContext, cE as PostMessageHandlerEventType, cF as CheckoutEventType, cG as CheckoutSuccessEventType, b_ as Web3Provider, l as useTranslation, ak as ErrorView, n as jsxs, aj as LoadingView, a as Box, aB as Fragment, z as Environment, cH as CHECKOUT_APP_URL, cI as CheckoutFlowType, cJ as ENV_DEVELOPMENT } from './index-DnQfQojQ.js';
|
|
2
2
|
|
|
3
3
|
const initialCheckoutState = {
|
|
4
4
|
checkout: null,
|
|
@@ -175,6 +175,8 @@ function useEip6963Relayer() {
|
|
|
175
175
|
postMessageHandler?.send(PostMessageHandlerEventType.EIP_6963_EVENT, {
|
|
176
176
|
message: 'eip6963:announceProvider',
|
|
177
177
|
info: event.detail.info,
|
|
178
|
+
isPassport: event.detail.provider?.isPassport,
|
|
179
|
+
isMetamask: event.detail.provider?.isMetamask,
|
|
178
180
|
});
|
|
179
181
|
}, [postMessageHandler]);
|
|
180
182
|
reactExports.useEffect(() => {
|
|
@@ -200,6 +202,11 @@ function useEip6963Relayer() {
|
|
|
200
202
|
}, [postMessageHandler, onRequest]);
|
|
201
203
|
}
|
|
202
204
|
|
|
205
|
+
var ConnectMethods;
|
|
206
|
+
(function (ConnectMethods) {
|
|
207
|
+
ConnectMethods["REQUEST_ACCOUNTS"] = "eth_requestAccounts";
|
|
208
|
+
ConnectMethods["REQUEST_PERMISSIONS"] = "wallet_requestPermissions";
|
|
209
|
+
})(ConnectMethods || (ConnectMethods = {}));
|
|
203
210
|
function useProviderRelay() {
|
|
204
211
|
const [{ checkout, postMessageHandler, provider }, checkoutDispatch] = useCheckoutContext();
|
|
205
212
|
const unsubscribePostMessageHandler = reactExports.useRef();
|
|
@@ -226,11 +233,7 @@ function useProviderRelay() {
|
|
|
226
233
|
});
|
|
227
234
|
}
|
|
228
235
|
catch (error) {
|
|
229
|
-
|
|
230
|
-
postMessageHandler.send(PostMessageHandlerEventType.PROVIDER_RELAY, {
|
|
231
|
-
response: { id: payload.jsonRpcRequestMessage.id, error: error.message, jsonrpc: '2.0' },
|
|
232
|
-
eip6963Info: payload.eip6963Info,
|
|
233
|
-
});
|
|
236
|
+
throw new Error(error);
|
|
234
237
|
}
|
|
235
238
|
}, [postMessageHandler]);
|
|
236
239
|
/**
|
|
@@ -249,26 +252,25 @@ function useProviderRelay() {
|
|
|
249
252
|
console.error('PARENT - requested provider not found', providerRelayPayload?.eip6963Info, injectedProviders);
|
|
250
253
|
return;
|
|
251
254
|
}
|
|
252
|
-
// If provider is not defined, connect the target provider
|
|
253
255
|
let currentProvider = provider;
|
|
256
|
+
// If provider is not defined, create a provider
|
|
254
257
|
if (!currentProvider && targetProvider) {
|
|
255
|
-
|
|
256
|
-
provider: new Web3Provider(targetProvider.provider),
|
|
257
|
-
});
|
|
258
|
-
currentProvider = connectResponse.provider;
|
|
259
|
-
// Set provider and execute the request
|
|
260
|
-
checkoutDispatch({
|
|
261
|
-
payload: {
|
|
262
|
-
type: CheckoutActions.SET_PROVIDER,
|
|
263
|
-
provider: currentProvider,
|
|
264
|
-
},
|
|
265
|
-
});
|
|
258
|
+
currentProvider = new Web3Provider(targetProvider.provider);
|
|
266
259
|
}
|
|
267
260
|
if (!currentProvider) {
|
|
268
261
|
throw new Error('Provider is not defined');
|
|
269
262
|
}
|
|
270
263
|
try {
|
|
271
264
|
await execute(providerRelayPayload, currentProvider);
|
|
265
|
+
if (providerRelayPayload.jsonRpcRequestMessage.method === ConnectMethods.REQUEST_ACCOUNTS
|
|
266
|
+
|| providerRelayPayload.jsonRpcRequestMessage.method === ConnectMethods.REQUEST_PERMISSIONS) {
|
|
267
|
+
checkoutDispatch({
|
|
268
|
+
payload: {
|
|
269
|
+
type: CheckoutActions.SET_PROVIDER,
|
|
270
|
+
provider: currentProvider,
|
|
271
|
+
},
|
|
272
|
+
});
|
|
273
|
+
}
|
|
272
274
|
}
|
|
273
275
|
catch (error) {
|
|
274
276
|
// Send the error using the postMessageHandler
|
|
@@ -282,16 +284,12 @@ function useProviderRelay() {
|
|
|
282
284
|
* Subscribe to provider relay messages
|
|
283
285
|
*/
|
|
284
286
|
reactExports.useEffect(() => {
|
|
285
|
-
// TODO we need to unsubscribe everywhere
|
|
286
287
|
if (!postMessageHandler)
|
|
287
288
|
return;
|
|
288
289
|
unsubscribePostMessageHandler.current?.();
|
|
289
290
|
unsubscribePostMessageHandler.current = postMessageHandler?.subscribe(onJsonRpcRequestMessage);
|
|
290
291
|
}, [postMessageHandler, onJsonRpcRequestMessage]);
|
|
291
292
|
}
|
|
292
|
-
// TODO -
|
|
293
|
-
// 1 - commit the unsub part
|
|
294
|
-
// 2 - add unsubs to all postMessageHandlers subscriptions
|
|
295
293
|
|
|
296
294
|
/**
|
|
297
295
|
* The timeout in milliseconds for the iframe to be initialized.
|
|
@@ -316,6 +314,20 @@ const IFRAME_ALLOW_PERMISSIONS = `
|
|
|
316
314
|
.trim()
|
|
317
315
|
.replace(/\n/g, '');
|
|
318
316
|
|
|
317
|
+
function useWidgetProviderEventRelayer() {
|
|
318
|
+
const [checkoutState] = useCheckoutContext();
|
|
319
|
+
const { postMessageHandler } = checkoutState;
|
|
320
|
+
const onWidgetProviderEvent = reactExports.useCallback(() => {
|
|
321
|
+
postMessageHandler?.send(PostMessageHandlerEventType.WIDGET_PROVIDER_EVENT, {});
|
|
322
|
+
}, [postMessageHandler]);
|
|
323
|
+
reactExports.useEffect(() => {
|
|
324
|
+
if (!postMessageHandler)
|
|
325
|
+
return () => { };
|
|
326
|
+
window.addEventListener(PostMessageHandlerEventType.WIDGET_PROVIDER_EVENT, onWidgetProviderEvent);
|
|
327
|
+
return () => window.removeEventListener(PostMessageHandlerEventType.WIDGET_PROVIDER_EVENT, onWidgetProviderEvent);
|
|
328
|
+
}, [postMessageHandler, onWidgetProviderEvent]);
|
|
329
|
+
}
|
|
330
|
+
|
|
319
331
|
function CheckoutAppIframe() {
|
|
320
332
|
const { t } = useTranslation();
|
|
321
333
|
const iframeRef = reactExports.useRef(null);
|
|
@@ -326,6 +338,7 @@ function CheckoutAppIframe() {
|
|
|
326
338
|
useCheckoutEventsRelayer();
|
|
327
339
|
useEip6963Relayer();
|
|
328
340
|
useProviderRelay();
|
|
341
|
+
useWidgetProviderEventRelayer();
|
|
329
342
|
const loading = !iframeURL || !iframeContentWindow || !initialised;
|
|
330
343
|
const { eventTargetState: { eventTarget }, } = reactExports.useContext(EventTargetContext);
|
|
331
344
|
reactExports.useEffect(() => {
|
|
@@ -373,6 +386,21 @@ function CheckoutAppIframe() {
|
|
|
373
386
|
} }))] }));
|
|
374
387
|
}
|
|
375
388
|
|
|
389
|
+
/**
|
|
390
|
+
* Encodes a JSON object using base64 encoding.
|
|
391
|
+
*/
|
|
392
|
+
const encodeObject = async (value) => {
|
|
393
|
+
try {
|
|
394
|
+
const str = JSON.stringify(value);
|
|
395
|
+
const base64String = btoa(str);
|
|
396
|
+
return encodeURIComponent(base64String);
|
|
397
|
+
}
|
|
398
|
+
catch (error) {
|
|
399
|
+
throw new Error(`Compression failed: ${error.message}`);
|
|
400
|
+
}
|
|
401
|
+
};
|
|
402
|
+
|
|
403
|
+
/* eslint-disable no-case-declarations */
|
|
376
404
|
/**
|
|
377
405
|
* Converts a record of parameters to a query string.
|
|
378
406
|
*/
|
|
@@ -391,7 +419,7 @@ const toQueryString = (params) => {
|
|
|
391
419
|
/**
|
|
392
420
|
* Maps the flow configuration and params to the corresponding query parameters.
|
|
393
421
|
*/
|
|
394
|
-
const getIframeParams = (params, widgetConfig, checkoutConfig) => {
|
|
422
|
+
const getIframeParams = async (params, widgetConfig, checkoutConfig) => {
|
|
395
423
|
const { flow } = params;
|
|
396
424
|
const commonConfig = {
|
|
397
425
|
theme: widgetConfig.theme,
|
|
@@ -461,6 +489,7 @@ const getIframeParams = (params, widgetConfig, checkoutConfig) => {
|
|
|
461
489
|
toAmount: params.tokenAddress,
|
|
462
490
|
});
|
|
463
491
|
case CheckoutFlowType.SALE:
|
|
492
|
+
const items = await encodeObject(params.items || []);
|
|
464
493
|
return toQueryString({
|
|
465
494
|
...commonConfig,
|
|
466
495
|
...(widgetConfig.sale || {}),
|
|
@@ -473,7 +502,7 @@ const getIframeParams = (params, widgetConfig, checkoutConfig) => {
|
|
|
473
502
|
// TODO: Get from hub
|
|
474
503
|
environmentId: params.environmentId,
|
|
475
504
|
collectionName: params.collectionName,
|
|
476
|
-
items
|
|
505
|
+
items,
|
|
477
506
|
preferredCurrency: params.preferredCurrency,
|
|
478
507
|
excludePaymentTypes: params.excludePaymentTypes,
|
|
479
508
|
excludeFiatCurrencies: params.excludeFiatCurrencies,
|
|
@@ -485,10 +514,11 @@ const getIframeParams = (params, widgetConfig, checkoutConfig) => {
|
|
|
485
514
|
/**
|
|
486
515
|
* Returns the iframe URL for the Checkout App based on the environment.
|
|
487
516
|
*/
|
|
488
|
-
const getIframeURL = (params, widgetConfig, checkoutConfig) => {
|
|
517
|
+
const getIframeURL = async (params, widgetConfig, checkoutConfig) => {
|
|
489
518
|
const { flow } = params;
|
|
490
519
|
const { publishableKey } = checkoutConfig;
|
|
491
|
-
|
|
520
|
+
if (!publishableKey)
|
|
521
|
+
return '';
|
|
492
522
|
let environment = checkoutConfig.environment || Environment.SANDBOX;
|
|
493
523
|
if (checkoutConfig.isDevelopment) {
|
|
494
524
|
environment = ENV_DEVELOPMENT;
|
|
@@ -496,10 +526,11 @@ const getIframeURL = (params, widgetConfig, checkoutConfig) => {
|
|
|
496
526
|
if (checkoutConfig.overrides?.environment) {
|
|
497
527
|
environment = checkoutConfig.overrides.environment;
|
|
498
528
|
}
|
|
499
|
-
const baseURL = checkoutConfig.overrides?.checkoutAppUrl
|
|
500
|
-
|
|
501
|
-
const
|
|
502
|
-
|
|
529
|
+
const baseURL = checkoutConfig.overrides?.checkoutAppUrl
|
|
530
|
+
?? CHECKOUT_APP_URL[environment];
|
|
531
|
+
const queryParams = await getIframeParams(params, widgetConfig, checkoutConfig);
|
|
532
|
+
const iframeURL = `${baseURL}/${flow}?${queryParams}`;
|
|
533
|
+
return iframeURL;
|
|
503
534
|
};
|
|
504
535
|
|
|
505
536
|
/**
|
|
@@ -519,13 +550,28 @@ const useMount = (effect, deps, compare) => {
|
|
|
519
550
|
}, [deps, effect, compare]);
|
|
520
551
|
};
|
|
521
552
|
|
|
553
|
+
/**
|
|
554
|
+
* Handle asynchronous operations with memoization.
|
|
555
|
+
* It only re-executes the async function when dependencies change.
|
|
556
|
+
*/
|
|
557
|
+
const useAsyncMemo = (asyncFn, dependencies) => {
|
|
558
|
+
const [value, setValue] = reactExports.useState();
|
|
559
|
+
reactExports.useEffect(() => {
|
|
560
|
+
let isMounted = true;
|
|
561
|
+
asyncFn().then((result) => {
|
|
562
|
+
if (isMounted)
|
|
563
|
+
setValue(result);
|
|
564
|
+
});
|
|
565
|
+
return () => {
|
|
566
|
+
isMounted = false;
|
|
567
|
+
};
|
|
568
|
+
}, dependencies);
|
|
569
|
+
return value;
|
|
570
|
+
};
|
|
571
|
+
|
|
522
572
|
function CheckoutWidget(props) {
|
|
523
573
|
const { config, checkout, params, provider, } = props;
|
|
524
|
-
const
|
|
525
|
-
if (!checkout.config.publishableKey)
|
|
526
|
-
return ['', ''];
|
|
527
|
-
return getIframeURL(params, config, checkout.config);
|
|
528
|
-
}, [params, config, checkout.config]);
|
|
574
|
+
const iframeURL = useAsyncMemo(async () => getIframeURL(params, config, checkout.config), [params, config, checkout.config]);
|
|
529
575
|
const [checkoutState, checkoutDispatch] = reactExports.useReducer(checkoutReducer, initialCheckoutState);
|
|
530
576
|
const checkoutReducerValues = reactExports.useMemo(() => ({
|
|
531
577
|
checkoutState: { ...checkoutState, iframeURL, checkout },
|