@getpara/react-common 2.0.0-alpha.3 → 2.0.0-alpha.6
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/chunk-GOCCUU3Z.js +42 -0
- package/dist/classes/ParaInternal.d.ts +1 -1
- package/dist/classes/ParaInternal.js +22 -0
- package/dist/classes/index.js +2 -0
- package/dist/components/HeroSpinner.js +55 -0
- package/dist/components/KnownDevices.js +60 -0
- package/dist/components/MoonPayEmbed.js +184 -0
- package/dist/components/NetworkSpeedBanner.d.ts +5 -0
- package/dist/components/NetworkSpeedBanner.js +80 -0
- package/dist/components/QRCode.js +80 -0
- package/dist/components/RampEmbed.js +103 -0
- package/dist/components/StripeEmbed.d.ts +1 -1
- package/dist/components/StripeEmbed.js +138 -0
- package/dist/components/UserIdentifier.js +66 -0
- package/dist/components/common.d.ts +3 -3
- package/dist/components/common.js +54 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +10 -0
- package/dist/constants/aaguiMetadata.js +145 -0
- package/dist/hooks/index.js +2 -0
- package/dist/hooks/useCopyToClipboard.js +36 -0
- package/dist/index.js +5 -1279
- package/dist/package.json +6 -0
- package/dist/types/externalWalletCommon.d.ts +4 -2
- package/dist/types/externalWalletCommon.js +32 -0
- package/dist/types/index.js +2 -0
- package/dist/utils/formatBiometricHints.js +51 -0
- package/dist/utils/getBrowserName.js +7 -0
- package/dist/utils/getDeviceLogo.js +36 -0
- package/dist/utils/getDeviceModelName.js +21 -0
- package/dist/utils/getExternalWalletDisplayName.d.ts +2 -5
- package/dist/utils/getExternalWalletDisplayName.js +22 -0
- package/dist/utils/index.d.ts +7 -2
- package/dist/utils/index.js +124 -0
- package/dist/utils/offRampSend.js +75 -0
- package/package.json +4 -4
- package/dist/index.js.br +0 -0
- package/dist/index.js.gz +0 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
6
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
+
var __spreadValues = (a, b) => {
|
|
8
|
+
for (var prop in b || (b = {}))
|
|
9
|
+
if (__hasOwnProp.call(b, prop))
|
|
10
|
+
__defNormalProp(a, prop, b[prop]);
|
|
11
|
+
if (__getOwnPropSymbols)
|
|
12
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
13
|
+
if (__propIsEnum.call(b, prop))
|
|
14
|
+
__defNormalProp(a, prop, b[prop]);
|
|
15
|
+
}
|
|
16
|
+
return a;
|
|
17
|
+
};
|
|
18
|
+
var __async = (__this, __arguments, generator) => {
|
|
19
|
+
return new Promise((resolve, reject) => {
|
|
20
|
+
var fulfilled = (value) => {
|
|
21
|
+
try {
|
|
22
|
+
step(generator.next(value));
|
|
23
|
+
} catch (e) {
|
|
24
|
+
reject(e);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
var rejected = (value) => {
|
|
28
|
+
try {
|
|
29
|
+
step(generator.throw(value));
|
|
30
|
+
} catch (e) {
|
|
31
|
+
reject(e);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
35
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export {
|
|
40
|
+
__spreadValues,
|
|
41
|
+
__async
|
|
42
|
+
};
|
|
@@ -20,6 +20,6 @@ export declare class ParaInternal extends ParaWeb {
|
|
|
20
20
|
constructPortalUrl: (type: import("@getpara/core-sdk/dist/types/types").PortalUrlType, opts?: import("@getpara/core-sdk/dist/types/types").PortalUrlOptions) => Promise<string>;
|
|
21
21
|
getNewCredentialAndUrl: ({ authMethod, isForNewDevice, portalTheme, shorten, }?: import("@getpara/core-sdk/dist/types/types").NewCredentialUrlParams) => Promise<{
|
|
22
22
|
credentialId: string;
|
|
23
|
-
url
|
|
23
|
+
url?: string;
|
|
24
24
|
}>;
|
|
25
25
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import "../chunk-GOCCUU3Z.js";
|
|
3
|
+
import ParaWeb from "@getpara/web-sdk";
|
|
4
|
+
class ParaInternal extends ParaWeb {
|
|
5
|
+
constructor() {
|
|
6
|
+
super(...arguments);
|
|
7
|
+
this.setupAfterLogin = super.setupAfterLogin;
|
|
8
|
+
this.getSupportedCreateAuthMethods = super.getSupportedCreateAuthMethods;
|
|
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.setAuth = super.setAuth;
|
|
15
|
+
this.supportedAuthMethods = super.supportedAuthMethods;
|
|
16
|
+
this.constructPortalUrl = super.constructPortalUrl;
|
|
17
|
+
this.getNewCredentialAndUrl = super.getNewCredentialAndUrl;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
ParaInternal
|
|
22
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import "../chunk-GOCCUU3Z.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-GOCCUU3Z.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,184 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
__async
|
|
4
|
+
} from "../chunk-GOCCUU3Z.js";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
import { getNetworkPrefix, OnRampProvider, OnRampPurchaseStatus } from "@getpara/web-sdk";
|
|
7
|
+
import { lazy, useCallback, useEffect, useMemo, useState } from "react";
|
|
8
|
+
import { reverseCurrencyLookup, offRampSend, getCurrencyCode } from "../utils/index.js";
|
|
9
|
+
import styled from "styled-components";
|
|
10
|
+
const MOONPAY_PUBLISHABLE_KEY = "pk_live_EQva4LydtNDE0Rwd9X7SG9w58wqOzbux";
|
|
11
|
+
const MOONPAY_PUBLISHABLE_KEY_TEST = "pk_test_HYobzemmTBXxcSStVA4dSED6jT";
|
|
12
|
+
const MoonPayEmbed = ({ para, isDark, isEmbedded, onRampConfig, onRampPurchase, setOnRampPurchase }) => {
|
|
13
|
+
const [LazyMoonPayBuyWidget, setLazyMoonPayBuyWidget] = useState(null);
|
|
14
|
+
const [LazyMoonPaySellWidget, setLazyMoonPaySellWidget] = useState(null);
|
|
15
|
+
const [LazyMoonPayProvider, setLazyMoonPayProvider] = useState(null);
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
const _LazyMoonPayBuyWidget = lazy(
|
|
18
|
+
() => import("@moonpay/moonpay-react").then((mod) => ({ default: mod.MoonPayBuyWidget }))
|
|
19
|
+
);
|
|
20
|
+
const _LazyMoonPaySellWidget = lazy(
|
|
21
|
+
() => import("@moonpay/moonpay-react").then((mod) => ({ default: mod.MoonPaySellWidget }))
|
|
22
|
+
);
|
|
23
|
+
const _LazyMoonPayProvider = lazy(
|
|
24
|
+
() => import("@moonpay/moonpay-react").then((mod) => ({ default: mod.MoonPayProvider }))
|
|
25
|
+
);
|
|
26
|
+
setLazyMoonPayBuyWidget(_LazyMoonPayBuyWidget);
|
|
27
|
+
setLazyMoonPaySellWidget(_LazyMoonPaySellWidget);
|
|
28
|
+
setLazyMoonPayProvider(_LazyMoonPayProvider);
|
|
29
|
+
}, []);
|
|
30
|
+
const apiKey = onRampPurchase.testMode ? MOONPAY_PUBLISHABLE_KEY_TEST : MOONPAY_PUBLISHABLE_KEY;
|
|
31
|
+
const onUrlSignatureRequested = useCallback(
|
|
32
|
+
(url) => __async(void 0, null, function* () {
|
|
33
|
+
if (!para.getUserId() || !onRampPurchase.walletType) {
|
|
34
|
+
throw new Error("missing required fields");
|
|
35
|
+
}
|
|
36
|
+
const res = yield para.ctx.client.signMoonPayUrl(para.getUserId(), {
|
|
37
|
+
url,
|
|
38
|
+
type: onRampPurchase.walletType,
|
|
39
|
+
cosmosPrefix: getNetworkPrefix(onRampPurchase.network),
|
|
40
|
+
testMode: onRampPurchase.testMode,
|
|
41
|
+
walletId: onRampPurchase.walletId || void 0,
|
|
42
|
+
externalWalletAddress: onRampPurchase.externalWalletAddress || void 0
|
|
43
|
+
});
|
|
44
|
+
return res.data.signature;
|
|
45
|
+
}),
|
|
46
|
+
[onRampPurchase.walletId, onRampPurchase.walletType, para.cosmosPrefix, onRampPurchase.testMode, para]
|
|
47
|
+
);
|
|
48
|
+
const onTransactionCompleted = useCallback(
|
|
49
|
+
(payload) => __async(void 0, null, function* () {
|
|
50
|
+
try {
|
|
51
|
+
const [network, asset] = reverseCurrencyLookup(
|
|
52
|
+
onRampConfig.assetInfo,
|
|
53
|
+
OnRampProvider.MOONPAY,
|
|
54
|
+
payload.quoteCurrency.code
|
|
55
|
+
);
|
|
56
|
+
const updated = yield para.ctx.client.updateOnRampPurchase({
|
|
57
|
+
userId: para.getUserId(),
|
|
58
|
+
walletId: onRampPurchase.walletId,
|
|
59
|
+
purchaseId: onRampPurchase.id,
|
|
60
|
+
externalWalletAddress: onRampPurchase.externalWalletAddress,
|
|
61
|
+
updates: {
|
|
62
|
+
fiatQuantity: payload.baseCurrencyAmount.toString(),
|
|
63
|
+
fiat: payload.baseCurrency.code,
|
|
64
|
+
network,
|
|
65
|
+
asset,
|
|
66
|
+
assetQuantity: payload.quoteCurrencyAmount.toString(),
|
|
67
|
+
status: OnRampPurchaseStatus.FINISHED
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
setOnRampPurchase(updated);
|
|
71
|
+
if (!isEmbedded) {
|
|
72
|
+
setTimeout(() => {
|
|
73
|
+
if (typeof window !== "undefined") {
|
|
74
|
+
window.close();
|
|
75
|
+
}
|
|
76
|
+
}, 5e3);
|
|
77
|
+
}
|
|
78
|
+
} catch (e) {
|
|
79
|
+
console.error(e);
|
|
80
|
+
}
|
|
81
|
+
}),
|
|
82
|
+
[onRampPurchase.walletId, onRampPurchase.id, onRampPurchase.externalWalletAddress, isEmbedded]
|
|
83
|
+
);
|
|
84
|
+
const onInitiateDeposit = useCallback(
|
|
85
|
+
(payload) => __async(void 0, null, function* () {
|
|
86
|
+
const txHash = yield offRampSend(para, onRampPurchase, setOnRampPurchase, {
|
|
87
|
+
assetQuantity: payload.cryptoCurrencyAmount,
|
|
88
|
+
fiatQuantity: payload.fiatCurrencyAmount || void 0,
|
|
89
|
+
fiat: payload.fiatCurrency.code.toUpperCase(),
|
|
90
|
+
destinationAddress: payload.depositWalletAddress,
|
|
91
|
+
contractAddress: payload.cryptoCurrency.contractAddress,
|
|
92
|
+
chainId: payload.cryptoCurrency.chainId
|
|
93
|
+
});
|
|
94
|
+
return { depositId: txHash, cancelTransactionOnError: false };
|
|
95
|
+
}),
|
|
96
|
+
[
|
|
97
|
+
para,
|
|
98
|
+
onRampPurchase.id,
|
|
99
|
+
onRampPurchase.testMode,
|
|
100
|
+
onRampPurchase.walletId,
|
|
101
|
+
onRampPurchase.walletType,
|
|
102
|
+
setOnRampPurchase
|
|
103
|
+
]
|
|
104
|
+
);
|
|
105
|
+
const embed = useMemo(() => {
|
|
106
|
+
if (!LazyMoonPayBuyWidget || !LazyMoonPaySellWidget) {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
const currencyCode = getCurrencyCode(onRampConfig, {
|
|
110
|
+
network: onRampPurchase.network,
|
|
111
|
+
asset: onRampPurchase.asset,
|
|
112
|
+
provider: OnRampProvider.MOONPAY
|
|
113
|
+
});
|
|
114
|
+
return onRampPurchase.type === "BUY" ? /* @__PURE__ */ jsx(
|
|
115
|
+
LazyMoonPayBuyWidget,
|
|
116
|
+
{
|
|
117
|
+
variant: "embedded",
|
|
118
|
+
baseCurrencyCode: onRampPurchase.fiat,
|
|
119
|
+
baseCurrencyAmount: onRampPurchase.fiatQuantity,
|
|
120
|
+
currencyCode,
|
|
121
|
+
walletAddress: onRampPurchase.address,
|
|
122
|
+
visible: true,
|
|
123
|
+
theme: isDark ? "dark" : "light",
|
|
124
|
+
style: {
|
|
125
|
+
height: "100%",
|
|
126
|
+
width: "100%",
|
|
127
|
+
border: "none",
|
|
128
|
+
borderRadius: 0,
|
|
129
|
+
margin: 0
|
|
130
|
+
},
|
|
131
|
+
onTransactionCompleted,
|
|
132
|
+
onUrlSignatureRequested
|
|
133
|
+
}
|
|
134
|
+
) : /* @__PURE__ */ jsx(
|
|
135
|
+
LazyMoonPaySellWidget,
|
|
136
|
+
{
|
|
137
|
+
variant: "embedded",
|
|
138
|
+
visible: true,
|
|
139
|
+
theme: isDark ? "dark" : "light",
|
|
140
|
+
style: {
|
|
141
|
+
height: "100%",
|
|
142
|
+
width: "100%",
|
|
143
|
+
border: "none",
|
|
144
|
+
borderRadius: 0,
|
|
145
|
+
margin: 0
|
|
146
|
+
},
|
|
147
|
+
baseCurrencyCode: currencyCode,
|
|
148
|
+
refundWalletAddress: onRampPurchase.address,
|
|
149
|
+
onInitiateDeposit,
|
|
150
|
+
onTransactionCompleted,
|
|
151
|
+
onUrlSignatureRequested
|
|
152
|
+
}
|
|
153
|
+
);
|
|
154
|
+
}, [
|
|
155
|
+
onRampPurchase.type,
|
|
156
|
+
onRampPurchase.address,
|
|
157
|
+
onRampPurchase.walletId,
|
|
158
|
+
onRampPurchase.walletType,
|
|
159
|
+
onRampPurchase.asset,
|
|
160
|
+
onInitiateDeposit,
|
|
161
|
+
onTransactionCompleted,
|
|
162
|
+
onUrlSignatureRequested,
|
|
163
|
+
isDark,
|
|
164
|
+
LazyMoonPayBuyWidget,
|
|
165
|
+
LazyMoonPaySellWidget
|
|
166
|
+
]);
|
|
167
|
+
if (!LazyMoonPayProvider) {
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
return /* @__PURE__ */ jsx(Container, { isEmbedded, children: /* @__PURE__ */ jsx(LazyMoonPayProvider, { apiKey, debug: onRampPurchase.testMode, children: embed }) });
|
|
171
|
+
};
|
|
172
|
+
var MoonPayEmbed_default = MoonPayEmbed;
|
|
173
|
+
const Container = styled.div`
|
|
174
|
+
width: ${({ isEmbedded }) => isEmbedded ? "100%" : "100vw"};
|
|
175
|
+
height: ${({ isEmbedded }) => isEmbedded ? "640px" : "100vh"};
|
|
176
|
+
|
|
177
|
+
iframe {
|
|
178
|
+
border: 0 !important;
|
|
179
|
+
}
|
|
180
|
+
`;
|
|
181
|
+
export {
|
|
182
|
+
MoonPayEmbed,
|
|
183
|
+
MoonPayEmbed_default as default
|
|
184
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import "../chunk-GOCCUU3Z.js";
|
|
3
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
import { useEffect, useState } from "react";
|
|
5
|
+
import styled from "styled-components";
|
|
6
|
+
import { CpslIcon } from "@getpara/react-components";
|
|
7
|
+
const BannerContainerWrapper = styled.div`
|
|
8
|
+
display: flex;
|
|
9
|
+
justify-content: center;
|
|
10
|
+
align-items: center;
|
|
11
|
+
width: 100%;
|
|
12
|
+
background-color: transparent;
|
|
13
|
+
`;
|
|
14
|
+
const BannerContainer = styled.div`
|
|
15
|
+
display: flex;
|
|
16
|
+
justify-content: center;
|
|
17
|
+
align-items: center;
|
|
18
|
+
max-width: ${({ $maxWidth }) => $maxWidth || "100%"};
|
|
19
|
+
box-sizing: border-box;
|
|
20
|
+
padding: 6px;
|
|
21
|
+
border-radius: 12px;
|
|
22
|
+
background-color: transparent;
|
|
23
|
+
position: relative;
|
|
24
|
+
z-index: 10;
|
|
25
|
+
display: inline-flex;
|
|
26
|
+
white-space: nowrap;
|
|
27
|
+
text-overflow: ellipsis;
|
|
28
|
+
overflow: hidden;
|
|
29
|
+
`;
|
|
30
|
+
const WarningIcon = styled(CpslIcon)`
|
|
31
|
+
--icon-color: #fbbc04;
|
|
32
|
+
--width: ${({ $size }) => $size || "24px"};
|
|
33
|
+
--height: ${({ $size }) => $size || "24px"};
|
|
34
|
+
margin-right: 6px;
|
|
35
|
+
flex-shrink: 0;
|
|
36
|
+
`;
|
|
37
|
+
const BannerText = styled.span`
|
|
38
|
+
font-family: var(--cpsl-default-font);
|
|
39
|
+
font-weight: 500;
|
|
40
|
+
font-size: ${({ $fontSize }) => $fontSize || "14px"};
|
|
41
|
+
color: var(--cpsl-color-black);
|
|
42
|
+
flex: 1;
|
|
43
|
+
`;
|
|
44
|
+
const NetworkSpeedBanner = ({
|
|
45
|
+
fontSize,
|
|
46
|
+
iconSize,
|
|
47
|
+
maxWidth
|
|
48
|
+
}) => {
|
|
49
|
+
const [isSlowNetwork, setIsSlowNetwork] = useState(false);
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
var _a;
|
|
52
|
+
const connection = navigator == null ? void 0 : navigator.connection;
|
|
53
|
+
const checkNetworkSpeed = () => {
|
|
54
|
+
if (connection) {
|
|
55
|
+
const isSlow = connection.effectiveType === "2g" || connection.effectiveType === "slow-2g" || connection.downlink && connection.downlink < 0.5;
|
|
56
|
+
setIsSlowNetwork(isSlow);
|
|
57
|
+
} else {
|
|
58
|
+
setIsSlowNetwork(false);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
checkNetworkSpeed();
|
|
62
|
+
(_a = connection == null ? void 0 : connection.addEventListener) == null ? void 0 : _a.call(connection, "change", checkNetworkSpeed);
|
|
63
|
+
const intervalId = setInterval(checkNetworkSpeed, 15e3);
|
|
64
|
+
return () => {
|
|
65
|
+
var _a2;
|
|
66
|
+
clearInterval(intervalId);
|
|
67
|
+
(_a2 = connection == null ? void 0 : connection.removeEventListener) == null ? void 0 : _a2.call(connection, "change", checkNetworkSpeed);
|
|
68
|
+
};
|
|
69
|
+
}, []);
|
|
70
|
+
if (!isSlowNetwork) {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
return /* @__PURE__ */ jsx(BannerContainerWrapper, { children: /* @__PURE__ */ jsxs(BannerContainer, { $maxWidth: maxWidth, children: [
|
|
74
|
+
/* @__PURE__ */ jsx(WarningIcon, { $size: iconSize, icon: "alertTriangle" }),
|
|
75
|
+
/* @__PURE__ */ jsx(BannerText, { $fontSize: fontSize, children: "Your network is slow. This may impact your experience." })
|
|
76
|
+
] }) });
|
|
77
|
+
};
|
|
78
|
+
export {
|
|
79
|
+
NetworkSpeedBanner
|
|
80
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import "../chunk-GOCCUU3Z.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-GOCCUU3Z.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
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Props } from '../types/index.js';
|
|
2
2
|
export declare const STRIPE_PUBLISHABLE_KEY = "pk_live_51MvquNGrzDeP5yP9EgVSMBPQbrbg0oHDjPIIXypePd0jzOFjbadyfO7wBKLHhUtbKIUiEUVC3YYcTJyAmJ8xA7JE00T2UDfYKz";
|
|
3
|
-
export declare const STRIPE_PUBLISHABLE_KEY_TEST = "
|
|
3
|
+
export declare const STRIPE_PUBLISHABLE_KEY_TEST = "pk_test_51MvquNGrzDeP5yP98WgPaAUgQ50I3OpfPhVfiLO47FBHepJnZRPO62IzZY2uxT5ovhSS10RwcTcnaVil1mcJOzIi00dHapODdS";
|
|
4
4
|
export declare const StripeEmbed: ({ para, isDark, isEmbedded, onRampPurchase, setOnRampPurchase }: Props) => import("react/jsx-runtime").JSX.Element;
|