@getpara/react-common 1.7.0 → 1.8.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.
@@ -0,0 +1,46 @@
1
+ "use client";
2
+ var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
4
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
5
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
8
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
+ var __spreadValues = (a, b) => {
10
+ for (var prop in b || (b = {}))
11
+ if (__hasOwnProp.call(b, prop))
12
+ __defNormalProp(a, prop, b[prop]);
13
+ if (__getOwnPropSymbols)
14
+ for (var prop of __getOwnPropSymbols(b)) {
15
+ if (__propIsEnum.call(b, prop))
16
+ __defNormalProp(a, prop, b[prop]);
17
+ }
18
+ return a;
19
+ };
20
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
21
+ var __async = (__this, __arguments, generator) => {
22
+ return new Promise((resolve, reject) => {
23
+ var fulfilled = (value) => {
24
+ try {
25
+ step(generator.next(value));
26
+ } catch (e) {
27
+ reject(e);
28
+ }
29
+ };
30
+ var rejected = (value) => {
31
+ try {
32
+ step(generator.throw(value));
33
+ } catch (e) {
34
+ reject(e);
35
+ }
36
+ };
37
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
38
+ step((generator = generator.apply(__this, __arguments)).next());
39
+ });
40
+ };
41
+
42
+ export {
43
+ __spreadValues,
44
+ __spreadProps,
45
+ __async
46
+ };
@@ -0,0 +1,25 @@
1
+ "use client";
2
+ import "../chunk-IV3L3JVM.js";
3
+ import ParaWeb from "@getpara/web-sdk";
4
+ class ParaInternal extends ParaWeb {
5
+ constructor() {
6
+ super(...arguments);
7
+ this.getSupportedCreateAuthMethods = super.getSupportedCreateAuthMethods;
8
+ this.isUsingExternalWallet = super.isUsingExternalWallet;
9
+ this.getTransmissionKeyShares = super.getTransmissionKeyShares;
10
+ this.userSetupAfterLogin = super.userSetupAfterLogin;
11
+ this.setLoginEncryptionKeyPair = super.setLoginEncryptionKeyPair;
12
+ this.getPortalURL = super.getPortalURL;
13
+ this.isProviderModalDisabled = super.isProviderModalDisabled;
14
+ this.supportedAuthMethods = super.supportedAuthMethods;
15
+ this.getUserBiometricLocationHints = super.getUserBiometricLocationHints;
16
+ this.exitLoops = super.exitLoops;
17
+ this.exitLogin = super.exitLogin;
18
+ this.exitAccountCreation = super.exitAccountCreation;
19
+ this.exitOAuth = super.exitOAuth;
20
+ this.exitFarcaster = super.exitFarcaster;
21
+ }
22
+ }
23
+ export {
24
+ ParaInternal
25
+ };
@@ -0,0 +1,2 @@
1
+ "use client";
2
+ export * from "./ParaInternal.js";
@@ -0,0 +1,55 @@
1
+ "use client";
2
+ import "../chunk-IV3L3JVM.js";
3
+ import { jsx, jsxs } from "react/jsx-runtime";
4
+ import { CpslIcon, CpslSpinner, CpslText } from "@getpara/react-components";
5
+ import styled from "styled-components";
6
+ function HeroSpinner({
7
+ icon,
8
+ status = "inactive",
9
+ text
10
+ }) {
11
+ return /* @__PURE__ */ jsxs(Root, { children: [
12
+ /* @__PURE__ */ jsxs(Hero, { children: [
13
+ /* @__PURE__ */ jsx(Spinner, { size: 150, barWidth: 9, variant: status === "loading" ? "default" : status }),
14
+ icon && /* @__PURE__ */ jsx(CpslIcon, { icon, size: "80px" })
15
+ ] }),
16
+ /* @__PURE__ */ jsxs(Text, { status, children: [
17
+ status === "error" && /* @__PURE__ */ jsx(CpslIcon, { icon: "alertCircle", size: "16px", style: { stroke: "currentColor" } }),
18
+ /* @__PURE__ */ jsx(CpslText, { variant: "bodyM", weight: "semiBold", color: status === "error" ? "error" : "primary", children: text })
19
+ ] })
20
+ ] });
21
+ }
22
+ const Root = styled.div`
23
+ height: 276px;
24
+ display: flex;
25
+ flex-direction: column;
26
+ justify-content: center;
27
+ align-items: center;
28
+ gap: 16px;
29
+ `;
30
+ const Hero = styled.div`
31
+ width: 150px;
32
+ height: 150px;
33
+ margin: 16px 0;
34
+ display: flex;
35
+ justify-content: center;
36
+ align-items: center;
37
+ position: relative;
38
+ `;
39
+ const Text = styled.div`
40
+ display: flex;
41
+ gap: 4px;
42
+ align-items: center;
43
+ color: ${({ status }) => status === "error" ? "var(--cpsl-color-utility-red)" : "auto"};
44
+ `;
45
+ const Spinner = styled(CpslSpinner)`
46
+ position: absolute;
47
+ width: 150px;
48
+ height: 150px;
49
+ top: 0;
50
+ left: 0;
51
+ right: 0;
52
+ `;
53
+ export {
54
+ HeroSpinner
55
+ };
@@ -0,0 +1,60 @@
1
+ "use client";
2
+ import "../chunk-IV3L3JVM.js";
3
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
4
+ import { CpslButton, CpslIcon, CpslText } from "@getpara/react-components";
5
+ import styled from "styled-components";
6
+ import { CenteredColumnContainer, FullWidthFilledDisabledInput, CenteredText } from "./common.js";
7
+ import { QRCode } from "./QRCode.js";
8
+ import { getDeviceLogo, getDeviceModelName } from "../utils/index.js";
9
+ import { useCopyToClipboard } from "../hooks/index.js";
10
+ const KnownDevices = ({ hints, link, showCurrentDevice }) => {
11
+ const [isCopied, copy] = useCopyToClipboard();
12
+ const handleCopy = () => {
13
+ copy(link);
14
+ };
15
+ return /* @__PURE__ */ jsxs(Container, { children: [
16
+ /* @__PURE__ */ jsx(CenteredText, { weight: "semiBold", children: "Continue with one of your other known devices" }),
17
+ !!hints.formattedHints.length && /* @__PURE__ */ jsx(DevicesContainer, { children: hints.formattedHints.map(
18
+ (hint) => {
19
+ var _a, _b, _c;
20
+ return (showCurrentDevice && hint.isKnownDevice || !hint.isKnownDevice) && /* @__PURE__ */ jsxs(DeviceListItem, { children: [
21
+ /* @__PURE__ */ jsx(DeviceLogo, { icon: getDeviceLogo(hint.device.vendor, hint.isMobile) }),
22
+ /* @__PURE__ */ jsx(CpslText, { weight: "medium", color: "contrast", children: (_b = (_a = getDeviceModelName(hint.device.model)) != null ? _a : hint.device.vendor) != null ? _b : hint.os.name }),
23
+ (hint.browser || hint.passwordManager) && /* @__PURE__ */ jsxs(Fragment, { children: [
24
+ /* @__PURE__ */ jsx(CpslText, { weight: "medium", color: "secondary", children: "using" }),
25
+ /* @__PURE__ */ jsx(CpslText, { weight: "medium", color: "contrast", children: (_c = hint.passwordManager) != null ? _c : hint.browser.name })
26
+ ] })
27
+ ] }, hint.key);
28
+ }
29
+ ) }),
30
+ hints.hasMobileDevice ? /* @__PURE__ */ jsx(QRCode, { link, icon: "paraIconQr" }) : /* @__PURE__ */ jsxs(CenteredColumnContainer, { children: [
31
+ /* @__PURE__ */ jsx(FullWidthFilledDisabledInput, { noAutoDisable: true, readonly: true, disabled: true, value: link, children: /* @__PURE__ */ jsx(CpslButton, { slot: "end", variant: "ghost", onClick: handleCopy, children: /* @__PURE__ */ jsx(CpslIcon, { icon: isCopied ? "check" : "copy" }) }) }),
32
+ /* @__PURE__ */ jsx(CenteredText, { color: "secondary", variant: "bodyS", weight: "medium", children: "Navigate to this link using your other device" })
33
+ ] })
34
+ ] });
35
+ };
36
+ const Container = styled(CenteredColumnContainer)`
37
+ gap: 16px;
38
+ `;
39
+ const DevicesContainer = styled.div`
40
+ display: flex;
41
+ flex-direction: column;
42
+ gap: 8px;
43
+ background: var(--cpsl-color-background-4);
44
+ padding: 16px;
45
+ width: 100%;
46
+ border-radius: 16px;
47
+ `;
48
+ const DeviceListItem = styled.div`
49
+ display: flex;
50
+ gap: 4px;
51
+ align-items: center;
52
+ `;
53
+ const DeviceLogo = styled(CpslIcon)`
54
+ --icon-color: var(--cpsl-color-text-contrast);
55
+ --height: 16px;
56
+ --width: 16px;
57
+ `;
58
+ export {
59
+ KnownDevices
60
+ };
@@ -0,0 +1,195 @@
1
+ "use client";
2
+ import {
3
+ __async,
4
+ __spreadProps,
5
+ __spreadValues
6
+ } from "../chunk-IV3L3JVM.js";
7
+ import { jsx } from "react/jsx-runtime";
8
+ import { OnRampProvider, OnRampPurchaseStatus } from "@getpara/web-sdk";
9
+ import { lazy, useCallback, useEffect, useMemo, useState } from "react";
10
+ import { getCurrencyCodes, reverseCurrencyLookup, offRampSend } from "../utils/index.js";
11
+ import styled from "styled-components";
12
+ const MOONPAY_PUBLISHABLE_KEY = "pk_live_EQva4LydtNDE0Rwd9X7SG9w58wqOzbux";
13
+ const MOONPAY_PUBLISHABLE_KEY_TEST = "pk_test_HYobzemmTBXxcSStVA4dSED6jT";
14
+ const MoonPayEmbed = ({ para, isDark, isEmbedded, onRampConfig, onRampPurchase, setOnRampPurchase }) => {
15
+ const [LazyMoonPayBuyWidget, setLazyMoonPayBuyWidget] = useState(null);
16
+ const [LazyMoonPaySellWidget, setLazyMoonPaySellWidget] = useState(null);
17
+ const [LazyMoonPayProvider, setLazyMoonPayProvider] = useState(null);
18
+ useEffect(() => {
19
+ const _LazyMoonPayBuyWidget = lazy(
20
+ () => import("@moonpay/moonpay-react").then((mod) => ({ default: mod.MoonPayBuyWidget }))
21
+ );
22
+ const _LazyMoonPaySellWidget = lazy(
23
+ () => import("@moonpay/moonpay-react").then((mod) => ({ default: mod.MoonPaySellWidget }))
24
+ );
25
+ const _LazyMoonPayProvider = lazy(
26
+ () => import("@moonpay/moonpay-react").then((mod) => ({ default: mod.MoonPayProvider }))
27
+ );
28
+ setLazyMoonPayBuyWidget(_LazyMoonPayBuyWidget);
29
+ setLazyMoonPaySellWidget(_LazyMoonPaySellWidget);
30
+ setLazyMoonPayProvider(_LazyMoonPayProvider);
31
+ }, []);
32
+ const apiKey = onRampPurchase.testMode ? MOONPAY_PUBLISHABLE_KEY_TEST : MOONPAY_PUBLISHABLE_KEY;
33
+ const onUrlSignatureRequested = useCallback(
34
+ (url) => __async(void 0, null, function* () {
35
+ if (!para.getUserId() || !onRampPurchase.walletType) {
36
+ throw new Error("missing required fields");
37
+ }
38
+ const res = yield para.ctx.client.signMoonPayUrl(para.getUserId(), {
39
+ url,
40
+ type: onRampPurchase.walletType,
41
+ cosmosPrefix: para.cosmosPrefix,
42
+ testMode: onRampPurchase.testMode,
43
+ walletId: onRampPurchase.walletId || void 0,
44
+ externalWalletAddress: onRampPurchase.externalWalletAddress || void 0
45
+ });
46
+ return res.data.signature;
47
+ }),
48
+ [onRampPurchase.walletId, onRampPurchase.walletType, para.cosmosPrefix, onRampPurchase.testMode, para]
49
+ );
50
+ const { currencyCodes, defaultCurrencyCode } = useMemo(
51
+ () => getCurrencyCodes(onRampConfig, {
52
+ provider: OnRampProvider.MOONPAY,
53
+ walletType: onRampPurchase.walletType,
54
+ purchaseType: onRampPurchase.type
55
+ }),
56
+ [onRampPurchase.walletType, onRampPurchase.type, onRampConfig.assetInfo, onRampConfig == null ? void 0 : onRampConfig.allowedAssets]
57
+ );
58
+ const onTransactionCompleted = useCallback(
59
+ (payload) => __async(void 0, null, function* () {
60
+ try {
61
+ const [network, asset] = reverseCurrencyLookup(
62
+ onRampConfig.assetInfo,
63
+ OnRampProvider.MOONPAY,
64
+ payload.quoteCurrency.code
65
+ );
66
+ const updated = yield para.ctx.client.updateOnRampPurchase({
67
+ userId: para.getUserId(),
68
+ walletId: onRampPurchase.walletId,
69
+ purchaseId: onRampPurchase.id,
70
+ externalWalletAddress: onRampPurchase.externalWalletAddress,
71
+ updates: {
72
+ fiatQuantity: payload.baseCurrencyAmount.toString(),
73
+ fiat: payload.baseCurrency.code,
74
+ network,
75
+ asset,
76
+ assetQuantity: payload.quoteCurrencyAmount.toString(),
77
+ status: OnRampPurchaseStatus.FINISHED
78
+ }
79
+ });
80
+ setOnRampPurchase(updated);
81
+ if (!isEmbedded) {
82
+ setTimeout(() => {
83
+ if (typeof window !== "undefined") {
84
+ window.close();
85
+ }
86
+ }, 5e3);
87
+ }
88
+ } catch (e) {
89
+ console.error(e);
90
+ }
91
+ }),
92
+ [onRampPurchase.walletId, onRampPurchase.id, onRampPurchase.externalWalletAddress, isEmbedded]
93
+ );
94
+ const onInitiateDeposit = useCallback(
95
+ (payload) => __async(void 0, null, function* () {
96
+ const txHash = yield offRampSend(para, onRampPurchase, setOnRampPurchase, {
97
+ assetQuantity: payload.cryptoCurrencyAmount,
98
+ fiatQuantity: payload.fiatCurrencyAmount || void 0,
99
+ fiat: payload.fiatCurrency.code.toUpperCase(),
100
+ destinationAddress: payload.depositWalletAddress,
101
+ contractAddress: payload.cryptoCurrency.contractAddress,
102
+ chainId: payload.cryptoCurrency.chainId
103
+ });
104
+ return { depositId: txHash, cancelTransactionOnError: false };
105
+ }),
106
+ [
107
+ para,
108
+ onRampPurchase.id,
109
+ onRampPurchase.testMode,
110
+ onRampPurchase.walletId,
111
+ onRampPurchase.walletType,
112
+ setOnRampPurchase
113
+ ]
114
+ );
115
+ const embed = useMemo(() => {
116
+ if (!LazyMoonPayBuyWidget || !LazyMoonPaySellWidget) {
117
+ return null;
118
+ }
119
+ const walletAddresses = currencyCodes.reduce((acc, code) => {
120
+ return __spreadProps(__spreadValues({}, acc), { [code.toLowerCase()]: onRampPurchase.address });
121
+ }, {});
122
+ return onRampPurchase.type === "BUY" ? /* @__PURE__ */ jsx(
123
+ LazyMoonPayBuyWidget,
124
+ {
125
+ variant: "embedded",
126
+ baseCurrencyCode: onRampPurchase.fiat,
127
+ baseCurrencyAmount: onRampPurchase.fiatQuantity,
128
+ showOnlyCurrencies: currencyCodes.join(","),
129
+ defaultCurrencyCode,
130
+ walletAddresses: JSON.stringify(walletAddresses),
131
+ visible: true,
132
+ theme: isDark ? "dark" : "light",
133
+ style: {
134
+ height: "100%",
135
+ width: "100%",
136
+ border: "none",
137
+ borderRadius: 0,
138
+ margin: 0
139
+ },
140
+ onTransactionCompleted,
141
+ onUrlSignatureRequested
142
+ }
143
+ ) : /* @__PURE__ */ jsx(
144
+ LazyMoonPaySellWidget,
145
+ {
146
+ variant: "embedded",
147
+ refundWalletAddresses: JSON.stringify(walletAddresses),
148
+ visible: true,
149
+ theme: isDark ? "dark" : "light",
150
+ style: {
151
+ height: "100%",
152
+ width: "100%",
153
+ border: "none",
154
+ borderRadius: 0,
155
+ margin: 0
156
+ },
157
+ showOnlyCurrencies: currencyCodes.join(","),
158
+ defaultCurrencyCode: currencyCodes[0],
159
+ onInitiateDeposit,
160
+ onTransactionCompleted,
161
+ onUrlSignatureRequested
162
+ }
163
+ );
164
+ }, [
165
+ onRampPurchase.type,
166
+ onRampPurchase.address,
167
+ onRampPurchase.walletId,
168
+ onRampPurchase.walletType,
169
+ defaultCurrencyCode,
170
+ currencyCodes,
171
+ onInitiateDeposit,
172
+ onTransactionCompleted,
173
+ onUrlSignatureRequested,
174
+ isDark,
175
+ LazyMoonPayBuyWidget,
176
+ LazyMoonPaySellWidget
177
+ ]);
178
+ if (!LazyMoonPayProvider) {
179
+ return null;
180
+ }
181
+ return /* @__PURE__ */ jsx(Container, { isEmbedded, children: /* @__PURE__ */ jsx(LazyMoonPayProvider, { apiKey, debug: onRampPurchase.testMode, children: embed }) });
182
+ };
183
+ var MoonPayEmbed_default = MoonPayEmbed;
184
+ const Container = styled.div`
185
+ width: ${({ isEmbedded }) => isEmbedded ? "100%" : "100vw"};
186
+ height: ${({ isEmbedded }) => isEmbedded ? "640px" : "100vh"};
187
+
188
+ iframe {
189
+ border: 0 !important;
190
+ }
191
+ `;
192
+ export {
193
+ MoonPayEmbed,
194
+ MoonPayEmbed_default as default
195
+ };
@@ -0,0 +1,80 @@
1
+ "use client";
2
+ import "../chunk-IV3L3JVM.js";
3
+ import { jsx, jsxs } from "react/jsx-runtime";
4
+ import { CpslButton, CpslIcon, CpslQrCode, CpslSpinner, CpslText } from "@getpara/react-components";
5
+ import styled from "styled-components";
6
+ import { useCopyToClipboard } from "../hooks/index.js";
7
+ import { isMobile } from "@getpara/web-sdk";
8
+ const QRCode = ({ link, imageSrc, icon, qrSize = 202, spinnerSize = 60 }) => {
9
+ const [isCopied, copy] = useCopyToClipboard();
10
+ const isMobileScreen = isMobile();
11
+ const handleCopy = () => {
12
+ copy(link);
13
+ };
14
+ return /* @__PURE__ */ jsxs(QRContainer, { $isMobile: isMobileScreen, children: [
15
+ isMobileScreen && /* @__PURE__ */ jsxs(MobileCopyButton, { fullWidth: true, onClick: handleCopy, children: [
16
+ /* @__PURE__ */ jsx(CopyIcon, { slot: "start", icon: isCopied ? "check" : "copy" }),
17
+ /* @__PURE__ */ jsx(CpslText, { variant: "bodyS", children: isCopied ? "Copied" : "Copy Link Instead" })
18
+ ] }),
19
+ !link ? /* @__PURE__ */ jsx(LoadingContainer, { $size: qrSize, children: /* @__PURE__ */ jsx(CpslSpinner, { size: spinnerSize }) }) : /* @__PURE__ */ jsx(StyledQRCode, { url: link, size: qrSize, icon, imageSrc }),
20
+ !isMobileScreen && /* @__PURE__ */ jsxs(CopyButton, { size: "small", onClick: handleCopy, children: [
21
+ /* @__PURE__ */ jsx(CopyIcon, { slot: "start", icon: isCopied ? "check" : "copy" }),
22
+ /* @__PURE__ */ jsx(CpslText, { variant: "body2XS", children: isCopied ? "Copied" : "Copy Link Instead" })
23
+ ] })
24
+ ] });
25
+ };
26
+ const QRContainer = styled.div`
27
+ display: flex;
28
+ flex-direction: column;
29
+ justify-content: center;
30
+ align-items: center;
31
+ border: 1px solid;
32
+ border-color: var(--cpsl-color-background-16);
33
+ border-radius: 16px;
34
+ background-color: white;
35
+ overflow: hidden;
36
+ padding-bottom: ${({ $isMobile }) => $isMobile ? "0px" : "16px"};
37
+ padding-top: ${({ $isMobile }) => $isMobile ? "16px" : "0px"};
38
+ `;
39
+ const StyledQRCode = styled(CpslQrCode)`
40
+ --qr-box-shadow: none;
41
+ --qr-border-radius: 0px;
42
+ `;
43
+ const CopyButton = styled(CpslButton)`
44
+ --button-primary-color: var(--cpsl-color-text-contrast);
45
+ --button-primary-background-color: var(--cpsl-color-background-4);
46
+
47
+ --button-primary-hover-color: var(--cpsl-color-text-contrast);
48
+ --button-primary-hover-background-color: var(--cpsl-color-background-16);
49
+
50
+ --button-primary-active-color: var(--cpsl-color-text-contrast);
51
+ --button-primary-active-background-color: var(--cpsl-color-background-4);
52
+
53
+ --button-padding-start: 8px;
54
+ --button-padding-end: 8px;
55
+ --button-padding-top: 2px;
56
+ --button-padding-bottom: 2px;
57
+
58
+ --button-border-radius: 1000px;
59
+ `;
60
+ const MobileCopyButton = styled(CopyButton)`
61
+ --button-padding-top: 4px;
62
+ --button-padding-bottom: 4px;
63
+
64
+ padding: 0px 12px;
65
+ `;
66
+ const CopyIcon = styled(CpslIcon)`
67
+ --width: 16px;
68
+ --height: 16px;
69
+ --icon-color: var(--cpsl-color-text-contrast);
70
+ `;
71
+ const LoadingContainer = styled.div`
72
+ display: flex;
73
+ justify-content: center;
74
+ align-items: center;
75
+ height: ${({ $size }) => `${$size}px`};
76
+ width: ${({ $size }) => `${$size}px`};
77
+ `;
78
+ export {
79
+ QRCode
80
+ };
@@ -0,0 +1,103 @@
1
+ "use client";
2
+ import {
3
+ __async
4
+ } from "../chunk-IV3L3JVM.js";
5
+ import { jsx } from "react/jsx-runtime";
6
+ import { useEffect, useRef } from "react";
7
+ import { RampInstantSDK } from "@ramp-network/ramp-instant-sdk";
8
+ import { Network, OnRampAsset, OnRampProvider, getPortalBaseURL } from "@getpara/web-sdk";
9
+ import {
10
+ getChainId,
11
+ getContractAddressFromAsset,
12
+ getCurrencyCodes,
13
+ reverseCurrencyLookup,
14
+ offRampSend
15
+ } from "../utils/index.js";
16
+ const TEST_MODE_FORBIDDEN = ["ETH_ETH", "ETH_USDC"];
17
+ const RampEmbed = ({
18
+ para,
19
+ appName,
20
+ onRampConfig,
21
+ onRampPurchase,
22
+ isEmbedded,
23
+ apiKey,
24
+ onClose,
25
+ setOnRampPurchase
26
+ }) => {
27
+ const { currencyCodes } = getCurrencyCodes(onRampConfig, {
28
+ provider: OnRampProvider.RAMP,
29
+ purchaseType: onRampPurchase.type,
30
+ walletType: onRampPurchase.walletType
31
+ });
32
+ const isMounted = useRef(false);
33
+ useEffect(() => {
34
+ if (!isMounted.current) {
35
+ try {
36
+ const widget = new RampInstantSDK({
37
+ hostAppName: appName,
38
+ swapAsset: currencyCodes.filter((code) => !onRampPurchase.testMode || !TEST_MODE_FORBIDDEN.includes(code)).join(","),
39
+ fiatValue: onRampPurchase.fiatQuantity,
40
+ fiatCurrency: onRampPurchase.fiat,
41
+ hostLogoUrl: `${getPortalBaseURL(para.ctx)}/wordmark_black.svg`,
42
+ hostApiKey: apiKey,
43
+ userAddress: onRampPurchase.address,
44
+ userEmailAddress: para.getEmail(),
45
+ url: (onRampPurchase == null ? void 0 : onRampPurchase.testMode) ? "https://app.demo.ramp.network" : "https://app.ramp.network",
46
+ enabledFlows: [onRampPurchase.type === "BUY" ? "ONRAMP" : "OFFRAMP"],
47
+ useSendCryptoCallback: true,
48
+ variant: "embedded-mobile",
49
+ containerNode: document.getElementById("ramp-container")
50
+ }).on("PURCHASE_CREATED", (e) => __async(void 0, null, function* () {
51
+ const p = e.payload.purchase;
52
+ const [network, asset] = onRampPurchase.testMode ? [Network.ETHEREUM, OnRampAsset.ETHEREUM] : reverseCurrencyLookup(onRampConfig.assetInfo, OnRampProvider.RAMP, p.asset.symbol) || [];
53
+ const updated = yield para.ctx.client.updateOnRampPurchase({
54
+ userId: para.getUserId(),
55
+ walletId: onRampPurchase.walletId,
56
+ externalWalletAddress: onRampPurchase.externalWalletAddress,
57
+ purchaseId: onRampPurchase.id,
58
+ updates: {
59
+ providerKey: p.id,
60
+ fiatQuantity: p.fiatValue,
61
+ fiat: p.fiatCurrency,
62
+ assetQuantity: p.cryptoAmount,
63
+ asset,
64
+ network
65
+ }
66
+ });
67
+ setOnRampPurchase(updated);
68
+ })).on("WIDGET_CLOSE", () => __async(void 0, null, function* () {
69
+ onClose == null ? void 0 : onClose();
70
+ if (!isEmbedded) {
71
+ setTimeout(() => {
72
+ if (typeof window !== "undefined") {
73
+ window.close();
74
+ }
75
+ }, 5e3);
76
+ }
77
+ })).onSendCrypto((assetInfo, amount, address) => __async(void 0, null, function* () {
78
+ try {
79
+ const [network, asset] = reverseCurrencyLookup(onRampConfig.assetInfo, OnRampProvider.RAMP, assetInfo.symbol);
80
+ const txHash = yield offRampSend(para, onRampPurchase, setOnRampPurchase, {
81
+ assetQuantity: amount,
82
+ destinationAddress: address,
83
+ contractAddress: getContractAddressFromAsset(network, asset),
84
+ chainId: getChainId(network),
85
+ testMode: onRampPurchase.testMode
86
+ });
87
+ return { txHash };
88
+ } catch (e) {
89
+ console.error(e);
90
+ }
91
+ }));
92
+ widget.show();
93
+ isMounted.current = true;
94
+ } catch (e) {
95
+ console.error(e);
96
+ }
97
+ }
98
+ }, []);
99
+ return /* @__PURE__ */ jsx("div", { id: "ramp-container", style: { minWidth: "320px", width: "100%", height: "767px" } });
100
+ };
101
+ export {
102
+ RampEmbed
103
+ };