@imtbl/sdk 1.57.0 → 1.58.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/dist/{blockchain_data-BtWkKJIA.js → blockchain_data-Tn79t2TG.js} +2 -2
- package/dist/blockchain_data.js +3 -3
- package/dist/browser/checkout/{AddFundsWidget-C_PbSgrh.js → AddFundsWidget-CQ8eDnA4.js} +134 -145
- package/dist/browser/checkout/{BridgeWidget-n8xOPTQ2.js → BridgeWidget-BODgt1Sl.js} +8 -8
- package/dist/browser/checkout/{CheckoutWidget-kQ-Im8vB.js → CheckoutWidget-BIu60m93.js} +16 -16
- package/dist/browser/checkout/{EllipsizedText-Ppn9TC1R.js → EllipsizedText-BezxpXlh.js} +1 -1
- package/dist/browser/checkout/{FeesBreakdown-k6lIF8xc.js → FeesBreakdown-G2U4Al4H.js} +1 -1
- package/dist/browser/checkout/{HandoverContent-8S6KoHhH.js → HandoverContent-D5DaYSVN.js} +1 -1
- package/dist/browser/checkout/{OnRampWidget-v4Op5f05.js → OnRampWidget-_RKv23W3.js} +3 -3
- package/dist/browser/checkout/{SaleWidget-CmGSUnEX.js → SaleWidget-Dnxay7PT.js} +13 -13
- package/dist/browser/checkout/{SpendingCapHero-CDj3Iw9j.js → SpendingCapHero-CS1MBdgx.js} +1 -1
- package/dist/browser/checkout/{SwapWidget-DDg7cV7V.js → SwapWidget-uVOkXbBB.js} +8 -8
- package/dist/browser/checkout/{TopUpView-C_ACzI2Q.js → TopUpView-IETrf6SF.js} +2 -2
- package/dist/browser/checkout/{WalletWidget--bOcJPeF.js → WalletWidget-0PhjwOoc.js} +5 -5
- package/dist/browser/checkout/{auto-track-BNEtiRai.js → auto-track-Cxa9AlDh.js} +1 -1
- package/dist/browser/checkout/{balance-3-nAoqgO.js → balance-B1D3omi8.js} +3 -3
- package/dist/browser/checkout/{index-BMKU17nO.js → index-4h8fLbUy.js} +1 -1
- package/dist/browser/checkout/{index-iN9TbfIB.js → index-5i4ytcU4.js} +1 -1
- package/dist/browser/checkout/{index-BD7XwXYb.js → index-BaCEegez.js} +1 -1
- package/dist/browser/checkout/{index-9nmTUuc5.js → index-CxBBl_z8.js} +1 -1
- package/dist/browser/checkout/{index-WUiS3XIP.js → index-D1EnuFx8.js} +2 -2
- package/dist/browser/checkout/{index-ClpwX2z9.js → index-DVt2j3lK.js} +130 -28
- package/dist/browser/checkout/{index-DUWR3KD0.js → index-OynKJ8Cq.js} +1 -1
- package/dist/browser/checkout/{index-D6xurPdk.js → index-TAnDlCww.js} +1 -1
- package/dist/browser/checkout/{index-BZOpAz8z.js → index-aSIb1jOx.js} +1 -1
- package/dist/browser/checkout/{index.umd--iUfBvJV.js → index.umd-ca2LA9_o.js} +1 -1
- package/dist/browser/checkout/{retry-D5EXmyEZ.js → retry-CJesv1Z0.js} +1 -1
- package/dist/browser/checkout/sdk.js +5 -5
- package/dist/browser/checkout/{useInterval-Tf0MmB55.js → useInterval-tTXFxNm-.js} +1 -1
- package/dist/browser/checkout/widgets-esm.js +1 -1
- package/dist/browser/checkout/widgets.js +241 -150
- package/dist/{checkout-YSKtCNzS.js → checkout-DN5Kz6FE.js} +7 -8
- package/dist/checkout.d.ts +30 -5
- package/dist/checkout.js +5 -5
- package/dist/{config-lzHVTMnS.js → config-Il8NWBhS.js} +1 -1
- package/dist/config.js +1 -1
- package/dist/{index-B4K4memG.js → index-BmFOXDhV.js} +4 -4
- package/dist/{index-Cl5xYcTa.js → index-BvAP3MCR.js} +1 -1
- package/dist/{index-DCJMvVVX.js → index-CCO9QhXx.js} +1 -1
- package/dist/{index-DCRICFBo.js → index-CPNtDMZA.js} +1 -1
- package/dist/{index-BBLIOOxO.js → index-CnIu4Ekm.js} +1 -1
- package/dist/{index-C2PMWCyz.js → index-PXJvJIbg.js} +3 -3
- package/dist/index.browser.js +5 -5
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +14 -13
- package/dist/index.d.ts +30 -5
- package/dist/index.js +14 -14
- package/dist/{minting_backend-BeyswK6a.js → minting_backend-C6AVNuF-.js} +3 -3
- package/dist/minting_backend.js +5 -5
- package/dist/{orderbook-DgElnB3K.js → orderbook-DYF6OPtl.js} +1 -1
- package/dist/orderbook.js +2 -2
- package/dist/{passport-zkpBoEch.js → passport-BtDa-0e1.js} +8 -6
- package/dist/passport.d.ts +5 -0
- package/dist/passport.js +4 -4
- package/dist/{webhook-niZzHikY.js → webhook-DtqDevFb.js} +1 -1
- package/dist/webhook.js +2 -2
- package/dist/{x-CGvwkxPx.js → x-DFHzAdlx.js} +3 -3
- package/dist/x.js +4 -4
- package/package.json +1 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { _ as _objectWithoutProperties, z as useTheme, cA as useForwardLocalDomRef, cq as useGetSubcomponentChild, cB as useSplitApartChildrenAndSubComponents, r as reactExports, F as merge$2, cC as useResizeObserver, q as jsxs, j as jsx, J as SmartClone, K as Box, H as isChildSubcomponent, G as flattenChildren, Y as Body, cD as useTheme$1, bt as Icon, x as ButtCon, y as Button, T as _defineProperty, aq as isDualVariantIcon, cp as _slicedToArray, cE as isNumberWithinTotal, A as getStartingSize, cr as BaseClickable, R as ClassNames, cF as _toConsumableArray, cG as isError, cd as Badge, cH as FramedIcon, bV as FramedImage, cI as FramedLogo, b5 as Stack, co as hFlex, cJ as usePrevious, cK as useBrowserEffect, cL as getHeadingTextStyles, cM as vFlex, cN as centerFlexChildren, cO as FormControlLabel, cP as FormControlValidation, cQ as FormControlCaption, I as IMTBLWidgetEvents, cR as AddFundsEventType, cS as getDefaultExportFromCjs, cT as commonjsGlobal, l as useTranslation, a4 as MenuItem, a5 as tokenValueFormat, cU as DEFAULT_TOKEN_FORMATTING_DECIMALS, aM as BigNumber, cV as FramedVideo, a$ as motion, b1 as listItemVariants, b7 as Divider, aW as Fragment, b0 as listVariants,
|
|
2
|
-
import { f as formatUnits, p as parseUnits } from './index-
|
|
3
|
-
import { E as EllipsizedText, C as Contract } from './EllipsizedText-
|
|
4
|
-
import { r as retry, T as TokenImage } from './retry-
|
|
5
|
-
import { H as HandoverContent } from './HandoverContent-
|
|
6
|
-
import { F as FeesBreakdown } from './FeesBreakdown-
|
|
1
|
+
import { _ as _objectWithoutProperties, z as useTheme, cA as useForwardLocalDomRef, cq as useGetSubcomponentChild, cB as useSplitApartChildrenAndSubComponents, r as reactExports, F as merge$2, cC as useResizeObserver, q as jsxs, j as jsx, J as SmartClone, K as Box, H as isChildSubcomponent, G as flattenChildren, Y as Body, cD as useTheme$1, bt as Icon, x as ButtCon, y as Button, T as _defineProperty, aq as isDualVariantIcon, cp as _slicedToArray, cE as isNumberWithinTotal, A as getStartingSize, cr as BaseClickable, R as ClassNames, cF as _toConsumableArray, cG as isError, cd as Badge, cH as FramedIcon, bV as FramedImage, cI as FramedLogo, b5 as Stack, co as hFlex, cJ as usePrevious, cK as useBrowserEffect, cL as getHeadingTextStyles, cM as vFlex, cN as centerFlexChildren, cO as FormControlLabel, cP as FormControlValidation, cQ as FormControlCaption, I as IMTBLWidgetEvents, cR as AddFundsEventType, cS as getDefaultExportFromCjs, cT as commonjsGlobal, l as useTranslation, a4 as MenuItem, a5 as tokenValueFormat, cU as DEFAULT_TOKEN_FORMATTING_DECIMALS, aM as BigNumber, cV as getRemoteVideo, cW as FramedVideo, a$ as motion, b1 as listItemVariants, b7 as Divider, aW as Fragment, b0 as listVariants, cX as useProvidersContext, at as Drawer, $ as useAnalytics, c0 as WalletDrawer, cY as UnableToConnectDrawer, cZ as ChangedYourMindDrawer, c_ as ConnectEIP6963ProviderError, a6 as UserJourney, c$ as getProviderSlugFromRdns, bZ as WalletProviderRdns, b_ as Web3Provider, d0 as connectEIP6963Provider, d1 as identifyUser, d2 as ProvidersContextActions, X as ViewContext, V as ViewActions, o as SharedViews, k as ChainId, d3 as commonjsRequire, bm as getRemoteImage, as as Heading, aX as useHandover, aY as HandoverTarget, a1 as EventTargetContext, aZ as getRemoteRive, b$ as useInjectedProviders, bu as getDefaultTokenImage, d4 as OverflowDrawerMenu, an as SimpleLayout, U as TokenFilterTypes, h as getL2ChainId, a7 as orchestrationEvents, d5 as requireSecp256k1$1, d6 as requireLib_commonjs, d7 as require$$0$2, d8 as bech32$2, d9 as bnExports$1, da as require$$0$3, db as getAugmentedNamespace, dc as require$$0$4, dd as minimalisticAssert, de as require$$2, df as hash$6, dg as MaxUint256, dh as merge$3, di as SvgIcon, dj as WalletWarningHero, a3 as Environment, dk as t, aC as Link, cx as PriceDisplay, L as LoadingView, aD as viewReducer, aE as initialViewState, dl as isValidAddress, bx as amountInputValidation, br as CloudImage, E as ErrorView, cj as ServiceUnavailableErrorView, ck as ServiceType } from './index-DVt2j3lK.js';
|
|
2
|
+
import { f as formatUnits, p as parseUnits } from './index-4h8fLbUy.js';
|
|
3
|
+
import { E as EllipsizedText, C as Contract } from './EllipsizedText-BezxpXlh.js';
|
|
4
|
+
import { r as retry, T as TokenImage } from './retry-CJesv1Z0.js';
|
|
5
|
+
import { H as HandoverContent } from './HandoverContent-D5DaYSVN.js';
|
|
6
|
+
import { F as FeesBreakdown } from './FeesBreakdown-G2U4Al4H.js';
|
|
7
7
|
|
|
8
8
|
var bannerSx = {
|
|
9
9
|
d: "flex",
|
|
@@ -1565,6 +1565,7 @@ var AddFundsErrorTypes;
|
|
|
1565
1565
|
AddFundsErrorTypes["WALLET_REJECTED"] = "WALLET_REJECTED";
|
|
1566
1566
|
AddFundsErrorTypes["WALLET_REJECTED_NO_FUNDS"] = "WALLET_REJECTED_NO_FUNDS";
|
|
1567
1567
|
AddFundsErrorTypes["WALLET_POPUP_BLOCKED"] = "WALLET_POPUP_BLOCKED";
|
|
1568
|
+
AddFundsErrorTypes["ENVIRONMENT_ERROR"] = "ENVIRONMENT_ERROR";
|
|
1568
1569
|
})(AddFundsErrorTypes || (AddFundsErrorTypes = {}));
|
|
1569
1570
|
|
|
1570
1571
|
function FiatOption({ type, onClick, disabled = false, size = 'small', rc = jsx("span", {}), }) {
|
|
@@ -1623,7 +1624,13 @@ function getTotalRouteFees(route) {
|
|
|
1623
1624
|
* Formats a number to a string with a maximum number of decimals
|
|
1624
1625
|
* removing trailing zeros
|
|
1625
1626
|
*/
|
|
1626
|
-
const getFormattedAmounts = (
|
|
1627
|
+
const getFormattedAmounts = (value, maxDecimals = DEFAULT_TOKEN_FORMATTING_DECIMALS) => {
|
|
1628
|
+
const amount = typeof value === 'number' ? value : parseFloat(value);
|
|
1629
|
+
if (amount > 0 && amount < 1) {
|
|
1630
|
+
return tokenValueFormat(amount, maxDecimals).replace(/\.?0+$/, '');
|
|
1631
|
+
}
|
|
1632
|
+
return tokenValueFormat(amount, maxDecimals);
|
|
1633
|
+
};
|
|
1627
1634
|
/**
|
|
1628
1635
|
* Converts a crypto amount to a formatted string
|
|
1629
1636
|
*/
|
|
@@ -1653,13 +1660,12 @@ function getRouteAndTokenBalances(routeData) {
|
|
|
1653
1660
|
if (!routeData) {
|
|
1654
1661
|
return emptyRouteBalance;
|
|
1655
1662
|
}
|
|
1656
|
-
const { fromToken } = routeData.amountData;
|
|
1657
1663
|
const usdPrice = routeData?.route.route.estimate.fromToken.usdPrice;
|
|
1658
1664
|
if (!usdPrice) {
|
|
1659
1665
|
return emptyRouteBalance;
|
|
1660
1666
|
}
|
|
1661
1667
|
const { balance } = routeData.amountData;
|
|
1662
|
-
const routeBalance = getFormattedNumber(balance.balance,
|
|
1668
|
+
const routeBalance = getFormattedNumber(balance.balance, balance?.decimals, balance?.decimals);
|
|
1663
1669
|
const routeBalanceUsd = (parseFloat(routeBalance) * usdPrice).toString();
|
|
1664
1670
|
const fromAmount = getFormattedNumber(routeData.route.route.estimate.fromAmount, routeData.route.route.estimate.fromToken.decimals);
|
|
1665
1671
|
const fromAmountUsd = getFormattedAmounts(routeData.route.route.estimate.fromAmountUSD ?? '');
|
|
@@ -1689,7 +1695,7 @@ function RouteOption({ routeData, onClick, chains, disabled = false, isFastest =
|
|
|
1689
1695
|
size,
|
|
1690
1696
|
onClick: disabled ? undefined : handleClick,
|
|
1691
1697
|
};
|
|
1692
|
-
return (jsxs(MenuItem, { ...menuItemProps, children: [jsx(MenuItem.Label, { children: fromToken.name }), chain && (jsxs(Sticker, { position: { x: 'right', y: 'bottom' }, children: [jsx(Sticker.FramedImage, { use: jsx("img", { src: chain.iconUrl, alt: chain.name }), size: "xSmall" }), jsx(MenuItem.FramedImage, { circularFrame: true,
|
|
1698
|
+
return (jsxs(MenuItem, { ...menuItemProps, children: [jsx(MenuItem.Label, { children: fromToken.name }), chain && (jsxs(Sticker, { position: { x: 'right', y: 'bottom' }, children: [jsx(Sticker.FramedImage, { use: jsx("img", { src: chain.iconUrl, alt: chain.name }), size: "xSmall" }), jsx(MenuItem.FramedImage, { circularFrame: true, use: jsx("img", { src: fromToken.iconUrl, alt: fromToken.name }) })] })), jsx(MenuItem.Caption, { children: `Balance: USD ${routeBalanceUsd}` }), jsx(MenuItem.PriceDisplay, { price: fromAmount, children: jsx(MenuItem.PriceDisplay.Caption, { children: `USD $${fromAmountUsd}` }) }), jsxs(MenuItem.BottomSlot, { children: [jsx(MenuItem.BottomSlot.Divider, {}), jsxs(Stack, { rc: jsx("span", {}), direction: "row", justifyContent: "space-between", sx: {
|
|
1693
1699
|
w: '100%',
|
|
1694
1700
|
}, children: [jsxs(Body, { sx: {
|
|
1695
1701
|
...hFlex,
|
|
@@ -1706,11 +1712,11 @@ const defaultFiatOptions = [
|
|
|
1706
1712
|
FiatOptionType.DEBIT,
|
|
1707
1713
|
FiatOptionType.CREDIT,
|
|
1708
1714
|
];
|
|
1709
|
-
function Options({ routes, chains, onCardClick, onRouteClick, size, showOnrampOption, insufficientBalance, selectedIndex, }) {
|
|
1715
|
+
function Options({ checkout, routes, chains, onCardClick, onRouteClick, size, showOnrampOption, insufficientBalance, selectedIndex, }) {
|
|
1710
1716
|
// @NOTE: early exit with loading related UI, when the
|
|
1711
1717
|
// routes are not yet available
|
|
1712
1718
|
if (!routes?.length && !insufficientBalance) {
|
|
1713
|
-
return (jsxs(Stack, { sx: { pt: 'base.spacing.x3' }, alignItems: "stretch", gap: "base.spacing.x1", children: [jsx(MenuItem, { shimmer: "withBottomSlot", size: "small", emphasized: true }), jsx(MenuItem, { shimmer: "withBottomSlot", size: "small", emphasized: true }), jsxs(Body, { sx: { textAlign: 'center', mt: 'base.spacing.x6' }, size: "small", children: ["Finding the best value", jsx("br", {}), "across all chains"] }), jsx(FramedVideo, { mimeType: "video/mp4", videoUrl:
|
|
1719
|
+
return (jsxs(Stack, { sx: { pt: 'base.spacing.x3' }, alignItems: "stretch", gap: "base.spacing.x1", children: [jsx(MenuItem, { shimmer: "withBottomSlot", size: "small", emphasized: true }), jsx(MenuItem, { shimmer: "withBottomSlot", size: "small", emphasized: true }), jsxs(Body, { sx: { textAlign: 'center', mt: 'base.spacing.x6' }, size: "small", children: ["Finding the best value", jsx("br", {}), "across all chains"] }), jsx(FramedVideo, { mimeType: "video/mp4", videoUrl: getRemoteVideo(checkout.config.environment, '/loading_bubble-small.mp4'), sx: { alignSelf: 'center', mt: 'base.spacing.x2' }, size: "large", circularFrame: true })] }));
|
|
1714
1720
|
}
|
|
1715
1721
|
const routeOptions = routes?.map((routeData, index) => (jsx(RouteOption, { size: size, routeData: routeData, chains: chains, onClick: () => onRouteClick(routeData, index), isFastest: index === 0, selected: index === selectedIndex, rc: jsx(motion.div, { variants: listItemVariants }) }, `route-option-${routeData.amountData.fromToken.chainId}-${routeData.amountData.fromToken.address}`)));
|
|
1716
1722
|
const fiatOptions = reactExports.useMemo(() => {
|
|
@@ -1726,12 +1732,12 @@ function Options({ routes, chains, onCardClick, onRouteClick, size, showOnrampOp
|
|
|
1726
1732
|
return (jsxs(Stack, { sx: { py: 'base.spacing.x3' }, alignItems: "stretch", gap: "base.spacing.x1", testId: "options-list", justifyContent: "center", rc: jsx(motion.div, { variants: listVariants, initial: "hidden", animate: "show" }), children: [routeOptions, noFundsBanner, fiatOptions] }));
|
|
1727
1733
|
}
|
|
1728
1734
|
|
|
1729
|
-
function OptionsDrawer({ routes, visible, onClose, onRouteClick, onCardClick, showOnrampOption,
|
|
1735
|
+
function OptionsDrawer({ checkout, routes, visible, onClose, onRouteClick, onCardClick, showOnrampOption,
|
|
1730
1736
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
1731
1737
|
showSwapOption,
|
|
1732
1738
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
1733
1739
|
showBridgeOption, insufficientBalance, }) {
|
|
1734
|
-
const { addFundsState: { chains } } = reactExports.useContext(AddFundsContext);
|
|
1740
|
+
const { addFundsState: { chains }, } = reactExports.useContext(AddFundsContext);
|
|
1735
1741
|
const { providersState: { fromProviderInfo, fromAddress }, } = useProvidersContext();
|
|
1736
1742
|
const selectedRouteIndex = reactExports.useRef(0);
|
|
1737
1743
|
const handleOnRouteClick = (route, index) => {
|
|
@@ -1741,7 +1747,7 @@ showBridgeOption, insufficientBalance, }) {
|
|
|
1741
1747
|
return (jsx(Drawer, { size: "full", visible: visible, showHeaderBar: false, onCloseDrawer: onClose, children: jsxs(Drawer.Content, { rc: jsx(motion.div, { variants: listVariants, initial: "hidden", animate: "show" }), sx: {
|
|
1742
1748
|
pt: 'base.spacing.x3',
|
|
1743
1749
|
px: 'base.spacing.x3',
|
|
1744
|
-
}, children: [jsxs(MenuItem, { size: "xSmall", children: [jsx(MenuItem.FramedImage, { padded: true, emphasized: true, use: jsx("img", { src: fromProviderInfo?.icon, alt: fromProviderInfo?.name }) }), jsx(MenuItem.Label, { children: "Pay from" }), jsxs(MenuItem.Caption, { children: [fromProviderInfo?.name, ' • ', jsx(EllipsizedText, { text: fromAddress ?? '', sx: { c: 'inherit', fontSize: 'inherit' } })] }), jsx(MenuItem.StatefulButtCon, { icon: "ChevronExpand", onClick: onClose })] }), jsx(Options, { size: "small", routes: routes, chains: chains, onCardClick: onCardClick, onRouteClick: handleOnRouteClick, showOnrampOption: showOnrampOption, insufficientBalance: insufficientBalance, selectedIndex: selectedRouteIndex.current })] }) }));
|
|
1750
|
+
}, children: [jsxs(MenuItem, { size: "xSmall", children: [jsx(MenuItem.FramedImage, { padded: true, emphasized: true, use: jsx("img", { src: fromProviderInfo?.icon, alt: fromProviderInfo?.name }), sx: { mx: 'base.spacing.x2' } }), jsx(MenuItem.Label, { children: "Pay from" }), jsxs(MenuItem.Caption, { children: [fromProviderInfo?.name, ' • ', jsx(EllipsizedText, { text: fromAddress ?? '', sx: { c: 'inherit', fontSize: 'inherit' } })] }), jsx(MenuItem.StatefulButtCon, { icon: "ChevronExpand", onClick: onClose })] }), jsx(Options, { size: "small", checkout: checkout, routes: routes, chains: chains, onCardClick: onCardClick, onRouteClick: handleOnRouteClick, showOnrampOption: showOnrampOption, insufficientBalance: insufficientBalance, selectedIndex: selectedRouteIndex.current })] }) }));
|
|
1745
1751
|
}
|
|
1746
1752
|
|
|
1747
1753
|
const delay = (ms) => new Promise((resolve) => {
|
|
@@ -1875,12 +1881,12 @@ const useRoutes = () => {
|
|
|
1875
1881
|
allRoutes.push(...(await getRoutes(squid, slicedAmountDataArray, toTokenAddress)));
|
|
1876
1882
|
await delay(delayMs);
|
|
1877
1883
|
}));
|
|
1884
|
+
const sortedRoutes = sortRoutesByFastestTime(allRoutes);
|
|
1878
1885
|
// Only update routes if the request is the latest one
|
|
1879
1886
|
if (currentRequestId === latestRequestIdRef.current) {
|
|
1880
|
-
const sortedRoutes = sortRoutesByFastestTime(allRoutes);
|
|
1881
1887
|
setRoutes(sortedRoutes);
|
|
1882
1888
|
}
|
|
1883
|
-
return
|
|
1889
|
+
return sortedRoutes;
|
|
1884
1890
|
};
|
|
1885
1891
|
return {
|
|
1886
1892
|
fetchRoutesWithRateLimit,
|
|
@@ -1907,7 +1913,7 @@ function SelectedRouteOptionContainer({ children, onClick, selected, }) {
|
|
|
1907
1913
|
: `calc(100% + (${base.spacing.x16}))`),
|
|
1908
1914
|
}, rc: jsx("span", { ...(onClick ? { onClick } : {}) }), children: children }));
|
|
1909
1915
|
}
|
|
1910
|
-
function SelectedRouteOption({ routeData, chains, loading = false, withSelectedWallet = false, withSelectedToken = false, withSelectedAmount = false, insufficientBalance = false, showOnrampOption = false, onClick, }) {
|
|
1916
|
+
function SelectedRouteOption({ checkout, routeData, chains, loading = false, withSelectedWallet = false, withSelectedToken = false, withSelectedAmount = false, insufficientBalance = false, showOnrampOption = false, onClick, }) {
|
|
1911
1917
|
const { fromToken } = routeData?.amountData ?? {};
|
|
1912
1918
|
const chain = chains?.find((c) => c.id === fromToken?.chainId);
|
|
1913
1919
|
const { routeBalanceUsd, fromAmount, fromAmountUsd } = reactExports.useMemo(() => getRouteAndTokenBalances(routeData), [routeData]);
|
|
@@ -1920,7 +1926,7 @@ function SelectedRouteOption({ routeData, chains, loading = false, withSelectedW
|
|
|
1920
1926
|
return true;
|
|
1921
1927
|
}, [onClick, loading, routeData]);
|
|
1922
1928
|
if (!routeData && loading) {
|
|
1923
|
-
return (jsxs(SelectedRouteOptionContainer, { onClick: handleOnClick, selected: withSelectedWallet, children: [jsx(MenuItem.FramedVideo, { videoUrl:
|
|
1929
|
+
return (jsxs(SelectedRouteOptionContainer, { onClick: handleOnClick, selected: withSelectedWallet, children: [jsx(MenuItem.FramedVideo, { videoUrl: getRemoteVideo(checkout.config.environment, '/loading_bubble-small.mp4'), padded: true, mimeType: "video/mp4", circularFrame: true }), jsx(MenuItem.Caption, { children: "Finding the best payment route..." })] }));
|
|
1924
1930
|
}
|
|
1925
1931
|
if ((!routeData && !loading) || insufficientBalance) {
|
|
1926
1932
|
let icon = 'Sparkle';
|
|
@@ -1944,92 +1950,28 @@ function SelectedRouteOption({ routeData, chains, loading = false, withSelectedW
|
|
|
1944
1950
|
}
|
|
1945
1951
|
return (jsxs(SelectedRouteOptionContainer, { onClick: handleOnClick, selected: withSelectedWallet, children: [jsx(MenuItem.FramedIcon, { icon: icon, variant: "bold", circularFrame: true, emphasized: false }), jsx(MenuItem.Caption, { children: copy })] }));
|
|
1946
1952
|
}
|
|
1947
|
-
return (jsxs(SelectedRouteOptionContainer, { onClick: handleOnClick, selected: withSelectedWallet, children: [chain && (jsxs(Sticker, { position: { x: 'right', y: 'bottom' }, children: [jsx(Sticker.FramedImage, { use: jsx("img", { src: chain.iconUrl, alt: chain.name }), sx: {
|
|
1953
|
+
return (jsxs(SelectedRouteOptionContainer, { onClick: handleOnClick, selected: withSelectedWallet, children: [chain && (jsxs(Sticker, { position: { x: 'right', y: 'bottom' }, children: [jsx(Sticker.FramedImage, { use: jsx("img", { src: chain.iconUrl, alt: chain.name }), size: "xSmall", sx: { bottom: 'base.spacing.x2', right: 'base.spacing.x2' } }), jsx(MenuItem.FramedImage, { circularFrame: true, padded: true, use: jsx("img", { src: fromToken?.iconUrl, alt: fromToken?.name }) })] })), jsxs(Stack, { direction: "row", justifyContent: "space-between", alignItems: "center", sx: { w: '100%' }, children: [jsxs(Stack, { gap: "0px", children: [jsx(MenuItem.Label, { children: fromToken?.name }), jsx(MenuItem.Caption, { children: `Balance USD $${routeBalanceUsd}` })] }), jsx(MenuItem.PriceDisplay, { price: fromAmount, children: jsx(MenuItem.PriceDisplay.Caption, { children: `USD $${fromAmountUsd}` }) })] })] }));
|
|
1948
1954
|
}
|
|
1949
1955
|
|
|
1950
|
-
|
|
1956
|
+
const disabledStyles = {
|
|
1957
|
+
cursor: 'not-allowed',
|
|
1958
|
+
bg: 'base.color.translucent.inverse.800',
|
|
1959
|
+
};
|
|
1960
|
+
function SelectedWallet({ label, children, onClick, providerInfo, disabled, }) {
|
|
1951
1961
|
const selected = !!children && providerInfo?.rdns;
|
|
1952
1962
|
const size = selected ? 'xSmall' : 'small';
|
|
1953
|
-
return (jsxs(MenuItem, { size: size,
|
|
1963
|
+
return (jsxs(MenuItem, { size: size, disabled: disabled, emphasized: !disabled, onClick: disabled ? undefined : onClick, sx: {
|
|
1964
|
+
py: selected ? 'base.spacing.x3' : undefined,
|
|
1965
|
+
...(disabled ? disabledStyles : {}),
|
|
1966
|
+
}, children: [!providerInfo?.icon && (jsx(MenuItem.FramedIcon, { icon: "Wallet", variant: "bold", emphasized: false })), providerInfo?.icon && (jsx(MenuItem.FramedImage, { padded: true, sx: { mx: selected ? 'base.spacing.x2' : undefined }, use: jsx("img", { src: providerInfo.icon, alt: providerInfo.name }) })), jsx(MenuItem.Label, { children: label }), providerInfo?.name && (jsxs(MenuItem.Caption, { children: [providerInfo?.name, ' • ', jsx(EllipsizedText, { text: providerInfo.address ?? '', sx: { c: 'inherit', fontSize: 'inherit' } })] })), jsx(MenuItem.BottomSlot, { children: children })] }));
|
|
1954
1967
|
}
|
|
1955
1968
|
|
|
1956
|
-
function
|
|
1957
|
-
const { t } = useTranslation();
|
|
1958
|
-
return (jsx(Drawer, { size: "full", visible: visible, showHeaderBar: false, children: jsxs(Drawer.Content, { children: [jsx(ButtCon, { icon: "Close", variant: "tertiary", sx: {
|
|
1959
|
-
pos: 'absolute',
|
|
1960
|
-
top: 'base.spacing.x5',
|
|
1961
|
-
left: 'base.spacing.x5',
|
|
1962
|
-
backdropFilter: 'blur(30px)',
|
|
1963
|
-
}, onClick: onCloseDrawer }), jsx(WalletWarningHero, {}), jsxs(Box, { sx: { px: 'base.spacing.x6' }, children: [jsx(Heading, { sx: {
|
|
1964
|
-
marginTop: 'base.spacing.x6',
|
|
1965
|
-
marginBottom: 'base.spacing.x2',
|
|
1966
|
-
textAlign: 'center',
|
|
1967
|
-
}, children: t('views.CONNECT_WALLET.nonPassportDrawer.heading') }), jsxs(Body, { size: "medium", sx: {
|
|
1968
|
-
display: 'block',
|
|
1969
|
-
textAlign: 'center',
|
|
1970
|
-
color: 'base.color.text.body.secondary',
|
|
1971
|
-
marginBottom: 'base.spacing.x21',
|
|
1972
|
-
}, children: [jsx(Trans, { i18nKey: t('views.CONNECT_WALLET.nonPassportDrawer.body1'), components: {
|
|
1973
|
-
layerswapLink: (jsx(Link, { size: "small", rc: (jsx("a", { target: "_blank", href: "https://toolkit.immutable.com/cex-deposit", rel: "noreferrer" })) })),
|
|
1974
|
-
} }), jsx("br", {}), jsx("br", {}), t('views.CONNECT_WALLET.nonPassportDrawer.body2')] })] }), jsx(Box, { sx: {
|
|
1975
|
-
display: 'flex',
|
|
1976
|
-
flexDirection: 'column',
|
|
1977
|
-
paddingX: 'base.spacing.x6',
|
|
1978
|
-
width: '100%',
|
|
1979
|
-
}, children: jsx(Button, { sx: { width: '100%', marginBottom: 'base.spacing.x10' }, testId: "non-passport-cta-button", variant: "primary", size: "large", onClick: handleCtaButtonClick, children: t('views.CONNECT_WALLET.nonPassportDrawer.buttonText') }) })] }) }));
|
|
1980
|
-
}
|
|
1981
|
-
|
|
1982
|
-
var ConnectEIP6963ProviderError;
|
|
1983
|
-
(function (ConnectEIP6963ProviderError) {
|
|
1984
|
-
ConnectEIP6963ProviderError["CONNECT_ERROR"] = "CONNECT_ERROR";
|
|
1985
|
-
ConnectEIP6963ProviderError["SANCTIONED_ADDRESS"] = "SANCTIONED_ADDRESS";
|
|
1986
|
-
ConnectEIP6963ProviderError["USER_REJECTED_REQUEST_ERROR"] = "USER_REJECTED_REQUEST_ERROR";
|
|
1987
|
-
})(ConnectEIP6963ProviderError || (ConnectEIP6963ProviderError = {}));
|
|
1988
|
-
const connectEIP6963Provider = async (providerDetail, checkout) => {
|
|
1989
|
-
const web3Provider = new Web3Provider(providerDetail.provider);
|
|
1990
|
-
try {
|
|
1991
|
-
const requestWalletPermissions = providerDetail.info.rdns === WalletProviderRdns.METAMASK;
|
|
1992
|
-
const connectResult = await checkout.connect({
|
|
1993
|
-
provider: web3Provider,
|
|
1994
|
-
requestWalletPermissions,
|
|
1995
|
-
});
|
|
1996
|
-
const address = await connectResult.provider.getSigner().getAddress();
|
|
1997
|
-
const isSanctioned = await checkout.checkIsAddressSanctioned(address, checkout.config.environment);
|
|
1998
|
-
if (isSanctioned) {
|
|
1999
|
-
throw new CheckoutError('Sanctioned address', ConnectEIP6963ProviderError.SANCTIONED_ADDRESS);
|
|
2000
|
-
}
|
|
2001
|
-
addProviderListenersForWidgetRoot(connectResult.provider);
|
|
2002
|
-
return {
|
|
2003
|
-
provider: connectResult.provider,
|
|
2004
|
-
providerName: getProviderSlugFromRdns(providerDetail.info.rdns),
|
|
2005
|
-
};
|
|
2006
|
-
}
|
|
2007
|
-
catch (error) {
|
|
2008
|
-
switch (error.type) {
|
|
2009
|
-
case CheckoutErrorType.USER_REJECTED_REQUEST_ERROR:
|
|
2010
|
-
throw new Error(ConnectEIP6963ProviderError.USER_REJECTED_REQUEST_ERROR);
|
|
2011
|
-
case ConnectEIP6963ProviderError.SANCTIONED_ADDRESS:
|
|
2012
|
-
throw new Error(ConnectEIP6963ProviderError.SANCTIONED_ADDRESS);
|
|
2013
|
-
default:
|
|
2014
|
-
throw new Error(ConnectEIP6963ProviderError.CONNECT_ERROR);
|
|
2015
|
-
}
|
|
2016
|
-
}
|
|
2017
|
-
};
|
|
2018
|
-
|
|
2019
|
-
function ConnectWalletDrawer({ heading, visible, onClose, onConnect, onError, providerType, walletOptions, bottomSlot, menuItemSize = 'small', disabledOptions = [], }) {
|
|
1969
|
+
function ConnectWalletDrawer({ heading, visible, onClose, onConnect, onError, providerType, walletOptions, bottomSlot, menuItemSize = 'small', disabledOptions = [], getShouldRequestWalletPermissions, }) {
|
|
2020
1970
|
const { providersState: { checkout }, providersDispatch, } = useProvidersContext();
|
|
2021
1971
|
const { identify, track } = useAnalytics();
|
|
2022
1972
|
const prevWalletChangeEvent = reactExports.useRef();
|
|
2023
|
-
const [showNonPassportWarning, setShowNonPassportWarning] = reactExports.useState(false);
|
|
2024
1973
|
const [showUnableToConnectDrawer, setShowUnableToConnectDrawer] = reactExports.useState(false);
|
|
2025
1974
|
const [showChangedMindDrawer, setShowChangedMindDrawer] = reactExports.useState(false);
|
|
2026
|
-
const shouldShowNonPassportWarning = (rdns) => {
|
|
2027
|
-
const hasSeenWarning = localStorage.getItem(HAS_SEEN_NON_PASSPORT_WARNING_KEY);
|
|
2028
|
-
if (rdns !== WalletProviderRdns.PASSPORT && !hasSeenWarning) {
|
|
2029
|
-
return true;
|
|
2030
|
-
}
|
|
2031
|
-
return false;
|
|
2032
|
-
};
|
|
2033
1975
|
const setProviderInContext = async (provider, providerInfo) => {
|
|
2034
1976
|
const address = await provider.getSigner().getAddress();
|
|
2035
1977
|
if (providerType === 'from') {
|
|
@@ -2052,6 +1994,7 @@ function ConnectWalletDrawer({ heading, visible, onClose, onConnect, onError, pr
|
|
|
2052
1994
|
},
|
|
2053
1995
|
});
|
|
2054
1996
|
}
|
|
1997
|
+
return address;
|
|
2055
1998
|
};
|
|
2056
1999
|
const handleOnWalletChangeEvent = async (event) => {
|
|
2057
2000
|
if (!checkout) {
|
|
@@ -2063,11 +2006,6 @@ function ConnectWalletDrawer({ heading, visible, onClose, onConnect, onError, pr
|
|
|
2063
2006
|
prevWalletChangeEvent.current = event;
|
|
2064
2007
|
const { providerDetail } = event;
|
|
2065
2008
|
const { info } = providerDetail;
|
|
2066
|
-
// check if selected a non passport wallet
|
|
2067
|
-
if (shouldShowNonPassportWarning(info.rdns)) {
|
|
2068
|
-
setShowNonPassportWarning(true);
|
|
2069
|
-
return;
|
|
2070
|
-
}
|
|
2071
2009
|
// Trigger analytics connect wallet, menu item, with wallet details
|
|
2072
2010
|
track({
|
|
2073
2011
|
userJourney: UserJourney.CONNECT,
|
|
@@ -2089,13 +2027,15 @@ function ConnectWalletDrawer({ heading, visible, onClose, onConnect, onError, pr
|
|
|
2089
2027
|
await checkout.passport?.logout();
|
|
2090
2028
|
}
|
|
2091
2029
|
}
|
|
2030
|
+
let address;
|
|
2092
2031
|
// Proceed to connect selected provider
|
|
2032
|
+
const shouldRequestWalletPermissions = getShouldRequestWalletPermissions?.(info);
|
|
2093
2033
|
try {
|
|
2094
|
-
const { provider } = await connectEIP6963Provider(providerDetail, checkout);
|
|
2034
|
+
const { provider } = await connectEIP6963Provider(providerDetail, checkout, shouldRequestWalletPermissions);
|
|
2095
2035
|
// Identify connected wallet
|
|
2096
2036
|
await identifyUser(identify, provider);
|
|
2097
2037
|
// Store selected provider as fromProvider in context
|
|
2098
|
-
setProviderInContext(provider, providerDetail.info);
|
|
2038
|
+
address = await setProviderInContext(provider, providerDetail.info);
|
|
2099
2039
|
// Notify successful connection
|
|
2100
2040
|
onConnect?.(provider, providerDetail.info);
|
|
2101
2041
|
}
|
|
@@ -2116,18 +2056,13 @@ function ConnectWalletDrawer({ heading, visible, onClose, onConnect, onError, pr
|
|
|
2116
2056
|
onError?.(errorType);
|
|
2117
2057
|
return;
|
|
2118
2058
|
}
|
|
2119
|
-
onClose();
|
|
2059
|
+
onClose(address);
|
|
2120
2060
|
};
|
|
2121
2061
|
const retrySelectedWallet = () => {
|
|
2122
2062
|
if (prevWalletChangeEvent.current) {
|
|
2123
2063
|
handleOnWalletChangeEvent(prevWalletChangeEvent.current);
|
|
2124
2064
|
}
|
|
2125
2065
|
};
|
|
2126
|
-
const handleCloseNonPassportWarningDrawer = () => {
|
|
2127
|
-
localStorage.setItem(HAS_SEEN_NON_PASSPORT_WARNING_KEY, 'true');
|
|
2128
|
-
setShowNonPassportWarning(false);
|
|
2129
|
-
retrySelectedWallet();
|
|
2130
|
-
};
|
|
2131
2066
|
const handleCloseChangedMindDrawer = () => {
|
|
2132
2067
|
setShowChangedMindDrawer(false);
|
|
2133
2068
|
retrySelectedWallet();
|
|
@@ -2135,13 +2070,14 @@ function ConnectWalletDrawer({ heading, visible, onClose, onConnect, onError, pr
|
|
|
2135
2070
|
return (jsxs(Fragment, { children: [jsx(WalletDrawer, { testId: "select-from-wallet-drawer", showWalletConnect: true, showDrawer: visible, drawerText: { heading }, walletOptions: walletOptions, disabledOptions: disabledOptions, menuItemSize: menuItemSize, setShowDrawer: (show) => {
|
|
2136
2071
|
if (show === false)
|
|
2137
2072
|
onClose();
|
|
2138
|
-
}, onWalletChange: handleOnWalletChangeEvent, bottomSlot: bottomSlot }), jsx(
|
|
2073
|
+
}, onWalletChange: handleOnWalletChangeEvent, bottomSlot: bottomSlot }), jsx(UnableToConnectDrawer, { visible: showUnableToConnectDrawer, checkout: checkout, onCloseDrawer: () => setShowUnableToConnectDrawer(false), onTryAgain: () => setShowUnableToConnectDrawer(false) }), jsx(ChangedYourMindDrawer, { visible: showChangedMindDrawer, checkout: checkout, onCloseDrawer: () => setShowChangedMindDrawer(false), onTryAgain: handleCloseChangedMindDrawer })] }));
|
|
2139
2074
|
}
|
|
2140
2075
|
|
|
2141
2076
|
function DeliverToWalletDrawer({ visible, onClose, onConnect, walletOptions, }) {
|
|
2077
|
+
const { providersState: { fromProviderInfo }, } = useProvidersContext();
|
|
2142
2078
|
const { viewDispatch } = reactExports.useContext(ViewContext);
|
|
2143
2079
|
const handleOnConnect = (provider, providerInfo) => {
|
|
2144
|
-
onConnect('to', provider, providerInfo);
|
|
2080
|
+
onConnect?.('to', provider, providerInfo);
|
|
2145
2081
|
};
|
|
2146
2082
|
const handleOnError = (errorType) => {
|
|
2147
2083
|
if (errorType === ConnectEIP6963ProviderError.SANCTIONED_ADDRESS) {
|
|
@@ -2157,7 +2093,11 @@ function DeliverToWalletDrawer({ visible, onClose, onConnect, walletOptions, })
|
|
|
2157
2093
|
});
|
|
2158
2094
|
}
|
|
2159
2095
|
};
|
|
2160
|
-
|
|
2096
|
+
// Becuase wallets extensions don't support multiple wallet connections
|
|
2097
|
+
// UX decides to have the user use the same wallet type they selected to pay with
|
|
2098
|
+
// ie: Metamask to Metamsk, will send to same wallet address
|
|
2099
|
+
const selectedSameFromWalletType = (providerInfo) => (fromProviderInfo?.rdns !== providerInfo.rdns ? undefined : false);
|
|
2100
|
+
return (jsx(ConnectWalletDrawer, { heading: "Deliver To", visible: visible, onClose: onClose, providerType: "to", walletOptions: walletOptions, onConnect: handleOnConnect, onError: handleOnError, getShouldRequestWalletPermissions: selectedSameFromWalletType }));
|
|
2161
2101
|
}
|
|
2162
2102
|
|
|
2163
2103
|
function PayWithWalletDrawer({ visible, onClose, onConnect, onPayWithCard, walletOptions, insufficientBalance, showOnRampOption = true, }) {
|
|
@@ -2194,7 +2134,7 @@ function PayWithWalletDrawer({ visible, onClose, onConnect, onPayWithCard, walle
|
|
|
2194
2134
|
return null;
|
|
2195
2135
|
return (jsxs(MenuItem, { size: "small", emphasized: true, onClick: () => {
|
|
2196
2136
|
onClose();
|
|
2197
|
-
onPayWithCard();
|
|
2137
|
+
onPayWithCard?.();
|
|
2198
2138
|
}, children: [jsx(MenuItem.FramedIcon, { icon: "BankCard", variant: "bold", emphasized: false }), jsx(MenuItem.Label, { children: "Pay with Card" })] }));
|
|
2199
2139
|
}, [onClose, onPayWithCard]);
|
|
2200
2140
|
return (jsx(ConnectWalletDrawer, { heading: insufficientBalance ? 'Choose another option' : 'Pay With', visible: visible, onClose: onClose, providerType: "from", walletOptions: walletOptions, disabledOptions: disabledOptions, bottomSlot: payWithCardItem, onConnect: handleOnConnect, onError: handleOnError }));
|
|
@@ -5192,6 +5132,12 @@ const useError = (environment) => {
|
|
|
5192
5132
|
secondaryButtonText: 'Close',
|
|
5193
5133
|
onSecondaryButtonClick: goBackToAddFundsView,
|
|
5194
5134
|
},
|
|
5135
|
+
[AddFundsErrorTypes.ENVIRONMENT_ERROR]: {
|
|
5136
|
+
headingText: 'Unsupported environment',
|
|
5137
|
+
subHeadingText: 'This is only supported in production environment.',
|
|
5138
|
+
secondaryButtonText: 'Close',
|
|
5139
|
+
onSecondaryButtonClick: closeWidget,
|
|
5140
|
+
},
|
|
5195
5141
|
};
|
|
5196
5142
|
const getErrorConfig = (errorType) => errorConfig[errorType];
|
|
5197
5143
|
const showErrorHandover = (errorType, data) => {
|
|
@@ -5206,7 +5152,7 @@ const useError = (environment) => {
|
|
|
5206
5152
|
addHandover({
|
|
5207
5153
|
animationUrl: getRemoteRive(environment, APPROVE_TXN_ANIMATION),
|
|
5208
5154
|
inputValue: RiveStateMachineInput.ERROR,
|
|
5209
|
-
children: jsx(HandoverContent, { headingText: getErrorConfig(errorType).headingText, subheadingText: getErrorConfig(errorType).subHeadingText, primaryButtonText: getErrorConfig(errorType).primaryButtonText, onPrimaryButtonClick: getErrorConfig(errorType).onPrimaryButtonClick, secondaryButtonText: getErrorConfig(errorType).secondaryButtonText, onSecondaryButtonClick: getErrorConfig(errorType).onSecondaryButtonClick }),
|
|
5155
|
+
children: (jsx(HandoverContent, { headingText: getErrorConfig(errorType).headingText, subheadingText: getErrorConfig(errorType).subHeadingText, primaryButtonText: getErrorConfig(errorType).primaryButtonText, onPrimaryButtonClick: getErrorConfig(errorType).onPrimaryButtonClick, secondaryButtonText: getErrorConfig(errorType).secondaryButtonText, onSecondaryButtonClick: getErrorConfig(errorType).onSecondaryButtonClick })),
|
|
5210
5156
|
});
|
|
5211
5157
|
};
|
|
5212
5158
|
return {
|
|
@@ -5265,20 +5211,22 @@ function AddFunds({ checkout, toAmount, config, toTokenAddress, showOnrampOption
|
|
|
5265
5211
|
});
|
|
5266
5212
|
};
|
|
5267
5213
|
const setSelectedRouteData = (route) => {
|
|
5268
|
-
|
|
5269
|
-
|
|
5270
|
-
|
|
5271
|
-
|
|
5272
|
-
|
|
5273
|
-
|
|
5274
|
-
|
|
5275
|
-
|
|
5276
|
-
|
|
5277
|
-
|
|
5278
|
-
|
|
5279
|
-
|
|
5280
|
-
|
|
5281
|
-
|
|
5214
|
+
if (route) {
|
|
5215
|
+
track({
|
|
5216
|
+
userJourney: UserJourney.ADD_FUNDS,
|
|
5217
|
+
screen: 'InputScreen',
|
|
5218
|
+
control: 'RoutesMenu',
|
|
5219
|
+
controlType: 'MenuItem',
|
|
5220
|
+
extras: {
|
|
5221
|
+
toTokenAddress: route.amountData.toToken.address,
|
|
5222
|
+
toTokenChainId: route.amountData.toToken.chainId,
|
|
5223
|
+
fromTokenAddress: route.amountData.fromToken.address,
|
|
5224
|
+
fromTokenChainId: route.amountData.fromToken.chainId,
|
|
5225
|
+
toAmount: route.amountData.toAmount,
|
|
5226
|
+
fromAmount: route.amountData.fromAmount,
|
|
5227
|
+
},
|
|
5228
|
+
});
|
|
5229
|
+
}
|
|
5282
5230
|
addFundsDispatch({
|
|
5283
5231
|
payload: {
|
|
5284
5232
|
type: AddFundsActions.SET_SELECTED_ROUTE_DATA,
|
|
@@ -5294,7 +5242,7 @@ function AddFunds({ checkout, toAmount, config, toTokenAddress, showOnrampOption
|
|
|
5294
5242
|
setInputValue(value);
|
|
5295
5243
|
setSelectedAmount(value);
|
|
5296
5244
|
};
|
|
5297
|
-
const { providersState: { fromProviderInfo, toProviderInfo, fromAddress, toAddress, }, } = useProvidersContext();
|
|
5245
|
+
const { providersState: { fromProviderInfo, toProviderInfo, fromAddress, toAddress, lockedToProvider, }, } = useProvidersContext();
|
|
5298
5246
|
const { providers } = useInjectedProviders({ checkout });
|
|
5299
5247
|
const walletOptions = reactExports.useMemo(() => providers
|
|
5300
5248
|
// TODO: Check if must filter passport on L1
|
|
@@ -5485,10 +5433,7 @@ function AddFunds({ checkout, toAmount, config, toTokenAddress, showOnrampOption
|
|
|
5485
5433
|
&& validateToAmount(inputValue).isValid;
|
|
5486
5434
|
const loading = (routeInputsReady || fetchingRoutes)
|
|
5487
5435
|
&& !(selectedRouteData || insufficientBalance);
|
|
5488
|
-
const readyToReview = routeInputsReady
|
|
5489
|
-
&& !!toAddress
|
|
5490
|
-
&& !!selectedRouteData
|
|
5491
|
-
&& !loading;
|
|
5436
|
+
const readyToReview = routeInputsReady && !!toAddress && !!selectedRouteData && !loading;
|
|
5492
5437
|
const handleWalletConnected = (providerType, provider, providerInfo) => {
|
|
5493
5438
|
track({
|
|
5494
5439
|
userJourney: UserJourney.ADD_FUNDS,
|
|
@@ -5526,20 +5471,20 @@ function AddFunds({ checkout, toAmount, config, toTokenAddress, showOnrampOption
|
|
|
5526
5471
|
boxShadow: ({ base }) => `0 0 0 ${base.border.size[200]} ${base.color.text.body.primary}`,
|
|
5527
5472
|
},
|
|
5528
5473
|
} })),
|
|
5529
|
-
}), children: tokenChoiceOptions }), showInitialEmptyState ? (jsx(Body, { children: "Add Token" })) : (jsxs(HeroFormControl, { validationStatus: inputValue === '0' ? 'error' : 'success', children: [jsxs(HeroFormControl.Label, { children: ["Add", ' ', selectedToken.symbol] }), jsx(HeroTextInput, { testId: "add-funds-amount-input", type: "number", value: inputValue, onChange: (value) => handleOnAmountInputChange(value), placeholder: "0", maxTextSize: "xLarge" }),
|
|
5474
|
+
}), children: tokenChoiceOptions }), showInitialEmptyState ? (jsx(Body, { children: "Add Token" })) : (jsxs(HeroFormControl, { validationStatus: inputValue === '0' ? 'error' : 'success', children: [jsxs(HeroFormControl.Label, { children: ["Add", ' ', selectedToken.symbol] }), jsx(HeroTextInput, { testId: "add-funds-amount-input", type: "number", value: inputValue, onChange: (value) => handleOnAmountInputChange(value), placeholder: "0", maxTextSize: "xLarge" }), jsxs(HeroFormControl.Caption, { children: ["USD $", selectedAmountUsd.toFixed(2)] })] }))] }), jsxs(Stack, { testId: "bottomSection", sx: {
|
|
5530
5475
|
alignSelf: 'stretch',
|
|
5531
5476
|
p: 'base.spacing.x3',
|
|
5532
5477
|
pb: 'base.spacing.x10',
|
|
5533
5478
|
bg: 'base.color.neutral.800',
|
|
5479
|
+
bradtl: 'base.borderRadius.x8',
|
|
5480
|
+
bradtr: 'base.borderRadius.x8',
|
|
5534
5481
|
}, gap: "base.spacing.x6", children: [jsxs(Stack, { gap: "0px", children: [jsxs(SelectedWallet, { label: "Pay with", providerInfo: {
|
|
5535
5482
|
...fromProviderInfo,
|
|
5536
5483
|
address: fromAddress,
|
|
5537
5484
|
}, onClick: (event) => {
|
|
5538
5485
|
event.stopPropagation();
|
|
5539
5486
|
setShowPayWithDrawer(true);
|
|
5540
|
-
}, children: [jsx(MenuItem.BottomSlot.Divider, { sx: {
|
|
5541
|
-
ml: fromAddress ? 'base.spacing.x2' : undefined,
|
|
5542
|
-
} }), jsx(SelectedRouteOption, { loading: loading, chains: chains, routeData: selectedRouteData, onClick: () => setShowOptionsDrawer(true), withSelectedToken: !!selectedToken, withSelectedAmount: parseFloat(inputValue) > 0, withSelectedWallet: !!fromAddress, insufficientBalance: insufficientBalance, showOnrampOption: shouldShowOnRampOption })] }), jsx(Stack, { sx: { pos: 'relative', h: 'base.spacing.x3' }, alignItems: "center", children: jsx(FramedIcon, { icon: "ArrowDown", sx: {
|
|
5487
|
+
}, children: [jsx(MenuItem.BottomSlot.Divider, { sx: fromAddress ? { ml: 'base.spacing.x4' } : undefined }), jsx(SelectedRouteOption, { checkout: checkout, loading: loading, chains: chains, routeData: selectedRouteData, onClick: () => setShowOptionsDrawer(true), withSelectedToken: !!selectedToken, withSelectedAmount: parseFloat(inputValue) > 0, withSelectedWallet: !!fromAddress, insufficientBalance: insufficientBalance, showOnrampOption: shouldShowOnRampOption })] }), jsx(Stack, { sx: { pos: 'relative', h: 'base.spacing.x3' }, alignItems: "center", children: jsx(FramedIcon, { icon: "ArrowDown", sx: {
|
|
5543
5488
|
top: '0',
|
|
5544
5489
|
pos: 'absolute',
|
|
5545
5490
|
translate: '0 -30%',
|
|
@@ -5547,7 +5492,7 @@ function AddFunds({ checkout, toAmount, config, toTokenAddress, showOnrampOption
|
|
|
5547
5492
|
} }) }), jsx(SelectedWallet, { label: "Deliver to", providerInfo: {
|
|
5548
5493
|
...toProviderInfo,
|
|
5549
5494
|
address: toAddress,
|
|
5550
|
-
}, onClick: () => setShowDeliverToDrawer(true) })] }), jsx(Button, { testId: "add-funds-button", size: "large", variant: readyToReview ? 'primary' : 'secondary', disabled: !readyToReview, onClick: handleReviewClick, sx: { opacity: readyToReview ? 1 : 0.5 }, children: "Review" }), jsx(PayWithWalletDrawer, { visible: showPayWithDrawer, walletOptions: walletOptions, onClose: () => setShowPayWithDrawer(false), onPayWithCard: handleCardClick, onConnect: handleWalletConnected, insufficientBalance: insufficientBalance, showOnRampOption: shouldShowOnRampOption }), jsx(OptionsDrawer, { routes: routes, showOnrampOption: shouldShowOnRampOption, showSwapOption: showSwapOption, showBridgeOption: showBridgeOption, visible: showOptionsDrawer, onClose: () => setShowOptionsDrawer(false), onCardClick: handleCardClick, onRouteClick: handleRouteClick, insufficientBalance: insufficientBalance }), jsx(DeliverToWalletDrawer, { visible: showDeliverToDrawer, walletOptions: walletOptions, onClose: () => setShowDeliverToDrawer(false)
|
|
5495
|
+
}, onClick: () => setShowDeliverToDrawer(true), disabled: lockedToProvider })] }), jsx(Button, { testId: "add-funds-button", size: "large", variant: readyToReview ? 'primary' : 'secondary', disabled: !readyToReview, onClick: handleReviewClick, sx: { opacity: readyToReview ? 1 : 0.5 }, children: "Review" }), jsx(PayWithWalletDrawer, { visible: showPayWithDrawer, walletOptions: walletOptions, onClose: () => setShowPayWithDrawer(false), onPayWithCard: handleCardClick, onConnect: handleWalletConnected, insufficientBalance: insufficientBalance, showOnRampOption: shouldShowOnRampOption }), jsx(OptionsDrawer, { checkout: checkout, routes: routes, showOnrampOption: shouldShowOnRampOption, showSwapOption: showSwapOption, showBridgeOption: showBridgeOption, visible: showOptionsDrawer, onClose: () => setShowOptionsDrawer(false), onCardClick: handleCardClick, onRouteClick: handleRouteClick, insufficientBalance: insufficientBalance }), jsx(DeliverToWalletDrawer, { visible: showDeliverToDrawer, walletOptions: walletOptions, onClose: () => setShowDeliverToDrawer(false) }), jsx(OnboardingDrawer, { environment: checkout?.config.environment })] })] }) }));
|
|
5551
5496
|
}
|
|
5552
5497
|
|
|
5553
5498
|
var dist$3 = {};
|
|
@@ -173289,10 +173234,12 @@ const useExecute = (environment) => {
|
|
|
173289
173234
|
if (reason.includes('rejected') && reason.includes('user')) {
|
|
173290
173235
|
errorType = AddFundsErrorTypes.WALLET_REJECTED;
|
|
173291
173236
|
}
|
|
173292
|
-
if (reason.includes('failed to submit')
|
|
173237
|
+
if (reason.includes('failed to submit')
|
|
173238
|
+
&& reason.includes('highest gas limit')) {
|
|
173293
173239
|
errorType = AddFundsErrorTypes.WALLET_REJECTED_NO_FUNDS;
|
|
173294
173240
|
}
|
|
173295
|
-
if (reason.includes('status failed')
|
|
173241
|
+
if (reason.includes('status failed')
|
|
173242
|
+
|| reason.includes('transaction failed')) {
|
|
173296
173243
|
errorType = AddFundsErrorTypes.TRANSACTION_FAILED;
|
|
173297
173244
|
}
|
|
173298
173245
|
const error = {
|
|
@@ -173301,7 +173248,7 @@ const useExecute = (environment) => {
|
|
|
173301
173248
|
};
|
|
173302
173249
|
showErrorHandover(errorType, { error });
|
|
173303
173250
|
};
|
|
173304
|
-
|
|
173251
|
+
// @TODO: Move to util function
|
|
173305
173252
|
const checkProviderChain = async (provider, chainId) => {
|
|
173306
173253
|
if (!provider.provider.request) {
|
|
173307
173254
|
throw new Error('provider does not have request method');
|
|
@@ -173397,7 +173344,6 @@ const useExecute = (environment) => {
|
|
|
173397
173344
|
}
|
|
173398
173345
|
};
|
|
173399
173346
|
return {
|
|
173400
|
-
convertToNetworkChangeableProvider,
|
|
173401
173347
|
checkProviderChain,
|
|
173402
173348
|
getAllowance,
|
|
173403
173349
|
approve,
|
|
@@ -173449,6 +173395,24 @@ function RouteFees({ visible, onClose, routeData, totalAmount, totalFiatAmount,
|
|
|
173449
173395
|
return (jsx(FeesBreakdown, { visible: visible, loading: !routeData, fees: [...feeCosts, ...gasCosts], tokenSymbol: tokenSymbol, totalAmount: getFormattedNumber(totalAmount, feesToken?.decimals), totalFiatAmount: getFormattedAmounts(totalFiatAmount), onCloseDrawer: onClose }));
|
|
173450
173396
|
}
|
|
173451
173397
|
|
|
173398
|
+
function AddressMissmatchDrawer({ visible, onClick, }) {
|
|
173399
|
+
return (jsx(Drawer, { size: "full", visible: visible, showHeaderBar: false, children: jsxs(Drawer.Content, { children: [jsx(WalletWarningHero, {}), jsxs(Box, { sx: { px: 'base.spacing.x6' }, children: [jsx(Heading, { sx: {
|
|
173400
|
+
marginTop: 'base.spacing.x6',
|
|
173401
|
+
marginBottom: 'base.spacing.x2',
|
|
173402
|
+
textAlign: 'center',
|
|
173403
|
+
}, children: "Oops! It seems your payment wallet has changed" }), jsx(Body, { size: "medium", sx: {
|
|
173404
|
+
display: 'block',
|
|
173405
|
+
textAlign: 'center',
|
|
173406
|
+
color: 'base.color.text.body.secondary',
|
|
173407
|
+
marginBottom: 'base.spacing.x21',
|
|
173408
|
+
}, children: "You'll be ask to re-connect the same wallet you selected to pay with before proceeding." })] }), jsx(Box, { sx: {
|
|
173409
|
+
display: 'flex',
|
|
173410
|
+
flexDirection: 'column',
|
|
173411
|
+
paddingX: 'base.spacing.x6',
|
|
173412
|
+
width: '100%',
|
|
173413
|
+
}, children: jsx(Button, { sx: { width: '100%', marginBottom: 'base.spacing.x10' }, testId: "non-passport-cta-button", variant: "primary", size: "large", onClick: onClick, children: "Re-select payment wallet" }) })] }) }));
|
|
173414
|
+
}
|
|
173415
|
+
|
|
173452
173416
|
/**
|
|
173453
173417
|
* Find a chain by its id
|
|
173454
173418
|
* @param chainId - The id of the chain to find
|
|
@@ -173469,6 +173433,8 @@ const getRouteChains = (chains, route) => ({
|
|
|
173469
173433
|
toChain: findChainById(route?.route.estimate.toToken.chainId, chains),
|
|
173470
173434
|
});
|
|
173471
173435
|
|
|
173436
|
+
const convertToNetworkChangeableProvider = async (provider) => new Web3Provider(provider.provider, 'any');
|
|
173437
|
+
|
|
173472
173438
|
const dividerSx = {
|
|
173473
173439
|
content: "''",
|
|
173474
173440
|
pos: 'absolute',
|
|
@@ -173484,11 +173450,12 @@ function Review({ data, showBackButton = false, onBackButtonClick, onCloseButton
|
|
|
173484
173450
|
const [route, setRoute] = reactExports.useState();
|
|
173485
173451
|
const [proceedDisabled, setProceedDisabled] = reactExports.useState(true);
|
|
173486
173452
|
const [showFeeBreakdown, setShowFeeBreakdown] = reactExports.useState(false);
|
|
173453
|
+
const [showAddressMissmatchDrawer, setShowAddressMissmatchDrawer] = reactExports.useState(false);
|
|
173487
173454
|
const { getAmountData, getRoute } = useRoutes();
|
|
173488
173455
|
const { addHandover, closeHandover } = useHandover({
|
|
173489
173456
|
id: HandoverTarget.GLOBAL,
|
|
173490
173457
|
});
|
|
173491
|
-
const {
|
|
173458
|
+
const { checkProviderChain, getAllowance, approve, execute, } = useExecute(checkout?.config.environment || Environment.SANDBOX);
|
|
173492
173459
|
reactExports.useEffect(() => {
|
|
173493
173460
|
page({
|
|
173494
173461
|
userJourney: UserJourney.ADD_FUNDS,
|
|
@@ -173547,6 +173514,11 @@ function Review({ data, showBackButton = false, onBackButtonClick, onCloseButton
|
|
|
173547
173514
|
if (!squid || !fromProvider || !route) {
|
|
173548
173515
|
return;
|
|
173549
173516
|
}
|
|
173517
|
+
const currentFromAddress = await fromProvider.getSigner().getAddress();
|
|
173518
|
+
if (currentFromAddress !== fromAddress) {
|
|
173519
|
+
setShowAddressMissmatchDrawer(true);
|
|
173520
|
+
return;
|
|
173521
|
+
}
|
|
173550
173522
|
clearInterval(getRouteIntervalIdRef.current);
|
|
173551
173523
|
setProceedDisabled(true);
|
|
173552
173524
|
showHandover(APPROVE_TXN_ANIMATION, RiveStateMachineInput.START, 'Preparing');
|
|
@@ -173587,7 +173559,6 @@ function Review({ data, showBackButton = false, onBackButtonClick, onCloseButton
|
|
|
173587
173559
|
approve,
|
|
173588
173560
|
showHandover,
|
|
173589
173561
|
checkProviderChain,
|
|
173590
|
-
convertToNetworkChangeableProvider,
|
|
173591
173562
|
getAllowance,
|
|
173592
173563
|
execute,
|
|
173593
173564
|
closeHandover,
|
|
@@ -173651,7 +173622,17 @@ function Review({ data, showBackButton = false, onBackButtonClick, onCloseButton
|
|
|
173651
173622
|
top: '-8px',
|
|
173652
173623
|
h: 'base.spacing.x5',
|
|
173653
173624
|
},
|
|
173654
|
-
} }), jsxs(Stack, { direction: "row", gap: "base.spacing.x6", sx: { py: 'base.spacing.x5', px: 'base.spacing.x7' }, alignItems: "center", children: [jsx(Stack, { direction: "row", sx: { w: 'base.spacing.x12' }, justifyContent: "center", children: jsx(FramedIcon, { icon: "Countdown", variant: "bold", size: "medium", circularFrame: true }) }), jsx(Body, { size: "small", sx: { flex: 1, c: 'base.color.text.body.secondary' }, children: formattedDuration }), routeFees] })] }), jsx(Button, { size: "large", onClick: handleTransaction, disabled: proceedDisabled, sx: { mt: 'auto', mb: 'base.spacing.x4', mx: 'base.spacing.x3' }, children: proceedDisabled ? 'Processing' : 'Proceed' })] })), !route && jsx(LoadingView, { loadingText: "Securing quote" })] }), jsx(RouteFees, { routeData: route, visible: showFeeBreakdown, onClose: () => setShowFeeBreakdown(false), totalAmount: totalFees, totalFiatAmount: totalFeesUsd })
|
|
173625
|
+
} }), jsxs(Stack, { direction: "row", gap: "base.spacing.x6", sx: { py: 'base.spacing.x5', px: 'base.spacing.x7' }, alignItems: "center", children: [jsx(Stack, { direction: "row", sx: { w: 'base.spacing.x12' }, justifyContent: "center", children: jsx(FramedIcon, { icon: "Countdown", variant: "bold", size: "medium", circularFrame: true }) }), jsx(Body, { size: "small", sx: { flex: 1, c: 'base.color.text.body.secondary' }, children: formattedDuration }), routeFees] })] }), jsx(Button, { size: "large", onClick: handleTransaction, disabled: proceedDisabled, sx: { mt: 'auto', mb: 'base.spacing.x4', mx: 'base.spacing.x3' }, children: proceedDisabled ? 'Processing' : 'Proceed' })] })), !route && !showAddressMissmatchDrawer && jsx(LoadingView, { loadingText: "Securing quote" })] }), jsx(RouteFees, { routeData: route, visible: showFeeBreakdown, onClose: () => setShowFeeBreakdown(false), totalAmount: totalFees, totalFiatAmount: totalFeesUsd }), jsx(AddressMissmatchDrawer, { visible: showAddressMissmatchDrawer, onClick: () => {
|
|
173626
|
+
setShowAddressMissmatchDrawer(false);
|
|
173627
|
+
viewDispatch({
|
|
173628
|
+
payload: {
|
|
173629
|
+
type: ViewActions.UPDATE_VIEW,
|
|
173630
|
+
view: {
|
|
173631
|
+
type: AddFundsWidgetViews.ADD_FUNDS,
|
|
173632
|
+
},
|
|
173633
|
+
},
|
|
173634
|
+
});
|
|
173635
|
+
} })] }));
|
|
173655
173636
|
}
|
|
173656
173637
|
|
|
173657
173638
|
const fetchBalances = async (squid, chains, provider) => {
|
|
@@ -173730,6 +173711,7 @@ const useTokens = (checkout) => {
|
|
|
173730
173711
|
|
|
173731
173712
|
function AddFundsWidget({ showOnrampOption = true, showSwapOption = true, showBridgeOption = true, toTokenAddress, toAmount, showBackButton, config, }) {
|
|
173732
173713
|
const fetchingBalances = reactExports.useRef(false);
|
|
173714
|
+
const { base: { colorMode } } = useTheme();
|
|
173733
173715
|
const [viewState, viewDispatch] = reactExports.useReducer(viewReducer, {
|
|
173734
173716
|
...initialViewState,
|
|
173735
173717
|
view: { type: AddFundsWidgetViews.ADD_FUNDS },
|
|
@@ -173751,6 +173733,11 @@ function AddFundsWidget({ showOnrampOption = true, showSwapOption = true, showBr
|
|
|
173751
173733
|
const squidSdk = useSquid(checkout);
|
|
173752
173734
|
const tokensResponse = useTokens(checkout);
|
|
173753
173735
|
const { showErrorHandover } = useError(checkout.config.environment ?? Environment.SANDBOX);
|
|
173736
|
+
reactExports.useEffect(() => {
|
|
173737
|
+
if (config.environment !== Environment.PRODUCTION) {
|
|
173738
|
+
showErrorHandover(AddFundsErrorTypes.ENVIRONMENT_ERROR);
|
|
173739
|
+
}
|
|
173740
|
+
}, [config]);
|
|
173754
173741
|
reactExports.useEffect(() => {
|
|
173755
173742
|
const isInvalidToTokenAddress = toTokenAddress && !isValidAddress(toTokenAddress);
|
|
173756
173743
|
const isInvalidToAmount = toAmount && !amountInputValidation(toAmount);
|
|
@@ -173818,13 +173805,15 @@ function AddFundsWidget({ showOnrampOption = true, showSwapOption = true, showBr
|
|
|
173818
173805
|
},
|
|
173819
173806
|
});
|
|
173820
173807
|
};
|
|
173821
|
-
return (jsx(ViewContext.Provider, { value: viewReducerValues, children: jsx(AddFundsContext.Provider, { value: addFundsReducerValues, children: jsxs(Stack, { sx: { pos: 'relative' }, children: [jsx(CloudImage, { use: (jsx("img", { src: getRemoteImage(config.environment,
|
|
173808
|
+
return (jsx(ViewContext.Provider, { value: viewReducerValues, children: jsx(AddFundsContext.Provider, { value: addFundsReducerValues, children: jsxs(Stack, { sx: { pos: 'relative' }, children: [jsx(CloudImage, { use: (jsx("img", { src: getRemoteImage(config.environment, `/add-funds-bg-texture-${colorMode}.webp`), alt: "blurry bg texture" })), sx: {
|
|
173822
173809
|
pos: 'absolute',
|
|
173823
173810
|
h: '100%',
|
|
173824
173811
|
w: '100%',
|
|
173825
173812
|
objectFit: 'cover',
|
|
173826
173813
|
objectPosition: 'center',
|
|
173827
|
-
} }), viewState.view.type === AddFundsWidgetViews.ADD_FUNDS && (jsx(AddFunds, { config: config, checkout: checkout, toTokenAddress: toTokenAddress, toAmount: toAmount, showBackButton: showBackButton, showOnrampOption: showOnrampOption, showSwapOption: showSwapOption, showBridgeOption: showBridgeOption, onCloseButtonClick: () => sendAddFundsCloseEvent(eventTarget)
|
|
173814
|
+
} }), viewState.view.type === AddFundsWidgetViews.ADD_FUNDS && (jsx(AddFunds, { config: config, checkout: checkout, toTokenAddress: toTokenAddress, toAmount: toAmount, showBackButton: showBackButton, showOnrampOption: showOnrampOption, showSwapOption: showSwapOption, showBridgeOption: showBridgeOption, onCloseButtonClick: () => sendAddFundsCloseEvent(eventTarget), onBackButtonClick: () => {
|
|
173815
|
+
orchestrationEvents.sendRequestGoBackEvent(eventTarget, IMTBLWidgetEvents.IMTBL_ADD_FUNDS_WIDGET_EVENT, {});
|
|
173816
|
+
} })), viewState.view.type === AddFundsWidgetViews.REVIEW && (jsx(Review, { data: viewState.view.data, onCloseButtonClick: () => sendAddFundsCloseEvent(eventTarget), onBackButtonClick: () => {
|
|
173828
173817
|
viewDispatch({
|
|
173829
173818
|
payload: {
|
|
173830
173819
|
type: ViewActions.GO_BACK,
|